Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@cygnus.com>
To: Andrew Cagney <ac131313@cygnus.com>,
	Scott Bambrough <scottb@netwinder.org>
Cc: GDB Mailing List <gdb@sourceware.cygnus.com>
Subject: store_floating() rewrite (was Re: bug in arm_push_arguments())
Date: Mon, 28 Feb 2000 11:02:00 -0000	[thread overview]
Message-ID: <1000228181141.ZM26089@ocotillo.lan> (raw)
In-Reply-To: <38BA642A.6F358273@cygnus.com>

On Feb 28, 11:03pm, Andrew Cagney wrote:

> Kevin Buttner wrote:
> > It seems to me that you should be able to use store_floating() to do
> > what you want.  It'll handle both the conversion and the byte swapping.
> 
> Yes, that looks correct. I'm just not 100% sure on it working - would
> one of those if()'s before the TARGET_EXTRACT_FLOATING() get in the way?
                                 ^^^^^^^^^^^^^^^^^^^^^^^

Did you mean TARGET_STORE_FLOATING?

The part that bothers me about the way that store_floating() is
implemented is that we're comparing the size of the thing we're trying
to store into (on the target) against sizes of the host formats.  I.e,
the following lines bother me.

  if (len == sizeof (float))
  else if (len == sizeof (double))
  else if (len == sizeof (DOUBLEST))

I think we should be comparing against the sizes of the target formats.

Suppose, for example, that we have the following configuration

    host float:		32 bits
    host double		64 bits
    target float	64 bits
    target double	128 bits

and that we enter store_floating with len == 8.

This'll cause us to wind up in the following code:

  else if (len == sizeof (double))
    {
      if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
	{
	  double doubleval = val;

	  memcpy (addr, &doubleval, sizeof (doubleval));
	}
      else
	floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
    }

Because the sizes of the doubles are different, HOST_DOUBLE_FORMAT
will not be the same as TARGET_DOUBLE_FORMAT.  This means that we'll
execute the floatformat_from_doublest call which attempts to store a
(target) double.

But this is wrong since the size of a target double is 16 bytes and we
were attempting to store a floating point value whose size is 8 bytes.

Here is my rewrite of this function:

void
store_floating (void *addr, int len, DOUBLEST val)
{
  if (HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT)
    {
      float floatval = val;

      memcpy (addr, &floatval, sizeof (floatval));
    }
  else if (HOST_DOUBLE_FORMAT == TARGET_DOUBLE_FORMAT)
    {
      double doubleval = val;

      memcpy (addr, &doubleval, sizeof (doubleval));
    }
  else if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
    memcpy (addr, &val, sizeof (val));
  else if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
    floatformat_from_doublest (TARGET_FLOAT_FORMAT, &val, addr);
  else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
    floatformat_from_doublest (TARGET_DOUBLE_FORMAT, &val, addr);
  else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
    floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
#ifdef TARGET_STORE_FLOATING
  else if (TARGET_STORE_FLOATING (addr, len, val))
    return;
#endif 
  else
    error ("Can't deal with a floating point number of %d bytes.", len);
}


  reply	other threads:[~2000-02-28 11:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <38B6C4A1.7A1461C4@netwinder.org>
2000-02-28  4:05 ` bug in arm_push_arguments() Andrew Cagney
2000-02-28 11:02   ` Kevin Buettner [this message]
2000-02-28 11:29     ` store_floating() rewrite (was Re: bug in arm_push_arguments()) Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1000228181141.ZM26089@ocotillo.lan \
    --to=kevinb@cygnus.com \
    --cc=ac131313@cygnus.com \
    --cc=gdb@sourceware.cygnus.com \
    --cc=scottb@netwinder.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox