public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Tracing for floating point values
@ 2000-12-08 14:57 Ben Elliston
  2000-12-14 17:04 ` Andrew Cagney
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Elliston @ 2000-12-08 14:57 UTC (permalink / raw)
  To: CGEN; +Cc: gdb

Currently, the TRACE_RESULTS web of macros/functions in
sim/common/cgen-trace.c don't know how to handle the 'f' printf-type for SF
and DF operands.  Only 'D' and 'x' are handled at present.

I set about fixing this yesterday.  There were two approaches I considered:

	* use the host's native printf %x.  Comments in sim-fpu.[hc]
	  indicate this is a bad mistake.  There's no guarantee that the
	  host will use the same floating point representation as the
	  target.

	* use sim_fpu's sim_fpu_print_fpu to output the real number
	  using cgen_trace_printf as its callback (which works nicely).
	  However, we get very detailed output!

	fr <- +1.0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000*2^+0

Which way seems right to jump?

Ben

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tracing for floating point values
  2000-12-08 14:57 Tracing for floating point values Ben Elliston
@ 2000-12-14 17:04 ` Andrew Cagney
  2000-12-14 17:57   ` Ben Elliston
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2000-12-14 17:04 UTC (permalink / raw)
  To: Ben Elliston; +Cc: CGEN, gdb

Ben Elliston wrote:
> 
> Currently, the TRACE_RESULTS web of macros/functions in
> sim/common/cgen-trace.c don't know how to handle the 'f' printf-type for SF
> and DF operands.  Only 'D' and 'x' are handled at present.
> 
> I set about fixing this yesterday.  There were two approaches I considered:
> 
>         * use the host's native printf %x.  Comments in sim-fpu.[hc]
>           indicate this is a bad mistake.  There's no guarantee that the
>           host will use the same floating point representation as the
>           target.

You would need to be very careful about SNaNs.

>         * use sim_fpu's sim_fpu_print_fpu to output the real number
>           using cgen_trace_printf as its callback (which works nicely).
>           However, we get very detailed output!
> 
>         fr <- +1.0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000*2^+0
> 
> Which way seems right to jump?

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.

	Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tracing for floating point values
  2000-12-14 17:04 ` Andrew Cagney
@ 2000-12-14 17:57   ` Ben Elliston
  0 siblings, 0 replies; 3+ messages in thread
From: Ben Elliston @ 2000-12-14 17:57 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb

   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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-12-14 17:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-08 14:57 Tracing for floating point values Ben Elliston
2000-12-14 17:04 ` Andrew Cagney
2000-12-14 17:57   ` Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).