This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [patch/rfc] Add host's floatformat
- From: DJ Delorie <dj at redhat dot com>
- To: cagney at gnu dot org
- Cc: binutils at sources dot redhat dot com, gdb-patches at sources dot redhat dot com
- Date: Sat, 1 May 2004 23:12:28 -0400
- Subject: Re: [patch/rfc] Add host's floatformat
- References: <40939DD4.3000706@gnu.org> <4093DC36.9040304@gnu.org>
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.