Back to Lo

Simd Max

docs/data/simd-max.md

1.53.0787 B
Original Source

Finds the maximum value in a collection using SIMD instructions. The suffix (x2, x4, x8, x16, x32, x64) indicates the number of lanes processed simultaneously.

Note: Choose the variant matching your CPU's capabilities. Higher lane counts provide better performance but require newer CPU support.

go
// Using AVX2 variant (32 lanes at once) - Intel Haswell+ / AMD Excavator+
max := simd.MaxInt8x32([]int8{5, 2, 8, 1, 9})
// 9
go
// Using AVX-512 variant (16 lanes at once) - Intel Skylake-X+
max := simd.MaxFloat32x16([]float32{3.5, 1.2, 4.8, 2.1})
// 4.8
go
// Using AVX variant (4 lanes at once) - works on all amd64
max := simd.MaxInt32x4([]int32{100, 50, 200, 75})
// 200
go
// Empty collection returns 0
max := simd.MaxUint16x8([]uint16{})
// 0