Skip to content

Commit f69703d

Browse files
committed
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 <[email protected]> Reviewed-by: Michael Stapelberg <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 7194caf commit f69703d

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ func (s *state) stmt(n ir.Node) {
20332033

20342034
// Check the cache first.
20352035
var merge *ssa.Block
2036-
if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Name) {
2036+
if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Family) {
20372037
// Note: we can only use the cache if we have the right atomic load instruction.
20382038
// Double-check that here.
20392039
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
57685768
var d *ssa.Value
57695769
if descriptor != nil {
57705770
d = s.newValue1A(ssa.OpAddr, byteptr, descriptor, s.sb)
5771-
if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Name) {
5771+
if base.Flag.N == 0 && rtabi.UseInterfaceSwitchCache(Arch.LinkArch.Family) {
57725772
// Note: we can only use the cache if we have the right atomic load instruction.
57735773
// Double-check that here.
57745774
if intrinsics.lookup(Arch.LinkArch.Arch, "internal/runtime/atomic", "Loadp") == nil {

src/cmd/internal/sys/arch.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44

55
package sys
66

7-
import "encoding/binary"
7+
import (
8+
"encoding/binary"
9+
"internal/goarch"
10+
)
811

9-
// ArchFamily represents a family of one or more related architectures.
10-
// For example, ppc64 and ppc64le are both members of the PPC64 family.
11-
type ArchFamily byte
12+
// TODO: just use goarch.ArchFamilyType directly
13+
type ArchFamily = goarch.ArchFamilyType
1214

1315
const (
14-
NoArch ArchFamily = iota
15-
AMD64
16-
ARM
17-
ARM64
18-
I386
19-
Loong64
20-
MIPS
21-
MIPS64
22-
PPC64
23-
RISCV64
24-
S390X
25-
Wasm
16+
AMD64 = goarch.AMD64
17+
ARM = goarch.ARM
18+
ARM64 = goarch.ARM64
19+
I386 = goarch.I386
20+
Loong64 = goarch.LOONG64
21+
MIPS = goarch.MIPS
22+
MIPS64 = goarch.MIPS64
23+
PPC64 = goarch.PPC64
24+
RISCV64 = goarch.RISCV64
25+
S390X = goarch.S390X
26+
Wasm = goarch.WASM
2627
)
2728

2829
// Arch represents an individual architecture.

src/internal/abi/switch.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package abi
66

7+
import "internal/goarch"
8+
79
type InterfaceSwitch struct {
810
Cache *InterfaceSwitchCache
911
NCases int
@@ -27,11 +29,11 @@ type InterfaceSwitchCacheEntry struct {
2729
Itab uintptr
2830
}
2931

30-
func UseInterfaceSwitchCache(goarch string) bool {
32+
func UseInterfaceSwitchCache(arch goarch.ArchFamilyType) bool {
3133
// We need an atomic load instruction to make the cache multithreaded-safe.
3234
// (AtomicLoadPtr needs to be implemented in cmd/compile/internal/ssa/_gen/ARCH.rules.)
33-
switch goarch {
34-
case "amd64", "arm64", "loong64", "mips", "mipsle", "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x":
35+
switch arch {
36+
case goarch.AMD64, goarch.ARM64, goarch.LOONG64, goarch.MIPS, goarch.MIPS64, goarch.PPC64, goarch.RISCV64, goarch.S390X:
3537
return true
3638
default:
3739
return false

src/internal/goarch/goarch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ package goarch
1212
//
1313
//go:generate go run gengoarch.go
1414

15+
// ArchFamilyType represents a family of one or more related architectures.
16+
// For example, ppc64 and ppc64le are both members of the PPC64 family.
1517
type ArchFamilyType int
1618

1719
const (

src/runtime/iface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func typeAssert(s *abi.TypeAssert, t *_type) *itab {
474474
tab = getitab(s.Inter, t, s.CanFail)
475475
}
476476

477-
if !abi.UseInterfaceSwitchCache(GOARCH) {
477+
if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
478478
return tab
479479
}
480480

@@ -574,7 +574,7 @@ func interfaceSwitch(s *abi.InterfaceSwitch, t *_type) (int, *itab) {
574574
}
575575
}
576576

577-
if !abi.UseInterfaceSwitchCache(GOARCH) {
577+
if !abi.UseInterfaceSwitchCache(goarch.ArchFamily) {
578578
return case_, tab
579579
}
580580

0 commit comments

Comments
 (0)