1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 type InterfaceSwitch struct {
8 Cache *InterfaceSwitchCache
11 // Array of NCases elements.
12 // Each case must be a non-empty interface type.
13 Cases [1]*InterfaceType
16 type InterfaceSwitchCache struct {
17 Mask uintptr // mask for index. Must be a power of 2 minus 1
18 Entries [1]InterfaceSwitchCacheEntry // Mask+1 entries total
21 type InterfaceSwitchCacheEntry struct {
22 // type of source value (a *Type)
24 // case # to dispatch to
26 // itab to use for resulting case variable (a *runtime.itab)
30 const go122InterfaceSwitchCache = true
32 func UseInterfaceSwitchCache(goarch string) bool {
33 if !go122InterfaceSwitchCache {
36 // We need an atomic load instruction to make the cache multithreaded-safe.
37 // (AtomicLoadPtr needs to be implemented in cmd/compile/internal/ssa/_gen/ARCH.rules.)
39 case "amd64", "arm64", "loong64", "mips", "mipsle", "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x":