This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCHv2 11/14] Apply LIT(x) to floating point literals in libm-test.c
- From: "Paul E. Murphy" <murphyp at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 20 May 2016 16:37:20 -0500
- Subject: [PATCHv2 11/14] Apply LIT(x) to floating point literals in libm-test.c
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1463779745 dot git dot murphyp at linux dot vnet dot ibm dot com>
- References: <cover dot 1463599718 dot git dot murphyp at linux dot vnet dot ibm dot com> <cover dot 1463779745 dot git dot murphyp at linux dot vnet dot ibm dot com>
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(-)
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";
}
--
2.4.11