New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: strength reduce floating point #19827
Comments
CL https://golang.org/cl/39295 mentions this issue. |
Let me be ignorant and ask whether turning floating point multiplication into addition is indeed a performance win. One requires touching an exponent; the other requires touching every bit and normalizing. |
For amd64, the Agner Fog tables say that turning an Conversely, on arm64, there may not be a win. Both Division, on the other hand, appears to be consistently more expensive (dozens of cycles of result latency... up to 64 on the A57). |
x*2 -> x+x is almost certainly a win. x*-2 -> -(x+x) is less clear. I could be convinced either way. |
At least on amd64, *2 is a win. I'll remove the *-2 code from the CL. |
Thanks for checking. |
x*2 -> x+x x/c, c power of 2 -> x*(1/c) Fixes golang#19827 Change-Id: I74c9f0b5b49b2ed26c0990314c7d1d5f9631b6f1 Reviewed-on: https://go-review.googlesource.com/39295 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
In cases where it doesn't affect correctness, we could strength reduce some floating-point ops.
For the divide->multiply reduction, we could do any value whose reciprocal is representable exactly. Is that just powers of two?
We already do x1,x-1,x/1,x/-1.
See issue #19819
The text was updated successfully, but these errors were encountered: