summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2014-06-29 20:19:59 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2014-06-29 20:20:06 +1000
commit699e7c457a5d49fb4f021ebd4b0a28d6278e4eb5 (patch)
tree6b3b5c8ac50b835a2a625ccaaaf00139f1a5ec6a /include
parenta8567d4b4eebb758fd3630636061a625763f0d1d (diff)
downloadflac-699e7c457a5d49fb4f021ebd4b0a28d6278e4eb5.tar.gz
include/share/endswap.h : Add endswapping of 16 bit values.
Also add macros H2LE_16 and H2LE_32, which do host to little-endian swapping of 16 and 32 bit values respectively.
Diffstat (limited to 'include')
-rw-r--r--include/share/endswap.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/share/endswap.h b/include/share/endswap.h
index e71f0f6c..74cdfc3b 100644
--- a/include/share/endswap.h
+++ b/include/share/endswap.h
@@ -33,21 +33,38 @@
#if HAVE_BSWAP32 /* GCC and Clang */
+#define ENDSWAP_16(x) (__builtin_bswap16 (x))
#define ENDSWAP_32(x) (__builtin_bswap32 (x))
#elif defined _MSC_VER /* Windows. Apparently in <stdlib.h>. */
+#define ENDSWAP_16(x) (_byteswap_ushort (x))
#define ENDSWAP_32(x) (_byteswap_ulong (x))
#elif defined HAVE_BYTESWAP_H /* Linux */
#include <byteswap.h>
+#define ENDSWAP_16(x) (bswap_16 (x))
#define ENDSWAP_32(x) (bswap_32 (x))
#else
+#define ENDSWAP_16(x) (((((x) >> 8) & 0xFF00) + ((x) & 0xFF00) << 8))
#define ENDSWAP_32(x) ((((x) >> 24) & 0xFF) + (((x) >> 8) & 0xFF00) + (((x) & 0xFF00) << 8) + (((x) & 0xFF) << 24))
#endif
+
+/* Host to little-endian byte swapping. */
+#if CPU_IS_BIG_ENDIAN
+
+#define H2LE_16(x) ENDSWAP_16 (x)
+#define H2LE_32(x) ENDSWAP_32 (x)
+
+#else
+
+#define H2LE_16(x) (x)
+#define H2LE_32(x) (x)
+
+#endif