Blame manual/libm-err-tab.pl

Packit 6c4009
#!/usr/bin/perl -w
Packit 6c4009
# Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
# Contributed by Andreas Jaeger <aj@suse.de>, 1999.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# Information about tests are stored in: %results
Packit 6c4009
# $results{$test}{"type"} is the result type, e.g. normal or complex.
Packit 6c4009
# In the following description $platform, $type and $float are:
Packit 6c4009
# - $platform is the used platform
Packit 6c4009
# - $type is either "normal", "real" (for the real part of a complex number)
Packit 6c4009
#   or "imag" (for the imaginary part # of a complex number).
Packit 6c4009
# - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
Packit 6c4009
#   It represents the underlying floating point type (float, double or long
Packit 6c4009
#   double) and if inline functions (the leading i stands for inline)
Packit 6c4009
#   are used.
Packit 6c4009
# $results{$test}{$platform}{$type}{$float} is defined and has a delta
Packit 6c4009
# or 'fail' as value.
Packit 6c4009
Packit 6c4009
use File::Find;
Packit 6c4009
Packit 6c4009
use strict;
Packit 6c4009
Packit 6c4009
use vars qw ($sources @platforms %pplatforms);
Packit 6c4009
use vars qw (%results @all_floats %suffices %all_functions);
Packit 6c4009
Packit 6c4009
Packit 6c4009
# all_floats is in output order and contains all recognised float types that
Packit 6c4009
# we're going to output
Packit 6c4009
@all_floats = ('float', 'double', 'ldouble', 'float128');
Packit 6c4009
%suffices =
Packit 6c4009
  ( 'float' => 'f',
Packit 6c4009
    'double' => '',
Packit 6c4009
    'ldouble' => 'l',
Packit 6c4009
    'float128' => 'f128'
Packit 6c4009
  );
Packit 6c4009
Packit 6c4009
# Pretty description of platform
Packit 6c4009
%pplatforms = ();
Packit 6c4009
Packit 6c4009
%all_functions = ();
Packit 6c4009
Packit 6c4009
if ($#ARGV == 0) {
Packit 6c4009
  $sources = $ARGV[0];
Packit 6c4009
} else {
Packit 6c4009
  $sources = '/usr/src/cvs/libc';
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
find (\&find_files, $sources);
Packit 6c4009
Packit 6c4009
@platforms = sort by_platforms @platforms;
Packit 6c4009
Packit 6c4009
&print_all;
Packit 6c4009
Packit 6c4009
sub find_files {
Packit 6c4009
  if ($_ eq 'libm-test-ulps') {
Packit 6c4009
    # print "Parsing $File::Find::name\n";
Packit 6c4009
    push @platforms, $File::Find::dir;
Packit 6c4009
    my ($file, $name);
Packit 6c4009
    $file = "${File::Find::name}-name";
Packit 6c4009
    open NAME, $file or die ("Can't open $file: $!");
Packit 6c4009
    $name = <NAME>;
Packit 6c4009
    chomp $name;
Packit 6c4009
    close NAME;
Packit 6c4009
    $pplatforms{$File::Find::dir} = $name;
Packit 6c4009
    &parse_ulps ($File::Find::name, $File::Find::dir);
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
# Parse ulps file
Packit 6c4009
sub parse_ulps {
Packit 6c4009
  my ($file, $platform) = @_;
Packit 6c4009
  my ($test, $type, $float, $eps, $ignore_fn);
Packit 6c4009
Packit 6c4009
  # $type has the following values:
Packit 6c4009
  # "normal": No complex variable
Packit 6c4009
  # "real": Real part of complex result
Packit 6c4009
  # "imag": Imaginary part of complex result
Packit 6c4009
  open ULP, $file  or die ("Can't open $file: $!");
Packit 6c4009
  while (<ULP>) {
Packit 6c4009
    chop;
Packit 6c4009
    # ignore comments and empty lines
Packit 6c4009
    next if /^#/;
Packit 6c4009
    next if /^\s*$/;
Packit 6c4009
    if (/^Function: /) {
Packit 6c4009
      if (/Real part of/) {
Packit 6c4009
	s/Real part of //;
Packit 6c4009
	$type = 'real';
Packit 6c4009
      } elsif (/Imaginary part of/) {
Packit 6c4009
	s/Imaginary part of //;
Packit 6c4009
	$type = 'imag';
Packit 6c4009
      } else {
Packit 6c4009
	$type = 'normal';
Packit 6c4009
      }
Packit 6c4009
      ($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
Packit 6c4009
      next;
Packit 6c4009
    }
Packit 6c4009
    if ($test =~ /_(downward|towardzero|upward|vlen)/) {
Packit 6c4009
      $ignore_fn = 1;
Packit 6c4009
    } else {
Packit 6c4009
      $ignore_fn = 0;
Packit 6c4009
      $all_functions{$test} = 1;
Packit 6c4009
    }
Packit 6c4009
    if (/^i?(float|double|ldouble|float128):/) {
Packit 6c4009
      ($float, $eps) = split /\s*:\s*/,$_,2;
Packit 6c4009
      if ($ignore_fn) {
Packit 6c4009
	next;
Packit 6c4009
      } elsif ($eps eq 'fail') {
Packit 6c4009
	$results{$test}{$platform}{$type}{$float} = 'fail';
Packit 6c4009
      } elsif ($eps eq "0") {
Packit 6c4009
	# ignore
Packit 6c4009
	next;
Packit 6c4009
      } elsif (!exists $results{$test}{$platform}{$type}{$float}
Packit 6c4009
	    || $results{$test}{$platform}{$type}{$float} ne 'fail') {
Packit 6c4009
	$results{$test}{$platform}{$type}{$float} = $eps;
Packit 6c4009
      }
Packit 6c4009
      if ($type =~ /^real|imag$/) {
Packit 6c4009
	$results{$test}{'type'} = 'complex';
Packit 6c4009
      } elsif ($type eq 'normal') {
Packit 6c4009
	$results{$test}{'type'} = 'normal';
Packit 6c4009
      }
Packit 6c4009
      next;
Packit 6c4009
    }
Packit 6c4009
    print "Skipping unknown entry: `$_'\n";
Packit 6c4009
  }
Packit 6c4009
  close ULP;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub get_value {
Packit 6c4009
  my ($fct, $platform, $type, $float) = @_;
Packit 6c4009
Packit 6c4009
  return (exists $results{$fct}{$platform}{$type}{$float}
Packit 6c4009
	  ? $results{$fct}{$platform}{$type}{$float} : "0");
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub print_platforms {
Packit 6c4009
  my (@p) = @_;
Packit 6c4009
  my ($fct, $platform, $float, $first, $i, $platform_no, $platform_total);
Packit 6c4009
Packit 6c4009
  print '@multitable {nexttowardf} ';
Packit 6c4009
  foreach (@p) {
Packit 6c4009
    print ' {1000 + i 1000}';
Packit 6c4009
  }
Packit 6c4009
  print "\n";
Packit 6c4009
Packit 6c4009
  print '@item Function ';
Packit 6c4009
  foreach (@p) {
Packit 6c4009
    print ' @tab ';
Packit 6c4009
    print $pplatforms{$_};
Packit 6c4009
  }
Packit 6c4009
  print "\n";
Packit 6c4009
Packit 6c4009
Packit 6c4009
  foreach $fct (sort keys %all_functions) {
Packit 6c4009
    foreach $float (@all_floats) {
Packit 6c4009
      print "\@item $fct$suffices{$float} ";
Packit 6c4009
      foreach $platform (@p) {
Packit 6c4009
	print ' @tab ';
Packit 6c4009
	if (exists $results{$fct}{$platform}{'normal'}{$float}
Packit 6c4009
	    || exists $results{$fct}{$platform}{'real'}{$float}
Packit 6c4009
	    || exists $results{$fct}{$platform}{'imag'}{$float}) {
Packit 6c4009
	  if ($results{$fct}{'type'} eq 'complex') {
Packit 6c4009
	    print &get_value ($fct, $platform, 'real', $float),
Packit 6c4009
	    ' + i ', &get_value ($fct, $platform, 'imag', $float);
Packit 6c4009
	  } else {
Packit 6c4009
	    print $results{$fct}{$platform}{'normal'}{$float};
Packit 6c4009
	  }
Packit 6c4009
	} else {
Packit 6c4009
	  print '-';
Packit 6c4009
	}
Packit 6c4009
      }
Packit 6c4009
      print "\n";
Packit 6c4009
    }
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
  print "\@end multitable\n";
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub print_all {
Packit 6c4009
  my ($i, $max);
Packit 6c4009
Packit 6c4009
  my ($columns) = 5;
Packit 6c4009
Packit 6c4009
  # Print only 5 platforms at a time.
Packit 6c4009
  for ($i=0; $i < $#platforms; $i+=$columns) {
Packit 6c4009
    $max = $i+$columns-1 > $#platforms ? $#platforms : $i+$columns-1;
Packit 6c4009
    print_platforms (@platforms[$i .. $max]);
Packit 6c4009
  }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
sub by_platforms {
Packit 6c4009
  return $pplatforms{$a} cmp $pplatforms{$b};
Packit 6c4009
}