[Mesa-dev] [PATCH 1/3] util: Add util_bswap64()

Matt Turner mattst88 at gmail.com
Wed Feb 19 15:43:41 PST 2014


On Wed, Feb 19, 2014 at 3:32 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Wed, Feb 19, 2014 at 6:09 PM, Tom Stellard <thomas.stellard at amd.com> wrote:
>> +/**
>> + * Reverse byte order of a 64bit word.
>> + */
>> +static INLINE uint64_t
>> +util_bswap64(uint64_t n)
>> +{
>> +   return ((uint64_t)util_bswap32(n & 0xffffffff) << 32) |
>> +          util_bswap32((n >> 32));
>
> Perhaps use __builtin_bswap64 if it's available? Not sure when it
> became available though.

When I fixed up bswap stuff in the X server a few years ago, I
discovered that gcc was really good at detecting open-coded bswap, and
less good at recognizing when it could constant fold __builtin_bswap.

Do some experiments, but make sure your experiments include not using
__builtin_bswap32 in util_bswap32.


More information about the mesa-dev mailing list