]> Cypherpunks repositories - gostls13.git/commit
math: use Trunc to implement Modf
authorMichael Munday <mndygolang+git@gmail.com>
Mon, 28 Jul 2025 23:30:04 +0000 (00:30 +0100)
committerMichael Munday <mndygolang+git@gmail.com>
Mon, 25 Aug 2025 19:46:11 +0000 (12:46 -0700)
commit25c2d4109f5061425ca2633fb12450d43839bb79
tree8807499e07fd842e59819ee34bf8c3db888b240c
parent4e05a070c4f88ebf43f0873e144c62d02d56060b
math: use Trunc to implement Modf

By implementing Modf using Trunc, rather than the other way round,
we can get a significant performance improvement on platforms where
Trunc is implemented as an intrinsic.

Trunc is implemented as an intrinsic on ppc64x and arm64 so the assembly
implementations of Modf are no longer needed (the compiler can generate
very similar code that can now potentially be inlined).

GOAMD64=v1

goos: linux
goarch: amd64
pkg: math
cpu: 12th Gen Intel(R) Core(TM) i7-12700T
        │       sec/op       │    sec/op     vs base                │
Gamma            4.257n ± 0%    3.890n ± 0%   -8.61% (p=0.000 n=10)
Modf            1.6110n ± 0%   0.4243n ± 0%  -73.67% (p=0.000 n=10)
geomean          2.619n         1.285n       -50.94%

GOAMD64=v2

goos: linux
goarch: amd64
pkg: math
cpu: 12th Gen Intel(R) Core(TM) i7-12700T
        │       sec/op       │    sec/op     vs base                │
Gamma            4.100n ± 1%    3.717n ± 0%   -9.35% (p=0.000 n=10)
Modf            1.6070n ± 0%   0.2158n ± 1%  -86.57% (p=0.000 n=10)
geomean          2.567n        0.8957n       -65.11%

Change-Id: I689a560c344cf1d39ef002b540749bacc3179786
Reviewed-on: https://go-review.googlesource.com/c/go/+/694896
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/math/floor.go
src/math/modf.go
src/math/modf_arm64.s [deleted file]
src/math/modf_asm.go [deleted file]
src/math/modf_noasm.go [deleted file]
src/math/modf_ppc64x.s [deleted file]