These are not standard function (these are gcc extensions), but you may be able to use them:
— Built-in Function: uint16_t __builtin_bswap16 (uint16_t x) Returns x
with the order of the bytes reversed; for example, 0xaabb becomes
0xbbaa. Byte here always means exactly 8 bits.
— Built-in Function: uint32_t __builtin_bswap32 (uint32_t x) Similar
to __builtin_bswap16, except the argument and return types are 32 bit.
— Built-in Function: uint64_t __builtin_bswap64 (uint64_t x) Similar
to __builtin_bswap32, except the argument and return types are 64 bit.
If you can use these, chances are it will result in more optimal code for your platform, if not, good job, submit a patch to gcc :)
Clang also has __builtin_bswap16() __builtin_bswap32() __builtin_bswap64()
Visual Studio
unsigned short _byteswap_ushort (
unsigned short val
);
unsigned long _byteswap_ulong (
unsigned long val
);
unsigned __int64 _byteswap_uint64 (
unsigned __int64 val
);
ICC has _bswap16, _bswap and _bswap64
*need further reference