util: Add util_bswap64() v3
authorTom Stellard <thomas.stellard@amd.com>
Wed, 19 Feb 2014 22:17:33 +0000 (14:17 -0800)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 24 Feb 2014 20:56:27 +0000 (12:56 -0800)
v2:
  - Use __builtin_bswap64()
  - Remove unnecessary mask
  - Add util_le64_to_cpu() helper

v3:
  - Remove unnecessary AC_SUBST

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
configure.ac
src/gallium/auxiliary/util/u_math.h

index 4cfdedb1461847117d250d388e29cc77758f9a84..b8e3161e116521771eb08a84b6c4e70f357ced52 100644 (file)
@@ -122,6 +122,7 @@ fi
 
 dnl Check for compiler builtins
 AX_GCC_BUILTIN([__builtin_bswap32])
+AX_GCC_BUILTIN([__builtin_bswap64])
 
 AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
 
index b0f0e3dbb8e926cc983e4e970934a7261097c700..0f498bc1531fcee927738471d74042222d20f51d 100644 (file)
@@ -717,9 +717,11 @@ util_bitcount(unsigned n)
  */
 
 #ifdef PIPE_ARCH_BIG_ENDIAN
+#define util_le64_to_cpu(x) util_bswap64(x)
 #define util_le32_to_cpu(x) util_bswap32(x)
 #define util_le16_to_cpu(x) util_bswap16(x)
 #else
+#define util_le64_to_cpu(x) (x)
 #define util_le32_to_cpu(x) (x)
 #define util_le16_to_cpu(x) (x)
 #endif
@@ -742,6 +744,20 @@ util_bswap32(uint32_t n)
 #endif
 }
 
+/**
+ * Reverse byte order of a 64bit word.
+ */
+static INLINE uint64_t
+util_bswap64(uint64_t n)
+{
+#if defined(HAVE___BUILTIN_BSWAP64)
+   return __builtin_bswap64(n);
+#else
+   return ((uint64_t)util_bswap32(n) << 32) |
+          util_bswap32((n >> 32));
+#endif
+}
+
 
 /**
  * Reverse byte order of a 16 bit word.