]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: delete divmod1e9
authorRuss Cox <rsc@golang.org>
Wed, 29 Oct 2025 17:38:37 +0000 (13:38 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 30 Oct 2025 16:55:09 +0000 (09:55 -0700)
The compiler is just as good now, even on 32-bit systems.

Change-Id: Ifee72c0e84a68703c0721a7a9f4ca5aa637ad5e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/716464
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/internal/strconv/ftoaryu.go

index 9349df955f3c76106ccb463346aa9a5056279975..473e5b65be8d4c6614640e9e76090732164a67b1 100644 (file)
@@ -324,9 +324,9 @@ func computeBounds(mant uint64, exp int, flt *floatInfo) (lower, central, upper
 
 func ryuDigits(d *decimalSlice, lower, central, upper uint64,
        c0, cup bool) {
-       lhi, llo := divmod1e9(lower)
-       chi, clo := divmod1e9(central)
-       uhi, ulo := divmod1e9(upper)
+       lhi, llo := uint32(lower/1e9), uint32(lower%1e9)
+       chi, clo := uint32(central/1e9), uint32(central%1e9)
+       uhi, ulo := uint32(upper/1e9), uint32(upper%1e9)
        if uhi == 0 {
                // only low digits (for denormals)
                ryuDigits32(d, llo, clo, ulo, c0, cup, 8)
@@ -510,15 +510,3 @@ func divisibleByPower5(m uint64, k int) bool {
        }
        return true
 }
-
-// divmod1e9 computes quotient and remainder of division by 1e9,
-// avoiding runtime uint64 division on 32-bit platforms.
-func divmod1e9(x uint64) (uint32, uint32) {
-       if host64bit {
-               return uint32(x / 1e9), uint32(x % 1e9)
-       }
-       // Use the same sequence of operations as the amd64 compiler.
-       hi, _ := bits.Mul64(x>>1, 0x89705f4136b4a598) // binary digits of 1e-9
-       q := hi >> 28
-       return uint32(q), uint32(x - q*1e9)
-}