From e9e05687dee08ba0f0fb07b076f1c3f47bb57f34 Mon Sep 17 00:00:00 2001 From: Gavin Lam Date: Thu, 15 Jan 2026 04:22:13 +0000 Subject: [PATCH] internal/runtime: remove math.Mul64 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 Reviewed-by: Jorropo Reviewed-by: Keith Randall Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/ssagen/intrinsics.go | 1 - .../internal/ssagen/intrinsics_test.go | 10 --------- src/internal/runtime/math/math.go | 21 ------------------- src/runtime/hash64.go | 4 ++-- src/runtime/rand.go | 6 +++--- 5 files changed, 5 insertions(+), 37 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/intrinsics.go b/src/cmd/compile/internal/ssagen/intrinsics.go index e2eebd783d..73923099bc 100644 --- a/src/cmd/compile/internal/ssagen/intrinsics.go +++ b/src/cmd/compile/internal/ssagen/intrinsics.go @@ -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]) diff --git a/src/cmd/compile/internal/ssagen/intrinsics_test.go b/src/cmd/compile/internal/ssagen/intrinsics_test.go index 3d866a6bf4..a85a8871e3 100644 --- a/src/cmd/compile/internal/ssagen/intrinsics_test.go +++ b/src/cmd/compile/internal/ssagen/intrinsics_test.go @@ -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{}{}, diff --git a/src/internal/runtime/math/math.go b/src/internal/runtime/math/math.go index 0af5aa3f76..e3b277a505 100644 --- a/src/internal/runtime/math/math.go +++ b/src/internal/runtime/math/math.go @@ -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. diff --git a/src/runtime/hash64.go b/src/runtime/hash64.go index ac26e660c6..d29ceab7eb 100644 --- a/src/runtime/hash64.go +++ b/src/runtime/hash64.go @@ -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) } diff --git a/src/runtime/rand.go b/src/runtime/rand.go index 1739e9f8f5..a30845b585 100644 --- a/src/runtime/rand.go +++ b/src/runtime/rand.go @@ -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) } -- 2.52.0