internal/abi: use arch family instead of arch string

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>
This commit is contained in:
Keith Randall 2025-02-24 10:19:39 -08:00
parent 7194caf11b
commit f69703d389
5 changed files with 28 additions and 23 deletions

View file

@ -2033,7 +2033,7 @@ func (s *state) stmt(n ir.Node) {
// Check the cache first. // Check the cache first.
var merge *ssa.Block 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. // Note: we can only use the cache if we have the right atomic load instruction.
// Double-check that here. // Double-check that here.
if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil { if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil {
@ -5768,7 +5768,7 @@ func (s *state) dottype1(pos src.XPos, src, dst *types.Type, iface, source, targ
var d *ssa.Value var d *ssa.Value
if descriptor != nil { if descriptor != nil {
d = s.newValue1A(ssa.OpAddr, byteptr, descriptor, s.sb) 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. // Note: we can only use the cache if we have the right atomic load instruction.
// Double-check that here. // Double-check that here.
if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil { if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil {

View file

@ -4,25 +4,26 @@
package sys package sys
import "encoding/binary" import (
"encoding/binary"
"internal/goarch"
)
// ArchFamily represents a family of one or more related architectures. // TODO: just use goarch.ArchFamilyType directly
// For example, ppc64 and ppc64le are both members of the PPC64 family. type ArchFamily = goarch.ArchFamilyType
type ArchFamily byte
const ( const (
NoArch ArchFamily = iota AMD64 = goarch.AMD64
AMD64 ARM = goarch.ARM
ARM ARM64 = goarch.ARM64
ARM64 I386 = goarch.I386
I386 Loong64 = goarch.LOONG64
Loong64 MIPS = goarch.MIPS
MIPS MIPS64 = goarch.MIPS64
MIPS64 PPC64 = goarch.PPC64
PPC64 RISCV64 = goarch.RISCV64
RISCV64 S390X = goarch.S390X
S390X Wasm = goarch.WASM
Wasm
) )
// Arch represents an individual architecture. // Arch represents an individual architecture.

View file

@ -4,6 +4,8 @@
package abi package abi
import "internal/goarch"
type InterfaceSwitch struct { type InterfaceSwitch struct {
Cache *InterfaceSwitchCache Cache *InterfaceSwitchCache
NCases int NCases int
@ -27,11 +29,11 @@ type InterfaceSwitchCacheEntry struct {
Itab uintptr 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. // 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.) // (AtomicLoadPtr needs to be implemented in cmd/compile/internal/ssa/_gen/ARCH.rules.)
switch goarch { switch arch {
case "amd64", "arm64", "loong64", "mips", "mipsle", "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x": case goarch.AMD64, goarch.ARM64, goarch.LOONG64, goarch.MIPS, goarch.MIPS64, goarch.PPC64, goarch.RISCV64, goarch.S390X:
return true return true
default: default:
return false return false

View file

@ -12,6 +12,8 @@ package goarch
// //
//go:generate go run gengoarch.go //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 type ArchFamilyType int
const ( const (

View file

@ -474,7 +474,7 @@ func typeAssert(s *abi.TypeAssert, t *_type) *itab {
tab = getitab(s.Inter, t, s.CanFail) tab = getitab(s.Inter, t, s.CanFail)
} }
if !abi.UseInterfaceSwitchCache(GOARCH) { if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
return tab return tab
} }
@ -574,7 +574,7 @@ func interfaceSwitch(s *abi.InterfaceSwitch, t *_type) (int, *itab) {
} }
} }
if !abi.UseInterfaceSwitchCache(GOARCH) { if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
return case_, tab return case_, tab
} }