#ifndef COM_ZORD_H #define COM_ZORD_H #include // #include extern const uint16_t com_zord_morton_table[]; /* Z-filling curve to help with cache and data locality. */ static inline uint32_t com_zord_order(uint16_t x, uint16_t y) { return (com_zord_morton_table[y >> 8] << 17) | (com_zord_morton_table[x >> 8] << 16) | (com_zord_morton_table[y & 0xFF] << 1) | (com_zord_morton_table[x & 0xFF]); // return _pdep_u32(x, 0x55555555) | _pdep_u32(y, 0xAAAAAAAA); } /* https://en.wikipedia.org/wiki/Z-order_curve#Coordinate_values*/ static inline uint32_t com_zord_inc_x(uint32_t z) { return (((z | 0b10101010) + 1) & 0b01010101) | (z & 0b10101010); } static inline uint32_t com_zord_dec_x(uint32_t z) { return (((z & 0b01010101) - 1) & 0b01010101) | (z & 0b10101010); } static inline uint32_t com_zord_inc_y(uint32_t z) { return (((z | 0b01010101) + 1) & 0b10101010) | (z & 0b01010101); } static inline uint32_t com_zord_dec_y(uint32_t z) { return (((z & 0b10101010) - 1) & 0b10101010) | (z & 0b01010101); } #endif