Skip to content

Commit 7781878

Browse files
4a6f656cpull[bot]
authored andcommitted
cmd/compile/internal/ssagen: improve intrinsic test
Now that we can pass configuration to initIntrinsics, clean up the intrinsic test and always enable power10. Additionally, provide an -update flag that prints out updated golden values. Change-Id: Ibfef339d513a4d67d53a5a310a82165592ca338f Reviewed-on: https://go-review.googlesource.com/c/go/+/607055 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 174a7c7 commit 7781878

File tree

1 file changed

+44
-28
lines changed

1 file changed

+44
-28
lines changed

src/cmd/compile/internal/ssagen/intrinsics_test.go

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
package ssagen
66

77
import (
8-
"internal/buildcfg"
8+
"flag"
9+
"fmt"
10+
"slices"
11+
"strings"
912
"testing"
1013

1114
"cmd/internal/sys"
1215
)
1316

17+
var updateIntrinsics = flag.Bool("update", false, "Print an updated intrinsics table")
18+
1419
type testIntrinsicKey struct {
1520
archName string
1621
pkg string
@@ -785,6 +790,8 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
785790
{"ppc64", "internal/runtime/math", "Add64"}: struct{}{},
786791
{"ppc64", "internal/runtime/math", "Mul64"}: struct{}{},
787792
{"ppc64", "internal/runtime/math", "MulUintptr"}: struct{}{},
793+
{"ppc64", "internal/runtime/sys", "Bswap32"}: struct{}{},
794+
{"ppc64", "internal/runtime/sys", "Bswap64"}: struct{}{},
788795
{"ppc64", "internal/runtime/sys", "Len64"}: struct{}{},
789796
{"ppc64", "internal/runtime/sys", "Len8"}: struct{}{},
790797
{"ppc64", "internal/runtime/sys", "OnesCount64"}: struct{}{},
@@ -814,6 +821,9 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
814821
{"ppc64", "math/bits", "OnesCount32"}: struct{}{},
815822
{"ppc64", "math/bits", "OnesCount64"}: struct{}{},
816823
{"ppc64", "math/bits", "OnesCount8"}: struct{}{},
824+
{"ppc64", "math/bits", "ReverseBytes16"}: struct{}{},
825+
{"ppc64", "math/bits", "ReverseBytes32"}: struct{}{},
826+
{"ppc64", "math/bits", "ReverseBytes64"}: struct{}{},
817827
{"ppc64", "math/bits", "RotateLeft"}: struct{}{},
818828
{"ppc64", "math/bits", "RotateLeft32"}: struct{}{},
819829
{"ppc64", "math/bits", "RotateLeft64"}: struct{}{},
@@ -900,6 +910,8 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
900910
{"ppc64le", "internal/runtime/math", "Add64"}: struct{}{},
901911
{"ppc64le", "internal/runtime/math", "Mul64"}: struct{}{},
902912
{"ppc64le", "internal/runtime/math", "MulUintptr"}: struct{}{},
913+
{"ppc64le", "internal/runtime/sys", "Bswap32"}: struct{}{},
914+
{"ppc64le", "internal/runtime/sys", "Bswap64"}: struct{}{},
903915
{"ppc64le", "internal/runtime/sys", "Len64"}: struct{}{},
904916
{"ppc64le", "internal/runtime/sys", "Len8"}: struct{}{},
905917
{"ppc64le", "internal/runtime/sys", "OnesCount64"}: struct{}{},
@@ -929,6 +941,9 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
929941
{"ppc64le", "math/bits", "OnesCount32"}: struct{}{},
930942
{"ppc64le", "math/bits", "OnesCount64"}: struct{}{},
931943
{"ppc64le", "math/bits", "OnesCount8"}: struct{}{},
944+
{"ppc64le", "math/bits", "ReverseBytes16"}: struct{}{},
945+
{"ppc64le", "math/bits", "ReverseBytes32"}: struct{}{},
946+
{"ppc64le", "math/bits", "ReverseBytes64"}: struct{}{},
932947
{"ppc64le", "math/bits", "RotateLeft"}: struct{}{},
933948
{"ppc64le", "math/bits", "RotateLeft32"}: struct{}{},
934949
{"ppc64le", "math/bits", "RotateLeft64"}: struct{}{},
@@ -1219,43 +1234,44 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
12191234
{"wasm", "runtime", "slicebytetostringtmp"}: struct{}{},
12201235
}
12211236

1222-
var wantIntrinsicsPower10 = map[testIntrinsicKey]struct{}{
1223-
{"ppc64", "internal/runtime/sys", "Bswap32"}: struct{}{},
1224-
{"ppc64", "internal/runtime/sys", "Bswap64"}: struct{}{},
1225-
{"ppc64", "math/bits", "ReverseBytes16"}: struct{}{},
1226-
{"ppc64", "math/bits", "ReverseBytes32"}: struct{}{},
1227-
{"ppc64", "math/bits", "ReverseBytes64"}: struct{}{},
1228-
{"ppc64le", "internal/runtime/sys", "Bswap32"}: struct{}{},
1229-
{"ppc64le", "internal/runtime/sys", "Bswap64"}: struct{}{},
1230-
{"ppc64le", "math/bits", "ReverseBytes16"}: struct{}{},
1231-
{"ppc64le", "math/bits", "ReverseBytes32"}: struct{}{},
1232-
{"ppc64le", "math/bits", "ReverseBytes64"}: struct{}{},
1233-
}
1234-
12351237
func TestIntrinsics(t *testing.T) {
1236-
initIntrinsics(nil)
1237-
1238-
want := make(map[testIntrinsicKey]struct{})
1239-
for ik, iv := range wantIntrinsics {
1240-
want[ik] = iv
1238+
cfg := &intrinsicBuildConfig{
1239+
goppc64: 10,
12411240
}
1242-
if buildcfg.GOPPC64 >= 10 {
1243-
for ik, iv := range wantIntrinsicsPower10 {
1244-
want[ik] = iv
1241+
initIntrinsics(cfg)
1242+
1243+
if *updateIntrinsics {
1244+
var updatedIntrinsics []*testIntrinsicKey
1245+
for ik, _ := range intrinsics {
1246+
updatedIntrinsics = append(updatedIntrinsics, &testIntrinsicKey{ik.arch.Name, ik.pkg, ik.fn})
12451247
}
1248+
slices.SortFunc(updatedIntrinsics, func(a, b *testIntrinsicKey) int {
1249+
if n := strings.Compare(a.archName, b.archName); n != 0 {
1250+
return n
1251+
}
1252+
if n := strings.Compare(a.pkg, b.pkg); n != 0 {
1253+
return n
1254+
}
1255+
return strings.Compare(a.fn, b.fn)
1256+
})
1257+
for _, tik := range updatedIntrinsics {
1258+
fmt.Printf("\t{%q, %q, %q}: struct{}{},\n", tik.archName, tik.pkg, tik.fn)
1259+
}
1260+
return
12461261
}
12471262

1248-
got := make(map[testIntrinsicKey]struct{})
1263+
gotIntrinsics := make(map[testIntrinsicKey]struct{})
12491264
for ik, _ := range intrinsics {
1250-
got[testIntrinsicKey{ik.arch.Name, ik.pkg, ik.fn}] = struct{}{}
1265+
gotIntrinsics[testIntrinsicKey{ik.arch.Name, ik.pkg, ik.fn}] = struct{}{}
12511266
}
1252-
for ik, _ := range got {
1253-
if _, found := want[ik]; !found {
1267+
for ik, _ := range gotIntrinsics {
1268+
if _, found := wantIntrinsics[ik]; !found {
12541269
t.Errorf("Got unwanted intrinsic %v %v.%v", ik.archName, ik.pkg, ik.fn)
12551270
}
12561271
}
1257-
for ik, _ := range want {
1258-
if _, found := got[ik]; !found {
1272+
1273+
for ik, _ := range wantIntrinsics {
1274+
if _, found := gotIntrinsics[ik]; !found {
12591275
t.Errorf("Want intrinsic %v %v.%v", ik.archName, ik.pkg, ik.fn)
12601276
}
12611277
}

0 commit comments

Comments
 (0)