This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
paranoia harness update
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 16 Oct 2002 16:27:45 -0700
- Subject: paranoia harness update
Update for changes in real.h. As an aside, current results are:
* ieee_single and ieee_double are clean.
* ieee_extended_intel_96 detects one DEFECT concerning sqrt;
I'm fairly certain that's just a flaw in trying to use the
libc sqrtl here, since 3 such defects are found when using
native long doubles. I'll check to see if this is actually
the case, or if there's a problem with the arithmetic
afterward.
* ieee_quad has 2 DEFECTS, both due to the fact that the
sqrt implementation only has 64 bits of precision, not 113.
I'm not going to address this, as it's obvious what the
problem is.
* vax_f, vax_g are clean. The one FLAW merely confirms
the fact that vax doesn't have denormals, and so has
abrupt underflow near zero.
* vax_d has bizzare failures. This probably indicates that
either the target format encode or decode routine is broken.
* i370_single is clean with 3 FLAWs inherent in the
representation (base 16, no denormal, unbalanced range).
* i370_double has one additional DEFECT that wants looking at.
* The c4x encoders/decoders are broken
SERIOUS DEFECT: overflow past -1.7014118e+38
shrinks to 3.4028235e+38 .
* ibm_extended has 1 FAILURE and 1 FLAW, which _might_ be
inherent in the representation. Namely we've got 106 bits
of normal precision, but only 56 bits of denormal precision.
r~
* paranoia.cc (ENUM_BITFIELD): New.
(class): Define as klass around real.h.
(real_c_float): Not a template any longer; define MODE as a
class static constant; use real_format elements for SIZE.
Update uses of real_to_decimal and real_to_hexadecimal.
(main): Change -g argument to use a format name.
(mode_for_size): Remove.
Index: paranoia.cc
===================================================================
RCS file: /cvs/gcc/gcc/contrib/paranoia.cc,v
retrieving revision 1.1
diff -c -p -d -u -r1.1 paranoia.cc
--- paranoia.cc 16 Sep 2002 16:36:39 -0000 1.1
+++ paranoia.cc 16 Oct 2002 23:04:03 -0000
@@ -169,7 +169,12 @@ lines
};
#undef DEFTREECODE
+#define ENUM_BITFIELD(X) enum X
+#define class klass
+
#include "real.h"
+
+#undef class
}
/* We never produce signals from the library. Thus setjmp need do nothing. */
@@ -184,11 +189,13 @@ static int verbose_index = 0;
real.c. I.e. the object of this excersize. Templated so that we can
all fp sizes. */
-template<int SIZE, enum machine_mode MODE>
class real_c_float
{
+ public:
+ static const enum machine_mode MODE = SFmode;
+
private:
- long image[SIZE / 32];
+ long image[128 / 32];
void from_long(long);
void from_str(const char *);
@@ -241,9 +248,8 @@ class real_c_float
void ldexp (int);
};
-template<int SIZE, enum machine_mode MODE>
void
-real_c_float<SIZE, MODE>::from_long (long l)
+real_c_float::from_long (long l)
{
REAL_VALUE_TYPE f;
@@ -251,12 +257,11 @@ real_c_float<SIZE, MODE>::from_long (lon
real_to_target (image, &f, MODE);
}
-template<int SIZE, enum machine_mode MODE>
void
-real_c_float<SIZE, MODE>::from_str (const char *s)
+real_c_float::from_str (const char *s)
{
REAL_VALUE_TYPE f;
- char *p = s;
+ const char *p = s;
if (*p == '-' || *p == '+')
p++;
@@ -274,9 +279,8 @@ real_c_float<SIZE, MODE>::from_str (cons
real_to_target (image, &f, MODE);
}
-template<int SIZE, enum machine_mode MODE>
void
-real_c_float<SIZE, MODE>::binop (int code, const real_c_float &b)
+real_c_float::binop (int code, const real_c_float &b)
{
REAL_VALUE_TYPE ai, bi, ri;
@@ -288,13 +292,14 @@ real_c_float<SIZE, MODE>::binop (int cod
if (verbose)
{
char ab[64], bb[64], rb[64];
- const int digits = int(SIZE / 4);
+ const real_format *fmt = real_format_for_mode[MODE - QFmode];
+ const int digits = (fmt->p * fmt->log2_b + 3) / 4;
char symbol_for_code;
real_from_target (&ri, image, MODE);
- real_to_hexadecimal (ab, &ai, digits);
- real_to_hexadecimal (bb, &bi, digits);
- real_to_hexadecimal (rb, &ri, digits);
+ real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
+ real_to_hexadecimal (bb, &bi, sizeof(bb), digits, 0);
+ real_to_hexadecimal (rb, &ri, sizeof(rb), digits, 0);
switch (code)
{
@@ -319,9 +324,8 @@ real_c_float<SIZE, MODE>::binop (int cod
}
}
-template<int SIZE, enum machine_mode MODE>
void
-real_c_float<SIZE, MODE>::unop (int code)
+real_c_float::unop (int code)
{
REAL_VALUE_TYPE ai, ri;
@@ -332,12 +336,13 @@ real_c_float<SIZE, MODE>::unop (int code
if (verbose)
{
char ab[64], rb[64];
- const int digits = int(SIZE / 4);
+ const real_format *fmt = real_format_for_mode[MODE - QFmode];
+ const int digits = (fmt->p * fmt->log2_b + 3) / 4;
const char *symbol_for_code;
real_from_target (&ri, image, MODE);
- real_to_hexadecimal (ab, &ai, digits);
- real_to_hexadecimal (rb, &ri, digits);
+ real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
+ real_to_hexadecimal (rb, &ri, sizeof(rb), digits, 0);
switch (code)
{
@@ -356,9 +361,8 @@ real_c_float<SIZE, MODE>::unop (int code
}
}
-template<int SIZE, enum machine_mode MODE>
bool
-real_c_float<SIZE, MODE>::cmp (int code, const real_c_float &b) const
+real_c_float::cmp (int code, const real_c_float &b) const
{
REAL_VALUE_TYPE ai, bi;
bool ret;
@@ -370,11 +374,12 @@ real_c_float<SIZE, MODE>::cmp (int code,
if (verbose)
{
char ab[64], bb[64];
- const int digits = int(SIZE / 4);
+ const real_format *fmt = real_format_for_mode[MODE - QFmode];
+ const int digits = (fmt->p * fmt->log2_b + 3) / 4;
const char *symbol_for_code;
- real_to_hexadecimal (ab, &ai, digits);
- real_to_hexadecimal (bb, &bi, digits);
+ real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
+ real_to_hexadecimal (bb, &bi, sizeof(bb), digits, 0);
switch (code)
{
@@ -407,55 +412,52 @@ real_c_float<SIZE, MODE>::cmp (int code,
return ret;
}
-template<int SIZE, enum machine_mode MODE>
const char *
-real_c_float<SIZE, MODE>::str() const
+real_c_float::str() const
{
REAL_VALUE_TYPE f;
- const int digits = int(SIZE * .30102999566398119521 + 1);
+ const real_format *fmt = real_format_for_mode[MODE - QFmode];
+ const int digits = int(fmt->p * fmt->log2_b * .30102999566398119521 + 1);
real_from_target (&f, image, MODE);
char *buf = new char[digits + 10];
- real_to_decimal (buf, &f, digits);
+ real_to_decimal (buf, &f, digits+10, digits, 0);
return buf;
}
-template<int SIZE, enum machine_mode MODE>
const char *
-real_c_float<SIZE, MODE>::hex() const
+real_c_float::hex() const
{
REAL_VALUE_TYPE f;
- const int digits = int(SIZE / 4);
+ const real_format *fmt = real_format_for_mode[MODE - QFmode];
+ const int digits = (fmt->p * fmt->log2_b + 3) / 4;
real_from_target (&f, image, MODE);
char *buf = new char[digits + 10];
- real_to_hexadecimal (buf, &f, digits);
+ real_to_hexadecimal (buf, &f, digits+10, digits, 0);
return buf;
}
-template<int SIZE, enum machine_mode MODE>
long
-real_c_float<SIZE, MODE>::integer() const
+real_c_float::integer() const
{
REAL_VALUE_TYPE f;
real_from_target (&f, image, MODE);
return real_to_integer (&f);
}
-template<int SIZE, enum machine_mode MODE>
int
-real_c_float<SIZE, MODE>::exp() const
+real_c_float::exp() const
{
REAL_VALUE_TYPE f;
real_from_target (&f, image, MODE);
return real_exponent (&f);
}
-template<int SIZE, enum machine_mode MODE>
void
-real_c_float<SIZE, MODE>::ldexp (int exp)
+real_c_float::ldexp (int exp)
{
REAL_VALUE_TYPE ai;
@@ -2605,8 +2607,6 @@ Paranoia<FLOAT>::notify (const char *s)
int main(int ac, char **av)
{
- init_real_once ();
-
while (1)
switch (getopt (ac, av, "pvg:fdl"))
{
@@ -2620,30 +2620,49 @@ int main(int ac, char **av)
break;
case 'g':
{
- int size = strtol (optarg, 0, 0);
-
- switch (size)
- {
- case 32:
- Paranoia< real_c_float<32, SFmode> >().main();
- break;
-
- case 64:
- Paranoia< real_c_float<64, DFmode> >().main();
- break;
+ static const struct {
+ const char *name;
+ const struct real_format *fmt;
+ } fmts[] = {
+#define F(x) { #x, &x##_format }
+ F(ieee_single),
+ F(ieee_double),
+ F(ieee_extended_motorola),
+ F(ieee_extended_intel_96),
+ F(ieee_extended_intel_128),
+ F(ibm_extended),
+ F(ieee_quad),
+ F(vax_f),
+ F(vax_d),
+ F(vax_g),
+ F(i370_single),
+ F(i370_double),
+ F(c4x_single),
+ F(c4x_extended),
+#undef F
+ };
- case 96:
- Paranoia< real_c_float<96, XFmode> >().main();
- break;
+ int i, n = sizeof (fmts)/sizeof(*fmts);
- case 128:
- Paranoia< real_c_float<128, TFmode> >().main();
+ for (i = 0; i < n; ++i)
+ if (strcmp (fmts[i].name, optarg) == 0)
break;
- default:
- puts ("Invalid gcc implementation size.");
+ if (i == n)
+ {
+ printf ("Unknown implementation \"%s\"; "
+ "available implementations:\n", optarg);
+ for (i = 0; i < n; ++i)
+ printf ("\t%s\n", fmts[i].name);
return 1;
}
+
+ // We cheat and use the same mode all the time, but vary
+ // the format used for that mode.
+ real_format_for_mode[int(real_c_float::MODE) - int(QFmode)]
+ = fmts[i].fmt;
+
+ Paranoia<real_c_float>().main();
break;
}
@@ -2661,7 +2680,7 @@ int main(int ac, char **av)
case '?':
puts ("-p\tpause between pages");
- puts ("-g<N>\treal.c implementation size N");
+ puts ("-g<FMT>\treal.c implementation FMT");
puts ("-f\tnative float");
puts ("-d\tnative double");
puts ("-l\tnative long double");
@@ -2678,21 +2697,3 @@ fancy_abort ()
}
int target_flags = 0;
-
-extern "C"
-enum machine_mode
-mode_for_size (unsigned int size, enum mode_class, int)
-{
- switch (size)
- {
- case 32:
- return SFmode;
- case 64:
- return DFmode;
- case 96:
- return XFmode;
- case 128:
- return TFmode;
- }
- abort ();
-}