]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: precompute constant square roots
authorKevin Burke <kev@inburke.com>
Sun, 21 Aug 2016 05:05:47 +0000 (22:05 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 23 Aug 2016 17:30:55 +0000 (17:30 +0000)
commit8e24a98abe464161bc8937a84f78189684aa738d
tree31f6de169f24e740268652a74e9fe99a62067233
parentd00890b5f3e7846a7b4ab084fe39d279f21aad04
cmd/compile: precompute constant square roots

If a program wants to evaluate math.Sqrt for any constant value
(for example, math.Sqrt(3)), we can replace that expression with
its evaluation (1.7320508075688772) at compile time, instead of
generating a SQRT assembly command or equivalent.

Adds tests that math.Sqrt generates the correct values. I also
compiled a short program and verified that the Sqrt expression was
replaced by a constant value in the "after opt" step.

Adds a short doc to the top of generic.rules explaining what the file
does and how other files interact with it.

Fixes #15543.

Change-Id: I6b6e63ac61cec50763a09ba581024adeee03d4fa
Reviewed-on: https://go-review.googlesource.com/27457
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa_test.go
src/cmd/compile/internal/gc/testdata/sqrt_const.go [new file with mode: 0644]
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
src/cmd/compile/internal/ssa/value.go