|
|
Log in / Subscribe / Register

Little-endian PowerPC

Little-endian PowerPC

Posted Oct 7, 2010 18:55 UTC (Thu) by daniel (guest, #3181)
In reply to: Little-endian PowerPC by etienne
Parent article: Little-endian PowerPC

<i>Last time I looked gcc was not able to generate (did not know about) the bswap instruction.</i>

I doubt that, however what GCC does need is support for endian variable attributes with appropriate code generation. Last I looked, GCC has no such feature.


to post comments

Little-endian PowerPC

Posted Oct 8, 2010 14:25 UTC (Fri) by etienne (guest, #25256) [Link] (1 responses)

> I doubt that

GCC do know about the bswap instruction since 4.0 (I just checked the source), but I did not find a way to make GCC use it (i.e. either inline the bswap() or recognise the three shift sequence) on a i386 host...

Little-endian PowerPC

Posted Oct 8, 2010 15:29 UTC (Fri) by jengelh (subscriber, #33263) [Link]

>but I did not find a way to make GCC use it (i.e. either inline the bswap() or recognise the three shift sequence) on a i386 host...

Works here. Optimizer starts recognizing int s = ((((argc) & 0xff000000) >> 24) | (((argc) & 0x00ff0000) >> 8) | (((argc) & 0x0000ff00) << 8) | (((argc) & 0x000000ff) << 24)); on -O2 and issues a bswap for it.

Alternatively, you could use the same trick as glibc's htonl: int s = __bswap_32(argc). Or even directly __builtin_bswap32 as documented in gcc.info.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds