| // 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 ( |
| "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 . }} |
| {name: "{{.OpName}}", argLength: {{.OpInLen}}, commutative: {{.Comm}}}, |
| {{- end }} |
| } |
| } |
| ` |
| |
| // writeSIMDGenericOps generates the generic ops and writes it to simdAMD64ops.go |
| // within the specified directory. |
| func writeSIMDGenericOps(directory string, ops []Operation) error { |
| file, t, err := openFileAndPrepareTemplate(directory, "src/cmd/compile/internal/ssa/_gen/simdgenericOps.go", simdGenericOpsTmpl) |
| if err != nil { |
| return err |
| } |
| defer file.Close() |
| type genericOpsData struct { |
| sortKey string |
| OpName string |
| OpInLen int |
| Comm string |
| } |
| opsData := make([]genericOpsData, 0) |
| for _, op := range ops { |
| _, _, _, _, _, gOp, err := op.shape() |
| if err != nil { |
| return err |
| } |
| genericNames := gOp.Go + *gOp.In[0].Go |
| opsData = append(opsData, genericOpsData{*gOp.In[0].Go + gOp.Go, genericNames, len(gOp.In), op.Commutative}) |
| } |
| sort.Slice(opsData, func(i, j int) bool { |
| return opsData[i].sortKey < opsData[j].sortKey |
| }) |
| |
| err = t.Execute(file, opsData) |
| if err != nil { |
| return fmt.Errorf("failed to execute template: %w", err) |
| } |
| |
| return nil |
| } |