]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime: remove math.Mul64
authorGavin Lam <gavin.oss@tutamail.com>
Thu, 15 Jan 2026 04:22:13 +0000 (04:22 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 22 Jan 2026 20:48:33 +0000 (12:48 -0800)
internal/runtime/math.Mul64 is a copy of math/bits.Mul64 and redundant.

Change-Id: I4dd2ab531a32da97839c6b45cf90df6430811967
GitHub-Last-Rev: 1a73e16049ee346ccfa8f052856e49e10e202d70
GitHub-Pull-Request: golang/go#77187
Reviewed-on: https://go-review.googlesource.com/c/go/+/736500
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Carlos Amedee <carlos@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
src/internal/runtime/math/math.go
src/runtime/hash64.go
src/runtime/rand.go

index e2eebd783d5f76442b1aa84b0d82e7dc6ff7e1d0..73923099bcb0375fb9c8887ade53903650e2379a 100644 (file)
@@ -1232,7 +1232,6 @@ func initIntrinsics(cfg *intrinsicBuildConfig) {
                },
                all...)
        alias("math/bits", "Mul", "math/bits", "Mul64", p8...)
-       alias("internal/runtime/math", "Mul64", "math/bits", "Mul64", p8...)
        addF("math/bits", "Add64",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
                        return s.newValue3(ssa.OpAdd64carry, types.NewTuple(types.Types[types.TUINT64], types.Types[types.TUINT64]), args[0], args[1], args[2])
index 3d866a6bf4a8848499a8d61bdc066ef8567d7dc3..a85a8871e36d43684c3b3b1e5d72ce5296f0ae2d 100644 (file)
@@ -102,7 +102,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"amd64", "internal/runtime/maps", "ctrlGroupMatchEmptyOrDeleted"}: struct{}{},
        {"amd64", "internal/runtime/maps", "ctrlGroupMatchFull"}:           struct{}{},
        {"amd64", "internal/runtime/math", "Add64"}:                        struct{}{},
-       {"amd64", "internal/runtime/math", "Mul64"}:                        struct{}{},
        {"amd64", "internal/runtime/math", "MulUintptr"}:                   struct{}{},
        {"amd64", "internal/runtime/sys", "Bswap32"}:                       struct{}{},
        {"amd64", "internal/runtime/sys", "Bswap64"}:                       struct{}{},
@@ -273,7 +272,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"arm64", "internal/runtime/atomic", "Xchgint64"}:                  struct{}{},
        {"arm64", "internal/runtime/atomic", "Xchguintptr"}:                struct{}{},
        {"arm64", "internal/runtime/math", "Add64"}:                        struct{}{},
-       {"arm64", "internal/runtime/math", "Mul64"}:                        struct{}{},
        {"arm64", "internal/runtime/math", "MulUintptr"}:                   struct{}{},
        {"arm64", "internal/runtime/sys", "Bswap32"}:                       struct{}{},
        {"arm64", "internal/runtime/sys", "Bswap64"}:                       struct{}{},
@@ -420,7 +418,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"loong64", "internal/runtime/atomic", "Xchgint64"}:                struct{}{},
        {"loong64", "internal/runtime/atomic", "Xchguintptr"}:              struct{}{},
        {"loong64", "internal/runtime/math", "Add64"}:                      struct{}{},
-       {"loong64", "internal/runtime/math", "Mul64"}:                      struct{}{},
        {"loong64", "internal/runtime/math", "MulUintptr"}:                 struct{}{},
        {"loong64", "internal/runtime/sys", "Bswap32"}:                     struct{}{},
        {"loong64", "internal/runtime/sys", "Bswap64"}:                     struct{}{},
@@ -633,7 +630,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"mips64", "internal/runtime/atomic", "Xchgint64"}:                 struct{}{},
        {"mips64", "internal/runtime/atomic", "Xchguintptr"}:               struct{}{},
        {"mips64", "internal/runtime/math", "Add64"}:                       struct{}{},
-       {"mips64", "internal/runtime/math", "Mul64"}:                       struct{}{},
        {"mips64", "internal/runtime/math", "MulUintptr"}:                  struct{}{},
        {"mips64", "internal/runtime/sys", "GetCallerPC"}:                  struct{}{},
        {"mips64", "internal/runtime/sys", "GetCallerSP"}:                  struct{}{},
@@ -722,7 +718,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"mips64le", "internal/runtime/atomic", "Xchgint64"}:               struct{}{},
        {"mips64le", "internal/runtime/atomic", "Xchguintptr"}:             struct{}{},
        {"mips64le", "internal/runtime/math", "Add64"}:                     struct{}{},
-       {"mips64le", "internal/runtime/math", "Mul64"}:                     struct{}{},
        {"mips64le", "internal/runtime/math", "MulUintptr"}:                struct{}{},
        {"mips64le", "internal/runtime/sys", "GetCallerPC"}:                struct{}{},
        {"mips64le", "internal/runtime/sys", "GetCallerSP"}:                struct{}{},
@@ -883,7 +878,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"ppc64", "internal/runtime/atomic", "Xchgint64"}:                  struct{}{},
        {"ppc64", "internal/runtime/atomic", "Xchguintptr"}:                struct{}{},
        {"ppc64", "internal/runtime/math", "Add64"}:                        struct{}{},
-       {"ppc64", "internal/runtime/math", "Mul64"}:                        struct{}{},
        {"ppc64", "internal/runtime/math", "MulUintptr"}:                   struct{}{},
        {"ppc64", "internal/runtime/sys", "Bswap32"}:                       struct{}{},
        {"ppc64", "internal/runtime/sys", "Bswap64"}:                       struct{}{},
@@ -1009,7 +1003,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"ppc64le", "internal/runtime/atomic", "Xchgint64"}:                struct{}{},
        {"ppc64le", "internal/runtime/atomic", "Xchguintptr"}:              struct{}{},
        {"ppc64le", "internal/runtime/math", "Add64"}:                      struct{}{},
-       {"ppc64le", "internal/runtime/math", "Mul64"}:                      struct{}{},
        {"ppc64le", "internal/runtime/math", "MulUintptr"}:                 struct{}{},
        {"ppc64le", "internal/runtime/sys", "Bswap32"}:                     struct{}{},
        {"ppc64le", "internal/runtime/sys", "Bswap64"}:                     struct{}{},
@@ -1135,7 +1128,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"riscv64", "internal/runtime/atomic", "Xchgint64"}:                struct{}{},
        {"riscv64", "internal/runtime/atomic", "Xchguintptr"}:              struct{}{},
        {"riscv64", "internal/runtime/math", "Add64"}:                      struct{}{},
-       {"riscv64", "internal/runtime/math", "Mul64"}:                      struct{}{},
        {"riscv64", "internal/runtime/math", "MulUintptr"}:                 struct{}{},
        {"riscv64", "internal/runtime/sys", "Bswap32"}:                     struct{}{},
        {"riscv64", "internal/runtime/sys", "Bswap64"}:                     struct{}{},
@@ -1256,7 +1248,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"s390x", "internal/runtime/atomic", "Xchgint64"}:                  struct{}{},
        {"s390x", "internal/runtime/atomic", "Xchguintptr"}:                struct{}{},
        {"s390x", "internal/runtime/math", "Add64"}:                        struct{}{},
-       {"s390x", "internal/runtime/math", "Mul64"}:                        struct{}{},
        {"s390x", "internal/runtime/sys", "Bswap32"}:                       struct{}{},
        {"s390x", "internal/runtime/sys", "Bswap64"}:                       struct{}{},
        {"s390x", "internal/runtime/sys", "GetCallerPC"}:                   struct{}{},
@@ -1332,7 +1323,6 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
        {"s390x", "sync/atomic", "SwapUint64"}:                             struct{}{},
        {"s390x", "sync/atomic", "SwapUintptr"}:                            struct{}{},
        {"s390x", "crypto/internal/constanttime", "boolToUint8"}:           struct{}{},
-       {"wasm", "internal/runtime/math", "Mul64"}:                         struct{}{},
        {"wasm", "internal/runtime/sys", "GetCallerPC"}:                    struct{}{},
        {"wasm", "internal/runtime/sys", "GetCallerSP"}:                    struct{}{},
        {"wasm", "internal/runtime/sys", "GetClosurePtr"}:                  struct{}{},
index 0af5aa3f7610d803f1c333b66b9dc142a7712a89..e3b277a5054924d3df5102992af3369255eb761d 100644 (file)
@@ -25,27 +25,6 @@ func MulUintptr(a, b uintptr) (uintptr, bool) {
        return a * b, overflow
 }
 
-// Mul64 returns the 128-bit product of x and y: (hi, lo) = x * y
-// with the product bits' upper half returned in hi and the lower
-// half returned in lo.
-// This is a copy from math/bits.Mul64
-// On supported platforms this is an intrinsic lowered by the compiler.
-func Mul64(x, y uint64) (hi, lo uint64) {
-       const mask32 = 1<<32 - 1
-       x0 := x & mask32
-       x1 := x >> 32
-       y0 := y & mask32
-       y1 := y >> 32
-       w0 := x0 * y0
-       t := x1*y0 + w0>>32
-       w1 := t & mask32
-       w2 := t >> 32
-       w1 += x0 * y1
-       hi = x1*y1 + w2 + w1>>32
-       lo = x * y
-       return
-}
-
 // Add64 returns the sum with carry of x, y and carry: sum = x + y + carry.
 // The carry input must be 0 or 1; otherwise the behavior is undefined.
 // The carryOut output is guaranteed to be 0 or 1.
index ac26e660c6d44a9edc6d51a4c18df7c6da018022..d29ceab7eb2d0a024c79f10122af8589afa271b9 100644 (file)
@@ -10,7 +10,7 @@
 package runtime
 
 import (
-       "internal/runtime/math"
+       "math/bits"
        "unsafe"
 )
 
@@ -75,7 +75,7 @@ func memhash64Fallback(p unsafe.Pointer, seed uintptr) uintptr {
 }
 
 func mix(a, b uintptr) uintptr {
-       hi, lo := math.Mul64(uint64(a), uint64(b))
+       hi, lo := bits.Mul64(uint64(a), uint64(b))
        return uintptr(hi ^ lo)
 }
 
index 1739e9f8f5f4eb1fb0042c4c2a967fe05745f890..a30845b585e74f06f4c702828bc7f0552cec9110 100644 (file)
@@ -10,7 +10,7 @@ import (
        "internal/byteorder"
        "internal/chacha8rand"
        "internal/goarch"
-       "internal/runtime/math"
+       "math/bits"
        "unsafe"
        _ "unsafe" // for go:linkname
 )
@@ -227,13 +227,13 @@ func randn(n uint32) uint32 {
 func cheaprand() uint32 {
        mp := getg().m
        // Implement wyrand: https://github.com/wangyi-fudan/wyhash
-       // Only the platform that math.Mul64 can be lowered
+       // Only the platform that bits.Mul64 can be lowered
        // by the compiler should be in this list.
        if goarch.IsAmd64|goarch.IsArm64|goarch.IsPpc64|
                goarch.IsPpc64le|goarch.IsMips64|goarch.IsMips64le|
                goarch.IsS390x|goarch.IsRiscv64|goarch.IsLoong64 == 1 {
                mp.cheaprand += 0xa0761d6478bd642f
-               hi, lo := math.Mul64(mp.cheaprand, mp.cheaprand^0xe7037ed1a0b428db)
+               hi, lo := bits.Mul64(mp.cheaprand, mp.cheaprand^0xe7037ed1a0b428db)
                return uint32(hi ^ lo)
        }