diff mbox

[5/8] Apply LIT(x) to floating point literals in libm-test.c

Message ID dfeb4027547153931a89717c031ed691b9174a30.1463599718.git.murphyp@linux.vnet.ibm.com
State New
Headers show

Commit Message

Paul E. Murphy May 18, 2016, 8:55 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 | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

Comments

Joseph Myers May 18, 2016, 9:23 p.m. UTC | #1
On Wed, 18 May 2016, Paul E. Murphy wrote:

> +  # If it doesn't have a period or an exponent, its not an FP literal.
> +  if (index ($lit, ".") == -1 and $lit !~ /[pe]([+-])?[0-9]+/) {
> +    return $lit;

This would interpret e.g. 0x1e2 as a floating-point literal.  It looks 
like we don't have such literals in libm-test.inc at present (we do have 
0x1fffffe, which doesn't match your regular expression), but it still 
seems too fragile.
diff mbox

Patch

diff --git a/math/gen-libm-test.pl b/math/gen-libm-test.pl
index 17f17f7..3c6980f 100755
--- a/math/gen-libm-test.pl
+++ b/math/gen-libm-test.pl
@@ -151,6 +151,23 @@  sub show_exceptions {
   }
 }
 
+# Apply the LIT(x) macro to any floating point constants.
+sub apply_lit {
+  my ($lit) = @_;
+  my $lletter = substr $lit, -1;
+
+  # If it doesn't have a period or an exponent, its not an FP literal.
+  if (index ($lit, ".") == -1 and $lit !~ /[pe]([+-])?[0-9]+/) {
+    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) = @_;
@@ -241,7 +258,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;
     }
@@ -251,7 +272,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;
     }
@@ -281,6 +303,9 @@  sub parse_args {
 	} else {
 	  $ignore_result_all = 0;
 	}
+	if ($_ eq "f") {
+	  $result = apply_lit ($result)
+	}
 	$cline_res .= ", $result";
 	$current_arg++;
       } elsif ($_ eq 'c') {
@@ -298,6 +323,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') {
@@ -326,6 +353,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";
     }