[llvm-commits] [PATCH][System] Add SwapByteOrder and move implementation from Support/MathExtras.h.

Michael Spencer bigcheesegs at gmail.com
Fri Sep 24 14:36:56 PDT 2010

On Fri, Sep 17, 2010 at 11:40 AM, Rafael Espindola <espindola at google.com> wrote:
>> The generic code is actually being used for both COFF and ELF with
>> signed types, but it hasn't been tested because I've only tried out
>> x86{,-64} so far (and thus this function isn't called). If someone
>> could send me a small bigendian ELF file I could add a test for it and
>> make sure everything works.
> Is it common to try to byteswap signed integers? If not, it is
> probably a bit safer to just not support it. Things like
> int32_t foo;
> int64_t bar = SwapByteOrder(foo);

In this case it depends on what byte order foo is. If it is not host,
then the results will be as expected (byte swapped then sign
extended). If it is already host, then the result will be creepy, and
arguably as expected. It's an operation that doesn't make any sense,
and there's nothing SwapByteOrder can do about it.

> can be a bit surprising. The user might have intended to sign extend
> foo first, but that is not what is going to happen.
> I compiled gas with at target of ppc64-linux-gnu and passed it an
> empty .s. The produced .o is attached.
>> Thanks for the review!
>> - Michael Spencer
> Cheers,
> --
> Rafael Ávila de Espíndola

I added unittests to verify signed swaps work, and modified the
implementation to error out if any type is used other than
{signed,unsigned} {8,16,32,64}bit integer types.

New patch attached.

- Michael Spencer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: System-add-swap-byte-order.patch
Type: application/octet-stream
Size: 10620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100924/74490845/attachment.obj>

More information about the llvm-commits mailing list