math: replace assembly implementations of Abs with pure Go version
The compiler can do a fine job, and can also inline it.
From Jeremy Jackins's observation and rsc's recommendation in thread:
"Pure Go math.Abs outperforms assembly version"
https://groups.google.com/forum/#!topic/golang-dev/nP5mWvwAXZo
Updates #13095
Change-Id: I3066f8eaa327bb403173b29791cc8661d7c0532c
Reviewed-on: https://go-review.googlesource.com/16444
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/src/math/abs.go b/src/math/abs.go
index bc41a6d..e35e4da 100644
--- a/src/math/abs.go
+++ b/src/math/abs.go
@@ -9,9 +9,10 @@
// Special cases are:
// Abs(±Inf) = +Inf
// Abs(NaN) = NaN
-func Abs(x float64) float64
-
-func abs(x float64) float64 {
+func Abs(x float64) float64 {
+ // TODO: once golang.org/issue/13905 is fixed, change this to:
+ // return Float64frombits(Float64bits(x) &^ (1 << 63))
+ // But for now, this generates better code and can also be inlined:
switch {
case x < 0:
return -x