This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/5] Refactor tst-strtod-round.c


On 05/16/2016 05:49 PM, Joseph Myers wrote:
> On Mon, 16 May 2016, Paul E. Murphy wrote:
> 
>> +   gcc -std=gnu11 -O2 -Wall -Wextra gen-tst-strtod-round.c -lmpfr
>> +     -o gen-tst-strtod-round
>> +
>> +   (use of current MPC and MPFR versions recommended) and run it as:
> 
> The reference to MPC can't be correct.  This program does not use MPC.

Indeed, unnecessary.  I forgot to remove that bit after grabbing it
from gen-auto-tst-libm-tests.c.

> 
> So far this message has reached the libc-alpha list twice (you don't see 
> it twice in the archives because it has the same message-id each time).  
> I've seen this issue before with large messages coming to libc-alpha from 
> IBM (many duplicate copies of them arrive on the list), as if there is 
> some problem with IBM's mail server timing out before sourceware accepts 
> the message, or something like that.  Please try to get that mail system 
> problem fixed.

Ugh.  Thanks for pointing that out.  That is annoying.  I'll try.
 
> A further refactoring will be needed for testing new types with existing 
> formats: constant suffixes will need to be added when the header is used, 
> rather than being included when it is generated, so that the generated 
> constants for binary128 can be used with either "L" or "f128" (well, "q" 
> absent GCC support for "f128") suffixes depending on the type 
> corresponding to that format.  Do you intend to do that in a separate 
> patch?

Yes, I intentionally have avoided float128 specific changes.  I was
planning on just adding another entry to the formats table of
gen-tst-strtod-round.c and regenerating.  But, on second thought, with
a few small changes to the generator, it is possible to make the
generated output fully type generic.  I've attached the change which
applies atop patch 5.
>From bf7a99f7cbc3057ae5bdee616889236c70957e44 Mon Sep 17 00:00:00 2001
From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>
Date: Tue, 17 May 2016 10:32:43 -0500
Subject: [PATCH] Refactor tst-strtod-round-data.h to avoid adding a type
 suffix

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 | 36 +++++++++++++++++-------------------
 stdlib/tst-strtod.h           | 17 ++++++++++++-----
 2 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/stdlib/gen-tst-strtod-round.c b/stdlib/gen-tst-strtod-round.c
index ac0c96b..8d01654 100644
--- a/stdlib/gen-tst-strtod-round.c
+++ b/stdlib/gen-tst-strtod-round.c
@@ -61,17 +61,16 @@ string_to_fp (mpfr_t f, const char *s, mpfr_rnd_t rnd)
 }
 
 static void
-print_fp (mpfr_t f, const char *suffix, const char *suffix2)
+print_fp (mpfr_t f, const char *suffix)
 {
   if (mpfr_inf_p (f))
-    mpfr_printf ("\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", suffix2);
+    mpfr_printf ("\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", suffix);
   else
-    mpfr_printf ("\t%Ra%s%s", f, suffix, suffix2);
+    mpfr_printf ("\t%Ra%s", f, suffix);
 }
 
 static void
-round_str (const char *s, const char *suffix,
-	   int prec, int emin, int emax, bool ibm_ld)
+round_str (const char *s, int prec, int emin, int emax, bool ibm_ld)
 {
   mpfr_t f;
   mpfr_set_default_prec (prec);
@@ -93,13 +92,13 @@ round_str (const char *s, const char *suffix,
       mpfr_clear (max_value);
     }
   mpfr_printf ("\t%s,\n", r ? "false" : "true");
-  print_fp (f, suffix, ",\n");
+  print_fp (f, ",\n");
   string_to_fp (f, s, MPFR_RNDN);
-  print_fp (f, suffix, ",\n");
+  print_fp (f, ",\n");
   string_to_fp (f, s, MPFR_RNDZ);
-  print_fp (f, suffix, ",\n");
+  print_fp (f, ",\n");
   string_to_fp (f, s, MPFR_RNDU);
-  print_fp (f, suffix, "");
+  print_fp (f, "");
   mpfr_clear (f);
 }
 
@@ -107,21 +106,20 @@ static void
 round_for_all (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_printf ("  TEST (\"");
   const char *p;
@@ -135,8 +133,8 @@ round_for_all (const char *s)
   int i;
   for (i = 0; i < 7; i++)
     {
-      round_str (s, formats[i].suffix, formats[i].prec,
-		 formats[i].emin, formats[i].emax, formats[i].ibm_ld);
+      round_str (s, formats[i].prec, formats[i].emin, formats[i].emax,
+		 formats[i].ibm_ld);
       if (i < 6)
 	mpfr_printf (",\n");
     }
diff --git a/stdlib/tst-strtod.h b/stdlib/tst-strtod.h
index 4ea9daa..9c0dc40 100644
--- a/stdlib/tst-strtod.h
+++ b/stdlib/tst-strtod.h
@@ -99,7 +99,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,				\
@@ -112,13 +114,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( )
-- 
2.4.11


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]