|
@@ -34,8 +34,8 @@
|
|
|
#endif
|
|
|
|
|
|
|
|
|
-// There's no standard way to determine endianess at compile time.
|
|
|
-// Do not bother with mixed endian platforms, no one will ever compile on that.
|
|
|
+// There's no standard way to determine endianess at compile time. Try using
|
|
|
+// some well known non-standard macros for detection.
|
|
|
#if defined __BYTE_ORDER__
|
|
|
#define CPU_IS_LE __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
#elif defined _BYTE_ORDER
|
|
@@ -48,6 +48,7 @@
|
|
|
#warning "can't detect byte order, assume little endian"
|
|
|
#define CPU_IS_LE 1
|
|
|
#endif
|
|
|
+// NB mixed endian integer platforms are not supported.
|
|
|
|
|
|
#if CPU_IS_LE
|
|
|
// address/offset operations
|
|
@@ -56,7 +57,7 @@
|
|
|
#define MEM_LE2(a) (a)
|
|
|
#define MEM_LE4(a) (a)
|
|
|
// swapping
|
|
|
-#define CPU_BE2(v) (((v)<<16)|((v)>>16))
|
|
|
+#define CPU_BE2(v) ((u32)((u64)(v)<<16)|((v)>>16))
|
|
|
#define CPU_BE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
|
|
|
(((v)<<8)&0xff0000)|(u32)((v)<<24))
|
|
|
#define CPU_LE2(v) (v) // swap of 2*u16 in u32
|
|
@@ -70,7 +71,7 @@
|
|
|
// swapping
|
|
|
#define CPU_BE2(v) (v)
|
|
|
#define CPU_BE4(v) (v)
|
|
|
-#define CPU_LE2(v) (((v)<<16)|((v)>>16))
|
|
|
+#define CPU_LE2(v) ((u32)((u64)(v)<<16)|((v)>>16))
|
|
|
#define CPU_LE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
|
|
|
(((v)<<8)&0xff0000)|(u32)((v)<<24))
|
|
|
#endif
|