aboutsummaryrefslogtreecommitdiff
path: root/payloads/libpayload/include/endian.h
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2019-11-28 12:53:43 -0800
committerPatrick Georgi <pgeorgi@google.com>2019-12-06 15:08:50 +0000
commit879ea7fce8a21359ad80e4008c41587b3e1769ae (patch)
tree5c3ee9fc5d6d8e72aa164aeff1efc365e6de6ba5 /payloads/libpayload/include/endian.h
parent6fdf122fc391a894ae8ea340c58ef351be3dd5f1 (diff)
endian: Replace explicit byte swapping with compiler builtin
gcc seems to have some stupid problem with deciding when to inline byte swapping functions (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92716). Using the compiler builtin instead seems to solve the problem. (This doesn't yet solve the issue for the read_be32()-family of functions, which we should maybe just get rid of at some point?) Change-Id: Ia2a6d8ea98987266ccc32ffaa0a7f78965fca1cd Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/37343 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'payloads/libpayload/include/endian.h')
-rw-r--r--payloads/libpayload/include/endian.h29
1 files changed, 6 insertions, 23 deletions
diff --git a/payloads/libpayload/include/endian.h b/payloads/libpayload/include/endian.h
index ec0825dc31..dee45f227b 100644
--- a/payloads/libpayload/include/endian.h
+++ b/payloads/libpayload/include/endian.h
@@ -34,23 +34,6 @@
#include <arch/types.h>
#include <libpayload-config.h>
-static inline uint16_t swap_bytes16(uint16_t in)
-{
- return ((in & 0xFF) << 8) | ((in & 0xFF00) >> 8);
-}
-
-static inline uint32_t swap_bytes32(uint32_t in)
-{
- return ((in & 0xFF) << 24) | ((in & 0xFF00) << 8) |
- ((in & 0xFF0000) >> 8) | ((in & 0xFF000000) >> 24);
-}
-
-static inline uint64_t swap_bytes64(uint64_t in)
-{
- return ((uint64_t)swap_bytes32((uint32_t)in) << 32) |
- ((uint64_t)swap_bytes32((uint32_t)(in >> 32)));
-}
-
/* Endian functions from glibc 2.9 / BSD "endian.h" */
#if CONFIG(LP_BIG_ENDIAN)
@@ -59,15 +42,15 @@ static inline uint64_t swap_bytes64(uint64_t in)
#define htobe32(in) (in)
#define htobe64(in) (in)
-#define htole16(in) swap_bytes16(in)
-#define htole32(in) swap_bytes32(in)
-#define htole64(in) swap_bytes64(in)
+#define htole16(in) ((uint16_t)__builtin_bswap16(in))
+#define htole32(in) ((uint32_t)__builtin_bswap32(in))
+#define htole64(in) ((uint64_t)__builtin_bswap64(in))
#elif CONFIG(LP_LITTLE_ENDIAN)
-#define htobe16(in) swap_bytes16(in)
-#define htobe32(in) swap_bytes32(in)
-#define htobe64(in) swap_bytes64(in)
+#define htobe16(in) ((uint16_t)__builtin_bswap16(in))
+#define htobe32(in) ((uint32_t)__builtin_bswap32(in))
+#define htobe64(in) ((uint64_t)__builtin_bswap64(in))
#define htole16(in) (in)
#define htole32(in) (in)