go/src/simd/_gen/simdgen/gen_simdGenericOps.go

74 lines
1.8 KiB
Go
Raw Normal View History

[dev.simd] simd/_gen: migrate simdgen from x/arch This moves the simdgen tool and its supporting unify package from golang.org/x/arch/internal as of CL 695619 to simd/_gen in the main repo. The simdgen tool was started in x/arch to live next to xeddata and a few other assembler generators that already lived there. However, as we've been developing simdgen, we've discovered that there's a tremendous amount of process friction coordinating commits to x/arch with the corresponding generated files in the main repo. Many of the existing generators in x/arch were started before modules existed. In GOPATH world, it was impractical for them to live in the main repo because they have dependencies that are not allowed in the main repo. However, now that we have modules and can use small submodules in the main repo, we can isolate these dependencies to just the generators, making it practical for them to live in the main repo. This commit was generated by the following script: # Checks set -e if [[ ! -d src/simd ]]; then echo >&2 "$PWD is not the root of the main repo on dev.simd" exit 1 fi if [[ -z "$XEDDATA" ]]; then echo >&2 "Must set \$XEDDATA" exit 1 fi which go >/dev/null # Move simdgen from x/arch xarch=$(mktemp -d) git clone https://go.googlesource.com/arch $xarch xarchCL=$(git -C $xarch log -1 --format=%b | awk -F/ '/^Reviewed-on:/ {print $NF}') echo >&2 "x/arch CL: $xarchCL" mv $xarch/internal src/simd/_gen sed --in-place s,golang.org/x/arch/internal/,simd/_gen/, src/simd/_gen/*/*.go # Create self-contained module cat > src/simd/_gen/go.mod <<EOF module simd/_gen go 1.24 EOF cd src/simd/_gen go mod tidy git add . git gofmt # Regenerate file go run -C simdgen . -xedPath $XEDDATA -o godefs -goroot $(go env GOROOT) go.yaml types.yaml categories.yaml go run -C ../../cmd/compile/internal/ssa/_gen . Change-Id: I56dd8473e913a9eb1978d9b3b3518ed632972f6f Reviewed-on: https://go-review.googlesource.com/c/go/+/695975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-08-13 15:30:27 -04:00
// 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 = `
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: "UInt8"},
{{- 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)
buffer.WriteString(generatedHeader)
type genericOpsData struct {
OpName string
OpInLen int
Comm bool
}
type opData struct {
Ops []genericOpsData
OpsImm []genericOpsData
}
var opsData opData
for _, op := range ops {
if op.NoGenericOps != nil && *op.NoGenericOps == "true" {
continue
}
if op.SkipMaskedMethod() {
continue
}
[dev.simd] simd/_gen: migrate simdgen from x/arch This moves the simdgen tool and its supporting unify package from golang.org/x/arch/internal as of CL 695619 to simd/_gen in the main repo. The simdgen tool was started in x/arch to live next to xeddata and a few other assembler generators that already lived there. However, as we've been developing simdgen, we've discovered that there's a tremendous amount of process friction coordinating commits to x/arch with the corresponding generated files in the main repo. Many of the existing generators in x/arch were started before modules existed. In GOPATH world, it was impractical for them to live in the main repo because they have dependencies that are not allowed in the main repo. However, now that we have modules and can use small submodules in the main repo, we can isolate these dependencies to just the generators, making it practical for them to live in the main repo. This commit was generated by the following script: # Checks set -e if [[ ! -d src/simd ]]; then echo >&2 "$PWD is not the root of the main repo on dev.simd" exit 1 fi if [[ -z "$XEDDATA" ]]; then echo >&2 "Must set \$XEDDATA" exit 1 fi which go >/dev/null # Move simdgen from x/arch xarch=$(mktemp -d) git clone https://go.googlesource.com/arch $xarch xarchCL=$(git -C $xarch log -1 --format=%b | awk -F/ '/^Reviewed-on:/ {print $NF}') echo >&2 "x/arch CL: $xarchCL" mv $xarch/internal src/simd/_gen sed --in-place s,golang.org/x/arch/internal/,simd/_gen/, src/simd/_gen/*/*.go # Create self-contained module cat > src/simd/_gen/go.mod <<EOF module simd/_gen go 1.24 EOF cd src/simd/_gen go mod tidy git add . git gofmt # Regenerate file go run -C simdgen . -xedPath $XEDDATA -o godefs -goroot $(go env GOROOT) go.yaml types.yaml categories.yaml go run -C ../../cmd/compile/internal/ssa/_gen . Change-Id: I56dd8473e913a9eb1978d9b3b3518ed632972f6f Reviewed-on: https://go-review.googlesource.com/c/go/+/695975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-08-13 15:30:27 -04:00
_, _, _, immType, gOp := op.shape()
gOpData := genericOpsData{gOp.GenericName(), 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 compareNatural(opsData.Ops[i].OpName, opsData.Ops[j].OpName) < 0
})
sort.Slice(opsData.OpsImm, func(i, j int) bool {
return compareNatural(opsData.OpsImm[i].OpName, opsData.OpsImm[j].OpName) < 0
})
err := t.Execute(buffer, opsData)
if err != nil {
panic(fmt.Errorf("failed to execute template: %w", err))
}
return buffer
}