48 uint32_t morton_code(uint32_t x, uint32_t y, uint32_t z) {
49 x = (x | (x << 16)) & 0x030000FF;
50 x = (x | (x << 8)) & 0x0300F00F;
51 x = (x | (x << 4)) & 0x030C30C3;
52 x = (x | (x << 2)) & 0x09249249;
54 y = (y | (y << 16)) & 0x030000FF;
55 y = (y | (y << 8)) & 0x0300F00F;
56 y = (y | (y << 4)) & 0x030C30C3;
57 y = (y | (y << 2)) & 0x09249249;
59 z = (z | (z << 16)) & 0x030000FF;
60 z = (z | (z << 8)) & 0x0300F00F;
61 z = (z | (z << 4)) & 0x030C30C3;
62 z = (z | (z << 2)) & 0x09249249;
64 return x | (y << 1) | (z << 2);
68 uint64_t morton_code60(uint32_t x, uint32_t y, uint32_t z) {
69 uint32_t lo_x = x & 1023u;
70 uint32_t lo_y = y & 1023u;
71 uint32_t lo_z = z & 1023u;
72 uint32_t hi_x = x >> 10u;
73 uint32_t hi_y = y >> 10u;
74 uint32_t hi_z = z >> 10u;
76 return (uint64_t(morton_code(hi_x, hi_y, hi_z)) << 30) |
77 uint64_t(morton_code(lo_x, lo_y, lo_z));