Skip to content

Commit bce9b97

Browse files
authored
chore: update CPU feature detection to use archsimd package (#60)
1 parent e75321b commit bce9b97

3 files changed

Lines changed: 1 addition & 43 deletions

File tree

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ module github.com/nnnkkk7/go-simdcsv
44
// For local development on Apple Silicon, use Docker: make docker-test
55
// Using go 1.25 for IDE compatibility (SIMD code won't compile locally)
66
go 1.25
7-
8-
require golang.org/x/sys v0.40.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
2-
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=

simd_scanner.go

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,9 @@ import (
77
"simd/archsimd"
88
"sync"
99
"unsafe"
10-
11-
"golang.org/x/sys/cpu"
1210
)
1311

14-
// =============================================================================
15-
// AVX-512 CPU Detection and Fallback
16-
// =============================================================================
17-
//
18-
// NOTE: The simd/archsimd package in Go 1.26 is an experimental feature enabled via
19-
// GOEXPERIMENT=simd. This package is AMD64-specific, and a higher-level portable
20-
// SIMD package is planned for future development.
21-
// See: https://github.com/golang/go/issues/73787 (archsimd proposal)
22-
// See: https://go.dev/doc/go1.26 (Go 1.26 Release Notes)
23-
//
24-
// NOTE: The archsimd.Int8x64.Equal().ToBits() method internally uses the VPMOVB2M
25-
// instruction (AVX-512BW). This instruction causes SIGILL (illegal instruction) on
26-
// CPUs that do not support AVX-512, including GitHub Actions ubuntu-latest runners,
27-
// most CI environments, and older CPUs.
28-
//
29-
// TODO: Revisit this fallback implementation when the simd/archsimd package provides:
30-
// - Mandatory runtime CPU feature checks within the archsimd package
31-
// (Issue #73787: "It is an open question whether we want to enforce that a CPU
32-
// feature check must be performed before using a vector intrinsic.")
33-
// - AVX2-only alternative to ToBits() (using VPMOVMSKB instruction)
34-
// - A high-level portable SIMD package
35-
//
36-
// TODO: Replace golang.org/x/sys/cpu usage with official archsimd API (e.g.,
37-
// archsimd.HasAVX512()) when such API becomes available. Currently, the archsimd
38-
// package does not provide CPU feature detection functions (as of Go 1.26).
39-
//
40-
// =============================================================================
41-
4212
// useAVX512 indicates whether AVX-512 instructions are available at runtime.
43-
// This is set once at init time and used to dispatch to the appropriate implementation.
44-
//
45-
// NOTE: All three feature flags are required:
46-
// - AVX512F: Foundation 512-bit vector operations
47-
// - AVX512BW: Byte/word granularity operations (ToBits() uses VPMOVB2M)
48-
// - AVX512VL: 128/256-bit vector support with AVX-512 instructions
4913
var useAVX512 bool
5014

5115
// SIMD processing constants.
@@ -58,9 +22,7 @@ const (
5822
)
5923

6024
func init() {
61-
// NOTE: Using golang.org/x/sys/cpu for runtime CPU feature detection.
62-
// The archsimd package itself does not provide CPU detection functions (as of Go 1.26).
63-
useAVX512 = cpu.X86.HasAVX512F && cpu.X86.HasAVX512BW && cpu.X86.HasAVX512VL
25+
useAVX512 = archsimd.X86.AVX512()
6426
}
6527

6628
// =============================================================================

0 commit comments

Comments
 (0)