Skip to main content

Module kstep_pointer

Module kstep_pointer 

Source
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_stepStrideUse case
0sizeof(T) (tight pack)Default, contiguous Vec/array
12 * sizeof(T)Every other element
24 * sizeof(T)Sub-quarter access pattern
38 * sizeof(T)SIMD lane stride
664 * sizeof(T)Cache-line stride
124096 * 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§

KStepPointer
Strided pointer to T. Stride = sizeof(T) << k_step bytes.
StridedIter
Iterator yielding strided elements.