This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 6/8] Refactor CHOOSE() macro usage in libm-tests.inc
- From: "Paul E. Murphy" <murphyp at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Wed, 18 May 2016 15:55:54 -0500
- Subject: [PATCH 6/8] Refactor CHOOSE() macro usage in libm-tests.inc
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1463599718 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>
Use gen-libm-test.pl to generate these macros inside
libm-test-ulps.h as this simplifies adding new
types without having to modify a growing number of
static headers each time a type is added.
* math/gen-libm-test.pl (parse_ulps):
Dynamically generate type matching regex based on
the all_floats array.
(get_ulps): Generate the CHOOSE() macro used for each
test based on the all_floats array.
(output_ulps): Dynamically define the correct CHOOSE()
macros for each type based on the all_floats array.
* math/libm-test.inc: Remove comment about CHOOSE.
* math/test-double-finite.c [CHOOSE]: Remove.
* math/test-double-vlen2.h [CHOOSE]: Likewise.
* math/test-double-vlen4.h [CHOOSE]: Likewise.
* math/test-double-vlen8.h [CHOOSE]: Likewise.
* math/test-double.c [CHOOSE]: Likewise.
* math/test-float-finite.c [CHOOSE]: Likewise.
* math/test-float-vlen16.h [CHOOSE]: Likewise.
* math/test-float-vlen4.h [CHOOSE]: Likewise.
* math/test-float-vlen8.h [CHOOSE]: Likewise.
* math/test-float.c [CHOOSE]: Likewise.
* math/test-idouble.c [CHOOSE]: Likewise.
* math/test-ifloat.c [CHOOSE]: Likewise.
* math/test-ildoubl.c [CHOOSE]: Likewise.
* math/test-ldouble-finite.c [CHOOSE]: Likewise.
* math/test-ldouble.c [CHOOSE]: Likewise.
---
math/gen-libm-test.pl | 46 +++++++++++++++++++++++++++++++++++-----------
math/libm-test.inc | 1 -
math/test-double-finite.c | 1 -
math/test-double-vlen2.h | 1 -
math/test-double-vlen4.h | 1 -
math/test-double-vlen8.h | 1 -
math/test-double.c | 1 -
math/test-float-finite.c | 1 -
math/test-float-vlen16.h | 1 -
math/test-float-vlen4.h | 1 -
math/test-float-vlen8.h | 1 -
math/test-float.c | 1 -
math/test-idouble.c | 1 -
math/test-ifloat.c | 1 -
math/test-ildoubl.c | 1 -
math/test-ldouble-finite.c | 1 -
math/test-ldouble.c | 1 -
17 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/math/gen-libm-test.pl b/math/gen-libm-test.pl
index 2f5acc2..b252a39 100755
--- a/math/gen-libm-test.pl
+++ b/math/gen-libm-test.pl
@@ -585,7 +585,14 @@ sub generate_testfile {
# Parse ulps file
sub parse_ulps {
my ($file) = @_;
- my ($test, $type, $float, $eps);
+ my ($test, $type, $float, $eps, $float_regex);
+
+ # Build a basic regex to match type entries in the
+ # generated ULPS file.
+ foreach my $ftype (@all_floats) {
+ $float_regex .= "|" . $ftype;
+ }
+ $float_regex = "^" . substr ($float_regex, 1) . ":";
# $type has the following values:
# "normal": No complex variable
@@ -610,7 +617,7 @@ sub parse_ulps {
($test) = ($_ =~ /^Function:\s*\"([a-zA-Z0-9_]+)\"/);
next;
}
- if (/^i?(float|double|ldouble):/) {
+ if (/$float_regex/) {
($float, $eps) = split /\s*:\s*/,$_,2;
if ($eps eq "0") {
@@ -696,14 +703,12 @@ sub get_all_ulps_for_test {
my ($ldouble, $double, $float, $ildouble, $idouble, $ifloat);
if (exists $results{$test}{'has_ulps'}) {
- # XXX use all_floats (change order!)
- $ldouble = &get_ulps ($test, $type, "ldouble");
- $double = &get_ulps ($test, $type, "double");
- $float = &get_ulps ($test, $type, "float");
- $ildouble = &get_ulps ($test, $type, "ildouble");
- $idouble = &get_ulps ($test, $type, "idouble");
- $ifloat = &get_ulps ($test, $type, "ifloat");
- return "CHOOSE ($ldouble, $double, $float, $ildouble, $idouble, $ifloat)";
+ my $choose_str = "CHOOSE (";
+ foreach $float (@all_floats) {
+ $choose_str .= &get_ulps ($test, $type, $float) . ", ";
+ }
+ $choose_str = substr ($choose_str, 0, -2) . ")";
+ return $choose_str;
} else {
die "get_all_ulps_for_test called for \"$test\" with no ulps\n";
}
@@ -712,7 +717,7 @@ sub get_all_ulps_for_test {
# Print include file
sub output_ulps {
my ($file, $ulps_filename) = @_;
- my ($i, $fct, $type, $ulp, $ulp_real, $ulp_imag);
+ my ($i, $fct, $type, $ulp, $ulp_real, $ulp_imag, $choose);
my (%func_ulps, %func_real_ulps, %func_imag_ulps);
open ULP, ">$file" or die ("Can't open $file: $!");
@@ -721,6 +726,25 @@ sub output_ulps {
print ULP " from $ulps_filename with gen-libm-test.pl.\n";
print ULP " Don't change it - change instead the master files. */\n\n";
+ # Declare all the possible CHOOSE() variants based on the type being tested
+ # and whether inline functions are being tested.
+ $choose = "CHOOSE(C$all_floats[0]";
+ for ($i = 1; $i <= $#all_floats; $i++) {
+ $choose .= ", C" . $all_floats[$i];
+ }
+ $choose .= ")";
+ foreach my $type (@all_floats) {
+ if ($type =~ /^i/) {
+ $type = substr ($type, 1);
+ print ULP "#if defined TEST_" . uc ($type) . " && TEST_INLINE\n";
+ print ULP "# define " . $choose . " Ci$type\n";
+ } else {
+ print ULP "#if defined TEST_" . uc ($type) . " && !TEST_INLINE\n";
+ print ULP "# define " . $choose . " C$type\n";
+ }
+ print ULP "#endif\n";
+ }
+
foreach $fct (keys %results) {
$type = $results{$fct}{'type'};
if ($type eq 'normal') {
diff --git a/math/libm-test.inc b/math/libm-test.inc
index d5dc5fc..7350c1b 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -26,7 +26,6 @@
name with correct suffix (e.g. cosl or cosf)
FLOAT: floating point type to test
- TEST_MSG: informal message to be displayed
- CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat):
chooses one of the parameters as delta for testing
equality
PRINTF_EXPR Floating point conversion specification to print a variable
diff --git a/math/test-double-finite.c b/math/test-double-finite.c
index e7fa2a9..7f107aa 100644
--- a/math/test-double-finite.c
+++ b/math/test-double-finite.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing double (finite-math-only)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble
#include "libm-test.c"
diff --git a/math/test-double-vlen2.h b/math/test-double-vlen2.h
index 8a1d068..45351cb 100644
--- a/math/test-double-vlen2.h
+++ b/math/test-double-vlen2.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing double vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble
#define EXCEPTION_TESTS_double 0
#define ROUNDING_TESTS_double(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-double-vlen4.h b/math/test-double-vlen4.h
index 40ab58c..7078893 100644
--- a/math/test-double-vlen4.h
+++ b/math/test-double-vlen4.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing double vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble
#define EXCEPTION_TESTS_double 0
#define ROUNDING_TESTS_double(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-double-vlen8.h b/math/test-double-vlen8.h
index dddb52c..57168c5 100644
--- a/math/test-double-vlen8.h
+++ b/math/test-double-vlen8.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing double vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble
#define EXCEPTION_TESTS_double 0
#define ROUNDING_TESTS_double(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-double.c b/math/test-double.c
index 2647f66..3f84f40 100644
--- a/math/test-double.c
+++ b/math/test-double.c
@@ -23,6 +23,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing double (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble
#include "libm-test.c"
diff --git a/math/test-float-finite.c b/math/test-float-finite.c
index bd25a7b..3f5fe19 100644
--- a/math/test-float-finite.c
+++ b/math/test-float-finite.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing float (finite-math-only)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
#include "libm-test.c"
diff --git a/math/test-float-vlen16.h b/math/test-float-vlen16.h
index a2db3a5..d31336a 100644
--- a/math/test-float-vlen16.h
+++ b/math/test-float-vlen16.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing float vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
#define EXCEPTION_TESTS_float 0
#define ROUNDING_TESTS_float(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-float-vlen4.h b/math/test-float-vlen4.h
index 164749d..5a88fb8 100644
--- a/math/test-float-vlen4.h
+++ b/math/test-float-vlen4.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing float vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
#define EXCEPTION_TESTS_float 0
#define ROUNDING_TESTS_float(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-float-vlen8.h b/math/test-float-vlen8.h
index ce32df2..d1e5e6e 100644
--- a/math/test-float-vlen8.h
+++ b/math/test-float-vlen8.h
@@ -21,7 +21,6 @@
#include "test-math-vector.h"
#define TEST_MSG "testing float vector math (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
#define EXCEPTION_TESTS_float 0
#define ROUNDING_TESTS_float(MODE) ((MODE) == FE_TONEAREST)
diff --git a/math/test-float.c b/math/test-float.c
index 153b9ad..6be57bb 100644
--- a/math/test-float.c
+++ b/math/test-float.c
@@ -23,6 +23,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing float (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat
#include "libm-test.c"
diff --git a/math/test-idouble.c b/math/test-idouble.c
index fc1e8f8..10a3685 100644
--- a/math/test-idouble.c
+++ b/math/test-idouble.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing double (inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cinlinedouble
#include "libm-test.c"
diff --git a/math/test-ifloat.c b/math/test-ifloat.c
index 72c53ad..88bb5b8 100644
--- a/math/test-ifloat.c
+++ b/math/test-ifloat.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing float (inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cinlinefloat
#include "libm-test.c"
diff --git a/math/test-ildoubl.c b/math/test-ildoubl.c
index 08317ed..dc0efaa 100644
--- a/math/test-ildoubl.c
+++ b/math/test-ildoubl.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing long double (inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cinlinelongdouble
#include "libm-test.c"
diff --git a/math/test-ldouble-finite.c b/math/test-ldouble-finite.c
index 4c09778..8ac2d33 100644
--- a/math/test-ldouble-finite.c
+++ b/math/test-ldouble-finite.c
@@ -21,6 +21,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing long double (finite-math-only)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Clongdouble
#include "libm-test.c"
diff --git a/math/test-ldouble.c b/math/test-ldouble.c
index 944f6dd..a705fa4 100644
--- a/math/test-ldouble.c
+++ b/math/test-ldouble.c
@@ -23,6 +23,5 @@
#include "test-math-scalar.h"
#define TEST_MSG "testing long double (without inline functions)\n"
-#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Clongdouble
#include "libm-test.c"
--
2.4.11