[PATCHv3,3/3] Refactor tst-strtod-round-data.h to avoid adding a type suffix
diff mbox

Message ID 53e9c5a00ee5841cdb8335be2d280d2a8ce8c603.1464041464.git.murphyp@linux.vnet.ibm.com
State New
Headers show

Commit Message

Paul E. Murphy May 23, 2016, 10:18 p.m. UTC
Refactor the generator to avoid the need to mix the format and
the type.  This updates tst-strtod.h to append the proper suffix
for the type being tested.  This allows for a trivial addition
of float128.

NOTE: reviewers, you will need to build gen-tst-strtod-round.c
and regenerate tst-strtod-round-data.h.  This keeps the patch
concise.

	* stdlib/gen-tst-strtod-round.c (printfp): Remove the literal
	suffix.
	(round_str): Likewise.
	(round_for_all): Likewise.
	* stdlib/tst-strtod.h (TEST): Apply the correct literal
	suffix to floating point literals.
	(INFINITYf): New macro.
	(INFINITYL): Likewise.
	* stdlib/tst-strtod-round-data.h: Regenerate.
---
 stdlib/gen-tst-strtod-round.c | 40 +++++++++++++++++++---------------------
 stdlib/tst-strtod.h           | 17 ++++++++++++-----
 2 files changed, 31 insertions(+), 26 deletions(-)

Patch
diff mbox

diff --git a/stdlib/gen-tst-strtod-round.c b/stdlib/gen-tst-strtod-round.c
index 26c2ec2..897fc59 100644
--- a/stdlib/gen-tst-strtod-round.c
+++ b/stdlib/gen-tst-strtod-round.c
@@ -60,19 +60,18 @@  string_to_fp (mpfr_t f, const char *s, mpfr_rnd_t rnd)
 #endif
 }
 
-static void
-print_fp (FILE *fout, mpfr_t f, const char *suffix, const char *suffix2)
+void
+print_fp (FILE *fout, mpfr_t f, const char *suffix)
 {
   if (mpfr_inf_p (f))
-    mpfr_fprintf (fout, "\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "",
-		  suffix2);
+    mpfr_fprintf (fout, "\tINFINITY%s", mpfr_signbit (f) ? "-" : "");
   else
-    mpfr_fprintf (fout, "\t%Ra%s%s", f, suffix, suffix2);
+    mpfr_fprintf (fout, "\t%Ra%s", f, suffix);
 }
 
 static void
-round_str (FILE *fout, const char *s, const char *suffix,
-	   int prec, int emin, int emax, bool ibm_ld)
+round_str (FILE *fout, const char *s, int prec, int emin, int emax,
+	   bool ibm_ld)
 {
   mpfr_t f;
   mpfr_set_default_prec (prec);
@@ -94,13 +93,13 @@  round_str (FILE *fout, const char *s, const char *suffix,
       mpfr_clear (max_value);
     }
   mpfr_fprintf (fout, "\t%s,\n", r ? "false" : "true");
-  print_fp (fout, f, suffix, ",\n");
+  print_fp (fout, f, ",\n");
   string_to_fp (f, s, MPFR_RNDN);
-  print_fp (fout, f, suffix, ",\n");
+  print_fp (fout, f, ",\n");
   string_to_fp (f, s, MPFR_RNDZ);
-  print_fp (fout, f, suffix, ",\n");
+  print_fp (fout, f, ",\n");
   string_to_fp (f, s, MPFR_RNDU);
-  print_fp (fout, f, suffix, "");
+  print_fp (fout, f, "");
   mpfr_clear (f);
 }
 
@@ -108,21 +107,20 @@  static void
 round_for_all (FILE *fout, const char *s)
 {
   static const struct fmt {
-    const char *suffix;
     int prec;
     int emin;
     int emax;
     bool ibm_ld;
   } formats[7] = {
-    { "f", 24, -148, 128, false },
-    { "", 53, -1073, 1024, false },
-    { "L", 53, -1073, 1024, false },
+    { 24, -148, 128, false },
+    { 53, -1073, 1024, false },
+    { 53, -1073, 1024, false },
     /* This is the Intel extended float format.  */
-    { "L", 64, -16444, 16384, false },
+    { 64, -16444, 16384, false },
     /* This is the Motorola extended float format.  */
-    { "L", 64, -16445, 16384, false },
-    { "L", 106, -1073, 1024, true },
-    { "L", 113, -16493, 16384, false },
+    { 64, -16445, 16384, false },
+    { 106, -1073, 1024, true },
+    { 113, -16493, 16384, false },
   };
   mpfr_fprintf (fout, "  TEST (\"");
   const char *p;
@@ -136,8 +134,8 @@  round_for_all (FILE *fout, const char *s)
   int i;
   for (i = 0; i < 7; i++)
     {
-      round_str (fout, s, formats[i].suffix, formats[i].prec,
-		 formats[i].emin, formats[i].emax, formats[i].ibm_ld);
+      round_str (fout, s, formats[i].prec, formats[i].emin,
+		 formats[i].emax, formats[i].ibm_ld);
       if (i < 6)
 	mpfr_fprintf (fout, ",\n");
     }
diff --git a/stdlib/tst-strtod.h b/stdlib/tst-strtod.h
index a22e2b8..5bd5aa9 100644
--- a/stdlib/tst-strtod.h
+++ b/stdlib/tst-strtod.h
@@ -100,7 +100,9 @@ 
 
 /* This macro is used in conjunction with the output from the
    gen-tst-strtod-round utility to select the appropriately
-   rounded long double value for a given format.  */
+   rounded long double value for a given format.  Note that
+   the literal suffix must be appended before the token is
+   potentially expanded, so we can fixup such mangling later on.  */
 #define TEST(s,							\
 	     fx, fd, fn, fz, fu,				\
 	     dx, dd, dn, dz, du,				\
@@ -113,13 +115,18 @@ 
     s,								\
     { fx, dx, LDC (ld53x, ld64ix, ld64mx, ld106x, ld113x) },	\
     {								\
-    { fn, dn, LDC (ld53n, ld64in, ld64mn, ld106n, ld113n) },	\
-    { fd, dd, LDC (ld53d, ld64id, ld64md, ld106d, ld113d) },	\
-    { fz, dz, LDC (ld53z, ld64iz, ld64mz, ld106z, ld113z) },	\
-    { fu, du, LDC (ld53u, ld64iu, ld64mu, ld106u, ld113u) }	\
+    { fn ## f, dn, LDC (ld53n ## L, ld64in ## L, ld64mn ## L, ld106n ## L, ld113n ## L)},\
+    { fd ## f, dd, LDC (ld53d ## L, ld64id ## L, ld64md ## L, ld106d ## L, ld113d ## L)},\
+    { fz ## f, dz, LDC (ld53z ## L, ld64iz ## L, ld64mz ## L, ld106z ## L, ld113z ## L)},\
+    { fu ## f, du, LDC (ld53u ## L, ld64iu ## L, ld64mu ## L, ld106u ## L, ld113u ## L)} \
     }								\
   }
 
+/* Note that the above will mangle constants generated by
+   the generator program.  We fix those up below.  */
+#define INFINITYf INFINITY
+#define INFINITYL INFINITY
+
 struct test_exactness
   {
   STRUCT_FOREACH_TYPE ()