]> Cypherpunks repositories - gostls13.git/commitdiff
internal/abi: use arch family instead of arch string
authorKeith Randall <khr@golang.org>
Mon, 24 Feb 2025 18:19:39 +0000 (10:19 -0800)
committerKeith Randall <khr@golang.org>
Tue, 25 Feb 2025 14:55:59 +0000 (06:55 -0800)
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>
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/internal/sys/arch.go
src/internal/abi/switch.go
src/internal/goarch/goarch.go
src/runtime/iface.go

index 7c67bc55799f778ad7b75680a2b44d7166c280ed..306244424c14f50b389407992f9b8c255543cd30 100644 (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 {
index ee7089b544f57ad81d3d71630bdf3b8b2e7e3f5a..3c28ff04058c48a733b70da17bf49b7ed883b287 100644 (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.
index df6f99c945910f4575b72c28f49e2e4c8172f90e..a30fdd078b8ee3a60ea6713ff8821ebc3a08a41c 100644 (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
index 3dda62fadc21f3c881e76b3df021c5670b953d6b..f52fe6c42ec0fccf1429a7eb0db40477d35b8264 100644 (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 (
index 9986686417ab7ff72f0dd96b58bbf464e342fd70..0665c4b9840ced9331df92147d6ee7e17e9cc257 100644 (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
        }