Documentation
¶
Overview ¶
Package compute provides portable SIMD primitives for the dataset engines.
This package is a thin, zero-overhead wrapper around go-highway (hwy). It re-exports the complete hwy core API so that engine code never imports hwy directly — allowing the SIMD backend to be swapped transparently.
Architecture dispatch is automatic at runtime:
AMD64: AVX-512 → AVX2 → scalar ARM64: SVE → NEON → scalar Other: pure Go scalar fallback
All functions are generic over hwy.Lanes (float32, float64, int32, int64).
Index ¶
- func CompressStore[T Lanes](v Vec[T], mask Mask[T], dst []T) int
- func ConstValue[T Lanes](val float32) T
- func GetLane[T Lanes](v Vec[T], lane int) T
- func HasSIMD() bool
- func MaskStore[T Lanes](mask Mask[T], v Vec[T], data []T)
- func NumLanes[T Lanes]() int
- func ReduceMax[T Lanes](v Vec[T]) T
- func ReduceMin[T Lanes](v Vec[T]) T
- func ReduceSum[T Lanes](v Vec[T]) T
- func SIMDName() string
- func SliceAbs[T Lanes](dst, src []T)
- func SliceAdd[T Lanes](dst, a, b []T)
- func SliceAddScalar[T Lanes](dst, src []T, val T)
- func SliceDiv[T Floats](dst, a, b []T)
- func SliceMax[T Lanes](data []T) T
- func SliceMin[T Lanes](data []T) T
- func SliceMinMax[T Lanes](data []T) (lo, hi T)
- func SliceMul[T Lanes](dst, a, b []T)
- func SliceMulScalar[T Lanes](dst, src []T, val T)
- func SliceNeg[T Lanes](dst, src []T)
- func SlicePow(dst, src []float64, exp float64)
- func SliceSqrt(dst, src []float64)
- func SliceSub[T Lanes](dst, a, b []T)
- func SliceSum[T Lanes](data []T) T
- func Store[T Lanes](v Vec[T], data []T)
- func StoreSlice[T Lanes](v Vec[T], data []T)
- type Floats
- type Integers
- type Lanes
- type Mask
- func Equal[T Lanes](a, b Vec[T]) Mask[T]
- func GreaterEqual[T Lanes](a, b Vec[T]) Mask[T]
- func GreaterThan[T Lanes](a, b Vec[T]) Mask[T]
- func IsFinite[T Floats](v Vec[T]) Mask[T]
- func IsInf[T Floats](v Vec[T], sign int) Mask[T]
- func IsNaN[T Floats](v Vec[T]) Mask[T]
- func LessEqual[T Lanes](a, b Vec[T]) Mask[T]
- func LessThan[T Lanes](a, b Vec[T]) Mask[T]
- func NotEqual[T Lanes](a, b Vec[T]) Mask[T]
- type Vec
- func Abs[T Lanes](v Vec[T]) Vec[T]
- func Add[T Lanes](a, b Vec[T]) Vec[T]
- func And[T Lanes](a, b Vec[T]) Vec[T]
- func AndNot[T Lanes](a, b Vec[T]) Vec[T]
- func AsFloat32(v Vec[int32]) Vec[float32]
- func AsFloat64(v Vec[int64]) Vec[float64]
- func AsInt32(v Vec[float32]) Vec[int32]
- func AsInt64(v Vec[float64]) Vec[int64]
- func Broadcast[T Lanes](v Vec[T], lane int) Vec[T]
- func Const[T Lanes](val float32) Vec[T]
- func Div[T Floats](a, b Vec[T]) Vec[T]
- func FMA[T Floats](a, b, c Vec[T]) Vec[T]
- func IfThenElse[T Lanes](mask Mask[T], a, b Vec[T]) Vec[T]
- func IfThenElseZero[T Lanes](mask Mask[T], v Vec[T]) Vec[T]
- func IfThenZeroElse[T Lanes](mask Mask[T], v Vec[T]) Vec[T]
- func Iota[T Lanes]() Vec[T]
- func Load[T Lanes](data []T) Vec[T]
- func Load4[T Lanes](data []T) (a, b, c, d Vec[T])
- func LoadSlice[T Lanes](data []T) Vec[T]
- func MaskLoad[T Lanes](mask Mask[T], data []T) Vec[T]
- func Max[T Lanes](a, b Vec[T]) Vec[T]
- func Min[T Lanes](a, b Vec[T]) Vec[T]
- func Mul[T Lanes](a, b Vec[T]) Vec[T]
- func MulAdd[T Floats](a, b, c Vec[T]) Vec[T]
- func Neg[T Lanes](v Vec[T]) Vec[T]
- func Not[T Lanes](v Vec[T]) Vec[T]
- func Or[T Lanes](a, b Vec[T]) Vec[T]
- func Pow[T Floats](base, exp Vec[T]) Vec[T]
- func RSqrt[T Floats](v Vec[T]) Vec[T]
- func RSqrtNewtonRaphson[T Floats](v Vec[T]) Vec[T]
- func RSqrtPrecise[T Floats](v Vec[T]) Vec[T]
- func Reverse[T Lanes](v Vec[T]) Vec[T]
- func Reverse2[T Lanes](v Vec[T]) Vec[T]
- func Reverse4[T Lanes](v Vec[T]) Vec[T]
- func Reverse8[T Lanes](v Vec[T]) Vec[T]
- func RoundToEven[T Floats](v Vec[T]) Vec[T]
- func Set[T Lanes](val T) Vec[T]
- func ShiftLeft[T Integers](v Vec[T], bits int) Vec[T]
- func ShiftRight[T Integers](v Vec[T], bits int) Vec[T]
- func SignBit[T Lanes]() Vec[T]
- func Sqrt[T Floats](v Vec[T]) Vec[T]
- func Sub[T Lanes](a, b Vec[T]) Vec[T]
- func Xor[T Lanes](a, b Vec[T]) Vec[T]
- func Zero[T Lanes]() Vec[T]
- func ZeroIfNegative[T Lanes](v Vec[T]) Vec[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressStore ¶
CompressStore compresses elements based on a mask and stores them directly to a slice. It returns the number of elements successfully stored.
func ConstValue ¶
ConstValue converts a float32 constant to type T.
func HasSIMD ¶
func HasSIMD() bool
HasSIMD returns true if hardware SIMD acceleration is active. Returns false in scalar fallback mode (no GOEXPERIMENT=simd or HWY_NO_SIMD set).
func NumLanes ¶
NumLanes returns the number of lanes in a SIMD vector for type T on the current hardware (e.g. 8 for float64 on AVX-512).
func SIMDName ¶
func SIMDName() string
SIMDName returns the active SIMD target name (e.g. "avx512", "avx2", "neon", "scalar").
func SliceAddScalar ¶
func SliceAddScalar[T Lanes](dst, src []T, val T)
SliceAddScalar computes dst[i] = src[i] + val.
func SliceDiv ¶
func SliceDiv[T Floats](dst, a, b []T)
SliceDiv computes dst[i] = a[i] / b[i] (floats only).
func SliceMax ¶
func SliceMax[T Lanes](data []T) T
SliceMax computes the maximum element in a slice.
func SliceMin ¶
func SliceMin[T Lanes](data []T) T
SliceMin computes the minimum element in a slice.
func SliceMinMax ¶
func SliceMinMax[T Lanes](data []T) (lo, hi T)
SliceMinMax computes both min and max of a slice in a single pass.
func SliceMulScalar ¶
func SliceMulScalar[T Lanes](dst, src []T, val T)
SliceMulScalar computes dst[i] = src[i] * val.
func SliceSqrt ¶
func SliceSqrt(dst, src []float64)
SliceSqrt computes dst[i] = √src[i] (float64 only).
func SliceSum ¶
func SliceSum[T Lanes](data []T) T
SliceSum computes the sum of all elements in a slice.
func StoreSlice ¶
StoreSlice safely writes a vector to data, handling short slices.
Types ¶
type Mask ¶
Mask is a re-export of hwy.Mask.
func GreaterEqual ¶
GreaterEqual returns a mask where a[i] >= b[i].
func GreaterThan ¶
GreaterThan returns a mask where a[i] > b[i].
func IsInf ¶
IsInf returns a mask where v[i] is ±Inf. sign: 0 = either, >0 = +Inf only, <0 = -Inf only.
type Vec ¶
Vec is a re-export of hwy.Vec so callers never import hwy directly.
func Const ¶
Const returns a vector with all lanes set to the given float32 constant. Convenient for float literals: compute.Const[float64](0.5).
func IfThenElse ¶
IfThenElse returns a[i] where mask is true, b[i] otherwise.
func IfThenElseZero ¶
IfThenElseZero returns v[i] where mask is true, 0 otherwise.
func IfThenZeroElse ¶
IfThenZeroElse returns 0 where mask is true, v[i] otherwise.
func RSqrtNewtonRaphson ¶
RSqrtNewtonRaphson returns element-wise 1/√v refined with Newton-Raphson.
func RSqrtPrecise ¶
RSqrtPrecise returns element-wise 1/√v with full precision.
func RoundToEven ¶
RoundToEven returns element-wise banker's rounding (round half to even).
func ShiftRight ¶
ShiftRight returns element-wise v >> bits (integers only). Arithmetic for signed, logical for unsigned.
func SignBit ¶
SignBit returns a vector with the sign bit set in every lane. For floats: -0.0. For signed ints: minimum value. For unsigned: high bit.
func ZeroIfNegative ¶
ZeroIfNegative returns 0 where v[i] < 0, v[i] otherwise (ReLU).