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.
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 {
@ -5768,7 +5768,7 @@ func (s *state) dottype1(pos src.XPos, src, dst *types.Type, iface, source, targ
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 {

View file

@ -4,25 +4,26 @@
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.

View file

@ -4,6 +4,8 @@
package abi
import "internal/goarch"
type InterfaceSwitch struct {
Cache *InterfaceSwitchCache
NCases int
@ -27,11 +29,11 @@ type InterfaceSwitchCacheEntry struct {
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

View file

@ -12,6 +12,8 @@ package goarch
//
//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 (

View file

@ -474,7 +474,7 @@ func typeAssert(s *abi.TypeAssert, t *_type) *itab {
tab = getitab(s.Inter, t, s.CanFail)
}
if !abi.UseInterfaceSwitchCache(GOARCH) {
if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
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
}