This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[rfc/rfa] Almost eliminate HOST_{FLOAT,DOUBLE,...}_FORMAT


Hello,

Attached is a revised patch to defs.h and findvar.c to reduce the 
dependency on host floating point formats.

This patch changes GDB so that, if the host configury didn't specify the 
floating point format, it will fall back immediatly to floatformat_*(). 
  Previously, GDB would assume that the HOST had IEEE FP and try to use 
that.

For hosts that don't specify a HOST_*_FORMAT, this will mean a loss of 
FP precision when using GDB :-/

As an accidental side effect, this eliminates the problem where, if the 
the host/target both forgot to specify their long-double format/size, 
the code would assume that they were identical and do really bizare things.

	Andrew

PS: If you haven't figured it out, I'm tring to eliminate xm.h and 
(gasp) nm.h for at least one platform.
2001-06-29  Andrew Cagney  <ac131313@redhat.com>

	* defs.h (HOST_FLOAT_FORMAT): Delete macro.
	(HOST_DOUBLE_FORMAT): Ditto.
	(HOST_LONG_DOUBLE_FORMAT): Ditto.
	* findvar.c (extract_floating): Only use HOST_FLOAT_FORMAT,
	HOST_DOUBLE_FORMAT and HOST_LONG_DOUBLE_FORMAT when defined.
	(store_floating): Ditto.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.56
diff -p -r1.56 defs.h
*** defs.h	2001/06/28 04:31:36	1.56
--- defs.h	2001/06/29 17:08:20
*************** extern void store_address (void *, int, 
*** 1267,1303 ****
  
  extern void store_typed_address (void *buf, struct type *type, CORE_ADDR addr);
  
! /* Setup definitions for host and target floating point formats.  We need to
!    consider the format for `float', `double', and `long double' for both target
!    and host.  We need to do this so that we know what kind of conversions need
!    to be done when converting target numbers to and from the hosts DOUBLEST
!    data type.  */
  
- /* This is used to indicate that we don't know the format of the floating point
-    number.  Typically, this is useful for native ports, where the actual format
-    is irrelevant, since no conversions will be taking place.  */
- 
  extern const struct floatformat floatformat_unknown;
- 
- #if HOST_BYTE_ORDER == BIG_ENDIAN
- #ifndef HOST_FLOAT_FORMAT
- #define HOST_FLOAT_FORMAT &floatformat_ieee_single_big
- #endif
- #ifndef HOST_DOUBLE_FORMAT
- #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_big
- #endif
- #else /* LITTLE_ENDIAN */
- #ifndef HOST_FLOAT_FORMAT
- #define HOST_FLOAT_FORMAT &floatformat_ieee_single_little
- #endif
- #ifndef HOST_DOUBLE_FORMAT
- #define HOST_DOUBLE_FORMAT &floatformat_ieee_double_little
- #endif
- #endif
- 
- #ifndef HOST_LONG_DOUBLE_FORMAT
- #define HOST_LONG_DOUBLE_FORMAT &floatformat_unknown
- #endif
  
  /* Use `long double' if the host compiler supports it.  (Note that this is not
     necessarily any longer than `double'.  On SunOS/gcc, it's the same as
--- 1267,1276 ----
  
  extern void store_typed_address (void *buf, struct type *type, CORE_ADDR addr);
  
! /* This is used to indicate that we don't know the format of the
!    floating point number.  */
  
  extern const struct floatformat floatformat_unknown;
  
  /* Use `long double' if the host compiler supports it.  (Note that this is not
     necessarily any longer than `double'.  On SunOS/gcc, it's the same as
Index: findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.19
diff -p -r1.19 findvar.c
*** findvar.c	2001/03/06 08:21:07	1.19
--- findvar.c	2001/06/29 17:08:21
*************** extract_floating (void *addr, int len)
*** 304,342 ****
  
    if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
      {
        if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
  	{
  	  float retval;
- 
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
!       else
! 	floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
      {
        if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
  	{
  	  double retval;
- 
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
!       else
! 	floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
      {
        if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
  	{
  	  DOUBLEST retval;
- 
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
!       else
! 	floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
      }
    else
      {
--- 304,342 ----
  
    if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
      {
+ #ifdef HOST_FLOAT_FORMAT
        if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
  	{
  	  float retval;
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
! #endif
!       floatformat_to_doublest (TARGET_FLOAT_FORMAT, addr, &dretval);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
      {
+ #ifdef HOST_DOUBLE_FORMAT
        if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
  	{
  	  double retval;
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
! #endif
!       floatformat_to_doublest (TARGET_DOUBLE_FORMAT, addr, &dretval);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
      {
+ #ifdef HOST_LONG_DOUBLE_FORMAT
        if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
  	{
  	  DOUBLEST retval;
  	  memcpy (&retval, addr, sizeof (retval));
  	  return retval;
  	}
! #endif
!       floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, &dretval);
      }
    else
      {
*************** store_floating (void *addr, int len, DOU
*** 351,382 ****
  {
    if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
      {
        if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
  	{
  	  float floatval = val;
- 
  	  memcpy (addr, &floatval, sizeof (floatval));
  	}
!       else
! 	floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
      {
        if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
  	{
  	  double doubleval = val;
- 
  	  memcpy (addr, &doubleval, sizeof (doubleval));
  	}
!       else
! 	floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
      {
        if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
! 	memcpy (addr, &val, sizeof (val));
!       else
! 	floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
      }
    else
      {
--- 351,388 ----
  {
    if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
      {
+ #ifdef HOST_FLOAT_FORMAT
        if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
  	{
  	  float floatval = val;
  	  memcpy (addr, &floatval, sizeof (floatval));
+ 	  return;
  	}
! #endif
!       floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
      {
+ #ifdef HOST_DOUBLE_FORMAT
        if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
  	{
  	  double doubleval = val;
  	  memcpy (addr, &doubleval, sizeof (doubleval));
+ 	  return;
  	}
! #endif
!       floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
      }
    else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
      {
+ #ifdef HOST_LONG_DOUBLE_FORMAT
        if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
! 	{
! 	  memcpy (addr, &val, sizeof (val));
! 	  return;
! 	}
! #endif
!       floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
      }
    else
      {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]