]> Cypherpunks repositories - gostls13.git/commitdiff
math, cmd/internal/gc, cmd/7g: enable SQRT inlining, add assembly implementation
authorShenghou Ma <minux@golang.org>
Fri, 3 Apr 2015 22:15:26 +0000 (18:15 -0400)
committerMinux Ma <minux@golang.org>
Fri, 3 Apr 2015 23:48:00 +0000 (23:48 +0000)
benchmark                 old ns/op     new ns/op     delta
BenchmarkSqrt             474           16.5          -96.52%
BenchmarkSqrtIndirect     476           38.1          -92.00%
BenchmarkSqrtGo           484           483           -0.21%

Change-Id: I5ad0132feda0d3275a884523b9e79d83db4fc726
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/8465
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/7g/gsubr.go
src/cmd/7g/prog.go
src/cmd/internal/gc/walk.go
src/math/sqrt_arm64.s [new file with mode: 0644]
src/math/stubs_arm64.s

index 2d2bdb7ca4c3c0d0b77f1b3872b8cec3a5849f80..cea1e9205f8c343cd04417b4544d37f810c3f0d8 100644 (file)
@@ -938,6 +938,9 @@ func optoas(op int, t *gc.Type) int {
 
        case gc.ODIV<<16 | gc.TFLOAT64:
                a = arm64.AFDIVD
+
+       case gc.OSQRT<<16 | gc.TFLOAT64:
+               a = arm64.AFSQRTD
        }
 
        return a
index 2763e27a1eaf250ff01f45534707aae12b50069d..733c405fac77066b71a2d65f17930f97ca1d42ce 100644 (file)
@@ -60,18 +60,19 @@ var progtable = [arm64.ALAST]obj.ProgInfo{
        arm64.ACMP:   {gc.SizeQ | gc.LeftRead | gc.RegRead, 0, 0, 0},
 
        // Floating point.
-       arm64.AFADDD: {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFADDS: {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFSUBD: {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFSUBS: {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFNEGD: {gc.SizeD | gc.LeftRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFNEGS: {gc.SizeF | gc.LeftRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFMULD: {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFMULS: {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFDIVD: {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFDIVS: {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.AFCMPD: {gc.SizeD | gc.LeftRead | gc.RegRead, 0, 0, 0},
-       arm64.AFCMPS: {gc.SizeF | gc.LeftRead | gc.RegRead, 0, 0, 0},
+       arm64.AFADDD:  {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFADDS:  {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFSUBD:  {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFSUBS:  {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFNEGD:  {gc.SizeD | gc.LeftRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFNEGS:  {gc.SizeF | gc.LeftRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFSQRTD: {gc.SizeD | gc.LeftRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFMULD:  {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFMULS:  {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFDIVD:  {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFDIVS:  {gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
+       arm64.AFCMPD:  {gc.SizeD | gc.LeftRead | gc.RegRead, 0, 0, 0},
+       arm64.AFCMPS:  {gc.SizeF | gc.LeftRead | gc.RegRead, 0, 0, 0},
 
        // float -> integer
        arm64.AFCVTZSD:  {gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv, 0, 0, 0},
index a0a29d35ace1f5205ee168a136c5da6e5ad3185d..c845f783e50b9c4264ac0ea9662e5de3c4e82234 100644 (file)
@@ -624,7 +624,7 @@ func walkexpr(np **Node, init **NodeList) {
 
                if n.Left.Op == ONAME && n.Left.Sym.Name == "Sqrt" && n.Left.Sym.Pkg.Path == "math" {
                        switch Thearch.Thechar {
-                       case '5', '6':
+                       case '5', '6', '7':
                                n.Op = OSQRT
                                n.Left = n.List.N
                                n.List = nil
diff --git a/src/math/sqrt_arm64.s b/src/math/sqrt_arm64.s
new file mode 100644 (file)
index 0000000..9861446
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2015 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.
+
+#include "textflag.h"
+
+// func Sqrt(x float64) float64
+TEXT ·Sqrt(SB),NOSPLIT,$0
+       FMOVD   x+0(FP), F0
+       FSQRTD  F0, F0
+       FMOVD   F0, ret+8(FP)
+       RET
index 2ffd2289b8a4f3d89145c693301acfa108a2fd54..eea81e9241d8fb65e5490913659cfc025f1d41ef 100644 (file)
@@ -84,8 +84,5 @@ TEXT ·Sin(SB),NOSPLIT,$0
 TEXT ·Cos(SB),NOSPLIT,$0
        B ·cos(SB)
 
-TEXT ·Sqrt(SB),NOSPLIT,$0
-       B ·sqrt(SB)
-
 TEXT ·Tan(SB),NOSPLIT,$0
        B ·tan(SB)