Skip to content

Commit

Permalink
math: replace assembly implementations of Abs with pure Go version
Browse files Browse the repository at this point in the history
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 golang#13095

Change-Id: I3066f8eaa327bb403173b29791cc8661d7c0532c
Reviewed-on: https://go-review.googlesource.com/16444
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
bradfitz committed Oct 29, 2015
1 parent 51586aa commit 6f8a665
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 72 deletions.
7 changes: 4 additions & 3 deletions src/math/abs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ package math
// 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
Expand Down
12 changes: 0 additions & 12 deletions src/math/abs_386.s

This file was deleted.

14 changes: 0 additions & 14 deletions src/math/abs_amd64.s

This file was deleted.

5 changes: 0 additions & 5 deletions src/math/abs_amd64p32.s

This file was deleted.

13 changes: 0 additions & 13 deletions src/math/abs_arm.s

This file was deleted.

11 changes: 0 additions & 11 deletions src/math/abs_arm64.s

This file was deleted.

14 changes: 0 additions & 14 deletions src/math/abs_ppc64x.s

This file was deleted.

0 comments on commit 6f8a665

Please sign in to comment.