| // Copyright 2025 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "bytes" |
| "fmt" |
| "sort" |
| ) |
| |
| const simdGenericOpsTmpl = `// Code generated by x/arch/internal/simdgen using 'go run . -xedPath $XED_PATH -o godefs -goroot $GOROOT go.yaml types.yaml categories.yaml'; DO NOT EDIT. |
| package main |
| |
| func simdGenericOps() []opData { |
| return []opData{ |
| {{- range .Ops }} |
| {name: "{{.OpName}}", argLength: {{.OpInLen}}, commutative: {{.Comm}}}, |
| {{- end }} |
| {{- range .OpsImm }} |
| {name: "{{.OpName}}", argLength: {{.OpInLen}}, commutative: {{.Comm}}, aux: "Int8"}, |
| {{- end }} |
| } |
| } |
| ` |
| |
| // writeSIMDGenericOps generates the generic ops and writes it to simdAMD64ops.go |
| // within the specified directory. |
| func writeSIMDGenericOps(ops []Operation) *bytes.Buffer { |
| t := templateOf(simdGenericOpsTmpl, "simdgenericOps") |
| buffer := new(bytes.Buffer) |
| |
| type genericOpsData struct { |
| sortKey string |
| OpName string |
| OpInLen int |
| Comm string |
| } |
| type opData struct { |
| Ops []genericOpsData |
| OpsImm []genericOpsData |
| } |
| var opsData opData |
| for _, op := range ops { |
| _, _, _, immType, gOp := op.shape() |
| gOpData := genericOpsData{*gOp.In[0].Go + gOp.Go, genericName(gOp), len(gOp.In), op.Commutative} |
| if immType == VarImm || immType == ConstVarImm { |
| opsData.OpsImm = append(opsData.OpsImm, gOpData) |
| } else { |
| opsData.Ops = append(opsData.Ops, gOpData) |
| } |
| } |
| sort.Slice(opsData.Ops, func(i, j int) bool { |
| return opsData.Ops[i].sortKey < opsData.Ops[j].sortKey |
| }) |
| sort.Slice(opsData.OpsImm, func(i, j int) bool { |
| return opsData.OpsImm[i].sortKey < opsData.OpsImm[j].sortKey |
| }) |
| |
| err := t.Execute(buffer, opsData) |
| if err != nil { |
| panic(fmt.Errorf("failed to execute template: %w", err)) |
| } |
| |
| return buffer |
| } |