]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssagen: use an alias for math/bits.Len
authorJoel Sing <joel@sing.id.au>
Wed, 12 Mar 2025 11:55:49 +0000 (22:55 +1100)
committerGopher Robot <gobot@golang.org>
Wed, 12 Mar 2025 16:04:33 +0000 (09:04 -0700)
Rather than using a specific intrinsic for math/bits.Len, use a pair of
aliases instead. This requires less code and automatically adapts when
platforms have a math/bits.Len32 or math/bits.Len64 intrinsic.

Change-Id: I28b300172daaee26ef82a7530d9e96123663f541
Reviewed-on: https://go-review.googlesource.com/c/go/+/656995
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
src/cmd/compile/internal/ssagen/intrinsics.go

index 7a234a5b2ee6d9c7aff714559a434e93224a9b6b..abb63a99eb25924452853fca525579730153aa9a 100644 (file)
@@ -938,14 +938,9 @@ func initIntrinsics(cfg *intrinsicBuildConfig) {
                        return s.newValue1(ssa.OpBitLen8, types.Types[types.TINT], args[0])
                },
                sys.AMD64, sys.ARM, sys.ARM64, sys.Loong64, sys.MIPS, sys.PPC64, sys.S390X, sys.Wasm)
-       addF("math/bits", "Len",
-               func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
-                       if s.config.PtrSize == 4 {
-                               return s.newValue1(ssa.OpBitLen32, types.Types[types.TINT], args[0])
-                       }
-                       return s.newValue1(ssa.OpBitLen64, types.Types[types.TINT], args[0])
-               },
-               sys.AMD64, sys.ARM, sys.ARM64, sys.Loong64, sys.MIPS, sys.PPC64, sys.S390X, sys.Wasm)
+       alias("math/bits", "Len", "math/bits", "Len64", p8...)
+       alias("math/bits", "Len", "math/bits", "Len32", p4...)
+
        // LeadingZeros is handled because it trivially calls Len.
        addF("math/bits", "Reverse64",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {