diff options
| author | Keith Randall <khr@golang.org> | 2025-04-21 12:44:24 -0700 |
|---|---|---|
| committer | Keith Randall <khr@google.com> | 2025-04-22 10:24:18 -0700 |
| commit | 7d0cb2a2adec493b8ad9d79ef35354c8e20f0213 (patch) | |
| tree | 9e4bd4a4999810643be45d905dec4553013b0184 /test/codegen/mathbits.go | |
| parent | 7a177114df3e26f4362378e907a869c4fbbf38b7 (diff) | |
| download | go-7d0cb2a2adec493b8ad9d79ef35354c8e20f0213.tar.xz | |
cmd/compile: constant fold 128-bit multiplies
The full 64x64->128 multiply comes up when using bits.Mul64.
The 64x64->64+overflow multiply comes up in unsafe.Slice when using
a constant length.
Change-Id: I298515162ca07d804b2d699d03bc957ca30a4ebc
Reviewed-on: https://go-review.googlesource.com/c/go/+/667175
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'test/codegen/mathbits.go')
| -rw-r--r-- | test/codegen/mathbits.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index a9cf466780..873354b838 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -6,7 +6,10 @@ package codegen -import "math/bits" +import ( + "math/bits" + "unsafe" +) // ----------------------- // // bits.LeadingZeros // @@ -957,6 +960,17 @@ func Mul64LoOnly(x, y uint64) uint64 { return lo } +func Mul64Const() (uint64, uint64) { + // 7133701809754865664 == 99<<56 + // arm64:"MOVD\t[$]7133701809754865664, R1", "MOVD\t[$]88, R0" + return bits.Mul64(99+88<<8, 1<<56) +} + +func MulUintOverflow(p *uint64) []uint64 { + // arm64:"CMP\t[$]72" + return unsafe.Slice(p, 9) +} + // --------------- // // bits.Div* // // --------------- // |
