[5/8] Apply LIT(x) to floating point literals in libm-test.c
Commit Message
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
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.
@@ -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";
}