Mesa (master): util: Add util_memcpy_cpu_to_le32() v3

Tom Stellard tstellar at kemper.freedesktop.org
Mon Jul 28 15:21:35 UTC 2014


Module: Mesa
Branch: master
Commit: f0e0737922061f0eb38d5016c40d86226ee40e61
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f0e0737922061f0eb38d5016c40d86226ee40e61

Author: Tom Stellard <thomas.stellard at amd.com>
Date:   Fri Jul 18 15:55:08 2014 -0400

util: Add util_memcpy_cpu_to_le32() v3

v2:
  - Preserve word boundaries.

v3:
  - Use const and restrict.
  - Fix indentation.

Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

---

 src/gallium/auxiliary/util/u_math.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index b9ed197..f6dcb22 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -812,6 +812,23 @@ util_bswap16(uint16_t n)
           (n << 8);
 }
 
+static INLINE void*
+util_memcpy_cpu_to_le32(void * restrict dest, const void * restrict src, size_t n)
+{
+#ifdef PIPE_ARCH_BIG_ENDIAN
+   size_t i, e;
+   asset(n % 4 == 0);
+
+   for (i = 0, e = n / 4; i < e; i++) {
+      uint32_t * restrict d = (uint32_t* restrict)dest;
+      const uint32_t * restrict s = (const uint32_t* restrict)src;
+      d[i] = util_bswap32(s[i]);
+   }
+   return dest;
+#else
+   return memcpy(dest, src, n);
+#endif
+}
 
 /**
  * Clamp X to [MIN, MAX].




More information about the mesa-commit mailing list