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(-)
@@ -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");
}
@@ -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