Source file
src/simd/_gen/simdgen/gen_simdGenericOps.go
1
2
3
4
5 package main
6
7 import (
8 "bytes"
9 "fmt"
10 "sort"
11 )
12
13 const simdGenericOpsTmpl = `
14 package main
15
16 func simdGenericOps() []opData {
17 return []opData{
18 {{- range .Ops }}
19 {name: "{{.OpName}}", argLength: {{.OpInLen}}, commutative: {{.Comm}}},
20 {{- end }}
21 {{- range .OpsImm }}
22 {name: "{{.OpName}}", argLength: {{.OpInLen}}, commutative: {{.Comm}}, aux: "UInt8"},
23 {{- end }}
24 }
25 }
26 `
27
28
29
30 func writeSIMDGenericOps(ops []Operation) *bytes.Buffer {
31 t := templateOf(simdGenericOpsTmpl, "simdgenericOps")
32 buffer := new(bytes.Buffer)
33 buffer.WriteString(generatedHeader)
34
35 type genericOpsData struct {
36 OpName string
37 OpInLen int
38 Comm bool
39 }
40 type opData struct {
41 Ops []genericOpsData
42 OpsImm []genericOpsData
43 }
44 var opsData opData
45 for _, op := range ops {
46 if op.NoGenericOps != nil && *op.NoGenericOps == "true" {
47 continue
48 }
49 if op.SkipMaskedMethod() {
50 continue
51 }
52 _, _, _, immType, gOp := op.shape()
53 gOpData := genericOpsData{gOp.GenericName(), len(gOp.In), op.Commutative}
54 if immType == VarImm || immType == ConstVarImm {
55 opsData.OpsImm = append(opsData.OpsImm, gOpData)
56 } else {
57 opsData.Ops = append(opsData.Ops, gOpData)
58 }
59 }
60 sort.Slice(opsData.Ops, func(i, j int) bool {
61 return compareNatural(opsData.Ops[i].OpName, opsData.Ops[j].OpName) < 0
62 })
63 sort.Slice(opsData.OpsImm, func(i, j int) bool {
64 return compareNatural(opsData.OpsImm[i].OpName, opsData.OpsImm[j].OpName) < 0
65 })
66
67 err := t.Execute(buffer, opsData)
68 if err != nil {
69 panic(fmt.Errorf("failed to execute template: %w", err))
70 }
71
72 return buffer
73 }
74
View as plain text