mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
035f1b358a
* feat(exp,simd): adding SumAxB helpers * feat(exp,simd): adding MeanAxB and ClampAxB helpers * feat(exp,simd): adding MinAxB and MaxAxB helpers * refactor(exp,simd): group perf helper category + architecture * feat(exp,simd): adding ContainsAxB helpers * perf(exp,simd): cast to unsafe slice once * feat(exp,simd): call the right SIMD helper based on local architecture * chore: internal dependency linking * Update exp/simd/math.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * style: fix linter * style: fix linter * chore: enable simd in makefile * chore(ci): add simd package to test runs * chore(ci): add simd package to test runs only for go 1.26 * fix(simd): fix overflow * fix(simd): fix overflow and apply the same behavior than lo.Mean * doc(exp,simd): adding initial doc * refactor(simd): move intersect_avx2 and intersect_sse code into intersect_avx512 * fix(simd): call SSE fallback instead of lo.Sum for default helpers * feat(simd): cache simd features on package init to avoid repeated checks * perf(exp,simd): precompute length + improve code quality * perf(exp,simd): faster iteration for min/max value * test(exp,simd): adding benchmarks * test(exp,simd): adding benchmarks results * test(exp,simd): adding benchmarks results * doc(exp,simd): adding warning for overflows in SIMD operations * feat(exp,simd): adding more dispatch helpers * feat(exp,simd): adding SumBy variants * feat(exp,simd): adding MeanBy variants * fix(exp,simd): faster clamp * 💄 * doc(exp,simd): adding SumBy + MeanBy * fix(exp,simd): faster SIMD operations * chore(ci): enable the benchmarks temporary * chore(ci): display cpu architecture before running tests * chore(ci): github actions are hidding some useful stuffs * chore(ci): no SIMD VM available at Github during the weekend ??? * test(exp,simd): larger epsilon * oops * perf(exp,simd): faster iterations * doc(exp,simd): report last version of benchmarks * 💄 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
//go:build go1.26 && goexperiment.simd && amd64
|
|
|
|
package simd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"simd/archsimd"
|
|
)
|
|
|
|
// skipHelper is a small interface implemented by both *testing.T and *testing.B
|
|
// to allow unified CPU feature requirement checking for both tests and benchmarks.
|
|
type skipHelper interface {
|
|
Helper()
|
|
Skipf(format string, args ...any)
|
|
}
|
|
|
|
// How to check if your Linux CPU supports SIMD (avoids SIGILL):
|
|
//
|
|
// grep -E 'avx|sse' /proc/cpuinfo
|
|
//
|
|
// Or: lscpu | grep -i avx
|
|
//
|
|
// You need:
|
|
// - SSE tests (128-bit): sse2 (baseline on amd64), sse4.1/sse4.2 often used
|
|
// - AVX2 tests (256-bit): avx2 in flags
|
|
// - AVX-512 tests: avx512f (and often avx512bw, avx512vl)
|
|
//
|
|
// If your CPU lacks AVX2 or AVX-512, tests that use them will be skipped automatically.
|
|
|
|
// requireAVX2 skips the test/benchmark if the CPU does not support AVX2 (256-bit SIMD).
|
|
// Use at the start of each AVX2 test/benchmark to avoid SIGILL on older or non-x86 systems.
|
|
func requireAVX2(t skipHelper) {
|
|
t.Helper()
|
|
if !archsimd.X86.AVX2() {
|
|
t.Skipf("CPU does not support AVX2; skipping. Check compatibility: grep avx2 /proc/cpuinfo")
|
|
}
|
|
}
|
|
|
|
// requireAVX512 skips the test/benchmark if the CPU does not support AVX-512 Foundation.
|
|
// Use at the start of each AVX-512 test/benchmark to avoid SIGILL on CPUs without AVX-512.
|
|
func requireAVX512(t skipHelper) {
|
|
t.Helper()
|
|
if !archsimd.X86.AVX512() {
|
|
t.Skipf("CPU does not support AVX-512; skipping. Check compatibility: grep avx512 /proc/cpuinfo")
|
|
}
|
|
}
|
|
|
|
// PrintCPUFeatures prints detected x86 SIMD features (for debugging).
|
|
// Run: go test -run PrintCPUFeatures -v
|
|
func PrintCPUFeatures(t *testing.T) {
|
|
fmt.Fprintf(os.Stdout, "X86 HasAVX=%v HasAVX2=%v HasAVX512=%v\n",
|
|
archsimd.X86.AVX(), archsimd.X86.AVX2(), archsimd.X86.AVX512())
|
|
}
|