Source file src/simd/archsimd/_gen/simdgen/arch.go

     1  // Copyright 2025 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 main
     6  
     7  import "fmt"
     8  
     9  // ArchInfo contains all architecture-specific naming conventions.
    10  type ArchInfo struct {
    11  	Arch            string          // e.g., "amd64", "arm64"
    12  	ArchUpper       string          // e.g., "AMD64", "ARM64"
    13  	ObjArch         string          // e.g., "x86", "arm64" (for cmd/internal/obj/*)
    14  	RegInfoKeys     []string        // RegInfo shapes that generate SSA lowering code (gen_simdssa.go)
    15  	RegInfoSet      map[string]bool // Valid regInfo shapes (for gen_simdMachineOps.go)
    16  	RegInfoParams   string          // Function parameter declaration for generated ops (simd[AMD64|ARM64]ops.go)
    17  	GeneratedHeader string          // Header comment for generated files
    18  	Arrangements    []string        // SIMD arrangement suffixes (e.g., "4S", "2D" for ARM64; nil for amd64)
    19  }
    20  
    21  var amd64RegInfoKeys = []string{
    22  	"v11",
    23  	"v21",
    24  	"v2k",
    25  	"v2kv",
    26  	"v2kk",
    27  	"vkv",
    28  	"v31",
    29  	"v3kv",
    30  	"v11Imm8",
    31  	"vkvImm8",
    32  	"v21Imm8",
    33  	"v2kImm8",
    34  	"v2kkImm8",
    35  	"v31ResultInArg0",
    36  	"v3kvResultInArg0",
    37  	"vfpv",
    38  	"vfpkv",
    39  	"vgpvImm8",
    40  	"vgpImm8",
    41  	"v2kvImm8",
    42  	"vkvload",
    43  	"v21load",
    44  	"v31loadResultInArg0",
    45  	"v3kvloadResultInArg0",
    46  	"v2kvload",
    47  	"v2kload",
    48  	"v11load",
    49  	"v11loadImm8",
    50  	"vkvloadImm8",
    51  	"v21loadImm8",
    52  	"v2kloadImm8",
    53  	"v2kkloadImm8",
    54  	"v2kvloadImm8",
    55  	"v31ResultInArg0Imm8",
    56  	"v31loadResultInArg0Imm8",
    57  	"v21ResultInArg0",
    58  	"v21ResultInArg0Imm8",
    59  	"v31x0AtIn2ResultInArg0",
    60  	"v2kvResultInArg0",
    61  }
    62  
    63  var arm64RegInfoKeys = []string{
    64  	"v11",
    65  	"v11Imm",
    66  	"v11ImmIn1",
    67  	"v11Scalar",
    68  	"v11ScalarImmIn1",
    69  	"v21",
    70  	"v21Imm",
    71  	"v31ResultInArg0",
    72  	"vgpImmIn1",
    73  	"vgpvResultInArg0ImmOutIn0",
    74  	"vfpvResultInArg0ImmOutIn1",
    75  	"v11Long",
    76  	"v11Narrow",
    77  	"v11ImmNarrow",
    78  	"v11ImmLong",
    79  	"v21Long",
    80  	"v11Long2",
    81  	"v21Narrow2",
    82  	"v21ImmNarrow2",
    83  	"v11ImmLong2",
    84  	"v21Long2",
    85  	"v21List",
    86  	"v31ResultInArg0List",
    87  }
    88  
    89  var amd64RegInfoSet = map[string]bool{
    90  	"v11": true, "v21": true, "v2k": true, "v2kv": true, "v2kk": true, "vkv": true, "v31": true, "v3kv": true, "vgpv": true, "vgp": true, "vfpv": true, "vfpkv": true,
    91  	"w11": true, "w21": true, "w2k": true, "w2kw": true, "w2kk": true, "wkw": true, "w31": true, "w3kw": true, "wgpw": true, "wgp": true, "wfpw": true, "wfpkw": true,
    92  	"wkwload": true, "v21load": true, "v31load": true, "v11load": true, "w21load": true, "w31load": true, "w2kload": true, "w2kwload": true, "w11load": true,
    93  	"w3kwload": true, "w2kkload": true, "v31x0AtIn2": true,
    94  }
    95  
    96  var arm64RegInfoSet = map[string]bool{
    97  	"v11":                 true,
    98  	"v21":                 true,
    99  	"v21Imm":              true,
   100  	"v31":                 true,
   101  	"vgp":                 true,
   102  	"vgpv":                true,
   103  	"vfpv":                true,
   104  	"v11ImmIn1":           true,
   105  	"v11Long":             true,
   106  	"v11Narrow":           true,
   107  	"v11ImmNarrow":        true,
   108  	"v11ImmLong":          true,
   109  	"v21Long":             true,
   110  	"v11Long2":            true,
   111  	"v21Narrow2":          true,
   112  	"v21ImmNarrow2":       true,
   113  	"v11ImmLong2":         true,
   114  	"v21Long2":            true,
   115  	"v21List":             true,
   116  	"v31ResultInArg0List": true,
   117  }
   118  
   119  // arm64Arrangements contains the SIMD arrangement suffixes for ARM64 NEON.
   120  // These correspond to the ARNG_* constants in cmd/internal/obj/arm64/a.out.go.
   121  var arm64Arrangements = []string{
   122  	"8B", "16B", "1D", "4H", "8H", "2S", "4S", "2D", "1Q", "B", "H", "S", "D",
   123  }
   124  
   125  const amd64RegInfoParams = "v11, v21, v2k, vkv, v2kv, v2kk, v31, v3kv, vgpv, vgp, vfpv, vfpkv, w11, w21, w2k, wkw, w2kw, w2kk, w31, w3kw, wgpw, wgp, wfpw, wfpkw,\n\twkwload, v21load, v31load, v11load, w21load, w31load, w2kload, w2kwload, w11load, w3kwload, w2kkload, v31x0AtIn2 regInfo"
   126  
   127  const arm64RegInfoParams = "v11, v21, v31, vgp, vgpv, vfpv regInfo"
   128  
   129  const amd64GeneratedHeader = `// Code generated by 'simdgen -o godefs -goroot $GOROOT -arch amd64 -xedPath $XED_PATH go_amd64.yaml types.yaml categories.yaml'; DO NOT EDIT.
   130  `
   131  
   132  const arm64GeneratedHeader = `// Code generated by 'simdgen -o godefs -goroot $GOROOT -arch arm64 -arm64Path $ARM64_ISA_PATH go_arm64.yaml types.yaml categories.yaml'; DO NOT EDIT.
   133  `
   134  
   135  // GetArchInfo returns architecture-specific information based on the target architecture.
   136  func GetArchInfo(arch string) (ArchInfo, error) {
   137  	switch arch {
   138  	case "amd64":
   139  		return ArchInfo{
   140  			Arch:            "amd64",
   141  			ArchUpper:       "AMD64",
   142  			ObjArch:         "x86",
   143  			RegInfoKeys:     amd64RegInfoKeys,
   144  			RegInfoSet:      amd64RegInfoSet,
   145  			RegInfoParams:   amd64RegInfoParams,
   146  			GeneratedHeader: amd64GeneratedHeader,
   147  		}, nil
   148  	case "arm64":
   149  		return ArchInfo{
   150  			Arch:            "arm64",
   151  			ArchUpper:       "ARM64",
   152  			ObjArch:         "arm64",
   153  			RegInfoKeys:     arm64RegInfoKeys,
   154  			RegInfoSet:      arm64RegInfoSet,
   155  			RegInfoParams:   arm64RegInfoParams,
   156  			GeneratedHeader: arm64GeneratedHeader,
   157  			Arrangements:    arm64Arrangements,
   158  		}, nil
   159  	default:
   160  		return ArchInfo{}, fmt.Errorf("unsupported architecture: %s", arch)
   161  	}
   162  }
   163  
   164  // CurrentArch returns the ArchInfo for the current FlagArch setting.
   165  func CurrentArch() ArchInfo {
   166  	info, err := GetArchInfo(*FlagArch)
   167  	if err != nil {
   168  		panic(err)
   169  	}
   170  	return info
   171  }
   172  

View as plain text