/* Optimized __ieee754_expf function.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
Contributed by Intel Corporation.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
. */
#include
/* Short algorithm description:
*
* Let K = 64 (table size).
* e^x = 2^(x/log(2)) = 2^n * T[j] * (1 + P(y))
* where
* x = m*log(2)/K + y, y in [0.0..log(2)/K]
* m = n*K + j, m,n,j - signed integer, j in [0..K-1]
* values of 2^(j/K) are tabulated as T[j].
*
* P(y) is a minimax polynomial approximation of expf(x)-1
* on small interval [0.0..log(2)/K].
*
* P(y) = P3*y*y*y*y + P2*y*y*y + P1*y*y + P0*y, calculated as
* z = y*y; P(y) = (P3*z + P1)*z + (P2*z + P0)*y
*
* Special cases:
* expf(NaN) = NaN
* expf(+INF) = +INF
* expf(-INF) = 0
* expf(x) = 1 for subnormals
* for finite argument, only expf(0)=1 is exact
* expf(x) overflows if x>88.7228317260742190
* expf(x) underflows if x<-103.972076416015620
*/
.text
ENTRY(__ieee754_expf)
/* Input: single precision x in %xmm0 */
cvtss2sd %xmm0, %xmm1 /* Convert x to double precision */
movd %xmm0, %ecx /* Copy x */
movsd L(DP_KLN2)(%rip), %xmm2 /* DP K/log(2) */
movsd L(DP_P2)(%rip), %xmm3 /* DP P2 */
movl %ecx, %eax /* x */
mulsd %xmm1, %xmm2 /* DP x*K/log(2) */
andl $0x7fffffff, %ecx /* |x| */
lea L(DP_T)(%rip), %rsi /* address of table T[j] */
cmpl $0x42ad496b, %ecx /* |x|<125*log(2) ? */
movsd L(DP_P3)(%rip), %xmm4 /* DP P3 */
addsd L(DP_RS)(%rip), %xmm2 /* DP x*K/log(2)+RS */
jae L(special_paths)
/* Here if |x|<125*log(2) */
cmpl $0x31800000, %ecx /* |x|<2^(-28) ? */
jb L(small_arg)
/* Main path: here if 2^(-28)<=|x|<125*log(2) */
cvtsd2ss %xmm2, %xmm2 /* SP x*K/log(2)+RS */
movd %xmm2, %eax /* bits of n*K+j with trash */
subss L(SP_RS)(%rip), %xmm2 /* SP t=round(x*K/log(2)) */
movl %eax, %edx /* n*K+j with trash */
cvtss2sd %xmm2, %xmm2 /* DP t */
andl $0x3f, %eax /* bits of j */
mulsd L(DP_NLN2K)(%rip), %xmm2/* DP -t*log(2)/K */
andl $0xffffffc0, %edx /* bits of n */
#ifdef __AVX__
vaddsd %xmm1, %xmm2, %xmm0 /* DP y=x-t*log(2)/K */
vmulsd %xmm0, %xmm0, %xmm2 /* DP z=y*y */
#else
addsd %xmm1, %xmm2 /* DP y=x-t*log(2)/K */
movaps %xmm2, %xmm0 /* DP y */
mulsd %xmm2, %xmm2 /* DP z=y*y */
#endif
mulsd %xmm2, %xmm4 /* DP P3*z */
addl $0x1fc0, %edx /* bits of n + SP exponent bias */
mulsd %xmm2, %xmm3 /* DP P2*z */
shll $17, %edx /* SP 2^n */
addsd L(DP_P1)(%rip), %xmm4 /* DP P3*z+P1 */
addsd L(DP_P0)(%rip), %xmm3 /* DP P2*z+P0 */
movd %edx, %xmm1 /* SP 2^n */
mulsd %xmm2, %xmm4 /* DP (P3*z+P1)*z */
mulsd %xmm3, %xmm0 /* DP (P2*z+P0)*y */
addsd %xmm4, %xmm0 /* DP P(y) */
mulsd (%rsi,%rax,8), %xmm0 /* DP P(y)*T[j] */
addsd (%rsi,%rax,8), %xmm0 /* DP T[j]*(P(y)+1) */
cvtsd2ss %xmm0, %xmm0 /* SP T[j]*(P(y)+1) */
mulss %xmm1, %xmm0 /* SP result=2^n*(T[j]*(P(y)+1)) */
ret
.p2align 4
L(small_arg):
/* Here if 0<=|x|<2^(-28) */
addss L(SP_ONE)(%rip), %xmm0 /* 1.0 + x */
/* Return 1.0 with inexact raised, except for x==0 */
ret
.p2align 4
L(special_paths):
/* Here if 125*log(2)<=|x| */
shrl $31, %eax /* Get sign bit of x, and depending on it: */
lea L(SP_RANGE)(%rip), %rdx /* load over/underflow bound */
cmpl (%rdx,%rax,4), %ecx /* |x|under/overflow bound */
cmpl $0x7f800000, %ecx /* |x| is finite ? */
jae L(arg_inf_or_nan)
/* Here if |x|>under/overflow bound, and x is finite */
testq %rax, %rax /* sign of x nonzero ? */
je L(res_overflow)
/* Here if -inf0) */
movss L(SP_LARGE)(%rip), %xmm0/* load large value 2^100 */
mulss %xmm0, %xmm0 /* Return overflowed result (Inf or max normal) */
ret
.p2align 4
L(arg_inf_or_nan):
/* Here if |x| is Inf or NAN */
jne L(arg_nan) /* |x| is Inf ? */
/* Here if |x| is Inf */
lea L(SP_INF_0)(%rip), %rdx /* depending on sign of x: */
movss (%rdx,%rax,4), %xmm0 /* return zero or Inf */
ret
.p2align 4
L(arg_nan):
/* Here if |x| is NaN */
addss %xmm0, %xmm0 /* Return x+x (raise invalid) */
ret
.p2align 4
L(near_under_or_overflow):
/* Here if 125*log(2)<=|x|this bound, then result overflows */
.long 0x42cff1b4 /* if x