⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen-libm-test.pl

📁 Axis 221 camera embedded programing interface
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl -w# Copyright (C) 1999 Free Software Foundation, Inc.# This file is part of the GNU C Library.# Contributed by Andreas Jaeger <aj@suse.de>, 1999.# The GNU C Library is free software; you can redistribute it and/or# modify it under the terms of the GNU Lesser General Public# License as published by the Free Software Foundation; either# version 2.1 of the License, or (at your option) any later version.# The GNU C Library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU# Lesser General Public License for more details.# You should have received a copy of the GNU Lesser General Public# License along with the GNU C Library; if not, write to the Free# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA# 02111-1307 USA.# This file needs to be tidied up# Note that functions and tests share the same namespace.# Information about tests are stored in: %results# $results{$test}{"kind"} is either "fct" or "test" and flags whether this# is a maximal error of a function or a single test.# $results{$test}{"type"} is the result type, e.g. normal or complex.# $results{$test}{"has_ulps"} is set if deltas exist.# $results{$test}{"has_fails"} is set if exptected failures exist.# In the following description $type and $float are:# - $type is either "normal", "real" (for the real part of a complex number)#   or "imag" (for the imaginary part # of a complex number).# - $float is either of float, ifloat, double, idouble, ldouble, ildouble;#   It represents the underlying floating point type (float, double or long#   double) and if inline functions (the leading i stands for inline)#   are used.# $results{$test}{$type}{"fail"}{$float} is defined and has a 1 if# the test is expected to fail# $results{$test}{$type}{"ulp"}{$float} is defined and has a delta as valueuse Getopt::Std;use strict;use vars qw ($input $output);use vars qw (%results);use vars qw (@tests @functions);use vars qw ($count);use vars qw (%beautify @all_floats);use vars qw ($output_dir $ulps_file);# all_floats is sorted and contains all recognised float types@all_floats = ('double', 'float', 'idouble',	       'ifloat', 'ildouble', 'ldouble');%beautify =  ( "minus_zero" => "-0",    "plus_zero" => "+0",    "minus_infty" => "-inf",    "plus_infty" => "inf",    "nan_value" => "NaN",    "M_El" => "e",    "M_E2l" => "e^2",    "M_E3l" => "e^3",    "M_LOG10El", "log10(e)",    "M_PIl" => "pi",    "M_PI_34l" => "3/4 pi",    "M_PI_2l" => "pi/2",    "M_PI_4l" => "pi/4",    "M_PI_6l" => "pi/6",    "M_PI_34_LOG10El" => "3/4 pi*log10(e)",    "M_PI_LOG10El" => "pi*log10(e)",    "M_PI2_LOG10El" => "pi/2*log10(e)",    "M_PI4_LOG10El" => "pi/4*log10(e)",    "M_LOG_SQRT_PIl" => "log(sqrt(pi))",    "M_LOG_2_SQRT_PIl" => "log(2*sqrt(pi))",    "M_2_SQRT_PIl" => "2 sqrt (pi)",    "M_SQRT_PIl" => "sqrt (pi)",    "INVALID_EXCEPTION" => "invalid exception",    "DIVIDE_BY_ZERO_EXCEPTION" => "division by zero exception",    "INVALID_EXCEPTION_OK" => "invalid exception allowed",    "DIVIDE_BY_ZERO_EXCEPTION_OK" => "division by zero exception allowed",    "EXCEPTIONS_OK" => "exceptions allowed",    "IGNORE_ZERO_INF_SIGN" => "sign of zero/inf not specified","INVALID_EXCEPTION|IGNORE_ZERO_INF_SIGN" => "invalid exception and sign of zero/inf not specified"  );# get Options# Options:# u: ulps-file# h: help# o: output-directory# n: generate new ulps fileuse vars qw($opt_u $opt_h $opt_o $opt_n);getopts('u:o:nh');$ulps_file = 'libm-test-ulps';$output_dir = '';if ($opt_h) {  print "Usage: gen-libm-test.pl [OPTIONS]\n";  print " -h         print this help, then exit\n";  print " -o DIR     directory where generated files will be placed\n";  print " -n         only generate sorted file NewUlps from libm-test-ulps\n";  print " -u FILE    input file with ulps\n";  exit 0;}$ulps_file = $opt_u if ($opt_u);$output_dir = $opt_o if ($opt_o);$input = "libm-test.inc";$output = "${output_dir}libm-test.c";$count = 0;&parse_ulps ($ulps_file);&generate_testfile ($input, $output) unless ($opt_n);&output_ulps ("${output_dir}libm-test-ulps.h", $ulps_file) unless ($opt_n);&print_ulps_file ("${output_dir}NewUlps") if ($opt_n);# Return a nicer representationsub beautify {  my ($arg) = @_;  my ($tmp);  if (exists $beautify{$arg}) {    return $beautify{$arg};  }  if ($arg =~ /^-/) {    $tmp = $arg;    $tmp =~ s/^-//;    if (exists $beautify{$tmp}) {      return '-' . $beautify{$tmp};    }  }  if ($arg =~ /[0-9]L$/) {    $arg =~ s/L$//;  }  return $arg;}# Return a nicer representation of a complex numbersub build_complex_beautify {  my ($r, $i) = @_;  my ($str1, $str2);  $str1 = &beautify ($r);  $str2 = &beautify ($i);  if ($str2 =~ /^-/) {    $str2 =~ s/^-//;    $str1 .= ' - ' . $str2;  } else {    $str1 .= ' + ' . $str2;  }  $str1 .= ' i';  return $str1;}# Return name of a variablesub get_variable {  my ($number) = @_;  return "x" if ($number == 1);  return "y" if ($number == 2);  return "z" if ($number == 3);  # return x1,x2,...  $number =-3;  return "x$number";}# Add a new test to internal data structures and fill in the# ulps, failures and exception information for the C line.sub new_test {  my ($test, $exception) = @_;  my $rest;  # Add ulp, xfail  if (exists $results{$test}{'has_ulps'}) {    $rest = ", DELTA$count";  } else {    $rest = ', 0';  }  if (exists $results{$test}{'has_fails'}) {    $rest .= ", FAIL$count";  } else {    $rest .= ', 0';  }  if (defined $exception) {    $rest .= ", $exception";  } else {    $rest .= ', 0';  }  $rest .= ");\n";  # We must increment here to keep @tests and count in sync  push @tests, $test;  ++$count;  return $rest;}# Treat some functions especially.# Currently only sincos needs extra treatment.sub special_functions {  my ($file, $args) = @_;  my (@args, $str, $test, $cline);  @args = split /,\s*/, $args;  unless ($args[0] =~ /sincos/) {    die ("Don't know how to handle $args[0] extra.");  }  print $file "  FUNC (sincos) ($args[1], &sin_res, &cos_res);\n";  $str = 'sincos (' . &beautify ($args[1]) . ', &sin_res, &cos_res)';  # handle sin  $test = $str . ' puts ' . &beautify ($args[2]) . ' in sin_res';  if ($#args == 4) {    $test .= " plus " . &beautify ($args[4]);  }  $cline = "  check_float (\"$test\", sin_res, $args[2]";  $cline .= &new_test ($test, $args[4]);  print $file $cline;  # handle cos  $test = $str . ' puts ' . &beautify ($args[3]) . ' in cos_res';  $cline = "  check_float (\"$test\", cos_res, $args[3]";  # only tests once for exception  $cline .= &new_test ($test, undef);  print $file $cline;}# Parse the arguments to TEST_x_ysub parse_args {  my ($file, $descr, $args) = @_;  my (@args, $str, $descr_args, $descr_res, @descr);  my ($current_arg, $cline, $i);  my ($pre, $post, @special);  my ($extra_var, $call, $c_call);  if ($descr eq 'extra') {    &special_functions ($file, $args);    return;  }  ($descr_args, $descr_res) = split /_/,$descr, 2;  @args = split /,\s*/, $args;  $call = "$args[0] (";  # Generate first the string that's shown to the user  $current_arg = 1;  $extra_var = 0;  @descr = split //,$descr_args;  for ($i = 0; $i <= $#descr; $i++) {    if ($i >= 1) {      $call .= ', ';    }    # FLOAT, int, long int, long long int    if ($descr[$i] =~ /f|i|l|L/) {      $call .= &beautify ($args[$current_arg]);      ++$current_arg;      next;    }    # &FLOAT, &int - argument is added here    if ($descr[$i] =~ /F|I/) {      ++$extra_var;      $call .= '&' . &get_variable ($extra_var);      next;    }    # complex    if ($descr[$i] eq 'c') {      $call .= &build_complex_beautify ($args[$current_arg], $args[$current_arg+1]);      $current_arg += 2;      next;    }    die ("$descr[$i] is unknown");  }  $call .= ')';  $str = "$call == ";  # Result  @descr = split //,$descr_res;  foreach (@descr) {    if ($_ =~ /f|i|l|L/) {      $str .= &beautify ($args[$current_arg]);      ++$current_arg;    } elsif ($_ eq 'c') {      $str .= &build_complex_beautify ($args[$current_arg], $args[$current_arg+1]);      $current_arg += 2;    } elsif ($_ eq 'b') {      # boolean      $str .= ($args[$current_arg] == 0) ? "false" : "true";      ++$current_arg;    } elsif ($_ eq '1') {      ++$current_arg;    } else {      die ("$_ is unknown");    }  }  # consistency check  if ($current_arg == $#args) {    die ("wrong number of arguments")      unless ($args[$current_arg] =~ /EXCEPTION|IGNORE_ZERO_INF_SIGN/);  } elsif ($current_arg < $#args) {    die ("wrong number of arguments");  } elsif ($current_arg > ($#args+1)) {    die ("wrong number of arguments");  }  # check for exceptions  if ($current_arg <= $#args) {    $str .= " plus " . &beautify ($args[$current_arg]);  }  # Put the C program line together  # Reset some variables to start again  $current_arg = 1;  $extra_var = 0;  if (substr($descr_res,0,1) eq 'f') {    $cline = 'check_float'  } elsif (substr($descr_res,0,1) eq 'b') {    $cline = 'check_bool';  } elsif (substr($descr_res,0,1) eq 'c') {    $cline = 'check_complex';  } elsif (substr($descr_res,0,1) eq 'i') {    $cline = 'check_int';  } elsif (substr($descr_res,0,1) eq 'l') {    $cline = 'check_long';  } elsif (substr($descr_res,0,1) eq 'L') {    $cline = 'check_longlong';  }  # Special handling for some macros:  $cline .= " (\"$str\", ";  if ($args[0] =~ /fpclassify|isnormal|isfinite|signbit/) {    $c_call = "$args[0] (";  } else {    $c_call = " FUNC($args[0]) (";  }  @descr = split //,$descr_args;  for ($i=0; $i <= $#descr; $i++) {    if ($i >= 1) {      $c_call .= ', ';    }    # FLOAT, int, long int, long long int    if ($descr[$i] =~ /f|i|l|L/) {      $c_call .= $args[$current_arg];      $current_arg++;      next;    }    # &FLOAT, &int    if ($descr[$i] =~ /F|I/) {      ++$extra_var;      $c_call .= '&' . &get_variable ($extra_var);      next;    }    # complex    if ($descr[$i] eq 'c') {      $c_call .= "BUILD_COMPLEX ($args[$current_arg], $args[$current_arg+1])";      $current_arg += 2;      next;    }  }  $c_call .= ')';  $cline .= "$c_call, ";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -