Last active
October 13, 2020 19:09
-
-
Save daniel-j-h/69736fb5ec147d4212c5 to your computer and use it in GitHub Desktop.
Making use of Haswell's BMI2 PDEP instruction for Morton Codes / Z-Order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <immintrin.h> | |
// Z-order via bit interleaving a and b as in: a[31]b[31]a[30]b[30]... | |
inline std::uint64_t zorder(std::uint32_t a, std::uint32_t b) { | |
return _pdep_u64(a, 0xaaaaaaaaaaaaaaaaULL) | _pdep_u64(b, 0x5555555555555555ULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PDEP for zorder encoding, PEXT for zorder decoding: