Expand description
KStepPointer<T> - pointer with first-class stride encoding.
Storage: (base: *const T, k_step: u8). The stride between
consecutive elements is sizeof(T) << k_step. So:
| K_step | Stride | Use case |
|---|---|---|
| 0 | sizeof(T) (tight pack) | Default, contiguous Vec/array |
| 1 | 2 * sizeof(T) | Every other element |
| 2 | 4 * sizeof(T) | Sub-quarter access pattern |
| 3 | 8 * sizeof(T) | SIMD lane stride |
| 6 | 64 * sizeof(T) | Cache-line stride |
| 12 | 4096 * sizeof(T) | Page-aligned stride |
K_step is the pointer-side analog of quartz’s K_inner axis -
it controls the granularity of iteration. The advantage over a
runtime stride: usize is that K_step is a const-encoded shift
amount; the compiler can fold << k_step into address generation
and SIMD ops know the stride at codegen time.
§Architectural rationale
BLAS GEMM iterates over matrix rows AND columns with potentially
different strides. NumPy’s strided arrays do the same in higher
dimensions. Today these are all encoded as runtime stride: usize
fields - the compiler has to emit IMUL for each step. With KStep
the stride is 1 << k_step so the codegen is SHL (one cycle),
and the compiler can hoist the shift amount as an immediate.
Structs§
- KStep
Pointer - Strided pointer to
T. Stride =sizeof(T) << k_stepbytes. - Strided
Iter - Iterator yielding strided elements.