[PATCHv2,11/14] Apply LIT(x) to floating point literals in libm-test.c

Message ID d544a21f4e723511ac026930826fae446f7647d4.1463779745.git.murphyp@linux.vnet.ibm.com
State Superseded
Headers

Commit Message

Paul E. Murphy May 20, 2016, 9:37 p.m. UTC
  With the exception of the second argument of nexttoward,
any suffixes should be stripped from the test input, and
the macro LIT(x) should be applied to use the correct
suffix for the type being tested.

This applies post-processing to all of the test inputs
through gen-libm-test.pl to strip literal suffixes and
apply the LIT(x) macro, with one exception stated above.
This seems a bit cleaner than tossing the macro onto
everything albeit slightly more obfuscated.

	* math/gen-libm-test.pl: (apply_lit): New subroutine.
	(parse_args): Strip C suffix from floating point literals
	and wrap them with LIT().
---
 math/gen-libm-test.pl | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
  

Comments

Joseph Myers May 24, 2016, 3:43 p.m. UTC | #1
On Fri, 20 May 2016, Paul E. Murphy wrote:

>      if ($descr[$i] =~ /f|i|l|L/) {
> -      $cline .= ", $args[$current_arg]";
> +      if ($descr[$i] eq "f" and not ($args[0] eq "nexttoward" and $current_arg == 2)) {

Rather than specially checking for the name "nexttoward" here, I think it 
would be cleaner to use something other than "f" as the argument 
descriptor for the case where the argument is always long double, and 
rename struct test_ff_f_data_nexttoward accordingly.  (Strictly you don't 
need to create another macro like RUN_TEST_LOOP_ff_f with the 
corresponding name and use it for the nexttoward tests, but it's probably 
cleaner to do so as well.)

(Nothing should actually be using the first argument to TEST_* any more; 
it's a relic from when TEST_* generated code rather than data, which 
hasn't been cleaned up yet.)
  

Patch

diff --git a/math/gen-libm-test.pl b/math/gen-libm-test.pl
index c8790e1..40839e0 100755
--- a/math/gen-libm-test.pl
+++ b/math/gen-libm-test.pl
@@ -152,6 +152,30 @@  sub show_exceptions {
   }
 }
 
+# Apply the LIT(x) macro to any floating point constants.
+sub apply_lit {
+  my ($lit) = @_;
+  my $lletter = substr $lit, -1;
+  my $exp_re = "([+-])?[[:digit:]]+";
+
+  # Don't wrap something that does not look like a:
+  # hexadecimal FP value,
+  # base 10 integer raised to a power,
+  # something with a decimal point.
+  if ($lit !~ /([+-])?0x[[:xdigit:]\.]+[pP]$exp_re/
+      and $lit !~ /[[:digit:]]+[eE]$exp_re/
+      and $lit !~ /[[:digit:]]*\.[[:digit:]]*([eE]$exp_re)?/
+     ){
+    return $lit;
+  }
+
+  # Strip any suffixes from the constant
+  if ($lletter =~ /L|l|f|F/) {
+    chop $lit;
+  }
+  return "LIT ($lit)";
+}
+
 # Parse the arguments to TEST_x_y
 sub parse_args {
   my ($file, $descr, $args) = @_;
@@ -242,7 +266,11 @@  sub parse_args {
   for ($i=0; $i <= $#descr; $i++) {
     # FLOAT, int, long int, long long int
     if ($descr[$i] =~ /f|i|l|L/) {
-      $cline .= ", $args[$current_arg]";
+      if ($descr[$i] eq "f" and not ($args[0] eq "nexttoward" and $current_arg == 2)) {
+        $cline .= ", " . &apply_lit ($args[$current_arg]);
+      } else {
+        $cline .= ", $args[$current_arg]";
+      }
       $current_arg++;
       next;
     }
@@ -252,7 +280,8 @@  sub parse_args {
     }
     # complex
     if ($descr[$i] eq 'c') {
-      $cline .= ", $args[$current_arg], $args[$current_arg+1]";
+      $cline .= ", " . &apply_lit ($args[$current_arg]);
+      $cline .= ", " . &apply_lit ($args[$current_arg+1]);
       $current_arg += 2;
       next;
     }
@@ -282,6 +311,9 @@  sub parse_args {
 	} else {
 	  $ignore_result_all = 0;
 	}
+	if ($_ eq "f") {
+	  $result = apply_lit ($result)
+	}
 	$cline_res .= ", $result";
 	$current_arg++;
       } elsif ($_ eq 'c') {
@@ -299,6 +331,8 @@  sub parse_args {
 	} else {
 	  $ignore_result_all = 0;
 	}
+	$result1 = apply_lit ($result1);
+	$result2 = apply_lit ($result2);
 	$cline_res .= ", $result1, $result2";
 	$current_arg += 2;
       } elsif ($_ eq '1') {
@@ -327,6 +361,8 @@  sub parse_args {
       my ($run_extra) = ($extra_expected ne "IGNORE" ? 1 : 0);
       if (!$run_extra) {
 	$extra_expected = "0";
+      } else {
+	$extra_expected = apply_lit ($extra_expected);
       }
       $cline_res .= ", $run_extra, $extra_expected";
     }