Spatial‐Tiling - kirklasalle/SpaceEntropyCompression GitHub Wiki
Spatial Tiling & Geometric Locality Encoding
The Spatial Tiling module in SpaceEntropyCompression (SEC) maps multi-dimensional spatial points, vectors, and tensor fields into one-dimensional contiguous sequences while preserving geometric proximity. This page details the spatial partitioning algorithms, hardware-accelerated space-filling curves, and memory layout architectures employed in SEC.
1. Coordinate Normalization and Bounding
Before applying space-filling curves, arbitrary multi-dimensional spatial coordinates $\vec{p} \in \mathbb{R}^d$ are bounded and transformed to a normalized integer coordinate grid:
- AABB Evaluation: Compute the Axis-Aligned Bounding Box $(\vec{p}{min}, \vec{p}{max})$.
- Dimension Quantization: Scale continuous coordinates to $B$-bit unsigned integers ($B \in {10, 16, 21}$ for 3D coordinates fitting in 32-bit or 64-bit integer registers):
$$X_i = \text{clamp}\left( \left\lfloor \frac{p_i - p_{min, i}}{p_{max, i} - p_{min, i}} \cdot (2^B - 1) + 0.5 \right\rfloor, 0, 2^B - 1 \right)$$
2. Hardware-Accelerated Morton (Z-Order) Tiling
For high-throughput systems, SEC implements 3D Morton encoding via hardware bit interleaving:
$$\text{Morton3D}(X, Y, Z) = \text{InterleaveBits}(X) \mid (\text{InterleaveBits}(Y) \ll 1) \mid (\text{InterleaveBits}(Z) \ll 2)$$
X: ---- ---- ---- ---- ---- --x4 x3 x2 x1 x0
Y: ---- ---- ---- ---- ---- --y4 y3 y2 y1 y0
Z: ---- ---- ---- ---- ---- --z4 z3 z2 z1 z0
Morton: z4 y4 x4 z3 y3 x3 z2 y2 x2 z1 y1 x1 z0 y0 x0
BMI2 Hardware Instruction Acceleration (x86_64)
On modern x86_64 CPUs with BMI2 support, bit dilation executes in a single cycle using the Parallel Bits Deposit instruction (PDEP):
// 21-bit coordinate dilation into 64-bit mask 0x9249249249249249ULL
#include <immintrin.h>
inline uint64_t dilate_3d(uint32_t val) {
const uint64_t mask = 0x1249249249249249ULL; // bits spaced by 3
return _pdep_u64((uint64_t)val, mask);
}
inline uint64_t morton_encode_3d(uint32_t x, uint32_t y, uint32_t z) {
return dilate_3d(x) | (dilate_3d(y) << 1) | (dilate_3d(z) << 2);
}
On ARM64 (NEON) and Tier 0 embedded architectures, a 5-step branchless shift-and-mask LUT sequence is used as a zero-dependency fallback.
3. 3D Hilbert Curve Traversal
While Morton curves offer low encoding overhead, they exhibit large non-local coordinate jumps across octant boundaries. For maximum compression ratios, SEC implements 3D Hilbert space-filling curves, guaranteeing continuous geometric traversal:
$$\forall i, \quad | \vec{x}(\mathcal{H}(i+1)) - \vec{x}(\mathcal{H}(i)) |_1 = 1 \text{ grid unit}$$
State-Transformation Kernel
The 3D Hilbert mapping is evaluated through iterative quadrant state transitions:
[Level l = 0: Root] ---> Evaluate quadrant bit tuple (b_x, b_y, b_z)
│
▼
Lookup Gray Code Index
│
▼
Transform Orientation State
│
▼
[Level l + 1: Child] ---> Accumulate 3D Hilbert Coordinate
Hilbert traversal preserves spatial locality by 28% to 41% better than Morton curves on non-uniform cosmological point distributions, directly minimizing residual delta variances during entropy modeling.
4. Adaptive Multi-Resolution Spatial Chunking
To scale across massive datasets without unbounded memory overhead, datasets are partitioned into self-contained Spatial Chunks:
+-------------------------------------------------------------------+
| Spatial Chunk Header |
| - 64-bit Hilbert Base Origin (h_min, h_max) |
| - Bounding Box: [x_min, y_min, z_min] to [x_max, y_max, z_max] |
| - Coordinate Bit Depth (B), Quantization Scale (Δq) |
| - Uncompressed Element Count (N), Packed Payload Byte Size (S) |
+-------------------------------------------------------------------+
| Packed ANS Bitstream Payload |
| - Interleaved coordinate deltas (Δh, Δx, Δy, Δz) |
| - Optional metric compression tensor components (q_ij) |
+-------------------------------------------------------------------+
Chunking Specifications
- Target Chunk Size: 64 KB to 256 KB compressed payload (fitting entirely within CPU L2 cache).
- Independent Decodability: Chunks can be decompressed in parallel across multiple worker threads or GPU thread blocks without cross-chunk dependencies.
- Spatial Index Table: A compact root index stores chunk bounding boxes for rapid spatial range queries and frustum culling.
5. Memory Alignment & Cache Efficiency (SoA Layout)
SEC processes spatial data using a Struct-of-Arrays (SoA) memory layout rather than Array-of-Structs (AoS):
// Struct-of-Arrays (SoA) layout for optimal SIMD prefetching
struct alignas(64) SpatialFieldBlock {
uint32_t x[1024]; // 64-byte aligned
uint32_t y[1024]; // 64-byte aligned
uint32_t z[1024]; // 64-byte aligned
uint16_t vci[1024]; // Volumetric Compression Index
uint16_t tensor_q[1024][6]; // 6-component discrete curvature tensor
};
This layout allows AVX2 / AVX-512 / NEON vector execution units to load contiguous coordinates directly into SIMD registers without scatter-gather overhead.