|
5 | 5 | package ssagen
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "internal/buildcfg" |
| 8 | + "flag" |
| 9 | + "fmt" |
| 10 | + "slices" |
| 11 | + "strings" |
9 | 12 | "testing"
|
10 | 13 |
|
11 | 14 | "cmd/internal/sys"
|
12 | 15 | )
|
13 | 16 |
|
| 17 | +var updateIntrinsics = flag.Bool("update", false, "Print an updated intrinsics table") |
| 18 | + |
14 | 19 | type testIntrinsicKey struct {
|
15 | 20 | archName string
|
16 | 21 | pkg string
|
@@ -785,6 +790,8 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
|
785 | 790 | {"ppc64", "internal/runtime/math", "Add64"}: struct{}{},
|
786 | 791 | {"ppc64", "internal/runtime/math", "Mul64"}: struct{}{},
|
787 | 792 | {"ppc64", "internal/runtime/math", "MulUintptr"}: struct{}{},
|
| 793 | + {"ppc64", "internal/runtime/sys", "Bswap32"}: struct{}{}, |
| 794 | + {"ppc64", "internal/runtime/sys", "Bswap64"}: struct{}{}, |
788 | 795 | {"ppc64", "internal/runtime/sys", "Len64"}: struct{}{},
|
789 | 796 | {"ppc64", "internal/runtime/sys", "Len8"}: struct{}{},
|
790 | 797 | {"ppc64", "internal/runtime/sys", "OnesCount64"}: struct{}{},
|
@@ -814,6 +821,9 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
|
814 | 821 | {"ppc64", "math/bits", "OnesCount32"}: struct{}{},
|
815 | 822 | {"ppc64", "math/bits", "OnesCount64"}: struct{}{},
|
816 | 823 | {"ppc64", "math/bits", "OnesCount8"}: struct{}{},
|
| 824 | + {"ppc64", "math/bits", "ReverseBytes16"}: struct{}{}, |
| 825 | + {"ppc64", "math/bits", "ReverseBytes32"}: struct{}{}, |
| 826 | + {"ppc64", "math/bits", "ReverseBytes64"}: struct{}{}, |
817 | 827 | {"ppc64", "math/bits", "RotateLeft"}: struct{}{},
|
818 | 828 | {"ppc64", "math/bits", "RotateLeft32"}: struct{}{},
|
819 | 829 | {"ppc64", "math/bits", "RotateLeft64"}: struct{}{},
|
@@ -900,6 +910,8 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
|
900 | 910 | {"ppc64le", "internal/runtime/math", "Add64"}: struct{}{},
|
901 | 911 | {"ppc64le", "internal/runtime/math", "Mul64"}: struct{}{},
|
902 | 912 | {"ppc64le", "internal/runtime/math", "MulUintptr"}: struct{}{},
|
| 913 | + {"ppc64le", "internal/runtime/sys", "Bswap32"}: struct{}{}, |
| 914 | + {"ppc64le", "internal/runtime/sys", "Bswap64"}: struct{}{}, |
903 | 915 | {"ppc64le", "internal/runtime/sys", "Len64"}: struct{}{},
|
904 | 916 | {"ppc64le", "internal/runtime/sys", "Len8"}: struct{}{},
|
905 | 917 | {"ppc64le", "internal/runtime/sys", "OnesCount64"}: struct{}{},
|
@@ -929,6 +941,9 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
|
929 | 941 | {"ppc64le", "math/bits", "OnesCount32"}: struct{}{},
|
930 | 942 | {"ppc64le", "math/bits", "OnesCount64"}: struct{}{},
|
931 | 943 | {"ppc64le", "math/bits", "OnesCount8"}: struct{}{},
|
| 944 | + {"ppc64le", "math/bits", "ReverseBytes16"}: struct{}{}, |
| 945 | + {"ppc64le", "math/bits", "ReverseBytes32"}: struct{}{}, |
| 946 | + {"ppc64le", "math/bits", "ReverseBytes64"}: struct{}{}, |
932 | 947 | {"ppc64le", "math/bits", "RotateLeft"}: struct{}{},
|
933 | 948 | {"ppc64le", "math/bits", "RotateLeft32"}: struct{}{},
|
934 | 949 | {"ppc64le", "math/bits", "RotateLeft64"}: struct{}{},
|
@@ -1219,43 +1234,44 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
|
1219 | 1234 | {"wasm", "runtime", "slicebytetostringtmp"}: struct{}{},
|
1220 | 1235 | }
|
1221 | 1236 |
|
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 |
| - |
1235 | 1237 | 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, |
1241 | 1240 | }
|
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}) |
1245 | 1247 | }
|
| 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 |
1246 | 1261 | }
|
1247 | 1262 |
|
1248 |
| - got := make(map[testIntrinsicKey]struct{}) |
| 1263 | + gotIntrinsics := make(map[testIntrinsicKey]struct{}) |
1249 | 1264 | 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{}{} |
1251 | 1266 | }
|
1252 |
| - for ik, _ := range got { |
1253 |
| - if _, found := want[ik]; !found { |
| 1267 | + for ik, _ := range gotIntrinsics { |
| 1268 | + if _, found := wantIntrinsics[ik]; !found { |
1254 | 1269 | t.Errorf("Got unwanted intrinsic %v %v.%v", ik.archName, ik.pkg, ik.fn)
|
1255 | 1270 | }
|
1256 | 1271 | }
|
1257 |
| - for ik, _ := range want { |
1258 |
| - if _, found := got[ik]; !found { |
| 1272 | + |
| 1273 | + for ik, _ := range wantIntrinsics { |
| 1274 | + if _, found := gotIntrinsics[ik]; !found { |
1259 | 1275 | t.Errorf("Want intrinsic %v %v.%v", ik.archName, ik.pkg, ik.fn)
|
1260 | 1276 | }
|
1261 | 1277 | }
|
|
0 commit comments