Fix build issue on x86.
[glibc.git] / manual / libm-err-tab.pl
blob75f5e5b7b7219c3358e632517a11ef84a7a2a8c9
1 #!/usr/bin/perl -w
2 # Copyright (C) 1999-2017 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Andreas Jaeger <aj@suse.de>, 1999.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
20 # Information about tests are stored in: %results
21 # $results{$test}{"type"} is the result type, e.g. normal or complex.
22 # In the following description $platform, $type and $float are:
23 # - $platform is the used platform
24 # - $type is either "normal", "real" (for the real part of a complex number)
25 # or "imag" (for the imaginary part # of a complex number).
26 # - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
27 # It represents the underlying floating point type (float, double or long
28 # double) and if inline functions (the leading i stands for inline)
29 # are used.
30 # $results{$test}{$platform}{$type}{$float} is defined and has a delta
31 # or 'fail' as value.
33 use File::Find;
35 use strict;
37 use vars qw ($sources @platforms %pplatforms);
38 use vars qw (%results @all_floats %suffices %all_functions);
41 # all_floats is in output order and contains all recognised float types that
42 # we're going to output
43 @all_floats = ('float', 'double', 'ldouble');
44 %suffices =
45 ( 'float' => 'f',
46 'double' => '',
47 'ldouble' => 'l'
50 # Pretty description of platform
51 %pplatforms = ();
53 %all_functions = ();
55 if ($#ARGV == 0) {
56 $sources = $ARGV[0];
57 } else {
58 $sources = '/usr/src/cvs/libc';
61 find (\&find_files, $sources);
63 @platforms = sort by_platforms @platforms;
65 &print_all;
67 sub find_files {
68 if ($_ eq 'libm-test-ulps') {
69 # print "Parsing $File::Find::name\n";
70 push @platforms, $File::Find::dir;
71 my ($file, $name);
72 $file = "${File::Find::name}-name";
73 open NAME, $file or die ("Can't open $file: $!");
74 $name = <NAME>;
75 chomp $name;
76 close NAME;
77 $pplatforms{$File::Find::dir} = $name;
78 &parse_ulps ($File::Find::name, $File::Find::dir);
82 # Parse ulps file
83 sub parse_ulps {
84 my ($file, $platform) = @_;
85 my ($test, $type, $float, $eps, $ignore_fn);
87 # $type has the following values:
88 # "normal": No complex variable
89 # "real": Real part of complex result
90 # "imag": Imaginary part of complex result
91 open ULP, $file or die ("Can't open $file: $!");
92 while (<ULP>) {
93 chop;
94 # ignore comments and empty lines
95 next if /^#/;
96 next if /^\s*$/;
97 if (/^Function: /) {
98 if (/Real part of/) {
99 s/Real part of //;
100 $type = 'real';
101 } elsif (/Imaginary part of/) {
102 s/Imaginary part of //;
103 $type = 'imag';
104 } else {
105 $type = 'normal';
107 ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
108 next;
110 if ($test =~ /_(downward|towardzero|upward|vlen)/) {
111 $ignore_fn = 1;
112 } else {
113 $ignore_fn = 0;
114 $all_functions{$test} = 1;
116 if (/^i?(float|double|ldouble):/) {
117 ($float, $eps) = split /\s*:\s*/,$_,2;
118 if ($ignore_fn) {
119 next;
120 } elsif ($eps eq 'fail') {
121 $results{$test}{$platform}{$type}{$float} = 'fail';
122 } elsif ($eps eq "0") {
123 # ignore
124 next;
125 } elsif (!exists $results{$test}{$platform}{$type}{$float}
126 || $results{$test}{$platform}{$type}{$float} ne 'fail') {
127 $results{$test}{$platform}{$type}{$float} = $eps;
129 if ($type =~ /^real|imag$/) {
130 $results{$test}{'type'} = 'complex';
131 } elsif ($type eq 'normal') {
132 $results{$test}{'type'} = 'normal';
134 next;
136 print "Skipping unknown entry: `$_'\n";
138 close ULP;
141 sub get_value {
142 my ($fct, $platform, $type, $float) = @_;
144 return (exists $results{$fct}{$platform}{$type}{$float}
145 ? $results{$fct}{$platform}{$type}{$float} : "0");
148 sub print_platforms {
149 my (@p) = @_;
150 my ($fct, $platform, $float, $first, $i, $platform_no, $platform_total);
152 print '@multitable {nexttowardf} ';
153 foreach (@p) {
154 print ' {1000 + i 1000}';
156 print "\n";
158 print '@item Function ';
159 foreach (@p) {
160 print ' @tab ';
161 print $pplatforms{$_};
163 print "\n";
166 foreach $fct (sort keys %all_functions) {
167 foreach $float (@all_floats) {
168 print "\@item $fct$suffices{$float} ";
169 foreach $platform (@p) {
170 print ' @tab ';
171 if (exists $results{$fct}{$platform}{'normal'}{$float}
172 || exists $results{$fct}{$platform}{'real'}{$float}
173 || exists $results{$fct}{$platform}{'imag'}{$float}) {
174 if ($results{$fct}{'type'} eq 'complex') {
175 print &get_value ($fct, $platform, 'real', $float),
176 ' + i ', &get_value ($fct, $platform, 'imag', $float);
177 } else {
178 print $results{$fct}{$platform}{'normal'}{$float};
180 } else {
181 print '-';
184 print "\n";
188 print "\@end multitable\n";
191 sub print_all {
192 my ($i, $max);
194 my ($columns) = 5;
196 # Print only 5 platforms at a time.
197 for ($i=0; $i < $#platforms; $i+=$columns) {
198 $max = $i+$columns-1 > $#platforms ? $#platforms : $i+$columns-1;
199 print_platforms (@platforms[$i .. $max]);
203 sub by_platforms {
204 return $pplatforms{$a} cmp $pplatforms{$b};