Documentation
¶
Overview ¶
Package ref is the portable Go reference implementation of every kernel.
It defines the semantics. Every generated backend is differential-tested against it, and it is also the live fallback: the dispatcher runs these functions on architectures with no backend, in builds made with the purego tag, and below the per-kernel element threshold where crossing into assembly costs more than it saves.
It is therefore not throwaway code. The loops are written for bounds-check elimination because they run in the small-n hot path.
The numerical contract these functions define is documented on package kernel. The parts that are easy to get wrong:
- Floating-point reductions use exactly kernel.SumLanes accumulators and kernel.CombineTree, so every vector width reproduces them bit for bit.
- Dot multiplies and adds with separate roundings; it does not fuse.
- Minimum, Maximum, Min and Max implement IEEE-754-2019 minimum/maximum: NaN propagates, and +0 compares greater than -0.
- Integer Abs and Neg wrap, so Abs(MinInt32) is MinInt32, matching PABSD.
Index ¶
- func AbsFloat[T Float](dst, a []T)
- func AbsInt[T Integer](dst, a []T)
- func Acos[T float](dst, a []T)
- func Acosh[T float](dst, a []T)
- func Add[T Number](dst, a, b []T)
- func Add3[T Number](dst, a, b, c []T)
- func Add4[T Number](dst, a, b, c, d []T)
- func AddScalar[T Number](dst, a []T, s T)
- func AddScaled[T Number](dst, a, b []T, s T)
- func Adler32(p []byte, seed uint32) uint32
- func ArgMaxFloat[T Float](a []T) int
- func ArgMaxInt[T Integer](a []T) int
- func ArgMinFloat[T Float](a []T) int
- func ArgMinInt[T Integer](a []T) int
- func Asin[T float](dst, a []T)
- func Asinh[T float](dst, a []T)
- func Atan[T float](dst, a []T)
- func Atan2[T float](dst, a, b []T)
- func Atanh[T float](dst, a []T)
- func B64Decode(dst, src []byte) int
- func B64Encode(dst, src []byte) int
- func BF16ToF32(dst []float32, a []uint16)
- func BitAnd(dst, a, b []byte)
- func BitAndNot(dst, a, b []byte)
- func BitNot(dst, a []byte)
- func BitOr(dst, a, b []byte)
- func BitPackU32(dst, a []uint32, bits int32)
- func BitUnpackFastU32(dst, src []uint32, blocks int, bits uint32)
- func BitUnpackU32(dst, a []uint32, bits int32)
- func BitXor(dst, a, b []byte)
- func BitshuffleU8(dst, src []byte, dir byte)
- func ByteSwap[T Integer](dst, a []T)
- func CAbs64(dst []float32, a []complex64)
- func CAbs128(dst []float64, a []complex128)
- func CAdd[C complexT](dst, a, b []C)
- func CConj64(dst, a []complex64)
- func CConj128(dst, a []complex128)
- func CDiv64(dst, a, b []complex64)
- func CDiv128(dst, a, b []complex128)
- func CDot64(a, b []complex64) complex64
- func CDot128(a, b []complex128) complex128
- func CDotConj64(a, b []complex64) complex64
- func CDotConj128(a, b []complex128) complex128
- func CFromParts64(dst []complex64, re, im []float32)
- func CFromParts128(dst []complex128, re, im []float64)
- func CImag64(dst []float32, a []complex64)
- func CImag128(dst []float64, a []complex128)
- func CMul64(dst, a, b []complex64)
- func CMul128(dst, a, b []complex128)
- func CNeg[C complexT](dst, a []C)
- func CRC32C(p []byte, seed uint32) uint32
- func CReal64(dst []float32, a []complex64)
- func CReal128(dst []float64, a []complex128)
- func CScale64(dst, a []complex64, s float32)
- func CScale128(dst, a []complex128, s float64)
- func CSub[C complexT](dst, a, b []C)
- func CSum64(a []complex64) complex64
- func CSum128(a []complex128) complex128
- func Cbrt[T float](dst, a []T)
- func Ceil[T Float](dst, a []T)
- func ClampFloat[T Float](dst, a []T, lo, hi T)
- func ClampInt[T Integer](dst, a []T, lo, hi T)
- func CommonPrefix(a, b []byte) int
- func CompareBytes(a, b []byte) int
- func Compress[T any](dst, src []T, keep []bool) int
- func CompressBitsFloat32(dst, src []float32, bm []byte) int
- func CompressBitsFloat64(dst, src []float64, bm []byte) int
- func CompressBitsInt32(dst, src []int32, bm []byte) int
- func CompressBitsInt64(dst, src []int64, bm []byte) int
- func CompressFloat32(dst, src []float32, keep []bool) int
- func CompressFloat64(dst, src []float64, keep []bool) int
- func CompressInt32(dst, src []int32, keep []bool) int
- func CompressInt64(dst, src []int64, keep []bool) int
- func Convolve[T Number](dst, sig, ker []T)
- func Correlate[T Number](dst, sig, ker []T)
- func Cos[T float](dst, a []T)
- func Cosh[T float](dst, a []T)
- func CountAny(b, chars []byte) int
- func CountByte(b []byte, c byte) int
- func CountSeq(haystack, needle []byte) int
- func CumMaxFloat[T Float](dst, a []T)
- func CumMaxInt[T Integer](dst, a []T)
- func CumMinFloat[T Float](dst, a []T)
- func CumMinInt[T Integer](dst, a []T)
- func CumProdInt[T Integer](dst, a []T)
- func Deinterleave2U8(a, b, src []byte)
- func DequantizeI8(dst []float32, a []int8, scale float32, zeroPoint int32)
- func DequantizePerChannelI8(dst []float32, a []int8, scale []float32, zeroPoint []int32, ...)
- func DequantizePerChannelU8(dst []float32, a []uint8, scale []float32, zeroPoint []int32, ...)
- func DequantizeU8(dst []float32, a []uint8, scale float32, zeroPoint int32)
- func Diff[T Number](dst, a []T)
- func DifferenceInt[T Integer](dst, a, b []T) int
- func Div[T Float](dst, a, b []T)
- func DivScalar[T Number](dst, a []T, s T)
- func DotFloat[T Float](a, b []T) T
- func DotInt[T Integer](a, b []T) T
- func DtoaF64(dst []byte, v float64) int
- func EqualBytes(a, b []byte) bool
- func EqualFoldASCII(a, b []byte) bool
- func EqualMask[T number](dst []bool, a, b []T)
- func EqualScalarMask[T number](dst []bool, a []T, v T)
- func Erf[T float](dst, a []T)
- func Erfc[T float](dst, a []T)
- func Exp[T float](dst, a []T)
- func Exp2[T float](dst, a []T)
- func Expand[T any](dst, src []T, keep []bool) int
- func Expm1[T float](dst, a []T)
- func F8E4M3ToF32(dst []float32, a []byte)
- func F8E5M2ToF32(dst []float32, a []byte)
- func F16ToF32(dst []float32, a []uint16)
- func F32ToBF16(dst []uint16, a []float32)
- func F32ToF8E4M3(dst []byte, a []float32)
- func F32ToF8E5M2(dst []byte, a []float32)
- func F32ToF16(dst []uint16, a []float32)
- func FastCumProdFloat[T Float](dst, a []T)
- func FastCumSumFloat[T Float](dst, a []T)
- func Fill[T Number](dst []T, v T)
- func FillBytes(dst []byte, v byte)
- func FillFastFallbacks(s *kernel.Set)
- func Floor[T Float](dst, a []T)
- func FormatInts(dst []byte, vals []int64, sep byte) int
- func Gather[T number](dst, src []T, idx []int32)
- func GemmPackB[T Number](bp, b []T, k, n int)
- func GemvFloat[T float](dst, a, x []T, m, k int)
- func GemvInt[T integer](dst, a, x []T, m, k int)
- func Grayscale(dst, r, g, b []byte)
- func GreaterEqualMask[T number](dst []bool, a, b []T)
- func GreaterEqualScalarMask[T number](dst []bool, a []T, v T)
- func GreaterMask[T number](dst []bool, a, b []T)
- func GreaterScalarMask[T number](dst []bool, a []T, v T)
- func Hamming(a, b []byte) int
- func HammingWords(a, b []uint64) int
- func HashU64(dst, keys []uint64, seed uint64)
- func HexDecode(dst, src []byte) (int, bool)
- func HexEncode(dst, src []byte) int
- func Hypot[T float](dst, a, b []T)
- func Index(haystack, needle []byte) int
- func IndexAll(dst []int32, b []byte, c byte) int
- func IndexAllAny(dst []int32, b []byte, chars uint64) int
- func IndexAny(b, chars []byte) int
- func IndexAnyOrLess(b, chars []byte, lo byte) int
- func IndexByte(b []byte, c byte) int
- func IndexNonASCII(b []byte) int
- func IndexNonASCII16(b []uint16) int
- func IndexNotAny(b, chars []byte) int
- func Interleave2U8(dst, a, b []byte)
- func IntersectInt[T Integer](dst, a, b []T) int
- func IsASCII(b []byte) bool
- func JSONCopyRun(dst, b []byte, html byte) int
- func JSONCopyValid(dst, b []byte, html byte) int
- func JSONMasks(dst, b []byte, want uint32)
- func JSONQuote(dst, b []byte, html byte) int
- func JSONStage1(out []uint64, masks []byte, nw int, carr []uint64, res []int64)
- func JSONValid(b []byte, stk []uint64) int
- func JSONValidTokens(b []byte, masks []uint64, stk []uint64) int
- func L1DiffFloat[T Float](a, b []T) T
- func L1DiffInt[T Integer](a, b []T) T
- func L1NormFloat[T Float](a []T) T
- func L1NormInt[T Integer](a []T) T
- func LZ4BlockDecode(dst, src []byte) int
- func LastIndex(haystack, needle []byte) int
- func LastIndexByte(b []byte, c byte) int
- func LastIndexNotAny(b, chars []byte) int
- func LayerNorm[T float](dst, a, gamma, beta []T, shift, denom T)
- func LeadingZeros[T Integer](dst, a []T)
- func Lerp[T Number](dst, a, b []T, t T)
- func LessEqualMask[T number](dst []bool, a, b []T)
- func LessEqualScalarMask[T number](dst []bool, a []T, v T)
- func LessMask[T number](dst []bool, a, b []T)
- func LessScalarMask[T number](dst []bool, a []T, v T)
- func Log[T float](dst, a []T)
- func Log1p[T float](dst, a []T)
- func Log2[T float](dst, a []T)
- func Log10[T float](dst, a []T)
- func LowerBoundFloat[T Float](dst []int32, a, q []T)
- func LowerBoundInt[T Integer](dst []int32, a, q []T)
- func MaskAll(m []bool) bool
- func MaskAnd(dst, a, b []bool)
- func MaskAny(m []bool) bool
- func MaskBits(dst, b []byte, c byte)
- func MaskBitsAny(dst, b []byte, chars uint64)
- func MaskBitsAny4(dst, b []byte, chars uint32)
- func MaskBitsLess(dst, b []byte, c byte)
- func MaskCount(m []bool) int
- func MaskNot(dst, a []bool)
- func MaskOr(dst, a, b []bool)
- func MaskXor(dst, a, b []bool)
- func MatMul[T number](dst, a, b []T, m, k, n int)
- func MatMulPk[T Number](dst, a, bp []T, m, k, n int)
- func MaxReduceFloat[T Float](a []T) T
- func MaxReduceInt[T Integer](a []T) T
- func MaximumFloat[T Float](dst, a, b []T)
- func MaximumInt[T Integer](dst, a, b []T)
- func MergeSortedU32(dst, a, b []uint32) int
- func MinMaxFloat[T Float](a []T) (T, T)
- func MinMaxInt[T Integer](a []T) (T, T)
- func MinReduceFloat[T Float](a []T) T
- func MinReduceInt[T Integer](a []T) T
- func MinimumFloat[T Float](dst, a, b []T)
- func MinimumInt[T Integer](dst, a, b []T)
- func MovingAverage[T Number](dst, a []T, width int)
- func Mul[T Number](dst, a, b []T)
- func Mul3[T Number](dst, a, b, c []T)
- func Mul4[T Number](dst, a, b, c, d []T)
- func NarrowU16U8(dst []byte, s []uint16)
- func NarrowU32U8(dst []byte, s []uint32)
- func NegFloat[T Float](dst, a []T)
- func NegInt[T Integer](dst, a []T)
- func NormFloat[T Float](a []T) T
- func NotEqualMask[T number](dst []bool, a, b []T)
- func NotEqualScalarMask[T number](dst []bool, a []T, v T)
- func OnesCount[T Integer](dst, a []T)
- func ParseInts(dst []int64, src []byte, idx []int32) (int, bool)
- func ParseUints(dst []uint64, src []byte, idx []int32) (int, bool)
- func Partition[T Number](dst, src []T, pivot T) int
- func PolyEval[T Number](dst, x, coeffs []T)
- func PopCount(b []byte) int
- func Pow[T float](dst, a, b []T)
- func ProdInt[T Integer](a []T) T
- func QMatMulI8(dst []int32, a, b []int8, m, k, n int)
- func QuantizeI8(dst []int8, a []float32, scale float32, zeroPoint int32)
- func QuantizePerChannelI8(dst []int8, a []float32, scale []float32, zeroPoint []int32, ...)
- func QuantizePerChannelU8(dst []uint8, a []float32, scale []float32, zeroPoint []int32, ...)
- func QuantizeU8(dst []uint8, a []float32, scale float32, zeroPoint int32)
- func RGBToUV(u, v, r, g, b []byte)
- func RLEDecodeInt32(dst []int32, values, counts []int32) int
- func Ramp[T Number](dst []T, start, step T)
- func RandFillU64(dst []uint64, seed uint64)
- func RandomF32(dst []float32, seed uint64)
- func RandomF64(dst []float64, seed uint64)
- func RandomU64(dst []uint64, seed uint64)
- func RankOneFloat[T Float](a, x, y []T, alpha T, m, n int)
- func Reciprocal[T Float](dst, a []T)
- func ReplaceByte(dst, b []byte, old, with byte)
- func RequantizeI8(dst []int8, a []int32, scale float32, zeroPoint int32)
- func Reverse[T Number](dst, a []T)
- func ReverseBits[T Integer](dst, a []T)
- func RollingMaxFloat[T Float](dst, a []T, window int)
- func RollingMaxInt[T Integer](dst, a []T, window int)
- func RollingMinFloat[T Float](dst, a []T, window int)
- func RollingMinInt[T Integer](dst, a []T, window int)
- func RotateFloat[T Float](x, y []T, c, s T)
- func Rotl[T Integer](dst, a []T, s uint64)
- func Rotr[T Integer](dst, a []T, s uint64)
- func Round[T Float](dst, a []T)
- func RoundToEven[T Float](dst, a []T)
- func RunStartsI32(dst []bool, a []int32)
- func RunStartsI64(dst []bool, a []int64)
- func RunStartsU8(dst []bool, a []byte)
- func SatAdd[T Saturating](dst, a, b []T)
- func SatSub[T Saturating](dst, a, b []T)
- func Scale[T Number](dst, a []T, s T)
- func Scatter[T number](dst []T, idx []int32, src []T)
- func Select[T number](dst []T, mask []bool, yes, no []T)
- func Set() kernel.Set
- func ShiftDiv[T float](dst, a []T, shift, denom T)
- func Shl[T Integer](dst, a []T, s uint64)
- func Shr[T Integer](dst, a []T, s uint64)
- func Sigmoid[T float](dst, a []T)
- func Sin[T float](dst, a []T)
- func Sinh[T float](dst, a []T)
- func SortOrdered[T ordered](a []T)
- func SparseDotFloat[T Float](v []T, idx []int32, x []T) T
- func Sqrt[T Float](dst, a []T)
- func Sub[T Number](dst, a, b []T)
- func SubScalar[T Number](dst, a []T, s T)
- func SumFloat[T Float](a []T) T
- func SumInt[T Integer](a []T) T
- func SumLanesFloat[T float](dst, a []T)
- func SumSqDevFloat[T Float](a []T, c T) T
- func SumSqDevInt[T Integer](a []T, c T) T
- func SumSqDiffFloat[T Float](a, b []T) T
- func SumSqDiffInt[T Integer](a, b []T) T
- func SumSquaresFloat[T Float](a []T) T
- func SumSquaresInt[T Integer](a []T) T
- func SumValidFloat32(a []float32, bm []byte) float32
- func SumValidFloat64(a []float64, bm []byte) float64
- func SumValidInt32(a []int32, bm []byte) int32
- func SumValidInt64(a []int64, bm []byte) int64
- func SwapFloat[T Float](x, y []T)
- func SwapInt[T Integer](x, y []T)
- func Tan[T float](dst, a []T)
- func Tanh[T float](dst, a []T)
- func Tile[T number](dst, pattern []T)
- func ToLowerASCII(dst, b []byte)
- func ToUpperASCII(dst, b []byte)
- func TrailingZeros[T Integer](dst, a []T)
- func Transpose[T Number](dst, a []T, m, n int)
- func Transpose8x8U8(dst, src []byte)
- func Trunc[T Float](dst, a []T)
- func ValidUTF8(b []byte) bool
- func VarintDecodeU64(dst []uint64, src []byte) (n, consumed int)
- func VarintLenU32(dst []int32, a []uint32)
- func VarintLenU64(dst []int32, a []uint64)
- func VarintSizeU32(a []uint32) int
- func VarintSizeU64(a []uint64) int
- func WidenU8U16(dst []uint16, s []byte)
- func WidenU8U32(dst []uint32, s []byte)
- func ZigzagDecodeI8(dst []int8, a []byte)
- func ZigzagDecodeI16(dst []int16, a []uint16)
- func ZigzagDecodeI32(dst []int32, a []uint32)
- func ZigzagDecodeI64(dst []int64, a []uint64)
- func ZigzagEncodeI8(dst []byte, a []int8)
- func ZigzagEncodeI16(dst []uint16, a []int16)
- func ZigzagEncodeI32(dst []uint32, a []int32)
- func ZigzagEncodeI64(dst []uint64, a []int64)
- type Float
- type Integer
- type Number
- type Saturating
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Adler32 ¶ added in v1.16.0
Adler32 is RFC 1950's checksum, seedable for rolling use; seed 1 is the standard start. The specification for simd_adler32.
func ArgMaxFloat ¶
func ArgMinFloat ¶
func BitPackU32 ¶
func BitUnpackFastU32 ¶ added in v1.20.0
BitUnpackFastU32 is the width-specialized unpack over whole 32-value blocks, the specification for simd_bitunpack_fast_u32. Little-endian bit order, matching BitPack.
func BitUnpackU32 ¶
func BitshuffleU8 ¶ added in v1.20.0
BitshuffleU8 transposes bits over 64-byte tiles: with dir 0, output plane p byte g holds bit p of input bytes 8g..8g+7; dir 1 inverts. The specification for simd_bitshuffle_u8.
func CAbs128 ¶
func CAbs128(dst []float64, a []complex128)
func CConj128 ¶
func CConj128(dst, a []complex128)
func CDiv128 ¶
func CDiv128(dst, a, b []complex128)
func CDot128 ¶
func CDot128(a, b []complex128) complex128
func CDotConj64 ¶
func CDotConj128 ¶
func CDotConj128(a, b []complex128) complex128
func CFromParts64 ¶
func CFromParts128 ¶
func CFromParts128(dst []complex128, re, im []float64)
func CImag128 ¶
func CImag128(dst []float64, a []complex128)
func CMul128 ¶
func CMul128(dst, a, b []complex128)
func CRC32C ¶ added in v1.16.0
CRC32C is the Castagnoli CRC, matching hash/crc32's Castagnoli table and the crc32c instruction family. The specification for simd_crc32c.
func CReal128 ¶
func CReal128(dst []float64, a []complex128)
func CScale128 ¶
func CScale128(dst, a []complex128, s float64)
func CSum128 ¶
func CSum128(a []complex128) complex128
func ClampFloat ¶
func ClampFloat[T Float](dst, a []T, lo, hi T)
func CommonPrefix ¶
func CompareBytes ¶
func CompressBitsFloat32 ¶ added in v1.15.0
func CompressBitsFloat64 ¶ added in v1.15.0
func CompressBitsInt32 ¶ added in v1.15.0
func CompressBitsInt64 ¶ added in v1.15.0
func CompressFloat32 ¶
func CompressFloat64 ¶
func CompressInt32 ¶
func CompressInt64 ¶
func CumMaxFloat ¶
func CumMaxFloat[T Float](dst, a []T)
func CumMinFloat ¶
func CumMinFloat[T Float](dst, a []T)
func CumProdInt ¶
func CumProdInt[T Integer](dst, a []T)
CumProdInt is the EXACT integer product scan. Two's-complement multiplication is associative, so the blocked grouping is bit-identical to the serial loop for every input including ones that overflow — verified over four million deliberately overflowing values. It therefore needs no Fast prefix, and this is the reference the int32 kernel falls back to.
It is written as the blocked scan rather than as the obvious serial loop so that reference and kernel have the same shape, and a change to one is visibly a change to the other.
func Deinterleave2U8 ¶ added in v1.19.0
func Deinterleave2U8(a, b, src []byte)
Deinterleave2U8 is the inverse: a[i]=src[2i], b[i]=src[2i+1].
func DequantizePerChannelI8 ¶
func DequantizePerChannelU8 ¶
func DifferenceInt ¶
func DtoaF64 ¶ added in v1.17.0
DtoaF64 renders the finite float64 v into dst exactly as simdjson's appendFloat does -- encoding/json's format rule, the whole-number fast path, negative zero as "-0" -- and returns the byte count. dst must hold 25 bytes.
func EqualBytes ¶
func EqualFoldASCII ¶
func EqualScalarMask ¶
func EqualScalarMask[T number](dst []bool, a []T, v T)
func F8E4M3ToF32 ¶
func F8E5M2ToF32 ¶
func F32ToF8E4M3 ¶
func F32ToF8E5M2 ¶
func FastCumProdFloat ¶
func FastCumProdFloat[T Float](dst, a []T)
func FastCumSumFloat ¶
func FastCumSumFloat[T Float](dst, a []T)
FastCumSum and FastCumProd are the exported references the generated backends fall back to and the differential tests compare against.
FastCumSumFloat is the blocked scan for float32 and the SERIAL loop for float64, and that asymmetry is measured rather than arbitrary. Eight doubles fill one AVX-512 register, so the shift steps become cross-lane permutes, and against a serial chain of four-cycle adds the blocked form measured 0.91x — slower. float32 has sixteen lanes to hide the same latency and wins. Since no kernel is generated for float64, this branch is what every tier runs there, so they still agree with each other.
func FillFastFallbacks ¶
FillFastFallbacks points any Fast slot with no generated kernel at the accurate one, for both float groups of a backend.
It runs after a backend is fully assembled, which is the only moment the two cases can be distinguished, and it is what lets a caller use FastExp on every architecture without asking whether that architecture has it. A target where the Fast tier did not measure faster simply computes a more accurate answer, which an upper bound on error permits.
func FormatInts ¶
FormatInts is the reference formatter: exact-fit, so it succeeds wherever success is possible, which is what makes it the safe fallback for short destinations.
func GreaterEqualMask ¶
func GreaterEqualMask[T number](dst []bool, a, b []T)
func GreaterEqualScalarMask ¶
func GreaterEqualScalarMask[T number](dst []bool, a []T, v T)
func GreaterMask ¶
func GreaterMask[T number](dst []bool, a, b []T)
func GreaterScalarMask ¶
func GreaterScalarMask[T number](dst []bool, a []T, v T)
func HammingWords ¶
func HashU64 ¶ added in v1.20.0
HashU64 mixes each key through the splitmix64 finalizer with the seed folded in: bulk hashing for bloom filters and partitioning. The specification for simd_hash_u64.
func HexDecode ¶
HexDecode is exported for the generated dispatch tables, which name the reference by its exported identifier. The two results are what kept this portable before the generator could return a pair.
func IndexAllAny ¶ added in v1.3.0
IndexAllAny writes the offset of every byte in b that equals any of the up to eight values packed into chars, one per byte, and returns how many it wrote.
It stops when dst fills, matching the kernel: a caller who sizes dst for the expected number of matches and gets more must get a truncated answer rather than an overrun.
func IndexAnyOrLess ¶ added in v1.7.0
IndexAnyOrLess is exported for the dispatch table and the differential test.
func IndexNonASCII ¶
func IndexNonASCII16 ¶
func IndexNotAny ¶
func Interleave2U8 ¶ added in v1.19.0
func Interleave2U8(dst, a, b []byte)
Interleave2U8: dst[2i]=a[i], dst[2i+1]=b[i]. Specification for simd_interleave2_u8; n is min(len(a), len(b)), dst needs 2n.
func IntersectInt ¶
func JSONCopyRun ¶ added in v1.8.0
JSONCopyRun is exported for the dispatch table and the differential test.
func JSONCopyValid ¶ added in v1.10.0
JSONCopyValid copies the bytes an encoder can write verbatim and validates them in the same pass, returning the count or -1 if they were not valid UTF-8.
func JSONQuote ¶ added in v1.10.0
JSONQuote copies b into dst with escapes written in place. dst must hold 6*len(b), which is every byte becoming \\u00XX.
func JSONStage1 ¶ added in v1.11.0
JSONStage1 runs the JSON indexer's first word pass over the five JSONMasks regions: escape resolution, quote parity, the in-string mask, and the counts and worklists that ride along. It is the reference for the simd_json_stage1 kernel and mirrors it exactly; see the kernel's comment in csrc/bytes.c for the contract.
func JSONValid ¶ added in v1.13.0
JSONValid answers Valid in one fused pass: byte classification, escape resolution, quote parity, the in-string control check, escape-target validation and the grammar walk, one 64-byte block at a time. 1 valid, 0 invalid, -1 the spill filled (nesting deeper than 64*(len(stk)+1)). Reference for simd_json_valid; the per-block order of checks -- control bytes, then escapes, then grammar -- is part of the contract, because it decides whether a document that is both too deep and malformed reports 0 or -1.
func JSONValidTokens ¶ added in v1.12.0
JSONValidTokens is the grammar half of a JSON Valid: it walks every significant byte -- outside a string, not whitespace, read from the two masks -- and reports whether they form one well-formed value. 1 valid, 0 invalid, -1 the spill filled (nesting deeper than 64*(len(stk)+1)). Reference for simd_json_valid_tokens.
func L1DiffFloat ¶
func L1DiffFloat[T Float](a, b []T) T
func L1NormFloat ¶
func L1NormFloat[T Float](a []T) T
func LZ4BlockDecode ¶ added in v1.18.0
LZ4 block decoding, the portable reference and the specification for simd_lz4_block_decode.
The block format is sequences of
token | literal-length extension | literals | offset | match-length ext
with four-bit lengths in the token (15 escapes to 255-run extension bytes), a two-byte little-endian match offset into the output already written, and a minimum match of four. The final sequence carries only literals: input ending exactly after them is the one well-formed way a block ends.
LZ4BlockDecode returns the decoded length, or -1 for malformed input: truncated anywhere, a zero or too-far offset, or output past cap. The kernel must agree on the byte and on the -1, and the differential fuzz says so.
func LastIndexByte ¶
func LastIndexNotAny ¶
func LeadingZeros ¶
func LeadingZeros[T Integer](dst, a []T)
func LessEqualMask ¶
func LessEqualMask[T number](dst []bool, a, b []T)
func LessEqualScalarMask ¶
func LessEqualScalarMask[T number](dst []bool, a []T, v T)
func LessScalarMask ¶
func LessScalarMask[T number](dst []bool, a []T, v T)
func LowerBoundFloat ¶
func LowerBoundInt ¶
func MaskBitsAny ¶ added in v1.4.0
MaskBitsAny is MaskBits for a set of up to eight bytes packed one per byte of chars, the same encoding IndexAllAny takes.
func MaskBitsAny4 ¶ added in v1.5.0
MaskBitsAny4 is MaskBitsAny for a set of at most four bytes, packed one per byte of a uint32.
func MaskBitsLess ¶ added in v1.4.0
MaskBitsLess is MaskBits for an inequality: the bit is set where the byte is below c.
func MaxReduceFloat ¶
func MaxReduceFloat[T Float](a []T) T
func MaxReduceInt ¶
func MaxReduceInt[T Integer](a []T) T
func MaximumFloat ¶
func MaximumFloat[T Float](dst, a, b []T)
func MaximumInt ¶
func MaximumInt[T Integer](dst, a, b []T)
func MergeSortedU32 ¶ added in v1.19.0
MergeSortedU32 merges two ascending arrays into dst -- ties taken from a first -- returning the total written. dst must hold len(a)+len(b). The specification for simd_merge_sorted_u32.
func MinMaxFloat ¶
func MinMaxFloat[T Float](a []T) (T, T)
func MinReduceFloat ¶
func MinReduceFloat[T Float](a []T) T
func MinReduceInt ¶
func MinReduceInt[T Integer](a []T) T
func MinimumFloat ¶
func MinimumFloat[T Float](dst, a, b []T)
func MinimumInt ¶
func MinimumInt[T Integer](dst, a, b []T)
func MovingAverage ¶
func NarrowU16U8 ¶
func NarrowU32U8 ¶
func NotEqualMask ¶
func NotEqualMask[T number](dst []bool, a, b []T)
func NotEqualScalarMask ¶
func NotEqualScalarMask[T number](dst []bool, a []T, v T)
func ParseInts ¶
ParseInts is the reference for the integer field parser. Fields are src[start:idx[k]] with start one past the previous separator, which is the shape IndexAll produces.
func ParseUints ¶
ParseUints is ParseInts over the full uint64 range and with no sign.
A leading '+' is rejected rather than skipped, matching strconv.ParseUint with bitSize 64, which accepts no sign at all.
func QuantizePerChannelI8 ¶
func QuantizePerChannelU8 ¶
func RLEDecodeInt32 ¶ added in v1.19.0
RLEDecodeInt32 expands (values[k], counts[k]) run-length pairs into dst with the public RunLengthDecodeInt32 contract exactly: non-positive counts are skipped, the expansion stops when dst is full, and the total written comes back. The specification for simd_rle_decode_i32.
func RandFillU64 ¶ added in v1.19.0
RandFillU64 fills dst with the eight-stream xoshiro256++ sequence seeded from seed by splitmix64, lane-interleaved. The specification for simd_rand_fill_u64; kernel and reference emit the identical stream. Not cryptographic.
func RandomF64 ¶
RandomF64 takes the top 53 bits and scales by 2^-53, the construction that cannot produce 1.0 — the largest result is 1 - 2^-53.
func RankOneFloat ¶ added in v1.2.0
RankOneFloat is a[i*n+j] += alpha*x[i]*y[j].
The row scale is hoisted exactly as the kernel hoists it. Writing alpha*x[i]*y[j] in the inner loop would associate the multiplications differently and disagree with the kernel in the last place, which the differential suite would then report as a kernel bug.
func Reciprocal ¶
func Reciprocal[T Float](dst, a []T)
func ReplaceByte ¶
func ReverseBits ¶
func ReverseBits[T Integer](dst, a []T)
func RollingMaxFloat ¶
func RollingMaxInt ¶
func RollingMinFloat ¶
func RollingMinInt ¶
func RotateFloat ¶ added in v1.2.0
func RotateFloat[T Float](x, y []T, c, s T)
RotateFloat applies a Givens rotation to a pair of vectors, using the original x[i] in both assignments.
func RoundToEven ¶
func RoundToEven[T Float](dst, a []T)
func RunStartsI32 ¶
func RunStartsI64 ¶
func RunStartsU8 ¶
func SatAdd ¶
func SatAdd[T Saturating](dst, a, b []T)
func SatSub ¶
func SatSub[T Saturating](dst, a, b []T)
func SortOrdered ¶
func SortOrdered[T ordered](a []T)
SortOrdered sorts in place with the standard library's pdqsort.
It is here as the reference and as the small-case path, and on integers it is also the shipped implementation: see the note on the exported Sort.
func SparseDotFloat ¶
func SumLanesFloat ¶
func SumLanesFloat[T float](dst, a []T)
func SumSqDevFloat ¶
func SumSqDevFloat[T Float](a []T, c T) T
func SumSqDevInt ¶
func SumSqDevInt[T Integer](a []T, c T) T
func SumSqDiffFloat ¶
func SumSqDiffFloat[T Float](a, b []T) T
func SumSqDiffInt ¶
func SumSqDiffInt[T Integer](a, b []T) T
func SumSquaresFloat ¶
func SumSquaresFloat[T Float](a []T) T
func SumSquaresInt ¶
func SumSquaresInt[T Integer](a []T) T
func SumValidFloat32 ¶ added in v1.15.0
func SumValidFloat64 ¶ added in v1.15.0
func SumValidInt32 ¶ added in v1.15.0
func SumValidInt64 ¶ added in v1.15.0
func SwapInt ¶ added in v1.2.0
func SwapInt[T Integer](x, y []T)
SwapInt is SwapFloat for the integer types.
func ToLowerASCII ¶
func ToLowerASCII(dst, b []byte)
func ToUpperASCII ¶
func ToUpperASCII(dst, b []byte)
func TrailingZeros ¶
func TrailingZeros[T Integer](dst, a []T)
func Transpose8x8U8 ¶ added in v1.19.0
func Transpose8x8U8(dst, src []byte)
Transpose8x8U8 transposes n independent 64-byte tiles as 8x8 byte matrices.
func VarintDecodeU64 ¶ added in v1.20.0
VarintDecodeU64 decodes LEB128 varints from src into dst until either runs out, returning values written and bytes consumed. A varint that never terminates within ten bytes, or truncation mid-value, stops the walk with what was complete. The specification for simd_varint_decode_u64.
func VarintLenU32 ¶
func VarintLenU64 ¶
func VarintSizeU32 ¶
func VarintSizeU64 ¶
func WidenU8U16 ¶
func WidenU8U32 ¶
func ZigzagDecodeI8 ¶
func ZigzagDecodeI16 ¶
func ZigzagDecodeI32 ¶
func ZigzagDecodeI64 ¶
func ZigzagEncodeI8 ¶
func ZigzagEncodeI16 ¶
func ZigzagEncodeI32 ¶
func ZigzagEncodeI64 ¶
Types ¶
type Integer ¶
type Integer = integer
Integer is the integer half of it, for the operations that are not the same on floats: integer minimum is not IEEE minimum, and integer Abs wraps where float Abs clears a sign bit.
type Number ¶
type Number interface {
~float32 | ~float64 |
~int8 | ~int16 | ~int32 | ~int64 |
~uint8 | ~uint16 | ~uint32 | ~uint64
}
Number is any element type the kernels handle.
type Saturating ¶
type Saturating = satInteger
Saturating is the integer types that have saturating add and subtract. The 64-bit ones are absent for the reason kernels.saturating gives: there is nothing wider to detect the overflow in.