No point in using string comparison when we can use integer comparison instead.
Unify the constants in cmd/internal/sys and internal/goarch while
we are at it.
Change-Id: I5681a601030307b7b286f958a8965559cb43506d
Reviewed-on: https://go-review.googlesource.com/c/go/+/652175
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Keith Randall <khr@google.com>
// Check the cache first.
var merge *ssa.Block
- if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Name) {
+ if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Family) {
// Note: we can only use the cache if we have the right atomic load instruction.
// Double-check that here.
if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil {
var d *ssa.Value
if descriptor != nil {
d = s.newValue1A(ssa.OpAddr, byteptr, descriptor, s.sb)
- if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Name) {
+ if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Family) {
// Note: we can only use the cache if we have the right atomic load instruction.
// Double-check that here.
if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil {
package sys
-import "encoding/binary"
+import (
+ "encoding/binary"
+ "internal/goarch"
+)
-// ArchFamily represents a family of one or more related architectures.
-// For example, ppc64 and ppc64le are both members of the PPC64 family.
-type ArchFamily byte
+// TODO: just use goarch.ArchFamilyType directly
+type ArchFamily = goarch.ArchFamilyType
const (
- NoArch ArchFamily = iota
- AMD64
- ARM
- ARM64
- I386
- Loong64
- MIPS
- MIPS64
- PPC64
- RISCV64
- S390X
- Wasm
+ AMD64 = goarch.AMD64
+ ARM = goarch.ARM
+ ARM64 = goarch.ARM64
+ I386 = goarch.I386
+ Loong64 = goarch.LOONG64
+ MIPS = goarch.MIPS
+ MIPS64 = goarch.MIPS64
+ PPC64 = goarch.PPC64
+ RISCV64 = goarch.RISCV64
+ S390X = goarch.S390X
+ Wasm = goarch.WASM
)
// Arch represents an individual architecture.
package abi
+import "internal/goarch"
+
type InterfaceSwitch struct {
Cache *InterfaceSwitchCache
NCases int
Itab uintptr
}
-func UseInterfaceSwitchCache(goarch string) bool {
+func UseInterfaceSwitchCache(arch goarch.ArchFamilyType) bool {
// We need an atomic load instruction to make the cache multithreaded-safe.
// (AtomicLoadPtr needs to be implemented in cmd/compile/internal/ssa/_gen/ARCH.rules.)
- switch goarch {
- case "amd64", "arm64", "loong64", "mips", "mipsle", "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x":
+ switch arch {
+ case goarch.AMD64, goarch.ARM64, goarch.LOONG64, goarch.MIPS, goarch.MIPS64, goarch.PPC64, goarch.RISCV64, goarch.S390X:
return true
default:
return false
//
//go:generate go run gengoarch.go
+// ArchFamilyType represents a family of one or more related architectures.
+// For example, ppc64 and ppc64le are both members of the PPC64 family.
type ArchFamilyType int
const (
tab = getitab(s.Inter, t, s.CanFail)
}
- if !abi.UseInterfaceSwitchCache(GOARCH) {
+ if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
return tab
}
}
}
- if !abi.UseInterfaceSwitchCache(GOARCH) {
+ if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
return case_, tab
}