]> Cypherpunks repositories - gostls13.git/commitdiff
math: remove asm version of Dim
authorIlya Tocar <ilya.tocar@intel.com>
Wed, 29 Nov 2017 18:15:31 +0000 (12:15 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 30 Nov 2017 21:00:33 +0000 (21:00 +0000)
Dim performance has regressed by 14% vs 1.9 on amd64.
Current pure go version of Dim is faster and,
what is even more important for performance, is inlinable, so
instead of tweaking asm implementation, just remove it.
I had to update BenchmarkDim, because it was simply reloading
constant(answer) in a loop.
Perf data below:

name   old time/op  new time/op  delta
Dim-6  6.79ns ± 0%  1.60ns ± 1%  -76.39%  (p=0.000 n=7+10)

If I modify benchmark to be the same as in this CL results are even better:

name   old time/op  new time/op  delta
Dim-6  10.2ns ± 0%   1.6ns ± 1%  -84.27%  (p=0.000 n=8+10)

Updates #21913

Change-Id: I00e23c8affc293531e1d9f0e0e49f3a525634f53
Reviewed-on: https://go-review.googlesource.com/80695
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/math/all_test.go
src/math/dim.go
src/math/dim_386.s
src/math/dim_amd64.s
src/math/dim_arm.s
src/math/dim_arm64.s
src/math/stubs_mips64x.s
src/math/stubs_mipsx.s
src/math/stubs_ppc64x.s
src/math/stubs_s390x.s

index 7598d88570d93be4e784164ec002f99556266c28..0412c19e579f178809655f907a0ca8b993251bf1 100644 (file)
@@ -3210,7 +3210,7 @@ func BenchmarkAbs(b *testing.B) {
 func BenchmarkDim(b *testing.B) {
        x := 0.0
        for i := 0; i < b.N; i++ {
-               x = Dim(10, 3)
+               x = Dim(GlobalF, x)
        }
        GlobalF = x
 }
index ac0aa869d731e3086dabc37082ac861852d20f5d..d2e5d47f5c8ab3c6b5cd609cba1d76832c9f94a2 100644 (file)
@@ -10,9 +10,7 @@ package math
 //     Dim(+Inf, +Inf) = NaN
 //     Dim(-Inf, -Inf) = NaN
 //     Dim(x, NaN) = Dim(NaN, x) = NaN
-func Dim(x, y float64) float64
-
-func dim(x, y float64) float64 {
+func Dim(x, y float64) float64 {
        // The special cases result in NaN after the subtraction:
        //      +Inf - +Inf = NaN
        //      -Inf - -Inf = NaN
index 22b8abb017f70cf9ebe3a22b62b2940cb2144c43..2ee13886d7052e37bceffc9c92c6159260829f13 100644 (file)
@@ -4,9 +4,6 @@
 
 #include "textflag.h"
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       JMP ·dim(SB)
-
 TEXT ·Max(SB),NOSPLIT,$0
        JMP ·max(SB)
 
index 249f1b1569840d55d1a38cea098fdf3a6a3817ad..85c02e6e52ae2bccc15f40b8acd4aec5049a6971 100644 (file)
@@ -8,44 +8,6 @@
 #define NaN    0x7FF8000000000001
 #define NegInf 0xFFF0000000000000
 
-// func Dim(x, y float64) float64
-TEXT ·Dim(SB),NOSPLIT,$0
-       // (+Inf, +Inf) special case
-       MOVQ    x+0(FP), BX
-       MOVQ    y+8(FP), CX
-       MOVQ    $PosInf, AX
-       CMPQ    AX, BX
-       JNE     dim2
-       CMPQ    AX, CX
-       JEQ     bothInf
-dim2:  // (-Inf, -Inf) special case
-       MOVQ    $NegInf, AX
-       CMPQ    AX, BX
-       JNE     dim3
-       CMPQ    AX, CX
-       JEQ     bothInf
-dim3:  // (NaN, x) or (x, NaN)
-       MOVQ    $~(1<<63), DX
-       MOVQ    $PosInf, AX
-       ANDQ    DX, BX // x = |x|
-       CMPQ    AX, BX
-       JLT     isDimNaN
-       ANDQ    DX, CX // y = |y|
-       CMPQ    AX, CX
-       JLT     isDimNaN
-
-       MOVSD x+0(FP), X0
-       SUBSD y+8(FP), X0
-       MOVSD $(0.0), X1
-       MAXSD X1, X0
-       MOVSD X0, ret+16(FP)
-       RET
-bothInf: // Dim(-Inf, -Inf) or Dim(+Inf, +Inf)
-isDimNaN:
-       MOVQ    $NaN, AX
-       MOVQ    AX, ret+16(FP)
-       RET
-
 // func ·Max(x, y float64) float64
 TEXT ·Max(SB),NOSPLIT,$0
        // +Inf special cases
index 642e485bf9c6259d44de4aea87e0c037a9aee218..c6f1d87fb5bd8f4d68f24662b8cd689ab9fa176d 100644 (file)
@@ -4,9 +4,6 @@
 
 #include "textflag.h"
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       B ·dim(SB)
-
 TEXT ·Min(SB),NOSPLIT,$0
        B ·min(SB)
 
index 4b6b5929cd6d619cde4ea19ece0874c6f26e4855..2cb866ff3e987ff6b0e7538560ea237f1647bbea 100644 (file)
@@ -8,35 +8,6 @@
 #define NaN    0x7FF8000000000001
 #define NegInf 0xFFF0000000000000
 
-// func Dim(x, y float64) float64
-TEXT ·Dim(SB),NOSPLIT,$0
-       // (+Inf, +Inf) special case
-       MOVD    $PosInf, R0
-       MOVD    x+0(FP), R1
-       MOVD    y+8(FP), R2
-       CMP     R0, R1
-       BNE     dim2
-       CMP     R0, R2
-       BEQ     bothInf
-dim2:  // (-Inf, -Inf) special case
-       MOVD    $NegInf, R0
-       CMP     R0, R1
-       BNE     dim3
-       CMP     R0, R2
-       BEQ     bothInf
-dim3:  // normal case
-       FMOVD   R1, F0
-       FMOVD   R2, F1
-       FMOVD   $0.0, F2
-       FSUBD   F1, F0
-       FMAXD   F0, F2, F0
-       FMOVD   F0, ret+16(FP)
-       RET
-bothInf:
-       MOVD    $NaN, R0
-       MOVD    R0, ret+16(FP)
-       RET
-
 // func ·Max(x, y float64) float64
 TEXT ·Max(SB),NOSPLIT,$0
        // +Inf special cases
index a0e0e38810047948b9346cc42fa5dc2cc49ae1f0..b3ffa5b21ea33c6e34e9461edceab72d9035f239 100644 (file)
@@ -27,9 +27,6 @@ TEXT ·Atan(SB),NOSPLIT,$0
 TEXT ·Atanh(SB),NOSPLIT,$0
        JMP ·atanh(SB)
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       JMP ·dim(SB)
-
 TEXT ·Min(SB),NOSPLIT,$0
        JMP ·min(SB)
 
index e959f079bbc60a4eff81deac52de8ef2a1de620e..129898eb5fa4c5ba673e26c26b26eb0cf715130b 100644 (file)
@@ -27,9 +27,6 @@ TEXT ·Atan(SB),NOSPLIT,$0
 TEXT ·Atanh(SB),NOSPLIT,$0
        JMP     ·atanh(SB)
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       JMP     ·dim(SB)
-
 TEXT ·Min(SB),NOSPLIT,$0
        JMP     ·min(SB)
 
index 30c51ddeaf40748b74ca226f8cc5a67ff36d8304..dc5d6150883564bba27accc50d846d07e6e91371 100644 (file)
@@ -27,9 +27,6 @@ TEXT ·Atan(SB),NOSPLIT,$0
 TEXT ·Atanh(SB),NOSPLIT,$0
        BR ·atanh(SB)
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       BR ·dim(SB)
-
 TEXT ·Min(SB),NOSPLIT,$0
        BR ·min(SB)
 
index 4dceddac6323f52001de9023c2d8a9f24841c931..889e248db9a552aa1198184aa704d1399e1c3379 100644 (file)
@@ -4,9 +4,6 @@
 
 #include "textflag.h"
 
-TEXT ·Dim(SB),NOSPLIT,$0
-       BR ·dim(SB)
-
 TEXT ·Exp2(SB),NOSPLIT,$0
        BR ·exp2(SB)