]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssagen: use an alias for math/bits.OnesCount
authorJoel Sing <joel@sing.id.au>
Wed, 19 Mar 2025 13:09:52 +0000 (00:09 +1100)
committerGopher Robot <gobot@golang.org>
Thu, 20 Mar 2025 15:15:01 +0000 (08:15 -0700)
Currently, only amd64 has an intrinsic for math/bits.OnesCount, which
generates the same code as math/bits.OnesCount64. Replace this with
an alias that maps math/bits.OnesCount to math/bits.OnesCount64 on
64 bit platforms.

Change-Id: Ifa12a2173a201aacd52c3c22b9a948be6e314405
Reviewed-on: https://go-review.googlesource.com/c/go/+/659215
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index e1e464955515f9059b51acf19d62b785331a2bfb..f2b13045eb2d7dd73b46ffa7bc0e1ddbb03d0794 100644 (file)
@@ -1114,9 +1114,8 @@ func initIntrinsics(cfg *intrinsicBuildConfig) {
                        return s.newValue1(ssa.OpPopCount8, types.Types[types.TINT], args[0])
                },
                sys.S390X, sys.PPC64, sys.Wasm)
-       addF("math/bits", "OnesCount",
-               makeOnesCountAMD64(ssa.OpPopCount64),
-               sys.AMD64)
+       alias("math/bits", "OnesCount", "math/bits", "OnesCount64", p8...)
+
        addF("math/bits", "Mul64",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
                        return s.newValue2(ssa.OpMul64uhilo, types.NewTuple(types.Types[types.TUINT64], types.Types[types.TUINT64]), args[0], args[1])
index 192f91c1830cafdad7d561ade6555f47a06cdf4b..a06fdeedb2a6c59908c22273fc58f140cf380d3e 100644 (file)
@@ -297,6 +297,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"arm64", "math/bits", "Len8"}:                                     struct{}{},
        {"arm64", "math/bits", "Mul"}:                                      struct{}{},
        {"arm64", "math/bits", "Mul64"}:                                    struct{}{},
+       {"arm64", "math/bits", "OnesCount"}:                                struct{}{},
        {"arm64", "math/bits", "OnesCount16"}:                              struct{}{},
        {"arm64", "math/bits", "OnesCount32"}:                              struct{}{},
        {"arm64", "math/bits", "OnesCount64"}:                              struct{}{},
@@ -434,6 +435,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"loong64", "math/bits", "Len16"}:                                  struct{}{},
        {"loong64", "math/bits", "Len32"}:                                  struct{}{},
        {"loong64", "math/bits", "Len64"}:                                  struct{}{},
+       {"loong64", "math/bits", "OnesCount"}:                              struct{}{},
        {"loong64", "math/bits", "OnesCount16"}:                            struct{}{},
        {"loong64", "math/bits", "OnesCount32"}:                            struct{}{},
        {"loong64", "math/bits", "OnesCount64"}:                            struct{}{},
@@ -888,6 +890,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"ppc64", "math/bits", "Len8"}:                                     struct{}{},
        {"ppc64", "math/bits", "Mul"}:                                      struct{}{},
        {"ppc64", "math/bits", "Mul64"}:                                    struct{}{},
+       {"ppc64", "math/bits", "OnesCount"}:                                struct{}{},
        {"ppc64", "math/bits", "OnesCount16"}:                              struct{}{},
        {"ppc64", "math/bits", "OnesCount32"}:                              struct{}{},
        {"ppc64", "math/bits", "OnesCount64"}:                              struct{}{},
@@ -1011,6 +1014,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"ppc64le", "math/bits", "Len8"}:                                   struct{}{},
        {"ppc64le", "math/bits", "Mul"}:                                    struct{}{},
        {"ppc64le", "math/bits", "Mul64"}:                                  struct{}{},
+       {"ppc64le", "math/bits", "OnesCount"}:                              struct{}{},
        {"ppc64le", "math/bits", "OnesCount16"}:                            struct{}{},
        {"ppc64le", "math/bits", "OnesCount32"}:                            struct{}{},
        {"ppc64le", "math/bits", "OnesCount64"}:                            struct{}{},
@@ -1232,6 +1236,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"s390x", "math/bits", "Len8"}:                                     struct{}{},
        {"s390x", "math/bits", "Mul"}:                                      struct{}{},
        {"s390x", "math/bits", "Mul64"}:                                    struct{}{},
+       {"s390x", "math/bits", "OnesCount"}:                                struct{}{},
        {"s390x", "math/bits", "OnesCount16"}:                              struct{}{},
        {"s390x", "math/bits", "OnesCount32"}:                              struct{}{},
        {"s390x", "math/bits", "OnesCount64"}:                              struct{}{},
@@ -1298,6 +1303,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"wasm", "math/bits", "Len32"}:                                     struct{}{},
        {"wasm", "math/bits", "Len64"}:                                     struct{}{},
        {"wasm", "math/bits", "Len8"}:                                      struct{}{},
+       {"wasm", "math/bits", "OnesCount"}:                                 struct{}{},
        {"wasm", "math/bits", "OnesCount16"}:                               struct{}{},
        {"wasm", "math/bits", "OnesCount32"}:                               struct{}{},
        {"wasm", "math/bits", "OnesCount64"}:                               struct{}{},