aboutsummaryrefslogtreecommitdiffstats
path: root/src/endian.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/endian.c')
-rw-r--r--src/endian.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/endian.c b/src/endian.c
new file mode 100644
index 0000000..0229c57
--- /dev/null
+++ b/src/endian.c
@@ -0,0 +1,28 @@
+#include "endian.h"
+
+#include <inttypes.h>
+
+uint64_t l2__bswap_64_int(uint64_t in)
+{
+ return (in << 56)
+ | ((in & UINT64_C(0x000000000000FF00)) << 40)
+ | ((in & UINT64_C(0x0000000000FF0000)) << 24)
+ | ((in & UINT64_C(0x00000000FF000000)) << 8)
+ | ((in & UINT64_C(0x000000FF00000000)) >> 8)
+ | ((in & UINT64_C(0x0000FF0000000000)) >> 24)
+ | ((in & UINT64_C(0x00FF000000000000)) >> 40)
+ | (in >> 56);
+}
+
+uint32_t l2__bswap_32_int(uint32_t in)
+{
+ return (in << 24)
+ | ((in & UINT32_C(0x0000FF00)) << 8)
+ | ((in & UINT32_C(0x00FF0000)) >> 8)
+ | (in >> 24);
+}
+
+uint16_t l2__bswap_16_int(uint16_t in)
+{
+ return (in >> 8) | (in << 8);
+}