Commit cd7cb86d authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: don't use linkname to refer to internal/cpu

The runtime package already imports the internal/cpu package, so there
is no reason for it to use go:linkname comments to refer to
internal/cpu functions and variables. Since internal/cpu is internal,
we can just export those names. Removing the obscurity of go:linkname
outweighs the minor additional complexity added to the internal/cpu API.

Change-Id: Id89951b7f3fc67cd9bce67ac6d01d44a647a10ad
Reviewed-on: https://go-review.googlesource.com/128755
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarMartin Möhrmann <moehrmann@google.com>
parent 4e1b11e2
...@@ -6,9 +6,10 @@ ...@@ -6,9 +6,10 @@
// used by the Go standard library. // used by the Go standard library.
package cpu package cpu
// debugOptions is set to true by the runtime if go was compiled with GOEXPERIMENT=debugcpu // 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. // and GOOS is Linux or Darwin.
var debugOptions bool // This should not be changed after it is initialized.
var DebugOptions bool
// CacheLinePad is used to pad structs to avoid false sharing. // CacheLinePad is used to pad structs to avoid false sharing.
type CacheLinePad struct{ _ [CacheLineSize]byte } type CacheLinePad struct{ _ [CacheLineSize]byte }
...@@ -121,11 +122,11 @@ type s390x struct { ...@@ -121,11 +122,11 @@ type s390x struct {
_ CacheLinePad _ 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, // 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 // before normal init functions are run. env is set by runtime on Linux and Darwin
// if go was compiled with GOEXPERIMENT=debugcpu. // if go was compiled with GOEXPERIMENT=debugcpu.
func initialize(env string) { func Initialize(env string) {
doinit() doinit()
processOptions(env) processOptions(env)
} }
......
...@@ -7,10 +7,10 @@ package cpu ...@@ -7,10 +7,10 @@ package cpu
const CacheLineSize = 64 const CacheLineSize = 64
// arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. // 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 // These are initialized by archauxv in runtime/os_linux_arm64.go.
// archauxv(). // These should not be changed after they are initialized.
var hwcap uint var HWCap uint
var hwcap2 uint var HWCap2 uint
// HWCAP/HWCAP2 bits. These are exposed by Linux. // HWCAP/HWCAP2 bits. These are exposed by Linux.
const ( const (
...@@ -71,30 +71,30 @@ func doinit() { ...@@ -71,30 +71,30 @@ func doinit() {
} }
// HWCAP feature bits // HWCAP feature bits
ARM64.HasFP = isSet(hwcap, hwcap_FP) ARM64.HasFP = isSet(HWCap, hwcap_FP)
ARM64.HasASIMD = isSet(hwcap, hwcap_ASIMD) ARM64.HasASIMD = isSet(HWCap, hwcap_ASIMD)
ARM64.HasEVTSTRM = isSet(hwcap, hwcap_EVTSTRM) ARM64.HasEVTSTRM = isSet(HWCap, hwcap_EVTSTRM)
ARM64.HasAES = isSet(hwcap, hwcap_AES) ARM64.HasAES = isSet(HWCap, hwcap_AES)
ARM64.HasPMULL = isSet(hwcap, hwcap_PMULL) ARM64.HasPMULL = isSet(HWCap, hwcap_PMULL)
ARM64.HasSHA1 = isSet(hwcap, hwcap_SHA1) ARM64.HasSHA1 = isSet(HWCap, hwcap_SHA1)
ARM64.HasSHA2 = isSet(hwcap, hwcap_SHA2) ARM64.HasSHA2 = isSet(HWCap, hwcap_SHA2)
ARM64.HasCRC32 = isSet(hwcap, hwcap_CRC32) ARM64.HasCRC32 = isSet(HWCap, hwcap_CRC32)
ARM64.HasATOMICS = isSet(hwcap, hwcap_ATOMICS) ARM64.HasATOMICS = isSet(HWCap, hwcap_ATOMICS)
ARM64.HasFPHP = isSet(hwcap, hwcap_FPHP) ARM64.HasFPHP = isSet(HWCap, hwcap_FPHP)
ARM64.HasASIMDHP = isSet(hwcap, hwcap_ASIMDHP) ARM64.HasASIMDHP = isSet(HWCap, hwcap_ASIMDHP)
ARM64.HasCPUID = isSet(hwcap, hwcap_CPUID) ARM64.HasCPUID = isSet(HWCap, hwcap_CPUID)
ARM64.HasASIMDRDM = isSet(hwcap, hwcap_ASIMDRDM) ARM64.HasASIMDRDM = isSet(HWCap, hwcap_ASIMDRDM)
ARM64.HasJSCVT = isSet(hwcap, hwcap_JSCVT) ARM64.HasJSCVT = isSet(HWCap, hwcap_JSCVT)
ARM64.HasFCMA = isSet(hwcap, hwcap_FCMA) ARM64.HasFCMA = isSet(HWCap, hwcap_FCMA)
ARM64.HasLRCPC = isSet(hwcap, hwcap_LRCPC) ARM64.HasLRCPC = isSet(HWCap, hwcap_LRCPC)
ARM64.HasDCPOP = isSet(hwcap, hwcap_DCPOP) ARM64.HasDCPOP = isSet(HWCap, hwcap_DCPOP)
ARM64.HasSHA3 = isSet(hwcap, hwcap_SHA3) ARM64.HasSHA3 = isSet(HWCap, hwcap_SHA3)
ARM64.HasSM3 = isSet(hwcap, hwcap_SM3) ARM64.HasSM3 = isSet(HWCap, hwcap_SM3)
ARM64.HasSM4 = isSet(hwcap, hwcap_SM4) ARM64.HasSM4 = isSet(HWCap, hwcap_SM4)
ARM64.HasASIMDDP = isSet(hwcap, hwcap_ASIMDDP) ARM64.HasASIMDDP = isSet(HWCap, hwcap_ASIMDDP)
ARM64.HasSHA512 = isSet(hwcap, hwcap_SHA512) ARM64.HasSHA512 = isSet(HWCap, hwcap_SHA512)
ARM64.HasSVE = isSet(hwcap, hwcap_SVE) ARM64.HasSVE = isSet(HWCap, hwcap_SVE)
ARM64.HasASIMDFHM = isSet(hwcap, hwcap_ASIMDFHM) ARM64.HasASIMDFHM = isSet(HWCap, hwcap_ASIMDFHM)
} }
func isSet(hwc uint, value uint) bool { func isSet(hwc uint, value uint) bool {
......
...@@ -9,10 +9,10 @@ package cpu ...@@ -9,10 +9,10 @@ package cpu
const CacheLineSize = 128 const CacheLineSize = 128
// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. // 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 // These are initialized by archauxv in runtime/os_linux_ppc64x.go.
// archauxv(). // These should not be changed after they are initialized.
var hwcap uint var HWCap uint
var hwcap2 uint var HWCap2 uint
// HWCAP/HWCAP2 bits. These are exposed by the kernel. // HWCAP/HWCAP2 bits. These are exposed by the kernel.
const ( const (
...@@ -48,19 +48,19 @@ func doinit() { ...@@ -48,19 +48,19 @@ func doinit() {
} }
// HWCAP feature bits // HWCAP feature bits
PPC64.HasVMX = isSet(hwcap, _PPC_FEATURE_HAS_ALTIVEC) PPC64.HasVMX = isSet(HWCap, _PPC_FEATURE_HAS_ALTIVEC)
PPC64.HasDFP = isSet(hwcap, _PPC_FEATURE_HAS_DFP) PPC64.HasDFP = isSet(HWCap, _PPC_FEATURE_HAS_DFP)
PPC64.HasVSX = isSet(hwcap, _PPC_FEATURE_HAS_VSX) PPC64.HasVSX = isSet(HWCap, _PPC_FEATURE_HAS_VSX)
// HWCAP2 feature bits // HWCAP2 feature bits
PPC64.IsPOWER8 = isSet(hwcap2, _PPC_FEATURE2_ARCH_2_07) PPC64.IsPOWER8 = isSet(HWCap2, _PPC_FEATURE2_ARCH_2_07)
PPC64.HasHTM = isSet(hwcap2, _PPC_FEATURE2_HAS_HTM) PPC64.HasHTM = isSet(HWCap2, _PPC_FEATURE2_HAS_HTM)
PPC64.HasISEL = isSet(hwcap2, _PPC_FEATURE2_HAS_ISEL) PPC64.HasISEL = isSet(HWCap2, _PPC_FEATURE2_HAS_ISEL)
PPC64.HasVCRYPTO = isSet(hwcap2, _PPC_FEATURE2_HAS_VEC_CRYPTO) PPC64.HasVCRYPTO = isSet(HWCap2, _PPC_FEATURE2_HAS_VEC_CRYPTO)
PPC64.HasHTMNOSC = isSet(hwcap2, _PPC_FEATURE2_HTM_NOSC) PPC64.HasHTMNOSC = isSet(HWCap2, _PPC_FEATURE2_HTM_NOSC)
PPC64.IsPOWER9 = isSet(hwcap2, _PPC_FEATURE2_ARCH_3_00) PPC64.IsPOWER9 = isSet(HWCap2, _PPC_FEATURE2_ARCH_3_00)
PPC64.HasDARN = isSet(hwcap2, _PPC_FEATURE2_DARN) PPC64.HasDARN = isSet(HWCap2, _PPC_FEATURE2_DARN)
PPC64.HasSCV = isSet(hwcap2, _PPC_FEATURE2_SCV) PPC64.HasSCV = isSet(HWCap2, _PPC_FEATURE2_SCV)
} }
func isSet(hwc uint, value uint) bool { func isSet(hwc uint, value uint) bool {
......
...@@ -5,6 +5,5 @@ ...@@ -5,6 +5,5 @@
package cpu package cpu
var ( var (
Options = options Options = options
DebugOptions = debugOptions
) )
...@@ -6,20 +6,10 @@ ...@@ -6,20 +6,10 @@
package runtime package runtime
// For go:linkname import "internal/cpu"
import _ "unsafe"
var randomNumber uint32 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) { func archauxv(tag, val uintptr) {
switch tag { switch tag {
case _AT_RANDOM: case _AT_RANDOM:
...@@ -28,10 +18,13 @@ func archauxv(tag, val uintptr) { ...@@ -28,10 +18,13 @@ func archauxv(tag, val uintptr) {
// it as a byte array. // it as a byte array.
randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 | randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 |
uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24 uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24
case _AT_HWCAP: 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: case _AT_HWCAP2:
cpu_hwcap2 = uint(val) cpu.HWCap2 = uint(val)
} }
} }
......
...@@ -7,23 +7,16 @@ ...@@ -7,23 +7,16 @@
package runtime package runtime
// For go:linkname import "internal/cpu"
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
func archauxv(tag, val uintptr) { func archauxv(tag, val uintptr) {
switch tag { switch tag {
case _AT_HWCAP: 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: case _AT_HWCAP2:
cpu_hwcap2 = uint(val) cpu.HWCap2 = uint(val)
} }
} }
...@@ -477,20 +477,14 @@ const ( ...@@ -477,20 +477,14 @@ const (
_GoidCacheBatch = 16 _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 // 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() { func cpuinit() {
const prefix = "GODEBUGCPU=" const prefix = "GODEBUGCPU="
var env string var env string
if haveexperiment("debugcpu") && (GOOS == "linux" || GOOS == "darwin") { if haveexperiment("debugcpu") && (GOOS == "linux" || GOOS == "darwin") {
internal_cpu_debugOptions = true cpu.DebugOptions = true
// Similar to goenv_unix but extracts the environment value for // Similar to goenv_unix but extracts the environment value for
// GODEBUGCPU directly. // GODEBUGCPU directly.
...@@ -511,7 +505,7 @@ func cpuinit() { ...@@ -511,7 +505,7 @@ func cpuinit() {
} }
} }
internal_cpu_initialize(env) cpu.Initialize(env)
support_erms = cpu.X86.HasERMS support_erms = cpu.X86.HasERMS
support_popcnt = cpu.X86.HasPOPCNT support_popcnt = cpu.X86.HasPOPCNT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment