// used by the Go standard library.
package cpu
-// debugOptions is set to true by the runtime if go was compiled with GOEXPERIMENT=debugcpu
-// and GOOS is Linux or Darwin. This variable is linknamed in runtime/proc.go.
-var debugOptions bool
+// DebugOptions is set to true by the runtime if go was compiled with GOEXPERIMENT=debugcpu
+// and GOOS is Linux or Darwin.
+// This should not be changed after it is initialized.
+var DebugOptions bool
// CacheLinePad is used to pad structs to avoid false sharing.
type CacheLinePad struct{ _ [CacheLineSize]byte }
_ CacheLinePad
}
-// initialize examines the processor and sets the relevant variables above.
+// Initialize examines the processor and sets the relevant variables above.
// This is called by the runtime package early in program initialization,
// before normal init functions are run. env is set by runtime on Linux and Darwin
// if go was compiled with GOEXPERIMENT=debugcpu.
-func initialize(env string) {
+func Initialize(env string) {
doinit()
processOptions(env)
}
const CacheLineSize = 64
// arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
-// These are linknamed in runtime/os_linux_arm64.go and are initialized by
-// archauxv().
-var hwcap uint
-var hwcap2 uint
+// These are initialized by archauxv in runtime/os_linux_arm64.go.
+// These should not be changed after they are initialized.
+var HWCap uint
+var HWCap2 uint
// HWCAP/HWCAP2 bits. These are exposed by Linux.
const (
}
// HWCAP feature bits
- ARM64.HasFP = isSet(hwcap, hwcap_FP)
- ARM64.HasASIMD = isSet(hwcap, hwcap_ASIMD)
- ARM64.HasEVTSTRM = isSet(hwcap, hwcap_EVTSTRM)
- ARM64.HasAES = isSet(hwcap, hwcap_AES)
- ARM64.HasPMULL = isSet(hwcap, hwcap_PMULL)
- ARM64.HasSHA1 = isSet(hwcap, hwcap_SHA1)
- ARM64.HasSHA2 = isSet(hwcap, hwcap_SHA2)
- ARM64.HasCRC32 = isSet(hwcap, hwcap_CRC32)
- ARM64.HasATOMICS = isSet(hwcap, hwcap_ATOMICS)
- ARM64.HasFPHP = isSet(hwcap, hwcap_FPHP)
- ARM64.HasASIMDHP = isSet(hwcap, hwcap_ASIMDHP)
- ARM64.HasCPUID = isSet(hwcap, hwcap_CPUID)
- ARM64.HasASIMDRDM = isSet(hwcap, hwcap_ASIMDRDM)
- ARM64.HasJSCVT = isSet(hwcap, hwcap_JSCVT)
- ARM64.HasFCMA = isSet(hwcap, hwcap_FCMA)
- ARM64.HasLRCPC = isSet(hwcap, hwcap_LRCPC)
- ARM64.HasDCPOP = isSet(hwcap, hwcap_DCPOP)
- ARM64.HasSHA3 = isSet(hwcap, hwcap_SHA3)
- ARM64.HasSM3 = isSet(hwcap, hwcap_SM3)
- ARM64.HasSM4 = isSet(hwcap, hwcap_SM4)
- ARM64.HasASIMDDP = isSet(hwcap, hwcap_ASIMDDP)
- ARM64.HasSHA512 = isSet(hwcap, hwcap_SHA512)
- ARM64.HasSVE = isSet(hwcap, hwcap_SVE)
- ARM64.HasASIMDFHM = isSet(hwcap, hwcap_ASIMDFHM)
+ ARM64.HasFP = isSet(HWCap, hwcap_FP)
+ ARM64.HasASIMD = isSet(HWCap, hwcap_ASIMD)
+ ARM64.HasEVTSTRM = isSet(HWCap, hwcap_EVTSTRM)
+ ARM64.HasAES = isSet(HWCap, hwcap_AES)
+ ARM64.HasPMULL = isSet(HWCap, hwcap_PMULL)
+ ARM64.HasSHA1 = isSet(HWCap, hwcap_SHA1)
+ ARM64.HasSHA2 = isSet(HWCap, hwcap_SHA2)
+ ARM64.HasCRC32 = isSet(HWCap, hwcap_CRC32)
+ ARM64.HasATOMICS = isSet(HWCap, hwcap_ATOMICS)
+ ARM64.HasFPHP = isSet(HWCap, hwcap_FPHP)
+ ARM64.HasASIMDHP = isSet(HWCap, hwcap_ASIMDHP)
+ ARM64.HasCPUID = isSet(HWCap, hwcap_CPUID)
+ ARM64.HasASIMDRDM = isSet(HWCap, hwcap_ASIMDRDM)
+ ARM64.HasJSCVT = isSet(HWCap, hwcap_JSCVT)
+ ARM64.HasFCMA = isSet(HWCap, hwcap_FCMA)
+ ARM64.HasLRCPC = isSet(HWCap, hwcap_LRCPC)
+ ARM64.HasDCPOP = isSet(HWCap, hwcap_DCPOP)
+ ARM64.HasSHA3 = isSet(HWCap, hwcap_SHA3)
+ ARM64.HasSM3 = isSet(HWCap, hwcap_SM3)
+ ARM64.HasSM4 = isSet(HWCap, hwcap_SM4)
+ ARM64.HasASIMDDP = isSet(HWCap, hwcap_ASIMDDP)
+ ARM64.HasSHA512 = isSet(HWCap, hwcap_SHA512)
+ ARM64.HasSVE = isSet(HWCap, hwcap_SVE)
+ ARM64.HasASIMDFHM = isSet(HWCap, hwcap_ASIMDFHM)
}
func isSet(hwc uint, value uint) bool {
const CacheLineSize = 128
// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
-// These are linknamed in runtime/os_linux_ppc64x.go and are initialized by
-// archauxv().
-var hwcap uint
-var hwcap2 uint
+// These are initialized by archauxv in runtime/os_linux_ppc64x.go.
+// These should not be changed after they are initialized.
+var HWCap uint
+var HWCap2 uint
// HWCAP/HWCAP2 bits. These are exposed by the kernel.
const (
}
// HWCAP feature bits
- PPC64.HasVMX = isSet(hwcap, _PPC_FEATURE_HAS_ALTIVEC)
- PPC64.HasDFP = isSet(hwcap, _PPC_FEATURE_HAS_DFP)
- PPC64.HasVSX = isSet(hwcap, _PPC_FEATURE_HAS_VSX)
+ PPC64.HasVMX = isSet(HWCap, _PPC_FEATURE_HAS_ALTIVEC)
+ PPC64.HasDFP = isSet(HWCap, _PPC_FEATURE_HAS_DFP)
+ PPC64.HasVSX = isSet(HWCap, _PPC_FEATURE_HAS_VSX)
// HWCAP2 feature bits
- PPC64.IsPOWER8 = isSet(hwcap2, _PPC_FEATURE2_ARCH_2_07)
- PPC64.HasHTM = isSet(hwcap2, _PPC_FEATURE2_HAS_HTM)
- PPC64.HasISEL = isSet(hwcap2, _PPC_FEATURE2_HAS_ISEL)
- PPC64.HasVCRYPTO = isSet(hwcap2, _PPC_FEATURE2_HAS_VEC_CRYPTO)
- PPC64.HasHTMNOSC = isSet(hwcap2, _PPC_FEATURE2_HTM_NOSC)
- PPC64.IsPOWER9 = isSet(hwcap2, _PPC_FEATURE2_ARCH_3_00)
- PPC64.HasDARN = isSet(hwcap2, _PPC_FEATURE2_DARN)
- PPC64.HasSCV = isSet(hwcap2, _PPC_FEATURE2_SCV)
+ PPC64.IsPOWER8 = isSet(HWCap2, _PPC_FEATURE2_ARCH_2_07)
+ PPC64.HasHTM = isSet(HWCap2, _PPC_FEATURE2_HAS_HTM)
+ PPC64.HasISEL = isSet(HWCap2, _PPC_FEATURE2_HAS_ISEL)
+ PPC64.HasVCRYPTO = isSet(HWCap2, _PPC_FEATURE2_HAS_VEC_CRYPTO)
+ PPC64.HasHTMNOSC = isSet(HWCap2, _PPC_FEATURE2_HTM_NOSC)
+ PPC64.IsPOWER9 = isSet(HWCap2, _PPC_FEATURE2_ARCH_3_00)
+ PPC64.HasDARN = isSet(HWCap2, _PPC_FEATURE2_DARN)
+ PPC64.HasSCV = isSet(HWCap2, _PPC_FEATURE2_SCV)
}
func isSet(hwc uint, value uint) bool {
package cpu
var (
- Options = options
- DebugOptions = debugOptions
+ Options = options
)
package runtime
-// For go:linkname
-import _ "unsafe"
+import "internal/cpu"
var randomNumber uint32
-// arm64 doesn't have a 'cpuid' instruction equivalent and relies on
-// HWCAP/HWCAP2 bits for hardware capabilities.
-
-//go:linkname cpu_hwcap internal/cpu.hwcap
-var cpu_hwcap uint
-
-//go:linkname cpu_hwcap2 internal/cpu.hwcap2
-var cpu_hwcap2 uint
-
func archauxv(tag, val uintptr) {
switch tag {
case _AT_RANDOM:
// it as a byte array.
randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
+
case _AT_HWCAP:
- cpu_hwcap = uint(val)
+ // arm64 doesn't have a 'cpuid' instruction equivalent and relies on
+ // HWCAP/HWCAP2 bits for hardware capabilities.
+ cpu.HWCap = uint(val)
case _AT_HWCAP2:
- cpu_hwcap2 = uint(val)
+ cpu.HWCap2 = uint(val)
}
}
package runtime
-// For go:linkname
-import _ "unsafe"
-
-// ppc64x doesn't have a 'cpuid' instruction equivalent and relies on
-// HWCAP/HWCAP2 bits for hardware capabilities.
-
-//go:linkname cpu_hwcap internal/cpu.hwcap
-var cpu_hwcap uint
-
-//go:linkname cpu_hwcap2 internal/cpu.hwcap2
-var cpu_hwcap2 uint
+import "internal/cpu"
func archauxv(tag, val uintptr) {
switch tag {
case _AT_HWCAP:
- cpu_hwcap = uint(val)
+ // ppc64x doesn't have a 'cpuid' instruction
+ // equivalent and relies on HWCAP/HWCAP2 bits for
+ // hardware capabilities.
+ cpu.HWCap = uint(val)
case _AT_HWCAP2:
- cpu_hwcap2 = uint(val)
+ cpu.HWCap2 = uint(val)
}
}
_GoidCacheBatch = 16
)
-//go:linkname internal_cpu_initialize internal/cpu.initialize
-func internal_cpu_initialize(env string)
-
-//go:linkname internal_cpu_debugOptions internal/cpu.debugOptions
-var internal_cpu_debugOptions bool
-
// cpuinit extracts the environment variable GODEBUGCPU from the environment on
-// Linux and Darwin if the GOEXPERIMENT debugcpu was set and calls internal/cpu.initialize.
+// Linux and Darwin if the GOEXPERIMENT debugcpu was set and calls internal/cpu.Initialize.
func cpuinit() {
const prefix = "GODEBUGCPU="
var env string
if haveexperiment("debugcpu") && (GOOS == "linux" || GOOS == "darwin") {
- internal_cpu_debugOptions = true
+ cpu.DebugOptions = true
// Similar to goenv_unix but extracts the environment value for
// GODEBUGCPU directly.
}
}
- internal_cpu_initialize(env)
+ cpu.Initialize(env)
support_erms = cpu.X86.HasERMS
support_popcnt = cpu.X86.HasPOPCNT