#pragma once #include #include static inline uint64_t reverse64_n(uint64_t x, const uint8_t n) { x = bswap_64(x); x = ((x & UINT64_C(0x0f0f0f0f0f0f0f0f)) << 4) | ((x & UINT64_C(0xf0f0f0f0f0f0f0f0)) >> 4); x = ((x & UINT64_C(0x3333333333333333)) << 2) | ((x & UINT64_C(0xcccccccccccccccc)) >> 2); x = ((x & UINT64_C(0x5555555555555555)) << 1) | ((x & UINT64_C(0xaaaaaaaaaaaaaaaa)) >> 1); return x >> (64 - n); } static inline uint64_t reverse64(uint64_t x) { return reverse64_n(x, 64); }