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

Message ID 5bdcaff5-b5b1-2dc5-4801-63edbc3e2f81@linux.vnet.ibm.com
State Superseded
Delegated to: Joseph Myers
Headers

Commit Message

Paul E. Murphy May 17, 2016, 4:05 p.m. UTC
  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.
  

Comments

Joseph Myers May 17, 2016, 4:14 p.m. UTC | #1
On Tue, 17 May 2016, Paul E. Murphy wrote:

> > 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.

It's *also* a good idea to omit large generated file changes from patch 
postings, unless they are important for the review.  (When constant 
suffixes are eliminated from auto-libm-test-out - desirable for the same 
reasons as for the present patch - that will rewrite the whole file - a > 
60MB diff - and you certainly don't want to send that to the list.)
  
Paul E. Murphy May 17, 2016, 4:42 p.m. UTC | #2
On 05/17/2016 11:14 AM, Joseph Myers wrote:
> On Tue, 17 May 2016, Paul E. Murphy wrote:
> 
>>> 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.
> 
> It's *also* a good idea to omit large generated file changes from patch 
> postings, unless they are important for the review.  (When constant 
> suffixes are eliminated from auto-libm-test-out - desirable for the same 
> reasons as for the present patch - that will rewrite the whole file - a > 
> 60MB diff - and you certainly don't want to send that to the list.)

Admittedly, my cutoff for "too big" was still too big.  Lesson learned.

Anyhow, for those tests, we do have the opportunity to post-process
the content as part of building the tests.  In that (yet to be submitted
to libc-alpha) patchset, I updated gen-libm-test.pl to strip C99 literal
suffixes, then wrap them with a new macro named LIT() to apply the
appropriate suffix depending on the type under test. With the exception
of nexttoward and its long double second argument.
  
Joseph Myers May 17, 2016, 9:47 p.m. UTC | #3
On Tue, 17 May 2016, Paul E. Murphy wrote:

> Anyhow, for those tests, we do have the opportunity to post-process
> the content as part of building the tests.  In that (yet to be submitted
> to libc-alpha) patchset, I updated gen-libm-test.pl to strip C99 literal
> suffixes, then wrap them with a new macro named LIT() to apply the
> appropriate suffix depending on the type under test. With the exception
> of nexttoward and its long double second argument.

That seems reasonable (as in: eventually the logical format of 
auto-libm-test-out would be not to include the suffixes, but by removing 
the suffixes in gen-libm-test-pl you avoid the need for the large change 
until there's another reason for such a large change, e.g. for splitting 
up auto-libm-test-out into per-function files, which is something I want 
to do anyway both to reduce its size and to allow gen-auto-libm-tests to 
be used for complex functions for which MPC is extremely slow).  Of course 
all the constants in libm-test.inc and auto-libm-test-out for integer 
arguments and results should also be exceptions to getting suffixes added.

Presumably you deal with how some constants in libm-test.inc for 
floating-point arguments and results are integer constants that can't 
simply have a suffix added without adding "." as well to turn them into 
floating-point constants.  And all conditionals such as

#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384

need to be rewritten to check properties of the format, not macros such as 
TEST_LDOUBLE which say which type it is (in this case, testing MAX_EXP 
would suffice, but for tests of MANT_DIG, right now the MANT_DIG macro is 
confusingly *_MANT_DIG-1, so a simple substitution does not suffice 
without fixing MANT_DIG and its existing uses first to be less confusing).
  

Patch

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