cpuid.go

 1package platform
 2
 3// CpuFeatureFlags exposes methods for querying CPU capabilities
 4type CpuFeatureFlags interface {
 5	// Has returns true when the specified flag (represented as uint64) is supported
 6	Has(cpuFeature CpuFeature) bool
 7	// HasExtra returns true when the specified extraFlag (represented as uint64) is supported
 8	HasExtra(cpuFeature CpuFeature) bool
 9	// Raw returns the raw bitset that represents CPU features used by wazero. This can be used for cache keying.
10	// For now, we only use four features, so uint64 is enough.
11	Raw() uint64
12}
13
14type CpuFeature uint64
15
16const (
17	// CpuFeatureAmd64SSE3 is the flag to query CpuFeatureFlags.Has for SSEv3 capabilities on amd64
18	CpuFeatureAmd64SSE3 CpuFeature = 1
19	// CpuFeatureAmd64SSE4_1 is the flag to query CpuFeatureFlags.Has for SSEv4.1 capabilities on amd64
20	CpuFeatureAmd64SSE4_1 CpuFeature = 1 << 19
21	// CpuFeatureAmd64SSE4_2 is the flag to query CpuFeatureFlags.Has for SSEv4.2 capabilities on amd64
22	CpuFeatureAmd64SSE4_2 CpuFeature = 1 << 20
23	// Note: when adding new features, ensure that the feature is included in CpuFeatureFlags.Raw.
24)
25
26const (
27	// CpuExtraFeatureAmd64ABM is the flag to query CpuFeatureFlags.HasExtra for Advanced Bit Manipulation capabilities (e.g. LZCNT) on amd64
28	CpuExtraFeatureAmd64ABM CpuFeature = 1 << 5
29	// Note: when adding new features, ensure that the feature is included in CpuFeatureFlags.Raw.
30)
31
32const (
33	// CpuFeatureArm64Atomic is the flag to query CpuFeatureFlags.Has for Large System Extensions capabilities on arm64
34	CpuFeatureArm64Atomic CpuFeature = 1 << 21
35)