This is the mail archive of the
mailing list for the GCC project.
Re: make sure struct real_value's bitfields are packed
On Mon, Mar 22, 2004 at 09:56:00AM +0100, Falk Hueffner wrote:
> Alexandre Oliva <firstname.lastname@example.org> writes:
> > On Mar 21, 2004, Roger Sayle <email@example.com> wrote:
> >> On 21 Mar 2004, Alexandre Oliva wrote:
> >> +#define REAL_EXP(REAL) \
> >> + ((int)((REAL)->uexp ^ (unsigned int)(1 << (EXP_BITS - 1))) \
> >> + - (1 << (EXP_BITS - 1)))
> >> I hadn't come across this "(x ^ signbit) - signbit" idiom for
> >> implementing sign-extension before. Nice.
> > Yeah, I found it great as well when I learned about it in the binutils
> > list :-)
> > Maybe the middle-end could recognize such sequences and attempt to
> > optimize them into shifts or other forms of sign extension? Maybe
> > it already does? :-) Dunno, I haven't checked.
> I don't really like the idiom. It's obfuscated and requires a large
> constant, which is costly on some targets. Plain old
> (x << EXP_BITS) >> EXP_BITS is much more readable and already gets
> recognized by gcc as sign extension.
That old familiar shift left, shift right might not work at all. Even
if you know the number of bits in x. According to ISO/IEC 9899:1999,
shift right of negative signed quantities is implementation defined.
$ cat /tmp/sign.c
int foo (int x)
return ((x & 0xff) ^ 0x80) - 0x80;
$ gcc -S -O2 -fomit-frame-pointer /tmp/sign.c
$ cat sign.s
.type foo, @function
.size foo, .-foo
.ident "GCC: (GNU) 3.3 20030226 (prerelease) (SuSE Linux)"
IBM OzLabs - Linux Technology Centre