public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch/rfc] Add host's floatformat
@ 2004-05-01 12:53 Andrew Cagney
  2004-05-01 13:25 ` DJ Delorie
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-05-01 12:53 UTC (permalink / raw)
  To: binutils, gdb-patches, dj

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

Hello,

This patch adds the host's floatformat (when known) to floatformat.[hc]. 
  It lets us wack of a heap of bogus code in GDB's configury.

DJ, any comments?  I'll need to double commit.

Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 3139 bytes --]

2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* configure.ac: Define HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT, and
	HOST_LONG_DOUBLE_FORMAT.
	* configure, config.in: Re-generate.
	* floatformat.c (floatformat_float, floatformat_double)
	(floatformat_long_double): 

Index: include/ChangeLog
2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* floatformat.h (floatformat_float, floatformat_double)
	(floatformat_long_double): Declare.

Index: libiberty/configure.ac
===================================================================
RCS file: /cvs/src/src/libiberty/configure.ac,v
retrieving revision 1.6
diff -p -u -r1.6 configure.ac
--- libiberty/configure.ac	26 Apr 2004 18:23:59 -0000	1.6
+++ libiberty/configure.ac	1 May 2004 12:46:58 -0000
@@ -520,6 +520,28 @@ case "${host}" in
 esac
 AC_SUBST(pexecute)
 
+# Figure out which floatformat to use.
+case "${host}" in
+i[34567]86-*-*)
+	host_float_format="&floatformat_ieee_single_little"
+	host_double_format="&floatformat_ieee_double_little"
+	host_long_double_format="&floatformat_i387_ext"
+	;;
+hppa*-*-linux*)
+	host_float_format="&floatformat_ieee_single_big"
+	host_double_format="&floatformat_ieee_double_big"
+	host_long_double_format="&floatformat_ieee_double_big"
+	;;
+*)
+	host_float_format=0
+	host_double_format=0
+	host_long_double_format=0
+	;;
+esac
+AC_DEFINE_UNQUOTED(HOST_FLOAT_FORMAT,$host_float_format,[Host float floatformat])
+AC_DEFINE_UNQUOTED(HOST_DOUBLE_FORMAT,$host_double_format,[Host double floatformat])
+AC_DEFINE_UNQUOTED(HOST_LONG_DOUBLE_FORMAT,$host_long_double_format,[Host long double floatformat])
+
 libiberty_AC_FUNC_STRNCMP
 
 # Install a library built with a cross compiler in $(tooldir) rather
Index: libiberty/floatformat.c
===================================================================
RCS file: /cvs/src/src/libiberty/floatformat.c,v
retrieving revision 1.12
diff -p -u -r1.12 floatformat.c
--- libiberty/floatformat.c	3 Dec 2003 19:03:29 -0000	1.12
+++ libiberty/floatformat.c	1 May 2004 12:46:58 -0000
@@ -548,6 +548,10 @@ floatformat_is_valid (fmt, from)
   return fmt->is_valid (fmt, from);
 }
 
+/* If non-NULL, the host's floatformat.  */
+const struct floatformat *const floatformat_float = HOST_FLOAT_FORMAT;
+const struct floatformat *const floatformat_double = HOST_DOUBLE_FORMAT;
+const struct floatformat *const floatformat_long_double = HOST_LONG_DOUBLE_FORMAT;
 
 #ifdef IEEE_DEBUG
 
Index: include/floatformat.h
===================================================================
RCS file: /cvs/src/src/include/floatformat.h,v
retrieving revision 1.9
diff -p -u -r1.9 floatformat.h
--- include/floatformat.h	22 Sep 2003 17:41:02 -0000	1.9
+++ include/floatformat.h	1 May 2004 12:47:00 -0000
@@ -130,4 +130,9 @@ floatformat_from_double PARAMS ((const s
 extern int
 floatformat_is_valid PARAMS ((const struct floatformat *fmt, const char *from));
 
+/* If non-NULL, the host's floatformat.  */
+extern const struct floatformat *const floatformat_float;
+extern const struct floatformat *const floatformat_double;
+extern const struct floatformat *const floatformat_long_double;
+
 #endif	/* defined (FLOATFORMAT_H) */

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 12:53 [patch/rfc] Add host's floatformat Andrew Cagney
@ 2004-05-01 13:25 ` DJ Delorie
  2004-05-01 14:27   ` Andrew Cagney
  2004-05-01 14:06 ` Andreas Schwab
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: DJ Delorie @ 2004-05-01 13:25 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


> This patch adds the host's floatformat (when known) to floatformat.[hc]. 

Since we *are* the host, don't we *always* know what the host't float
format is?  I mean, we can just cast to float.  But still, we should
be able to auto-detect which floatformat is used at runtime, rather
than guess in configure (and miss lots of host processors).

We should be able to have a pre-compiled table of float constants and
their hex representations, and just scan the table for bit equality to
see which entries match.

It might be a bit more complex to code the first time around, but it
will be a lot less hackish in the long run (and maintenance-free :)

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 12:53 [patch/rfc] Add host's floatformat Andrew Cagney
  2004-05-01 13:25 ` DJ Delorie
@ 2004-05-01 14:06 ` Andreas Schwab
  2004-05-01 14:34 ` Mark Kettenis
  2004-05-01 17:20 ` Andrew Cagney
  3 siblings, 0 replies; 23+ messages in thread
From: Andreas Schwab @ 2004-05-01 14:06 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: binutils, gdb-patches, dj

Andrew Cagney <cagney@gnu.org> writes:

> +# Figure out which floatformat to use.
> +case "${host}" in
> +i[34567]86-*-*)
> +	host_float_format="&floatformat_ieee_single_little"
> +	host_double_format="&floatformat_ieee_double_little"
> +	host_long_double_format="&floatformat_i387_ext"
> +	;;
> +hppa*-*-linux*)
> +	host_float_format="&floatformat_ieee_single_big"
> +	host_double_format="&floatformat_ieee_double_big"
> +	host_long_double_format="&floatformat_ieee_double_big"
> +	;;
  +m68*-*-*)
  +	host_float_format="&floatformat_ieee_single_big"
  +	host_double_format="&floatformat_ieee_double_big"
  +	host_long_double_format="&floatformat_m68881_ext"
  +	;;

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 13:25 ` DJ Delorie
@ 2004-05-01 14:27   ` Andrew Cagney
  0 siblings, 0 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-05-01 14:27 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils, gdb-patches

>>This patch adds the host's floatformat (when known) to floatformat.[hc]. 
> 
> 
> Since we *are* the host, don't we *always* know what the host't float
> format is?  I mean, we can just cast to float.  But still, we should
> be able to auto-detect which floatformat is used at runtime, rather
> than guess in configure (and miss lots of host processors).
> 
> We should be able to have a pre-compiled table of float constants and
> their hex representations, and just scan the table for bit equality to
> see which entries match.
> 
> It might be a bit more complex to code the first time around, but it
> will be a lot less hackish in the long run (and maintenance-free :)

The patch, which is effectively lifed from GDB's code base has been 
working well.  However, I'll change those variables to functions so that 
the possability you describe can be easily implemented.

Andrew


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 12:53 [patch/rfc] Add host's floatformat Andrew Cagney
  2004-05-01 13:25 ` DJ Delorie
  2004-05-01 14:06 ` Andreas Schwab
@ 2004-05-01 14:34 ` Mark Kettenis
  2004-05-01 15:00   ` Andrew Cagney
  2004-05-01 17:20 ` Andrew Cagney
  3 siblings, 1 reply; 23+ messages in thread
From: Mark Kettenis @ 2004-05-01 14:34 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches, dj

   Date: Sat, 01 May 2004 08:53:40 -0400
   From: Andrew Cagney <cagney@gnu.org>

   Hello,

   This patch adds the host's floatformat (when known) to floatformat.[hc]. 
   It lets us wack of a heap of bogus code in GDB's configury.

Hmm.  I'm all for whacking the xm-*.h files, but isn't it better to
keep this local to GDB instead of stuffing it into libiberty?  If so,
we should probably put most of the stuff in configure.host, such that
we can avoid regenerating configure when updating the float support.

   DJ, any comments?  I'll need to double commit.

As for DJ's comments: yes a lookup table to determine things at
runtime would be better, but implementing that needs some serious
work.

Mark

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 14:34 ` Mark Kettenis
@ 2004-05-01 15:00   ` Andrew Cagney
  0 siblings, 0 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-05-01 15:00 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: binutils, gdb-patches, dj

> Date: Sat, 01 May 2004 08:53:40 -0400
>    From: Andrew Cagney <cagney@gnu.org>
> 
>    Hello,
> 
>    This patch adds the host's floatformat (when known) to floatformat.[hc]. 
>    It lets us wack of a heap of bogus code in GDB's configury.
> 
> Hmm.  I'm all for whacking the xm-*.h files, but isn't it better to
> keep this local to GDB instead of stuffing it into libiberty?  If so,
> we should probably put most of the stuff in configure.host, such that
> we can avoid regenerating configure when updating the float support.

Why?

It's a natural extension for liberty's floatformat database - knowledge 
of the host's formats.

As for autoconf, libiberty's using 2.5x so that (unlike with GDB) is a 
non-issue.

Andrew


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 12:53 [patch/rfc] Add host's floatformat Andrew Cagney
                   ` (2 preceding siblings ...)
  2004-05-01 14:34 ` Mark Kettenis
@ 2004-05-01 17:20 ` Andrew Cagney
  2004-05-02 10:04   ` Mark Kettenis
                     ` (2 more replies)
  3 siblings, 3 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-05-01 17:20 UTC (permalink / raw)
  To: binutils, gdb-patches; +Cc: dj

[-- Attachment #1: Type: text/plain, Size: 134 bytes --]

Here's a revised patch:

- uses functions instead of variables
- adds m68k
- adds _host_ to the function names

more comments?
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 6305 bytes --]

Index: include/ChangeLog
2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* floatformat.h (floatformat_host_float, floatformat_host_double)
	(floatformat_host_long_double): Declare.

Index: libiberty/ChangeLog
2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* configure.ac: Define HOST_FLOAT_FORMAT, HOST_DOUBLE_FORMAT, and
	HOST_LONG_DOUBLE_FORMAT.
	* configure, config.in: Re-generate.
	* floatformat.c (floatformat_host_float, floatformat_host_double)
	(floatformat_host_long_double): New functions.

Index: include/floatformat.h
===================================================================
RCS file: /cvs/src/src/include/floatformat.h,v
retrieving revision 1.9
diff -p -u -r1.9 floatformat.h
--- include/floatformat.h	22 Sep 2003 17:41:02 -0000	1.9
+++ include/floatformat.h	1 May 2004 17:17:36 -0000
@@ -1,5 +1,7 @@
 /* IEEE floating point support declarations, for GDB, the GNU Debugger.
-   Copyright 1991, 1994, 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
+
+   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2004 Free Software
+   Foundation, Inc.
 
 This file is part of GDB.
 
@@ -129,5 +131,11 @@ floatformat_from_double PARAMS ((const s
 
 extern int
 floatformat_is_valid PARAMS ((const struct floatformat *fmt, const char *from));
+
+/* If non-NULL, the host's floatformat corresponding to the compilers
+   "float", "double" and "long double" types.  */
+extern const struct floatformat *floatformat_host_float PARAMS ((void));
+extern const struct floatformat *floatformat_host_double PARAMS ((void));
+extern const struct floatformat *floatformat_host_long_double PARAMS ((void));
 
 #endif	/* defined (FLOATFORMAT_H) */
Index: libiberty/config.in
===================================================================
RCS file: /cvs/src/src/libiberty/config.in,v
retrieving revision 1.26
diff -p -u -r1.26 config.in
--- libiberty/config.in	22 Apr 2004 18:39:02 -0000	1.26
+++ libiberty/config.in	1 May 2004 17:17:43 -0000
@@ -313,6 +313,15 @@
 /* Define if you have the _system_configuration variable. */
 #undef HAVE__SYSTEM_CONFIGURATION
 
+/* Host double floatformat */
+#undef HOST_DOUBLE_FORMAT
+
+/* Host float floatformat */
+#undef HOST_FLOAT_FORMAT
+
+/* Host long double floatformat */
+#undef HOST_LONG_DOUBLE_FORMAT
+
 /* Define if the host machine stores words of multi-word integers in
    big-endian order. */
 #undef HOST_WORDS_BIG_ENDIAN
Index: libiberty/configure
===================================================================
RCS file: /cvs/src/src/libiberty/configure,v
retrieving revision 1.58
diff -p -u -r1.58 configure
--- libiberty/configure	26 Apr 2004 18:23:59 -0000	1.58
+++ libiberty/configure	1 May 2004 17:17:47 -0000
@@ -6293,6 +6293,45 @@ case "${host}" in
 esac
 
 
+# Figure out which floatformat to use.
+case "${host}" in
+i3456786-*-*)
+	host_float_format="&floatformat_ieee_single_little"
+	host_double_format="&floatformat_ieee_double_little"
+	host_long_double_format="&floatformat_i387_ext"
+	;;
+hppa*-*-linux*)
+	host_float_format="&floatformat_ieee_single_big"
+	host_double_format="&floatformat_ieee_double_big"
+	host_long_double_format="&floatformat_ieee_double_big"
+	;;
+m68*-*-*)
+	host_float_format="&floatformat_ieee_single_big"
+	host_double_format="&floatformat_ieee_double_big"
+	host_long_double_format="&floatformat_m68881_ext"
+	;;
+*)
+	host_float_format=0
+	host_double_format=0
+	host_long_double_format=0
+	;;
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define HOST_FLOAT_FORMAT $host_float_format
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HOST_DOUBLE_FORMAT $host_double_format
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HOST_LONG_DOUBLE_FORMAT $host_long_double_format
+_ACEOF
+
+
 if test x$gcc_no_link = xyes; then
   if test "x${ac_cv_func_mmap_fixed_mapped+set}" != xset; then
     ac_cv_func_mmap_fixed_mapped=no
Index: libiberty/configure.ac
===================================================================
RCS file: /cvs/src/src/libiberty/configure.ac,v
retrieving revision 1.6
diff -p -u -r1.6 configure.ac
--- libiberty/configure.ac	26 Apr 2004 18:23:59 -0000	1.6
+++ libiberty/configure.ac	1 May 2004 17:17:47 -0000
@@ -520,6 +520,33 @@ case "${host}" in
 esac
 AC_SUBST(pexecute)
 
+# Figure out which floatformat to use.
+case "${host}" in
+i[34567]86-*-*)
+	host_float_format="&floatformat_ieee_single_little"
+	host_double_format="&floatformat_ieee_double_little"
+	host_long_double_format="&floatformat_i387_ext"
+	;;
+hppa*-*-linux*)
+	host_float_format="&floatformat_ieee_single_big"
+	host_double_format="&floatformat_ieee_double_big"
+	host_long_double_format="&floatformat_ieee_double_big"
+	;;
+m68*-*-*)
+	host_float_format="&floatformat_ieee_single_big"
+	host_double_format="&floatformat_ieee_double_big"
+	host_long_double_format="&floatformat_m68881_ext"
+	;;
+*)
+	host_float_format=0
+	host_double_format=0
+	host_long_double_format=0
+	;;
+esac
+AC_DEFINE_UNQUOTED(HOST_FLOAT_FORMAT,$host_float_format,[Host float floatformat])
+AC_DEFINE_UNQUOTED(HOST_DOUBLE_FORMAT,$host_double_format,[Host double floatformat])
+AC_DEFINE_UNQUOTED(HOST_LONG_DOUBLE_FORMAT,$host_long_double_format,[Host long double floatformat])
+
 libiberty_AC_FUNC_STRNCMP
 
 # Install a library built with a cross compiler in $(tooldir) rather
Index: libiberty/floatformat.c
===================================================================
RCS file: /cvs/src/src/libiberty/floatformat.c,v
retrieving revision 1.12
diff -p -u -r1.12 floatformat.c
--- libiberty/floatformat.c	3 Dec 2003 19:03:29 -0000	1.12
+++ libiberty/floatformat.c	1 May 2004 17:17:47 -0000
@@ -1,5 +1,7 @@
 /* IEEE floating point support routines, for GDB, the GNU Debugger.
-   Copyright (C) 1991, 1994, 1999, 2000, 2003 Free Software Foundation, Inc.
+
+   Copyright 1991, 1994, 1999, 2000, 2003, 2004 Free Software
+   Foundation, Inc.
 
 This file is part of GDB.
 
@@ -548,6 +550,24 @@ floatformat_is_valid (fmt, from)
   return fmt->is_valid (fmt, from);
 }
 
+/* If non-NULL, the host's floatformat.  */
+const struct floatformat *
+floatformat_host_float ()
+{
+  return HOST_FLOAT_FORMAT;
+}
+
+const struct floatformat *
+floatformat_host_double ()
+{
+  return HOST_DOUBLE_FORMAT;
+}
+
+const struct floatformat *
+floatformat_host_long_double ()
+{
+  return HOST_LONG_DOUBLE_FORMAT;
+}
 
 #ifdef IEEE_DEBUG
 

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 17:20 ` Andrew Cagney
@ 2004-05-02 10:04   ` Mark Kettenis
  2004-05-02 20:49   ` DJ Delorie
  2004-05-02 20:49   ` DJ Delorie
  2 siblings, 0 replies; 23+ messages in thread
From: Mark Kettenis @ 2004-05-02 10:04 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches, dj

   Date: Sat, 01 May 2004 13:19:50 -0400
   From: Andrew Cagney <cagney@gnu.org>

   Here's a revised patch:

   - uses functions instead of variables
   - adds m68k
   - adds _host_ to the function names

   more comments?

Yup.  The i[34567]86 isn't properly quoted in configure.ac.

Mark

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 17:20 ` Andrew Cagney
  2004-05-02 10:04   ` Mark Kettenis
  2004-05-02 20:49   ` DJ Delorie
@ 2004-05-02 20:49   ` DJ Delorie
  2 siblings, 0 replies; 23+ messages in thread
From: DJ Delorie @ 2004-05-02 20:49 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


Also, please CC gcc-patches@gcc.gnu.org for libiberty patches.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-01 17:20 ` Andrew Cagney
  2004-05-02 10:04   ` Mark Kettenis
@ 2004-05-02 20:49   ` DJ Delorie
  2004-05-03 19:11     ` Andrew Cagney
  2004-05-02 20:49   ` DJ Delorie
  2 siblings, 1 reply; 23+ messages in thread
From: DJ Delorie @ 2004-05-02 20:49 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


Minor request: the functions should have "get" in there somewhere,
such as "floatformat_get_host_float" or "get_host_float_floatformat"
or something.  I can be talked out of this, though.

As for the code, I was thinking of something like this (probably got
the bit patterns wrong):

struct {
  float f;
  int size;
  unsigned char bits[8]; /* Expand as needed.  */
  const struct floatformat *ff;
} host_floats[] = {
  { 1.0, 4, {0x3f, 0xff, 0x00, 0x00, 0, 0, 0, 0 }, &floatformat_ieee_single_little },
  { 1.0, 4, {0x00, 0x00, 0xff, 0x3f, 0, 0, 0, 0 }, &floatformat_ieee_single_big }
  /* Fill in more as needed, choosing values to ensure uniqueness.  */
};

const struct floatformat *
floatformat_host_float ()
{
  static floatformat *ff = 0;
  static int ff_set = 0;

  if (!ff_set)
    {
      int i;
      ff_set = 1;
      for (i=0; i<sizeof(host_floats)/sizeof(host_floats[0]); i++)
        {
	  if (sizeof(float) == host_floats[i].size
              && memcmp (host_floats[i].f, host_floats[i].bits, sizeof(float)) == 0)
	    {
	      ff = host_floats[i].ff;
	      break;
	    }
        }
    }
  return ff;
}

We'd have to put in suitable #ifdefs for the long double cases, of course.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-02 20:49   ` DJ Delorie
@ 2004-05-03 19:11     ` Andrew Cagney
  2004-05-03 22:11       ` DJ Delorie
  0 siblings, 1 reply; 23+ messages in thread
From: Andrew Cagney @ 2004-05-03 19:11 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

> Minor request: the functions should have "get" in there somewhere,
> such as "floatformat_get_host_float" or "get_host_float_floatformat"
> or something.  I can be talked out of this, though.

Per the attached, it looks too verbose.  'nuf talking?

> As for the code, I was thinking of something like this (probably got
> the bit patterns wrong):

Like this?  I feel ill.

Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 5287 bytes --]

Index: include/ChangeLog
2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* floatformat.h (floatformat_get_host_float)
	(floatformat_get_host_double)
	(floatformat_get_host_long_double): Declare.

Index: libiberty/ChangeLog
2004-04-30  Andrew Cagney  <cagney@redhat.com>

	* configure.ac: Define HOST_LONG_DOUBLE.
	* configure, config.in: Re-generate.
	* floatformat.c (struct host_format, struct probe_state)
	(probe_host_format, floatformat_get_host_float)
	(floatformat_get_host_double, floatformat_get_host_long_double):
	New.  Find/return the floatformat corresponding to the host's
	float, double and long double types.

Index: include/floatformat.h
===================================================================
RCS file: /cvs/src/src/include/floatformat.h,v
retrieving revision 1.9
diff -p -u -r1.9 floatformat.h
--- include/floatformat.h	22 Sep 2003 17:41:02 -0000	1.9
+++ include/floatformat.h	3 May 2004 19:08:02 -0000
@@ -1,5 +1,7 @@
 /* IEEE floating point support declarations, for GDB, the GNU Debugger.
-   Copyright 1991, 1994, 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
+
+   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2004 Free Software
+   Foundation, Inc.
 
 This file is part of GDB.
 
@@ -129,5 +131,11 @@ floatformat_from_double PARAMS ((const s
 
 extern int
 floatformat_is_valid PARAMS ((const struct floatformat *fmt, const char *from));
+
+/* If non-NULL, the host's floatformat corresponding to the compilers
+   "float", "double" and "long double" types.  */
+extern const struct floatformat *floatformat_get_host_float PARAMS ((void));
+extern const struct floatformat *floatformat_get_host_double PARAMS ((void));
+extern const struct floatformat *floatformat_get_host_long_double PARAMS ((void));
 
 #endif	/* defined (FLOATFORMAT_H) */
Index: libiberty/configure.ac
===================================================================
RCS file: /cvs/src/src/libiberty/configure.ac,v
retrieving revision 1.6
diff -p -u -r1.6 configure.ac
--- libiberty/configure.ac	26 Apr 2004 18:23:59 -0000	1.6
+++ libiberty/configure.ac	3 May 2004 19:08:04 -0000
@@ -520,6 +520,18 @@ case "${host}" in
 esac
 AC_SUBST(pexecute)
 
+dnl See if compiler supports "long double" type.  Can't use AC_C_LONG_DOUBLE
+dnl because autoconf complains about cross-compilation issues.  However, this
+dnl code uses the same variables as the macro for compatibility.
+AC_MSG_CHECKING(for long double support in compiler)
+AC_CACHE_VAL(ac_cv_c_long_double,
+[AC_TRY_COMPILE(, [long double foo;],
+ac_cv_c_long_double=yes, ac_cv_c_long_double=no)])
+AC_MSG_RESULT($ac_cv_c_long_double)
+if test $ac_cv_c_long_double = yes; then
+  AC_DEFINE(HAVE_LONG_DOUBLE)
+fi
+
 libiberty_AC_FUNC_STRNCMP
 
 # Install a library built with a cross compiler in $(tooldir) rather
Index: libiberty/floatformat.c
===================================================================
RCS file: /cvs/src/src/libiberty/floatformat.c,v
retrieving revision 1.12
diff -p -u -r1.12 floatformat.c
--- libiberty/floatformat.c	3 Dec 2003 19:03:29 -0000	1.12
+++ libiberty/floatformat.c	3 May 2004 19:08:04 -0000
@@ -1,5 +1,7 @@
 /* IEEE floating point support routines, for GDB, the GNU Debugger.
-   Copyright (C) 1991, 1994, 1999, 2000, 2003 Free Software Foundation, Inc.
+
+   Copyright 1991, 1994, 1999, 2000, 2003, 2004 Free Software
+   Foundation, Inc.
 
 This file is part of GDB.
 
@@ -548,6 +550,78 @@ floatformat_is_valid (fmt, from)
   return fmt->is_valid (fmt, from);
 }
 
+/* If non-NULL, the host's floatformat.  */
+
+struct host_format
+{
+  long size;
+  const struct floatformat *ff;
+  /* Use "(gdb) x/16ob &val" to get the value.  */
+  const char *bits;
+};
+
+struct probe_state
+{
+  int probed;
+  const struct floatformat *ff;
+};
+
+static const struct floatformat *
+probe_host_format (struct probe_state *state, const void *one, long sizeof_one)
+{
+  static struct host_format host_one[] = {
+    { 4, &floatformat_ieee_single_big, "\77\200\0\0" },
+    { 4, &floatformat_ieee_single_little, "\0\0\200\77" },
+    { 8, &floatformat_ieee_double_big, "\77\360\0\0\0\0\0\0" },
+    { 8, &floatformat_ieee_double_little, "\0\0\0\0\0\0\360\77" },
+    { 16, &floatformat_i387_ext, "\0\0\0\0\0\0\0\200\377\77\0\0\0\0\0\0" },
+    { 0, NULL, NULL }
+  };
+  if (!state->probed)
+    {
+      const struct host_format *ff;
+
+      state->probed = 1;
+      for (ff = host_one; ff->ff != NULL; ff++)
+	{
+	  if (sizeof_one == ff->size
+	      && memcmp (one, ff->bits, sizeof_one) == 0)
+	    {
+	      state->ff = ff->ff;
+	      break;
+	    }
+	}
+    }
+  return state->ff;
+}
+
+const struct floatformat *
+floatformat_get_host_float ()
+{
+  static float one = 1.0;
+  static struct probe_state probe_state;
+  return probe_host_format (&probe_state, &one, sizeof (one));
+}
+
+const struct floatformat *
+floatformat_get_host_double ()
+{
+  static double one = 1.0;
+  static struct probe_state probe_state;
+  return probe_host_format (&probe_state, &one, sizeof (one));
+}
+
+const struct floatformat *
+floatformat_get_host_long_double ()
+{
+#if HAVE_LONG_DOUBLE
+  static long double one = 1.0;
+  static struct probe_state probe_state;
+  return probe_host_format (&probe_state, &one, sizeof (one));
+#else
+  return NULL;
+#endif
+}
 
 #ifdef IEEE_DEBUG
 

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 19:11     ` Andrew Cagney
@ 2004-05-03 22:11       ` DJ Delorie
  2004-05-03 22:29         ` Zack Weinberg
  2004-05-03 22:37         ` Andrew Cagney
  0 siblings, 2 replies; 23+ messages in thread
From: DJ Delorie @ 2004-05-03 22:11 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


> Like this?  I feel ill.

One problem with your approach is that "1.0" may not be a suitable
pattern to match for every FPU.  I left the test constant in the
structure because some FPUs may need more esoteric patterns to
differentiate themselves from other FPUs.  Hence the comment about
keeping them in order, too.

Again, libiberty patches must be posted to gcc-patches@gcc.gnu.org as
well as wherever else.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:11       ` DJ Delorie
@ 2004-05-03 22:29         ` Zack Weinberg
  2004-05-03 22:34           ` DJ Delorie
  2004-05-03 22:37         ` Andrew Cagney
  1 sibling, 1 reply; 23+ messages in thread
From: Zack Weinberg @ 2004-05-03 22:29 UTC (permalink / raw)
  To: DJ Delorie; +Cc: cagney, binutils, gdb-patches

DJ Delorie <dj@redhat.com> writes:

>> Like this?  I feel ill.
>
> One problem with your approach is that "1.0" may not be a suitable
> pattern to match for every FPU.  I left the test constant in the
> structure because some FPUs may need more esoteric patterns to
> differentiate themselves from other FPUs.  Hence the comment about
> keeping them in order, too.

Really, I don't see why this is better than a hardwired table mapping
CPU to floating point format.  You gotta have that for the target side
anyway.

zw

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:29         ` Zack Weinberg
@ 2004-05-03 22:34           ` DJ Delorie
  2004-07-26 21:12             ` Andrew Cagney
  0 siblings, 1 reply; 23+ messages in thread
From: DJ Delorie @ 2004-05-03 22:34 UTC (permalink / raw)
  To: zack; +Cc: cagney, binutils, gdb-patches


> Really, I don't see why this is better than a hardwired table
> mapping CPU to floating point format.

Because most FPUs are IEEE, so except for the ones that aren't, it
will auto-detect the FPU type.  Having a table means that CPUs default
to "broken", rather than defaulting to "probably works".

It also means we don't have to keep tweaking the table as people
change their minds about CPU naming schemes.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:11       ` DJ Delorie
  2004-05-03 22:29         ` Zack Weinberg
@ 2004-05-03 22:37         ` Andrew Cagney
  2004-05-03 22:44           ` DJ Delorie
  1 sibling, 1 reply; 23+ messages in thread
From: Andrew Cagney @ 2004-05-03 22:37 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils, gdb-patches

>>Like this?  I feel ill.
> 
> 
> One problem with your approach is that "1.0" may not be a suitable
> pattern to match for every FPU.  I left the test constant in the
> structure because some FPUs may need more esoteric patterns to
> differentiate themselves from other FPUs.  Hence the comment about
> keeping them in order, too.

Er, this pattern matching idea is your approach, not mine.  I'd rather 
just stick with configure.ac.  If there really is a problem such as you 
describe then surely the person that encounters that problem gets to fix it.

Andrew


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:37         ` Andrew Cagney
@ 2004-05-03 22:44           ` DJ Delorie
  2004-05-03 23:21             ` Andrew Cagney
  0 siblings, 1 reply; 23+ messages in thread
From: DJ Delorie @ 2004-05-03 22:44 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


> Er, this pattern matching idea is your approach, not mine.  I'd
> rather just stick with configure.ac.

And I offered a function that implemented it, too.  Why did you invent
a different one?

> If there really is a problem such as you describe then surely the
> person that encounters that problem gets to fix it.

Er, no.  The person who causes the problem gets to fix it.  Especially
when the problem is known beforehand, a workable solution is offered,
and you choose otherwise anyway.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:44           ` DJ Delorie
@ 2004-05-03 23:21             ` Andrew Cagney
  2004-05-03 23:48               ` DJ Delorie
  0 siblings, 1 reply; 23+ messages in thread
From: Andrew Cagney @ 2004-05-03 23:21 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils, gdb-patches

>>If there really is a problem such as you describe then surely the
>>> person that encounters that problem gets to fix it.
> 
> 
> Er, no.  The person who causes the problem gets to fix it.  Especially
> when the problem is known beforehand, a workable solution is offered,
> and you choose otherwise anyway.

Please point me at a case that doesn't work.

Andrew


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 23:21             ` Andrew Cagney
@ 2004-05-03 23:48               ` DJ Delorie
  2004-05-03 23:58                 ` Zack Weinberg
  2004-05-05 16:32                 ` Andrew Cagney
  0 siblings, 2 replies; 23+ messages in thread
From: DJ Delorie @ 2004-05-03 23:48 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


> > Er, no.  The person who causes the problem gets to fix it.  Especially
> > when the problem is known beforehand, a workable solution is offered,
> > and you choose otherwise anyway.
> 
> Please point me at a case that doesn't work.

I can't think of a concrete example off the top of my head, but then
again, that rationalizing would have me set IEEE as the default and
use configure.ac only to override it.

Although the playstation 2's FPU is just like IEEE but with different
denormals.

However, I would have picked a more interesting number if I was going
to use just one, like 0.00207.  That makes more exponent and mantissa
bits interesting.

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 23:48               ` DJ Delorie
@ 2004-05-03 23:58                 ` Zack Weinberg
  2004-05-04 14:11                   ` Andrew Cagney
  2004-05-05 16:32                 ` Andrew Cagney
  1 sibling, 1 reply; 23+ messages in thread
From: Zack Weinberg @ 2004-05-03 23:58 UTC (permalink / raw)
  To: DJ Delorie; +Cc: cagney, binutils, gdb-patches

DJ Delorie <dj@redhat.com> writes:

>> > Er, no.  The person who causes the problem gets to fix it.  Especially
>> > when the problem is known beforehand, a workable solution is offered,
>> > and you choose otherwise anyway.
>> 
>> Please point me at a case that doesn't work.
>
> I can't think of a concrete example off the top of my head, but then
> again, that rationalizing would have me set IEEE as the default and
> use configure.ac only to override it.

That seems sensible to me...

> However, I would have picked a more interesting number if I was going
> to use just one, like 0.00207.  That makes more exponent and mantissa
> bits interesting.

For awhile GCC's configure.in had a table like this -- tuned so that
you could just compile it and grep for strings in the object file.  We
got rid of it (GCC doesn't need to know the host float format anymore)
but it could be dug out of CVS.

zw

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 23:58                 ` Zack Weinberg
@ 2004-05-04 14:11                   ` Andrew Cagney
  0 siblings, 0 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-05-04 14:11 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: DJ Delorie, binutils, gdb-patches

> For awhile GCC's configure.in had a table like this -- tuned so that
> you could just compile it and grep for strings in the object file.  We
> got rid of it (GCC doesn't need to know the host float format anymore)
> but it could be dug out of CVS.

That's on GDB's wish list.  Change things so that it implements the 
inferior's FP (regardless of the host/target combination).  This whole 
thing was intended as a `temporary' hack.

Andrew


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 23:48               ` DJ Delorie
  2004-05-03 23:58                 ` Zack Weinberg
@ 2004-05-05 16:32                 ` Andrew Cagney
  2004-05-05 17:05                   ` DJ Delorie
  1 sibling, 1 reply; 23+ messages in thread
From: Andrew Cagney @ 2004-05-05 16:32 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils, gdb-patches

>>>> > Er, no.  The person who causes the problem gets to fix it.  Especially
>>>> > when the problem is known beforehand, a workable solution is offered,
>>>> > and you choose otherwise anyway.
>>
>>> 
>>> Please point me at a case that doesn't work.
> 
> 
> I can't think of a concrete example off the top of my head, but then
> again, that rationalizing would have me set IEEE as the default and
> use configure.ac only to override it.

So what's wrong with my code then?


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

* Re: [patch/rfc] Add host's floatformat
  2004-05-05 16:32                 ` Andrew Cagney
@ 2004-05-05 17:05                   ` DJ Delorie
  0 siblings, 0 replies; 23+ messages in thread
From: DJ Delorie @ 2004-05-05 17:05 UTC (permalink / raw)
  To: cagney; +Cc: binutils, gdb-patches


> So what's wrong with my code then?

I guess it's OK then, but please post it to gcc-patches@gcc.gnu.org

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

* Re: [patch/rfc] Add host's floatformat
  2004-05-03 22:34           ` DJ Delorie
@ 2004-07-26 21:12             ` Andrew Cagney
  0 siblings, 0 replies; 23+ messages in thread
From: Andrew Cagney @ 2004-07-26 21:12 UTC (permalink / raw)
  To: DJ Delorie; +Cc: zack, binutils, gdb-patches

[picking up a really old thread]

>>Really, I don't see why this is better than a hardwired table
>>> mapping CPU to floating point format.
> 
> 
> Because most FPUs are IEEE, so except for the ones that aren't, it
> will auto-detect the FPU type.  Having a table means that CPUs default
> to "broken", rather than defaulting to "probably works".
> 
> It also means we don't have to keep tweaking the table as people
> change their minds about CPU naming schemes

This assume that the floatformat code works.

Below is a table generated by using floatformat to convert the double 
1.0 into the corresponding architecture format.  Notice the arm_ext_big 
/ arm_littlebyte_bigword and double_big / double_littlebyte_bigword pairs:

3f800000                         floatformat_ieee_single_big
0000803f                         floatformat_ieee_single_little
3ff0000000000000                 floatformat_ieee_double_big
000000000000f03f                 floatformat_ieee_double_little
3ff0000000000000                 floatformat_ieee_double_littlebyte_bigword
0000000000000080ff3f             floatformat_i387_ext
3fff8000000000000000             floatformat_m88110_ext
3fff00008000000000000000         floatformat_m68881_ext
0000000000000080ff3f0000         floatformat_i960_ext
00003fff8000000000000000         floatformat_arm_ext_big
00003fff8000000000000000         floatformat_arm_ext_littlebyte_bigword
3ff00000000000000000000000000000 floatformat_m88110_ext_harris
3fffe000000000000000000000000000 floatformat_ia64_spill_big
00000000000000000000000000e0ff3f floatformat_ia64_spill_little
3fff0000000000000000000000000000 floatformat_ia64_quad_big
0000000000000000000000000000ff3f floatformat_ia64_quad_little

I'm withdrawing my patch.  I'll instead fix this as MarkK suggested - 
local to GDB.

Andrew


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

end of thread, other threads:[~2004-07-26 21:12 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-01 12:53 [patch/rfc] Add host's floatformat Andrew Cagney
2004-05-01 13:25 ` DJ Delorie
2004-05-01 14:27   ` Andrew Cagney
2004-05-01 14:06 ` Andreas Schwab
2004-05-01 14:34 ` Mark Kettenis
2004-05-01 15:00   ` Andrew Cagney
2004-05-01 17:20 ` Andrew Cagney
2004-05-02 10:04   ` Mark Kettenis
2004-05-02 20:49   ` DJ Delorie
2004-05-03 19:11     ` Andrew Cagney
2004-05-03 22:11       ` DJ Delorie
2004-05-03 22:29         ` Zack Weinberg
2004-05-03 22:34           ` DJ Delorie
2004-07-26 21:12             ` Andrew Cagney
2004-05-03 22:37         ` Andrew Cagney
2004-05-03 22:44           ` DJ Delorie
2004-05-03 23:21             ` Andrew Cagney
2004-05-03 23:48               ` DJ Delorie
2004-05-03 23:58                 ` Zack Weinberg
2004-05-04 14:11                   ` Andrew Cagney
2004-05-05 16:32                 ` Andrew Cagney
2004-05-05 17:05                   ` DJ Delorie
2004-05-02 20:49   ` DJ Delorie

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