Commit fc76a969 by Richard Henderson Committed by Richard Henderson

paranoia.cc (ENUM_BITFIELD): New.

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

From-SVN: r58226
parent e055ba36
2002-10-16 Richard Henderson <rth@redhat.com>
* 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.
2002-09-16 Richard Henderson <rth@redhat.com> 2002-09-16 Richard Henderson <rth@redhat.com>
* paranoia.cc: New file. * paranoia.cc: New file.
......
...@@ -169,7 +169,12 @@ lines ...@@ -169,7 +169,12 @@ lines
}; };
#undef DEFTREECODE #undef DEFTREECODE
#define ENUM_BITFIELD(X) enum X
#define class klass
#include "real.h" #include "real.h"
#undef class
} }
/* We never produce signals from the library. Thus setjmp need do nothing. */ /* We never produce signals from the library. Thus setjmp need do nothing. */
...@@ -184,11 +189,13 @@ static int verbose_index = 0; ...@@ -184,11 +189,13 @@ static int verbose_index = 0;
real.c. I.e. the object of this excersize. Templated so that we can real.c. I.e. the object of this excersize. Templated so that we can
all fp sizes. */ all fp sizes. */
template<int SIZE, enum machine_mode MODE>
class real_c_float class real_c_float
{ {
public:
static const enum machine_mode MODE = SFmode;
private: private:
long image[SIZE / 32]; long image[128 / 32];
void from_long(long); void from_long(long);
void from_str(const char *); void from_str(const char *);
...@@ -241,9 +248,8 @@ class real_c_float ...@@ -241,9 +248,8 @@ class real_c_float
void ldexp (int); void ldexp (int);
}; };
template<int SIZE, enum machine_mode MODE>
void void
real_c_float<SIZE, MODE>::from_long (long l) real_c_float::from_long (long l)
{ {
REAL_VALUE_TYPE f; REAL_VALUE_TYPE f;
...@@ -251,12 +257,11 @@ real_c_float<SIZE, MODE>::from_long (long l) ...@@ -251,12 +257,11 @@ real_c_float<SIZE, MODE>::from_long (long l)
real_to_target (image, &f, MODE); real_to_target (image, &f, MODE);
} }
template<int SIZE, enum machine_mode MODE>
void void
real_c_float<SIZE, MODE>::from_str (const char *s) real_c_float::from_str (const char *s)
{ {
REAL_VALUE_TYPE f; REAL_VALUE_TYPE f;
char *p = s; const char *p = s;
if (*p == '-' || *p == '+') if (*p == '-' || *p == '+')
p++; p++;
...@@ -274,9 +279,8 @@ real_c_float<SIZE, MODE>::from_str (const char *s) ...@@ -274,9 +279,8 @@ real_c_float<SIZE, MODE>::from_str (const char *s)
real_to_target (image, &f, MODE); real_to_target (image, &f, MODE);
} }
template<int SIZE, enum machine_mode MODE>
void 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; REAL_VALUE_TYPE ai, bi, ri;
...@@ -288,13 +292,14 @@ real_c_float<SIZE, MODE>::binop (int code, const real_c_float &b) ...@@ -288,13 +292,14 @@ real_c_float<SIZE, MODE>::binop (int code, const real_c_float &b)
if (verbose) if (verbose)
{ {
char ab[64], bb[64], rb[64]; 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; char symbol_for_code;
real_from_target (&ri, image, MODE); real_from_target (&ri, image, MODE);
real_to_hexadecimal (ab, &ai, digits); real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
real_to_hexadecimal (bb, &bi, digits); real_to_hexadecimal (bb, &bi, sizeof(bb), digits, 0);
real_to_hexadecimal (rb, &ri, digits); real_to_hexadecimal (rb, &ri, sizeof(rb), digits, 0);
switch (code) switch (code)
{ {
...@@ -319,9 +324,8 @@ real_c_float<SIZE, MODE>::binop (int code, const real_c_float &b) ...@@ -319,9 +324,8 @@ real_c_float<SIZE, MODE>::binop (int code, const real_c_float &b)
} }
} }
template<int SIZE, enum machine_mode MODE>
void void
real_c_float<SIZE, MODE>::unop (int code) real_c_float::unop (int code)
{ {
REAL_VALUE_TYPE ai, ri; REAL_VALUE_TYPE ai, ri;
...@@ -332,12 +336,13 @@ real_c_float<SIZE, MODE>::unop (int code) ...@@ -332,12 +336,13 @@ real_c_float<SIZE, MODE>::unop (int code)
if (verbose) if (verbose)
{ {
char ab[64], rb[64]; 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; const char *symbol_for_code;
real_from_target (&ri, image, MODE); real_from_target (&ri, image, MODE);
real_to_hexadecimal (ab, &ai, digits); real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
real_to_hexadecimal (rb, &ri, digits); real_to_hexadecimal (rb, &ri, sizeof(rb), digits, 0);
switch (code) switch (code)
{ {
...@@ -356,9 +361,8 @@ real_c_float<SIZE, MODE>::unop (int code) ...@@ -356,9 +361,8 @@ real_c_float<SIZE, MODE>::unop (int code)
} }
} }
template<int SIZE, enum machine_mode MODE>
bool 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; REAL_VALUE_TYPE ai, bi;
bool ret; bool ret;
...@@ -370,11 +374,12 @@ real_c_float<SIZE, MODE>::cmp (int code, const real_c_float &b) const ...@@ -370,11 +374,12 @@ real_c_float<SIZE, MODE>::cmp (int code, const real_c_float &b) const
if (verbose) if (verbose)
{ {
char ab[64], bb[64]; 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; const char *symbol_for_code;
real_to_hexadecimal (ab, &ai, digits); real_to_hexadecimal (ab, &ai, sizeof(ab), digits, 0);
real_to_hexadecimal (bb, &bi, digits); real_to_hexadecimal (bb, &bi, sizeof(bb), digits, 0);
switch (code) switch (code)
{ {
...@@ -407,55 +412,52 @@ real_c_float<SIZE, MODE>::cmp (int code, const real_c_float &b) const ...@@ -407,55 +412,52 @@ real_c_float<SIZE, MODE>::cmp (int code, const real_c_float &b) const
return ret; return ret;
} }
template<int SIZE, enum machine_mode MODE>
const char * const char *
real_c_float<SIZE, MODE>::str() const real_c_float::str() const
{ {
REAL_VALUE_TYPE f; 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); real_from_target (&f, image, MODE);
char *buf = new char[digits + 10]; char *buf = new char[digits + 10];
real_to_decimal (buf, &f, digits); real_to_decimal (buf, &f, digits+10, digits, 0);
return buf; return buf;
} }
template<int SIZE, enum machine_mode MODE>
const char * const char *
real_c_float<SIZE, MODE>::hex() const real_c_float::hex() const
{ {
REAL_VALUE_TYPE f; 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); real_from_target (&f, image, MODE);
char *buf = new char[digits + 10]; char *buf = new char[digits + 10];
real_to_hexadecimal (buf, &f, digits); real_to_hexadecimal (buf, &f, digits+10, digits, 0);
return buf; return buf;
} }
template<int SIZE, enum machine_mode MODE>
long long
real_c_float<SIZE, MODE>::integer() const real_c_float::integer() const
{ {
REAL_VALUE_TYPE f; REAL_VALUE_TYPE f;
real_from_target (&f, image, MODE); real_from_target (&f, image, MODE);
return real_to_integer (&f); return real_to_integer (&f);
} }
template<int SIZE, enum machine_mode MODE>
int int
real_c_float<SIZE, MODE>::exp() const real_c_float::exp() const
{ {
REAL_VALUE_TYPE f; REAL_VALUE_TYPE f;
real_from_target (&f, image, MODE); real_from_target (&f, image, MODE);
return real_exponent (&f); return real_exponent (&f);
} }
template<int SIZE, enum machine_mode MODE>
void void
real_c_float<SIZE, MODE>::ldexp (int exp) real_c_float::ldexp (int exp)
{ {
REAL_VALUE_TYPE ai; REAL_VALUE_TYPE ai;
...@@ -2605,8 +2607,6 @@ Paranoia<FLOAT>::notify (const char *s) ...@@ -2605,8 +2607,6 @@ Paranoia<FLOAT>::notify (const char *s)
int main(int ac, char **av) int main(int ac, char **av)
{ {
init_real_once ();
while (1) while (1)
switch (getopt (ac, av, "pvg:fdl")) switch (getopt (ac, av, "pvg:fdl"))
{ {
...@@ -2620,30 +2620,49 @@ int main(int ac, char **av) ...@@ -2620,30 +2620,49 @@ int main(int ac, char **av)
break; break;
case 'g': case 'g':
{ {
int size = strtol (optarg, 0, 0); static const struct {
const char *name;
switch (size) const struct real_format *fmt;
{ } fmts[] = {
case 32: #define F(x) { #x, &x##_format }
Paranoia< real_c_float<32, SFmode> >().main(); F(ieee_single),
break; F(ieee_double),
F(ieee_extended_motorola),
case 64: F(ieee_extended_intel_96),
Paranoia< real_c_float<64, DFmode> >().main(); F(ieee_extended_intel_128),
break; F(ibm_extended),
F(ieee_quad),
case 96: F(vax_f),
Paranoia< real_c_float<96, XFmode> >().main(); F(vax_d),
F(vax_g),
F(i370_single),
F(i370_double),
F(c4x_single),
F(c4x_extended),
#undef F
};
int i, n = sizeof (fmts)/sizeof(*fmts);
for (i = 0; i < n; ++i)
if (strcmp (fmts[i].name, optarg) == 0)
break; break;
case 128: if (i == n)
Paranoia< real_c_float<128, TFmode> >().main(); {
break; printf ("Unknown implementation \"%s\"; "
"available implementations:\n", optarg);
default: for (i = 0; i < n; ++i)
puts ("Invalid gcc implementation size."); printf ("\t%s\n", fmts[i].name);
return 1; 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; break;
} }
...@@ -2661,7 +2680,7 @@ int main(int ac, char **av) ...@@ -2661,7 +2680,7 @@ int main(int ac, char **av)
case '?': case '?':
puts ("-p\tpause between pages"); 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 ("-f\tnative float");
puts ("-d\tnative double"); puts ("-d\tnative double");
puts ("-l\tnative long double"); puts ("-l\tnative long double");
...@@ -2678,21 +2697,3 @@ fancy_abort () ...@@ -2678,21 +2697,3 @@ fancy_abort ()
} }
int target_flags = 0; 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 ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment