internal/runtime: remove math.Mul64

internal/runtime/math.Mul64 is a copy of math/bits.Mul64 and redundant.

Change-Id: I4dd2ab531a32da97839c6b45cf90df6430811967
GitHub-Last-Rev: 1a73e16049
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>
This commit is contained in:
Gavin Lam 2026-01-15 04:22:13 +00:00 committed by Gopher Robot
parent 1996c22f0a
commit e9e05687de
5 changed files with 5 additions and 37 deletions

View 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])

View 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{}{},

View 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.

View 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)
}

View 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)
}