summaryrefslogtreecommitdiff
path: root/src/core/bitmath_func.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-12-25 13:28:09 +0000
committerrubidium <rubidium@openttd.org>2007-12-25 13:28:09 +0000
commit851f19b341bd182c3f531ffe852963abb4b1737a (patch)
treec1450dea7c233ea47c2c3cc45df7e9e2cc64c928 /src/core/bitmath_func.hpp
parent81bf9f8503c52974c232252a20d1b1528be66d58 (diff)
downloadopenttd-851f19b341bd182c3f531ffe852963abb4b1737a.tar.xz
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
Diffstat (limited to 'src/core/bitmath_func.hpp')
-rw-r--r--src/core/bitmath_func.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp
index 6f9c35806..9042e6a7e 100644
--- a/src/core/bitmath_func.hpp
+++ b/src/core/bitmath_func.hpp
@@ -291,4 +291,34 @@ template<typename T> static inline T ROR(const T x, const uint8 n)
for (i = 0; b != 0; i++, b >>= 1) \
if (b & 1)
+
+#if defined(__APPLE__)
+ /* Make endian swapping use Apple's macros to increase speed
+ * (since it will use hardware swapping if available).
+ * Even though they should return uint16 and uint32, we get
+ * warnings if we don't cast those (why?) */
+ #define BSWAP32(x) ((uint32)Endian32_Swap(x))
+ #define BSWAP16(x) ((uint16)Endian16_Swap(x))
+#else
+ /**
+ * Perform a 32 bits endianness bitswap on x.
+ * @param x the variable to bitswap
+ * @return the bitswapped value.
+ */
+ static inline uint32 BSWAP32(uint32 x)
+ {
+ return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
+ }
+
+ /**
+ * Perform a 16 bits endianness bitswap on x.
+ * @param x the variable to bitswap
+ * @return the bitswapped value.
+ */
+ static inline uint16 BSWAP16(uint16 x)
+ {
+ return (x >> 8) | (x << 8);
+ }
+#endif /* __APPLE__ */
+
#endif /* BITMATH_FUNC_HPP */