]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile,math: remove all sqrt assembly code
authorWayne Zuo <wdvxdr@golangcn.org>
Wed, 3 Aug 2022 15:31:29 +0000 (23:31 +0800)
committerKeith Randall <khr@golang.org>
Mon, 15 Aug 2022 17:07:57 +0000 (17:07 +0000)
This CL make math.sqrt an intrinsic function, math.Sqrt is not affected
since compiler can inline it. With this change, we can remove all assembly
code for math.Sqrt that aims to speed up indirect call. The go compiler can
generate same or faster code (with regabi) for indirect call.

Benchmark on amd64:
name                 old time/op  new time/op  delta
SqrtIndirect         2.60ns ± 3%  1.03ns ± 4%  -60.24%  (p=0.000 n=10+10)
SqrtLatency          3.40ns ± 1%  3.32ns ± 1%   -2.26%  (p=0.000 n=10+8)
SqrtIndirectLatency  6.09ns ± 0%  3.31ns ± 0%  -45.67%  (p=0.000 n=10+10)
SqrtGoLatency        36.1ns ± 6%  34.6ns ± 1%     ~     (p=0.101 n=10+10)
SqrtPrime            2.53µs ± 2%  2.55µs ± 6%     ~     (p=0.398 n=9+9)

Change-Id: If4be0f242c1d9d4feca7d269fc9cd6e6066f163d
Reviewed-on: https://go-review.googlesource.com/c/go/+/421074
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 files changed:
src/cmd/compile/internal/ssagen/ssa.go
src/math/sqrt.go
src/math/sqrt_386.s [deleted file]
src/math/sqrt_amd64.s [deleted file]
src/math/sqrt_arm.s [deleted file]
src/math/sqrt_arm64.s [deleted file]
src/math/sqrt_asm.go [deleted file]
src/math/sqrt_mipsx.s [deleted file]
src/math/sqrt_noasm.go [deleted file]
src/math/sqrt_ppc64x.s [deleted file]
src/math/sqrt_riscv64.s [deleted file]
src/math/sqrt_s390x.s [deleted file]
src/math/sqrt_wasm.s [deleted file]

index 26e69ad05dcebf029d3f9e3d0cd85b042f11d6ba..835d1a803f7a70aa90135c35d74b74a3d6eb2644 100644 (file)
@@ -4302,7 +4302,7 @@ func InitTables() {
        alias("runtime/internal/atomic", "CasRel", "runtime/internal/atomic", "Cas", lwatomics...)
 
        /******** math ********/
-       addF("math", "Sqrt",
+       addF("math", "sqrt",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
                        return s.newValue1(ssa.OpSqrt, types.Types[types.TFLOAT64], args[0])
                },
index b6d80c2c6f8e5256a8d9f559f60c51b42ced099f..54929ebcaf74c30fdf6462d521e5aab5fc28942e 100644 (file)
@@ -91,15 +91,10 @@ package math
 //     Sqrt(x < 0) = NaN
 //     Sqrt(NaN) = NaN
 func Sqrt(x float64) float64 {
-       if haveArchSqrt {
-               return archSqrt(x)
-       }
        return sqrt(x)
 }
 
-// Note: Sqrt is implemented in assembly on some systems.
-// Others have assembly stubs that jump to func sqrt below.
-// On systems where Sqrt is a single instruction, the compiler
+// Note: On systems where Sqrt is a single instruction, the compiler
 // may turn a direct call into a direct use of that instruction instead.
 
 func sqrt(x float64) float64 {
diff --git a/src/math/sqrt_386.s b/src/math/sqrt_386.s
deleted file mode 100644 (file)
index 90aec13..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2009 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 archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       FMOVD   x+0(FP),F0
-       FSQRT
-       FMOVDP  F0,ret+8(FP)
-       RET
diff --git a/src/math/sqrt_amd64.s b/src/math/sqrt_amd64.s
deleted file mode 100644 (file)
index c3b110e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2009 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 archSqrt(x float64) float64
-TEXT ·archSqrt(SB), NOSPLIT, $0
-       XORPS  X0, X0 // break dependency
-       SQRTSD x+0(FP), X0
-       MOVSD  X0, ret+8(FP)
-       RET
diff --git a/src/math/sqrt_arm.s b/src/math/sqrt_arm.s
deleted file mode 100644 (file)
index 64792ec..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 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 archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       MOVB    runtime·goarm(SB), R11
-       CMP     $5, R11
-       BEQ     arm5
-       MOVD    x+0(FP),F0
-       SQRTD   F0,F0
-       MOVD    F0,ret+8(FP)
-       RET
-arm5:
-       // Tail call to Go implementation.
-       // Can't use JMP, as in softfloat mode SQRTD is rewritten
-       // to a CALL, which makes this function have a frame.
-       RET     ·sqrt(SB)
diff --git a/src/math/sqrt_arm64.s b/src/math/sqrt_arm64.s
deleted file mode 100644 (file)
index 36ba41a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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 archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       FMOVD   x+0(FP), F0
-       FSQRTD  F0, F0
-       FMOVD   F0, ret+8(FP)
-       RET
diff --git a/src/math/sqrt_asm.go b/src/math/sqrt_asm.go
deleted file mode 100644 (file)
index 2cec1a5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2021 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.
-
-//go:build 386 || amd64 || arm64 || arm || mips || mipsle || ppc64 || ppc64le || s390x || riscv64 || wasm
-
-package math
-
-const haveArchSqrt = true
-
-func archSqrt(x float64) float64
diff --git a/src/math/sqrt_mipsx.s b/src/math/sqrt_mipsx.s
deleted file mode 100644 (file)
index 291d4af..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.
-
-//go:build mips || mipsle
-// +build mips mipsle
-
-#include "textflag.h"
-
-// func archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-#ifdef GOMIPS_softfloat
-       JMP ·sqrt(SB)
-#else
-       MOVD    x+0(FP), F0
-       SQRTD   F0, F0
-       MOVD    F0, ret+8(FP)
-#endif
-       RET
diff --git a/src/math/sqrt_noasm.go b/src/math/sqrt_noasm.go
deleted file mode 100644 (file)
index 3979622..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2021 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.
-
-//go:build !386 && !amd64 && !arm64 && !arm && !mips && !mipsle && !ppc64 && !ppc64le && !s390x && !riscv64 && !wasm
-
-package math
-
-const haveArchSqrt = false
-
-func archSqrt(x float64) float64 {
-       panic("not implemented")
-}
diff --git a/src/math/sqrt_ppc64x.s b/src/math/sqrt_ppc64x.s
deleted file mode 100644 (file)
index c929da2..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// 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.
-
-//go:build ppc64 || ppc64le
-// +build ppc64 ppc64le
-
-#include "textflag.h"
-
-// func archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       FMOVD   x+0(FP), F0
-       FSQRT   F0, F0
-       FMOVD   F0, ret+8(FP)
-       RET
diff --git a/src/math/sqrt_riscv64.s b/src/math/sqrt_riscv64.s
deleted file mode 100644 (file)
index 0dbdbc9..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2020 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 archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       MOVD    x+0(FP), F0
-       FSQRTD  F0, F0
-       MOVD    F0, ret+8(FP)
-       RET
diff --git a/src/math/sqrt_s390x.s b/src/math/sqrt_s390x.s
deleted file mode 100644 (file)
index fa31f75..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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.
-
-#include "textflag.h"
-
-// func archSqrt(x float64) float64
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       FMOVD x+0(FP), F1
-       FSQRT F1, F1
-       FMOVD F1, ret+8(FP)
-       RET
diff --git a/src/math/sqrt_wasm.s b/src/math/sqrt_wasm.s
deleted file mode 100644 (file)
index fa6799d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2018 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"
-
-TEXT ·archSqrt(SB),NOSPLIT,$0
-       Get SP
-       F64Load x+0(FP)
-       F64Sqrt
-       F64Store ret+8(FP)
-       RET