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]
Other format: [Raw text]

Re: [patch/rfc] Add host's floatformat


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.


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