Floating Pt. Optimize on PA
Mark Klein
mklein@dis.com
Sun Dec 27 10:11:00 GMT 1998
At 05:25 PM 12/25/98 -0700, Jeffrey A Law wrote:
>I didn't do the full analysis, but I'm pretty sure your sample code is bogus.
>
>#define SET_DOUBLE(_t, _addr, _v) \
> ( (_t).d = (_v), \
> ((long*)(_addr))[0] = ((long*) &(_t))[0], \
> ((long*)(_addr))[1] = ((long*) &(_t))[1])
>
>Note that you references the data in "t" via t.d and ((long*) (&_t)[0] which
>produces undefined results according to ANSI.
The guys from Sun want to know:
At 06:21 PM 12/26/98 -0800, Nicholas Sterling wrote:
>Hmmm. I assume you're referring to this statement
>(I took this from K&R's ANSI C book):
>
>
> In general, a member of a union may not be inspected
> unless the value of the union has been assigned using
> that same member.
>
>
>It surprised me to find this, since it's a time-honored trick to write
>to one union member and read from another. It floors me that a
>compiler as popular as gcc is going to cause that to fail now.
>
>
>In any case, this seems to imply that the "right" way to do what we're
>trying to do (access the individual words of a multi-word entity) is to
>assign it to a double and then cast the address OF THAT DOUBLE to long*
>and dereference it. If I'm on the right track with this, then the
>following should work. Simply change
>
>
> #define SET_DOUBLE(_t, _addr, _v) \
> ( (_t).d = (_v), \
> ((long*)(_addr))[0] = ((long*) &(_t))[0], \
> ((long*)(_addr))[1] = ((long*) &(_t))[1])
>
>
>to
>
>
> #define SET_DOUBLE(_t, _addr, _v) \
> ( (_t).d = (_v), \
> ((long*)(_addr))[0] = ((long*) &(_t.d))[0], \
> ((long*)(_addr))[1] = ((long*) &(_t.d))[1])
>
>
>That is, take the address of _t.d rather than simply _t.
The results from the above change are the same ... there is a load word
that attempts to reference the floating point value in the union before
it has been stored into the frame.
If this isn't the case from ANSI that you're citing, would you please
clarify?
Thanks,
M.
--
Mark Klein DIS International, Ltd.
http://www.dis.com 415-892-8400
PGP Public Key Available
More information about the Gcc-bugs
mailing list