SIMD Vector Types
This module provides generic SIMD vector wrapper types that abstract over different SIMD widths (SSE, AVX2, AVX-512) and support runtime SIMD width selection within the AoSoA memory layout.
The SimdVec[N, T] type represents N values of type T that can be processed in parallel using SIMD instructions.
Reference: QEX simdWrap.nim and nimsimd for design patterns
Types
SimdF32x16 = SimdVec[16, float32]
- AVX-512: 16 x float32
SimdI32x16 = SimdVec[16, int32]
- AVX-512: 16 x int32
SimdVec[N; T] = object data*: array[N, T]
- Generic SIMD vector holding N elements of type T N is the number of SIMD lanes (e.g., 4, 8, 16) T is the scalar type (float32, float64, int32, int64)
SimdVecDyn[T] = object width*: int data*: seq[T]
- Dynamic SIMD vector with runtime-determined width Used when SIMD width is not known at compile time
Procs
proc `$`[T](v: SimdVecDyn[T]): string
proc `*`[N: static[int]; T](a, b: SimdVec[N, T]): SimdVec[N, T] {.inline.}
- Element-wise multiplication
proc `*`[T](a, b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `*`[T](a: SimdVecDyn[T]; b: T): SimdVecDyn[T] {.inline.}
proc `*`[T](a: T; b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `+`[T](a, b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `+`[T](a: SimdVecDyn[T]; b: T): SimdVecDyn[T] {.inline.}
proc `+`[T](a: T; b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `-`[T](a, b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `-`[T](a: SimdVecDyn[T]; b: T): SimdVecDyn[T] {.inline.}
proc `/`[T](a, b: SimdVecDyn[T]): SimdVecDyn[T] {.inline.}
proc `/`[T](a: SimdVecDyn[T]; b: T): SimdVecDyn[T] {.inline.}
proc loadStrided[N: static[int]; T](p: ptr T; stride: int): SimdVec[N, T] {. inline.}
- Load N values with given stride (gather)
proc newSimdVecDyn[T](width: int): SimdVecDyn[T]
- Create a zero-initialized dynamic SIMD vector
proc newSimdVecDyn[T](width: int; val: T): SimdVecDyn[T]
- Create a dynamic SIMD vector filled with a scalar value
proc storeStrided[N: static[int]; T](v: SimdVec[N, T]; p: ptr T; stride: int) {. inline.}
- Store N values with given stride (scatter)
proc sum[T](v: SimdVecDyn[T]): T {.inline.}