Debian Codegraph @

cpu/cpuid/cpuid.go

raw
1 // Package cpuid provides generic types used to represent CPU features supported
2 // by the architecture.
3 package cpuid
4
5 // CPU is a bitset of feature flags representing the capabilities of various CPU
6 // architeectures that this package provides optimized assembly routines for.
7 //
8 // The intent is to provide a stable ABI between the Go code that generate the
9 // assembly, and the program that uses the library functions.
10 type CPU uint64
11
12 // Feature represents a single CPU feature.
13 type Feature uint64
14
15 const (
16 // None is a Feature value that has no CPU features enabled.
17 None Feature = 0
18 // All is a Feature value that has all CPU features enabled.
19 All Feature = 0xFFFFFFFFFFFFFFFF
20 )
21
22 func (cpu CPU) Has(feature Feature) bool {
23 return (Feature(cpu) & feature) == feature
24 }
25
26 func (cpu *CPU) Set(feature Feature, enabled bool) {
27 if enabled {
28 *cpu |= CPU(feature)
29 } else {
30 *cpu &= ^CPU(feature)
31 }
32 }