]> Cypherpunks repositories - gostls13.git/commitdiff
math: improve sqrt for ppc64le,ppc64
authorLynn Boger <laboger@linux.vnet.ibm.com>
Tue, 16 Feb 2016 18:24:12 +0000 (12:24 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 10 Mar 2016 15:01:21 +0000 (15:01 +0000)
The existing implementation uses code written in Go to
implement Sqrt; this adds the assembler to use the sqrt
instruction for Power and makes the necessary changes to
allow it to be inlined.

The following tests showed this relative improvement:

benchmark                 delta
BenchmarkSqrt             -97.91%
BenchmarkSqrtIndirect     -96.65%
BenchmarkSqrtGo           -35.93%
BenchmarkSqrtPrime        -96.94%

Fixes #14349

Change-Id: I8074f4dc63486e756587564ceb320aca300bf5fa
Reviewed-on: https://go-review.googlesource.com/19515
Reviewed-by: Minux Ma <minux@golang.org>
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/ppc64/gsubr.go
src/cmd/compile/internal/ppc64/peep.go
src/cmd/compile/internal/ppc64/prog.go
src/math/sqrt_ppc64x.s [new file with mode: 0644]
src/math/stubs_ppc64x.s

index 30c1ecc040fd1409e28b8e3c653916474e3e09b8..531ddc3b8dc4b3565e6c12e3ba8970a5371fcdf1 100644 (file)
@@ -677,7 +677,7 @@ opswitch:
 
                if n.Left.Op == ONAME && n.Left.Sym.Name == "Sqrt" && n.Left.Sym.Pkg.Path == "math" {
                        switch Thearch.Thechar {
-                       case '5', '6', '7':
+                       case '5', '6', '7', '9':
                                n.Op = OSQRT
                                n.Left = n.List.First()
                                n.List.Set(nil)
index ce1d550cbf275e4ae0a3a33dc498c6b2564c7ecd..a1611c437bc42c97e8aaf148ac3704dd39ec95cf 100644 (file)
@@ -706,6 +706,7 @@ func optoas(op gc.Op, t *gc.Type) obj.As {
                OCMP_   = uint32(gc.OCMP) << 16
                OAS_    = uint32(gc.OAS) << 16
                OHMUL_  = uint32(gc.OHMUL) << 16
+               OSQRT_  = uint32(gc.OSQRT) << 16
        )
 
        a := obj.AXXX
@@ -1028,6 +1029,9 @@ func optoas(op gc.Op, t *gc.Type) obj.As {
 
        case ODIV_ | gc.TFLOAT64:
                a = ppc64.AFDIV
+
+       case OSQRT_ | gc.TFLOAT64:
+               a = ppc64.AFSQRT
        }
 
        return a
index 1bacd8f69e6b62a2dfc6f4365783b064fa7bc8ee..baca75680ade7510921a9d993a3d8f1ff574a809 100644 (file)
@@ -632,7 +632,8 @@ func copyu(p *obj.Prog, v *obj.Addr, s *obj.Addr) int {
                ppc64.AFMOVD,
                ppc64.AFRSP,
                ppc64.AFNEG,
-               ppc64.AFNEGCC:
+               ppc64.AFNEGCC,
+               ppc64.AFSQRT:
                if s != nil {
                        if copysub(&p.From, v, s, true) {
                                return 1
index bdd0d4a1792e0937bcf498398cb167a9fe0502ee..cb0e93b0c521c255218965f13a80d1f291085ba8 100644 (file)
@@ -73,6 +73,7 @@ var progtable = [ppc64.ALAST & obj.AMask]obj.ProgInfo{
        ppc64.AFCFID & obj.AMask:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite},
        ppc64.AFCMPU & obj.AMask:  {Flags: gc.SizeD | gc.LeftRead | gc.RightRead},
        ppc64.AFRSP & obj.AMask:   {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
+       ppc64.AFSQRT & obj.AMask:  {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite},
 
        // Moves
        ppc64.AMOVB & obj.AMask:  {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
diff --git a/src/math/sqrt_ppc64x.s b/src/math/sqrt_ppc64x.s
new file mode 100644 (file)
index 0000000..bcfb157
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2016 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ppc64 ppc64le
+
+#include "textflag.h"
+
+// func Sqrt(x float64) float64
+TEXT ·Sqrt(SB),NOSPLIT,$0
+       FMOVD   x+0(FP), F0
+       FSQRT   F0, F0
+       FMOVD   F0, ret+8(FP)
+       RET
index 42e54802344972eb9a4537000e0250c12115c83d..a57357e2ee5d24673f99c6fde8731c5ebeef7cd0 100644 (file)
@@ -84,8 +84,5 @@ TEXT ·Sin(SB),NOSPLIT,$0
 TEXT ·Cos(SB),NOSPLIT,$0
        BR ·cos(SB)
 
-TEXT ·Sqrt(SB),NOSPLIT,$0
-       BR ·sqrt(SB)
-
 TEXT ·Tan(SB),NOSPLIT,$0
        BR ·tan(SB)