aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/byteorder.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/include/byteorder.h b/include/byteorder.h
index 29910af..3ad4dd1 100644
--- a/include/byteorder.h
+++ b/include/byteorder.h
@@ -17,22 +17,24 @@
#ifndef BYTEORDER_H
#define BYTEORDER_H
+#include <stdint.h>
+
static inline uint16_t
bswap_16 (uint16_t x)
{
- return ((x&0xff00) >> 8) | ((x&0xff) << 8);
+ return __builtin_bswap16(x);
}
static inline uint32_t
bswap_32 (uint32_t x)
{
- return bswap_16(x >> 16) | (bswap_16(x) << 16);
+ return __builtin_bswap32(x);
}
static inline uint64_t
bswap_64 (uint64_t x)
{
- return (uint64_t) bswap_32(x >> 32) | (uint64_t) bswap_32(x) << 32;
+ return __builtin_bswap64(x);
}