diff options
| author | 2026-03-23 05:10:40 +0000 | |
|---|---|---|
| committer | 2026-03-23 05:10:40 +0000 | |
| commit | a75e16740e1a185d523153d86badf9b2c2bcc12e (patch) | |
| tree | 2e6324ed0823c25f9b9a2135b4872c6a3624a921 /internal/cpu/cpu_amd64.go | |
| parent | refstore: Improve interfaces, errors, and make batch work (diff) | |
| signature | No signature | |
Vendor a minimal internal/cpu for AMD64 only v0.1.93
Diffstat (limited to 'internal/cpu/cpu_amd64.go')
| -rw-r--r-- | internal/cpu/cpu_amd64.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/cpu/cpu_amd64.go b/internal/cpu/cpu_amd64.go new file mode 100644 index 00000000..f20c810a --- /dev/null +++ b/internal/cpu/cpu_amd64.go @@ -0,0 +1,33 @@ +//go:build amd64 && !purego + +package cpu + +const ( + cpuidOSXSAVE = 1 << 27 + cpuidAVX = 1 << 28 + cpuidAVX2 = 1 << 5 +) + +// cpuid is implemented in cpu_amd64.s. +func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) + +// xgetbv with ecx = 0 is implemented in cpu_amd64.s. +func xgetbv() (eax, edx uint32) + +func init() { + maxID, _, _, _ := cpuid(0, 0) + if maxID < 7 { + return + } + + _, _, ecx1, _ := cpuid(1, 0) + + osSupportsAVX := false + if ecx1&cpuidOSXSAVE != 0 { + eax, _ := xgetbv() + osSupportsAVX = eax&(1<<1) != 0 && eax&(1<<2) != 0 + } + + _, ebx7, _, _ := cpuid(7, 0) + X86.HasAVX2 = osSupportsAVX && ecx1&cpuidAVX != 0 && ebx7&cpuidAVX2 != 0 +} |
