From: Christoph Bumiller Date: Thu, 26 Nov 2009 15:58:59 +0000 (+0100) Subject: gallium/util: added util_bswap32() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e65258abf52bd1923a547f76bd7346bf5ed1c5c6;p=mesa.git gallium/util: added util_bswap32() --- diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index b7fc0586f39..7e75702701d 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -510,6 +510,23 @@ util_bitcount(unsigned n) } +/** + * Reverse byte order of a 32 bit word. + */ +static INLINE uint32_t +util_bswap32(uint32_t n) +{ +#if defined(PIPE_CC_GCC) + return __builtin_bswap32(n); +#else + return (n >> 24) | + ((n >> 8) & 0x0000ff00) | + ((n << 8) & 0x00ff0000) | + (n << 24); +#endif +} + + /** * Clamp X to [MIN, MAX]. * This is a macro to allow float, int, uint, etc. types.