User: Password:
|
|
Subscribe / Log in / New account

Little-endian PowerPC

Little-endian PowerPC

Posted Oct 8, 2010 14:25 UTC (Fri) by etienne (guest, #25256)
In reply to: Little-endian PowerPC by daniel
Parent article: Little-endian PowerPC

> 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...


(Log in to post comments)

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 © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds