[llvm-commits] [PATCH][GNU Build] Add LLVM_IS_TARGET_BIG_ENDIAN to config.h

Michael Spencer bigcheesegs at gmail.com
Fri Oct 22 11:04:46 PDT 2010


On Fri, Oct 22, 2010 at 10:17 AM, Duncan Sands <baldrick at free.fr> wrote:
> Hi Michael,
>
>>> I still don't get it.  If you want the endianness of the host, you can use llvm/System/Host.h.
>>
>> I want it at compile time.
>
> isLittleEndianHost and isBigEndianHost are designed to be turned into constants
> when compiled, so there is no efficiency loss in using them.  Do you really
> need more than this?
>
>> The point is so that you can memory map a file, and directly say "read
>> an unsigned 32 bit integer from this address encoded as littlendian."
>> On X86 this would just end up as a movl (%addr), %dest. While on PPC
>> this would expand to a read and a byteswap.
>
> Why don't you do:
>
> if (isLittleEndianHost) {
>   code for little endian host
> } else {
>   code for big endian host
> }
>
> ?
>
> The optimizers will remove the irrelevant branch.
>
> Ciao,
>
> Duncan.

After testing it appears that you are correct. I will switch the code
over to use those and remove the macro.

Thanks for the help.

- Michael Spencer




More information about the llvm-commits mailing list