summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-03-06 00:58:30 +0100
committerGitHub <noreply@github.com>2019-03-06 00:58:30 +0100
commitdddf8c672b988da7a1a6b2bbe8b57462a3b5897a (patch)
tree04f18cad3eb1d3221d2eaff01d7a405c3c718ab8
parentb4d5c1ab5be236b3b2b9f6b3b5f3445a2285df72 (diff)
parent64bce5a24bcf9c2d1ab1548c41a51626228583cc (diff)
Merge pull request #26668 from marxin/use-gcc-builtins-for-bswap
Use GCC builtins for bswap as compiler can then emit these via insn
-rw-r--r--core/typedefs.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/core/typedefs.h b/core/typedefs.h
index 966360d4f2..03514466c0 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -250,21 +250,34 @@ static inline int get_shift_from_power_of_2(unsigned int p_pixel) {
}
/** Swap 16 bits value for endianness */
+#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap16)
+#define BSWAP16(x) __builtin_bswap16(x)
+#else
static inline uint16_t BSWAP16(uint16_t x) {
return (x >> 8) | (x << 8);
}
+#endif
+
/** Swap 32 bits value for endianness */
+#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap32)
+#define BSWAP32(x) __builtin_bswap32(x)
+#else
static inline uint32_t BSWAP32(uint32_t x) {
return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24));
}
-/** Swap 64 bits value for endianness */
+#endif
+/** Swap 64 bits value for endianness */
+#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap64)
+#define BSWAP64(x) __builtin_bswap64(x)
+#else
static inline uint64_t BSWAP64(uint64_t x) {
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
return x;
}
+#endif
/** When compiling with RTTI, we can add an "extra"
* layer of safeness in many operations, so dynamic_cast