aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill_ofarrell <billo@ca.ibm.com>2018-07-31 19:48:52 -0400
committerIan Lance Taylor <iant@golang.org>2018-08-03 01:21:31 +0000
commitf04a002e5ab99868d89e3263cfe947853d87b2d6 (patch)
tree446ebd0f74a38d163aa5dab78ee266e0fd3a3e6f
parentdb810b6e394c38a0bd0eb52c3475d0fbc08469f8 (diff)
downloadgo-f04a002e5ab99868d89e3263cfe947853d87b2d6.tar.gz
go-f04a002e5ab99868d89e3263cfe947853d87b2d6.zip
math: ensure Erfc is not called with out-of-expected-range arguments on s390x
The existing implementation produces correct results with a wide range of inputs, but invalid results asymptotically. With this change we ensure correct asymptotic results on s390x Fixes #26477 Change-Id: I760c1f8177f7cab2d7622ab9a926dfb1f8113b49 Reviewed-on: https://go-review.googlesource.com/127119 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/math/erfc_s390x.s25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/math/erfc_s390x.s b/src/math/erfc_s390x.s
index 1a867ad9f4..57710b254b 100644
--- a/src/math/erfc_s390x.s
+++ b/src/math/erfc_s390x.s
@@ -4,7 +4,8 @@
#include "textflag.h"
-#define NegInf 0xFFF0000000000000
+#define Neg2p11 0xC000E147AE147AE1
+#define Pos15 0x402E
// Minimax polynomial coefficients and other constants
DATA ·erfcrodataL38<> + 0(SB)/8, $.234875460637085087E-01
@@ -136,21 +137,24 @@ GLOBL ·erfctab2069<> + 0(SB), RODATA, $128
// Erfc(NaN) = NaN
// The algorithm used is minimax polynomial approximation
// with coefficients determined with a Remez exchange algorithm.
+// This assembly implementation handles inputs in the range [-2.11, +15].
+// For all other inputs we call the generic Go implementation.
-TEXT ·erfcAsm(SB), NOSPLIT, $0-16
- //special case Erfc(+Inf) = 0
+TEXT ·erfcAsm(SB), NOSPLIT|NOFRAME, $0-16
MOVD x+0(FP), R1
- MOVD $NegInf, R2
- CMPUBEQ R1, R2, erfcIsPosInf
+ MOVD $Neg2p11, R2
+ CMPUBGT R1, R2, usego
FMOVD x+0(FP), F0
MOVD $·erfcrodataL38<>+0(SB), R9
- WORD $0xB3CD0010 //lgdr %r1, %f0
FMOVD F0, F2
SRAD $48, R1
- MOVH $0x3FFF, R3
MOVH R1, R2
ANDW $0x7FFF, R1
+ MOVH $Pos15, R3
+ CMPW R1, R3
+ BGT usego
+ MOVH $0x3FFF, R3
MOVW R1, R6
MOVW R3, R7
CMPBGT R6, R7, L2
@@ -523,8 +527,5 @@ L18:
L25:
FMOVD 568(R9), F2
BR L1
-erfcIsPosInf:
- FMOVD $(2.0), F1
- FMOVD F1, ret+8(FP)
- RET
-
+usego:
+ BR ·erfc(SB)