This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Tracing for floating point values
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: Tracing for floating point values
- From: Ben Elliston <bje at redhat dot com>
- Date: Fri, 15 Dec 2000 12:57:11 +1100 (EST)
- Cc: <gdb at sources dot redhat dot com>
What about a print function that outputs things in decimal - something
like ``%f'' or ``%g''. While the existing print function is really
useful for someone debugging the internals it isn't much use to normal
users.
This patch adds a new function, sim_fpu_printn_func() that allows you to
print a sim_fpu with a specific number of trailing digits. I also removed a
few blocks of crufty #if 0'd code.
Okay to commit?
2000-12-15 Ben Elliston <bje@redhat.com>
* sim-fpu.h (sim_fpu_printn_fpu): Declare.
* sim-fpu.c (print_bits): Add digits parameter. Print only as many
trailing digits as specified (-1 to print all digits).
(sim_fpu_print_fpu): New wrapper around sim_fpu_printn_fpu.
(sim_fpu_printn_fpu): Rename from sim_fpu_print_fpu; update calls
to print_bits().
*** sim-fpu.h 2000/03/02 09:10:27 1.11
--- sim-fpu.h 2000/12/15 01:46:50
***************
*** 402,410 ****
--- 402,417 ----
typedef void sim_fpu_print_func (void *, char *, ...);
+ /* Print a sim_fpu with full precision. */
INLINE_SIM_FPU (void) sim_fpu_print_fpu (const sim_fpu *f,
sim_fpu_print_func *print,
void *arg);
+
+ /* Print a sim_fpu with `n' trailing digits. */
+ INLINE_SIM_FPU (void) sim_fpu_printn_fpu (const sim_fpu *f,
+ sim_fpu_print_func *print,
+ int digits,
+ void *arg);
INLINE_SIM_FPU (void) sim_fpu_print_status (int status,
sim_fpu_print_func *print,
*** sim-fpu.c 2000/11/16 00:15:29 1.21
--- sim-fpu.c 2000/12/15 01:47:40
***************
*** 51,70 ****
#include "sim-assert.h"
! /* Debugging support. */
static void
print_bits (unsigned64 x,
int msbit,
sim_fpu_print_func print,
void *arg)
{
unsigned64 bit = LSBIT64 (msbit);
int i = 4;
! while (bit)
{
if (i == 0)
print (arg, ",");
if ((x & bit))
print (arg, "1");
else
--- 51,75 ----
#include "sim-assert.h"
! /* Debugging support.
! If digits is -1, then print all digits. */
static void
print_bits (unsigned64 x,
int msbit,
+ int digits,
sim_fpu_print_func print,
void *arg)
{
unsigned64 bit = LSBIT64 (msbit);
int i = 4;
! while (bit && digits)
{
if (i == 0)
print (arg, ",");
+ else
+ if (digits > 0) digits--;
+
if ((x & bit))
print (arg, "1");
else
***************
*** 1375,1388 ****
ASSERT (high >= LSBIT64 ((NR_FRAC_GUARD * 2) - 64));
ASSERT (LSBIT64 (((NR_FRAC_GUARD + 1) * 2) - 64) < IMPLICIT_1);
- #if 0
- printf ("\n");
- print_bits (high, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf (";");
- print_bits (low, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf ("\n");
- #endif
-
/* normalize */
do
{
--- 1380,1385 ----
***************
*** 1394,1406 ****
}
while (high < IMPLICIT_1);
- #if 0
- print_bits (high, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf (";");
- print_bits (low, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf ("\n");
- #endif
-
ASSERT (high >= IMPLICIT_1 && high < IMPLICIT_2);
if (low != 0)
{
--- 1391,1396 ----
***************
*** 1530,1545 ****
numerator <<= 1;
}
- #if 0
- printf ("\n");
- print_bits (quotient, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf ("\n");
- print_bits (numerator, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf ("\n");
- print_bits (denominator, 63, (sim_fpu_print_func*)fprintf, stdout);
- printf ("\n");
- #endif
-
/* discard (but save) the extra bits */
if ((quotient & LSMASK64 (NR_SPARE -1, 0)))
quotient = (quotient >> NR_SPARE) | 1;
--- 1520,1525 ----
***************
*** 2477,2493 ****
sim_fpu_print_func *print,
void *arg)
{
print (arg, "%s", f->sign ? "-" : "+");
switch (f->class)
{
case sim_fpu_class_qnan:
print (arg, "0.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, print, arg);
print (arg, "*QuietNaN");
break;
case sim_fpu_class_snan:
print (arg, "0.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, print, arg);
print (arg, "*SignalNaN");
break;
case sim_fpu_class_zero:
--- 2457,2482 ----
sim_fpu_print_func *print,
void *arg)
{
+ sim_fpu_printn_fpu (f, print, -1, arg);
+ }
+
+ INLINE_SIM_FPU (void)
+ sim_fpu_printn_fpu (const sim_fpu *f,
+ sim_fpu_print_func *print,
+ int digits,
+ void *arg)
+ {
print (arg, "%s", f->sign ? "-" : "+");
switch (f->class)
{
case sim_fpu_class_qnan:
print (arg, "0.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, digits, print, arg);
print (arg, "*QuietNaN");
break;
case sim_fpu_class_snan:
print (arg, "0.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, digits, print, arg);
print (arg, "*SignalNaN");
break;
case sim_fpu_class_zero:
***************
*** 2499,2505 ****
case sim_fpu_class_number:
case sim_fpu_class_denorm:
print (arg, "1.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, print, arg);
print (arg, "*2^%+-5d", f->normal_exp);
ASSERT (f->fraction >= IMPLICIT_1);
ASSERT (f->fraction < IMPLICIT_2);
--- 2488,2494 ----
case sim_fpu_class_number:
case sim_fpu_class_denorm:
print (arg, "1.");
! print_bits (f->fraction, NR_FRAC_GUARD - 1, digits, print, arg);
print (arg, "*2^%+-5d", f->normal_exp);
ASSERT (f->fraction >= IMPLICIT_1);
ASSERT (f->fraction < IMPLICIT_2);