diff options
| author | 2023-12-27 06:51:29 -0600 | |
|---|---|---|
| committer | 2023-12-27 06:51:29 -0600 | |
| commit | 5e141e336c3a2cb8921edcd7af6f14a29ff63942 (patch) | |
| tree | 80df676cd02693746b505aecbec5c9ee529b5e7b /src/endian.c | |
| parent | refactor instances (diff) | |
add cheap SHA1 implementation
Diffstat (limited to 'src/endian.c')
| -rw-r--r-- | src/endian.c | 28 |
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); +} |
