Source file src/simd/archsimd/_gen/sgutil/stableapi.go
1 // Copyright 2026 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. 4 5 package sgutil 6 7 import "strings" 8 9 // NonSpecAPI reports whether the exported declaration recv.name (or name, for 10 // a package-level declaration) in package pkg is one of the few APIs that 11 // spec doesn't describe but that may still be generally available. pkg is the 12 // package name, "simd" or "archsimd". Any other generally available API must 13 // come from spec. 14 // 15 // Each of these APIs may be either generally available or experimental. Since 16 // spec doesn't describe them, the code that defines each one decides which, 17 // so the phase check allows them in files of either phase. For example, 18 // simdgen puts a CPU feature query in cpu.go, which is generally available, if 19 // some generally available operation needs that feature, and in cpu_exp.go, 20 // which is experimental, otherwise. 21 func NonSpecAPI(pkg, recv, name string) bool { 22 switch pkg { 23 case "archsimd": 24 switch recv { 25 case "": 26 // The CPU feature sets: their types, and the variables that 27 // hold them. 28 return name == "X86Features" || name == "X86" || name == "ARM64Features" || name == "ARM64" 29 case "X86Features", "ARM64Features": 30 // The CPU feature queries. Spec describes operations, not the 31 // hardware features that implement them. 32 return true 33 } 34 case "simd": 35 switch { 36 case recv == "" && (name == "VectorBits" || name == "Emulated"): 37 // Queries about how package simd is implemented on the running 38 // hardware, which have no counterpart in spec's model of 39 // vector operations. 40 return true 41 case recv != "" && name == "ToArch": 42 // The conversions between the portable types and archsimd's 43 // types, which spec doesn't describe because it has no notion 44 // of the architecture-specific types (SPEC-TRANSITION.md ยง2.7). 45 return portableTypes[recv] 46 case recv == "" && strings.HasSuffix(name, "FromArch"): 47 // The other direction of those conversions, such as 48 // Int8sFromArch. 49 return portableTypes[strings.TrimSuffix(name, "FromArch")] 50 } 51 } 52 return false 53 } 54 55 // portableTypes are package simd's portable vector and mask types. 56 var portableTypes = map[string]bool{ 57 "Int8s": true, "Int16s": true, "Int32s": true, "Int64s": true, 58 "Uint8s": true, "Uint16s": true, "Uint32s": true, "Uint64s": true, 59 "Float32s": true, "Float64s": true, 60 "Mask8s": true, "Mask16s": true, "Mask32s": true, "Mask64s": true, 61 } 62