math: handle denormals in AMD64 Exp

Fixes #23164

Change-Id: I6e8c6443f3ef91df71e117cce1cfa1faba647dd7
Reviewed-on: https://go-review.googlesource.com/87337
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Wèi Cōngruì 2018-01-09 11:48:15 +08:00 committed by Robert Griesemer
parent 4907c62f99
commit 7fe2f549cc
2 changed files with 19 additions and 9 deletions

View file

@ -1014,6 +1014,8 @@ var vfexpSC = []float64{
1,
// near zero
3.725290298461915e-09,
// denormal
-740,
}
var expSC = []float64{
0,
@ -1026,6 +1028,7 @@ var expSC = []float64{
Inf(1),
2.718281828459045,
1.0000000037252903,
4.2e-322,
}
var vfexp2SC = []float64{

View file

@ -96,14 +96,13 @@ TEXT ·Exp(SB),NOSPLIT,$0
MULSD X1, X0
ADDSD exprodata<>+8(SB), X0
// return fr * 2**exponent
lastStep:
MOVL $0x3FF, AX // bias
ADDL AX, BX
JLE underflow
ldexp:
ADDL $0x3FF, BX // add bias
JLE denormal
CMPL BX, $0x7FF
JGE overflow
MOVL $52, CX
SHLQ CX, BX
lastStep:
SHLQ $52, BX
MOVQ BX, X1
MULSD X1, X0
MOVSD X0, ret+8(FP)
@ -115,14 +114,22 @@ notFinite:
JNE notNegInf
// -Inf, return 0
underflow: // return 0
MOVQ $0, AX
MOVQ AX, ret+8(FP)
MOVQ $0, ret+8(FP)
RET
overflow: // return +Inf
MOVQ $PosInf, BX
notNegInf: // NaN or +Inf, return x
MOVQ BX, ret+8(FP)
RET
denormal:
CMPL BX, $-52
JL underflow
ADDL $0x3FE, BX // add bias - 1
SHLQ $52, BX
MOVQ BX, X1
MULSD X1, X0
MOVQ $1, BX
JMP lastStep
avxfma:
MOVSD $LN2U, X2
@ -149,4 +156,4 @@ avxfma:
MULSD X1, X0
VADDSD exprodata<>+16(SB), X0, X1
VFMADD213SD exprodata<>+8(SB), X1, X0
JMP lastStep
JMP ldexp