|
morton-arithmetic 0.1.0
Fast Morton (Z-order) codes with O(1) arithmetic
|
Bulk (array) encode/decode/arithmetic with auto-vectorised + AVX-512 runtime dispatch. More...
#include <cstddef>#include <cstdint>#include <type_traits>#include "morton/morton.hpp"#include "morton/simd.hpp"
Go to the source code of this file.
Namespaces | |
| namespace | morton |
| namespace | morton::batch |
Functions | |
| template<unsigned Dim, unsigned Bits> | |
| void | morton::batch::add (const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, typename Morton< Dim, Bits >::coord_type k) |
Add the same k to axis of every code (wraps). | |
| template<unsigned Dim, unsigned Bits> | |
| void | morton::batch::sub (const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, typename Morton< Dim, Bits >::coord_type k) |
Subtract the same k from axis of every code (wraps). Vectorised. | |
| template<unsigned Dim, unsigned Bits> | |
| void | morton::batch::step (const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, int dir) |
Step every code one cell along ±axis (dir>=0 -> +1, else -1). Vectorised. | |
| template<unsigned Bits> | |
| void | morton::batch::encode2 (const typename Morton< 2, Bits >::coord_type *x, const typename Morton< 2, Bits >::coord_type *y, typename Morton< 2, Bits >::code_type *out, std::size_t n) |
| Encode arrays of coordinates (2D) into codes. | |
| template<unsigned Bits> | |
| void | morton::batch::encode3 (const typename Morton< 3, Bits >::coord_type *x, const typename Morton< 3, Bits >::coord_type *y, const typename Morton< 3, Bits >::coord_type *z, typename Morton< 3, Bits >::code_type *out, std::size_t n) |
| Encode arrays of coordinates (3D) into codes. | |
| template<unsigned Bits> | |
| void | morton::batch::decode2 (const typename Morton< 2, Bits >::code_type *in, typename Morton< 2, Bits >::coord_type *x, typename Morton< 2, Bits >::coord_type *y, std::size_t n) |
| Decode an array of codes back to coordinate arrays (2D). | |
| template<unsigned Bits> | |
| void | morton::batch::decode3 (const typename Morton< 3, Bits >::code_type *in, typename Morton< 3, Bits >::coord_type *x, typename Morton< 3, Bits >::coord_type *y, typename Morton< 3, Bits >::coord_type *z, std::size_t n) |
| Decode an array of codes back to coordinate arrays (3D). | |
Bulk (array) encode/decode/arithmetic with auto-vectorised + AVX-512 runtime dispatch.
The per-axis arithmetic is a short sequence of masked integer ops with a loop-invariant mask and increment, so these loops auto-vectorise (AVX2/AVX-512) under -O3: the compiler turns them into packed vpor/vpaddq/vpand. This is what gives the Python bindings near-native throughput, and what a SIMD-batch API would expose to C++ callers.
For 64-bit codes on x86-64 (GCC/Clang) these functions additionally dispatch at runtime to the hand-written AVX-512 kernels in simd.hpp when the running CPU has AVX-512F; otherwise they fall back to the auto-vectorised scalar loop below. The dispatch is transparent: results are bit-for-bit identical to the scalar path, and a single binary adapts to the host CPU.
SPDX-License-Identifier: MIT