2012-05-05 19:34:31 +00:00
|
|
|
/*
|
|
|
|
* Written by J.T. Conklin <jtc@netbsd.org>.
|
|
|
|
* Public domain.
|
|
|
|
*
|
|
|
|
* Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 8087 method for the exponential function is to calculate
|
|
|
|
* exp(x) = 2^(x log2(e))
|
|
|
|
* after separating integer and fractional parts
|
|
|
|
* x log2(e) = i + f, |f| <= .5
|
|
|
|
* 2^i is immediate but f needs to be precise for long double accuracy.
|
|
|
|
* Suppress range reduction error in computing f by the following.
|
|
|
|
* Separate x into integer and fractional parts
|
|
|
|
* x = xi + xf, |xf| <= .5
|
|
|
|
* Separate log2(e) into the sum of an exact number c0 and small part c1.
|
|
|
|
* c0 + c1 = log2(e) to extra precision
|
|
|
|
* Then
|
|
|
|
* f = (c0 xi - i) + c0 xf + c1 x
|
|
|
|
* where c0 xi is exact and so also is (c0 xi - i).
|
|
|
|
* -- moshier@na-net.ornl.gov
|
|
|
|
*/
|
|
|
|
|
2017-11-17 22:54:39 +00:00
|
|
|
#include <libm-alias-ldouble.h>
|
2012-05-05 19:34:31 +00:00
|
|
|
#include <machine/asm.h>
|
Refactor i386 libm code forcing underflow exceptions.
This patch refactors code in sysdeps/i386/fpu that forces underflow
exceptions to use common macros for that purpose as far as possible.
(Although some of the macros end up used in only one place, I think
it's cleanest to define all these macros together so that all the code
forcing underflow uses such macros. Some more uses of such macros
will also be introduced when fixing remaining bugs about missing
underflow exceptions, and it would be possible to do further
refactoring of the macros in i386-math-asm.h to share more code by
using other macros internally. Places that test for underflow by
examining the representation of the argument with integer operations,
rather that using floating-point comparisons on the argument or
result, are unchanged by this patch.)
Most of this code uses a macro MO to abstract away the differences
between PIC and non-PIC memory references to constants. log1p
functions, however, hardcoded PIC conditionals for this. Because the
common macros rely on the use of MO, I changed the log1p functions to
use the normal style here, and, for consistency, also made that change
to log1pl which is otherwise unaffected by this patch.
Tested for x86.
* sysdeps/i386/fpu/i386-math-asm.h (DEFINE_LDBL_MIN): New macro.
(FLT_CHECK_FORCE_UFLOW): Likewise.
(DBL_CHECK_FORCE_UFLOW): Likewise.
(FLT_CHECK_FORCE_UFLOW_NARROW): Likewise.
(DBL_CHECK_FORCE_UFLOW_NARROW): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
* sysdeps/i386/fpu/e_asin.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_asin): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_asinf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_asinf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_atan2.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atan2): Use DBL_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atan2f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atan2f): Use FLT_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atanh.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atanh): Use DBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_atanhf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atanhf): Use FLT_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_exp2l.S: Include <i386-math-asm.h>.
(ldbl_min): Replace with use of DEFINE_LDBL_MIN.
(__ieee754_exp2l): Use LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN.
* sysdeps/i386/fpu/e_expl.S: Include <i386-math-asm.h>.
[!USE_AS_EXPM1L] (cmin): Replace with use of DEFINE_LDBL_MIN.
(IEEE754_EXPL): Use LDBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/s_atan.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__atan): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_atanf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__atanf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_expm1.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__expm1): Use DBL_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_expm1f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__expm1f): Use FLT_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_log1p.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(MO): New macro.
(__log1p): Use MO. Use DBL_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(MO): New macro.
(__log1pf): Use MO. Use FLT_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pl.S (MO): New macro.
(__log1pl): Use MO.
2015-09-24 21:41:00 +00:00
|
|
|
#include <i386-math-asm.h>
|
2012-05-05 19:34:31 +00:00
|
|
|
|
2012-05-06 18:23:44 +00:00
|
|
|
#ifdef USE_AS_EXP10L
|
|
|
|
# define IEEE754_EXPL __ieee754_exp10l
|
|
|
|
# define EXPL_FINITE __exp10l_finite
|
|
|
|
# define FLDLOG fldl2t
|
2012-05-07 19:13:08 +00:00
|
|
|
#elif defined USE_AS_EXPM1L
|
|
|
|
# define IEEE754_EXPL __expm1l
|
|
|
|
# undef EXPL_FINITE
|
|
|
|
# define FLDLOG fldl2e
|
2012-05-06 18:23:44 +00:00
|
|
|
#else
|
|
|
|
# define IEEE754_EXPL __ieee754_expl
|
|
|
|
# define EXPL_FINITE __expl_finite
|
|
|
|
# define FLDLOG fldl2e
|
|
|
|
#endif
|
|
|
|
|
2012-05-05 19:34:31 +00:00
|
|
|
.section .rodata.cst16,"aM",@progbits,16
|
|
|
|
|
|
|
|
.p2align 4
|
2012-05-06 18:23:44 +00:00
|
|
|
#ifdef USE_AS_EXP10L
|
2012-08-02 19:04:29 +00:00
|
|
|
.type c0,@object
|
2012-05-06 18:23:44 +00:00
|
|
|
c0: .byte 0, 0, 0, 0, 0, 0, 0x9a, 0xd4, 0x00, 0x40
|
|
|
|
.byte 0, 0, 0, 0, 0, 0
|
|
|
|
ASM_SIZE_DIRECTIVE(c0)
|
2012-08-02 19:04:29 +00:00
|
|
|
.type c1,@object
|
2012-05-06 18:23:44 +00:00
|
|
|
c1: .byte 0x58, 0x92, 0xfc, 0x15, 0x37, 0x9a, 0x97, 0xf0, 0xef, 0x3f
|
|
|
|
.byte 0, 0, 0, 0, 0, 0
|
|
|
|
ASM_SIZE_DIRECTIVE(c1)
|
|
|
|
#else
|
2012-08-02 19:04:29 +00:00
|
|
|
.type c0,@object
|
2012-05-05 19:34:31 +00:00
|
|
|
c0: .byte 0, 0, 0, 0, 0, 0, 0xaa, 0xb8, 0xff, 0x3f
|
|
|
|
.byte 0, 0, 0, 0, 0, 0
|
|
|
|
ASM_SIZE_DIRECTIVE(c0)
|
2012-08-02 19:04:29 +00:00
|
|
|
.type c1,@object
|
2012-05-05 19:34:31 +00:00
|
|
|
c1: .byte 0x20, 0xfa, 0xee, 0xc2, 0x5f, 0x70, 0xa5, 0xec, 0xed, 0x3f
|
|
|
|
.byte 0, 0, 0, 0, 0, 0
|
|
|
|
ASM_SIZE_DIRECTIVE(c1)
|
2012-05-06 18:23:44 +00:00
|
|
|
#endif
|
2012-07-06 11:17:41 +00:00
|
|
|
#ifndef USE_AS_EXPM1L
|
2012-08-02 19:04:29 +00:00
|
|
|
.type csat,@object
|
2012-05-05 19:37:39 +00:00
|
|
|
csat: .byte 0, 0, 0, 0, 0, 0, 0, 0x80, 0x0e, 0x40
|
|
|
|
.byte 0, 0, 0, 0, 0, 0
|
|
|
|
ASM_SIZE_DIRECTIVE(csat)
|
Refactor i386 libm code forcing underflow exceptions.
This patch refactors code in sysdeps/i386/fpu that forces underflow
exceptions to use common macros for that purpose as far as possible.
(Although some of the macros end up used in only one place, I think
it's cleanest to define all these macros together so that all the code
forcing underflow uses such macros. Some more uses of such macros
will also be introduced when fixing remaining bugs about missing
underflow exceptions, and it would be possible to do further
refactoring of the macros in i386-math-asm.h to share more code by
using other macros internally. Places that test for underflow by
examining the representation of the argument with integer operations,
rather that using floating-point comparisons on the argument or
result, are unchanged by this patch.)
Most of this code uses a macro MO to abstract away the differences
between PIC and non-PIC memory references to constants. log1p
functions, however, hardcoded PIC conditionals for this. Because the
common macros rely on the use of MO, I changed the log1p functions to
use the normal style here, and, for consistency, also made that change
to log1pl which is otherwise unaffected by this patch.
Tested for x86.
* sysdeps/i386/fpu/i386-math-asm.h (DEFINE_LDBL_MIN): New macro.
(FLT_CHECK_FORCE_UFLOW): Likewise.
(DBL_CHECK_FORCE_UFLOW): Likewise.
(FLT_CHECK_FORCE_UFLOW_NARROW): Likewise.
(DBL_CHECK_FORCE_UFLOW_NARROW): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
* sysdeps/i386/fpu/e_asin.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_asin): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_asinf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_asinf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_atan2.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atan2): Use DBL_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atan2f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atan2f): Use FLT_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atanh.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atanh): Use DBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_atanhf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atanhf): Use FLT_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_exp2l.S: Include <i386-math-asm.h>.
(ldbl_min): Replace with use of DEFINE_LDBL_MIN.
(__ieee754_exp2l): Use LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN.
* sysdeps/i386/fpu/e_expl.S: Include <i386-math-asm.h>.
[!USE_AS_EXPM1L] (cmin): Replace with use of DEFINE_LDBL_MIN.
(IEEE754_EXPL): Use LDBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/s_atan.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__atan): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_atanf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__atanf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_expm1.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__expm1): Use DBL_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_expm1f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__expm1f): Use FLT_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_log1p.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(MO): New macro.
(__log1p): Use MO. Use DBL_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(MO): New macro.
(__log1pf): Use MO. Use FLT_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pl.S (MO): New macro.
(__log1pl): Use MO.
2015-09-24 21:41:00 +00:00
|
|
|
DEFINE_LDBL_MIN
|
2012-07-06 11:17:41 +00:00
|
|
|
#endif
|
2012-05-05 19:34:31 +00:00
|
|
|
|
|
|
|
#ifdef PIC
|
|
|
|
# define MO(op) op##@GOTOFF(%ecx)
|
|
|
|
#else
|
|
|
|
# define MO(op) op
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.text
|
2012-05-06 18:23:44 +00:00
|
|
|
ENTRY(IEEE754_EXPL)
|
2012-05-07 19:13:08 +00:00
|
|
|
#ifdef USE_AS_EXPM1L
|
|
|
|
movzwl 4+8(%esp), %eax
|
|
|
|
xorb $0x80, %ah // invert sign bit (now 1 is "positive")
|
|
|
|
cmpl $0xc006, %eax // is num positive and exp >= 6 (number is >= 128.0)?
|
|
|
|
jae HIDDEN_JUMPTARGET (__expl) // (if num is denormal, it is at least >= 64.0)
|
|
|
|
#endif
|
2012-05-05 19:34:31 +00:00
|
|
|
fldt 4(%esp)
|
|
|
|
/* I added the following ugly construct because expl(+-Inf) resulted
|
|
|
|
in NaN. The ugliness results from the bright minds at Intel.
|
|
|
|
For the i686 the code can be written better.
|
|
|
|
-- drepper@cygnus.com. */
|
|
|
|
fxam /* Is NaN or +-Inf? */
|
|
|
|
#ifdef PIC
|
|
|
|
LOAD_PIC_REG (cx)
|
|
|
|
#endif
|
2012-07-06 11:17:41 +00:00
|
|
|
#ifdef USE_AS_EXPM1L
|
|
|
|
xorb $0x80, %ah
|
|
|
|
cmpl $0xc006, %eax
|
|
|
|
fstsw %ax
|
|
|
|
movb $0x45, %dh
|
|
|
|
jb 4f
|
|
|
|
|
|
|
|
/* Below -64.0 (may be -NaN or -Inf). */
|
|
|
|
andb %ah, %dh
|
|
|
|
cmpb $0x01, %dh
|
2016-06-08 21:55:06 +00:00
|
|
|
je 6f /* Is +-NaN, jump. */
|
2012-07-06 11:17:41 +00:00
|
|
|
jmp 1f /* -large, possibly -Inf. */
|
|
|
|
|
|
|
|
4: /* In range -64.0 to 64.0 (may be +-0 but not NaN or +-Inf). */
|
|
|
|
/* Test for +-0 as argument. */
|
|
|
|
andb %ah, %dh
|
|
|
|
cmpb $0x40, %dh
|
|
|
|
je 2f
|
2014-06-24 21:00:08 +00:00
|
|
|
|
|
|
|
/* Test for arguments that are small but not subnormal. */
|
|
|
|
movzwl 4+8(%esp), %eax
|
|
|
|
andl $0x7fff, %eax
|
|
|
|
cmpl $0x3fbf, %eax
|
|
|
|
jge 3f
|
|
|
|
/* Argument's exponent below -64; avoid spurious underflow if
|
|
|
|
normal. */
|
|
|
|
cmpl $0x0001, %eax
|
|
|
|
jge 2f
|
2015-06-21 18:43:10 +00:00
|
|
|
/* Force underflow and return the argument, to avoid wrong signs
|
|
|
|
of zero results from the code below in some rounding modes. */
|
|
|
|
fld %st
|
|
|
|
fmul %st
|
|
|
|
fstp %st
|
|
|
|
jmp 2f
|
2012-07-06 11:17:41 +00:00
|
|
|
#else
|
2012-05-05 19:37:39 +00:00
|
|
|
movzwl 4+8(%esp), %eax
|
|
|
|
andl $0x7fff, %eax
|
|
|
|
cmpl $0x400d, %eax
|
2014-03-27 18:41:14 +00:00
|
|
|
jg 5f
|
|
|
|
cmpl $0x3fbc, %eax
|
|
|
|
jge 3f
|
|
|
|
/* Argument's exponent below -67, result rounds to 1. */
|
|
|
|
fld1
|
|
|
|
faddp
|
|
|
|
jmp 2f
|
|
|
|
5: /* Overflow, underflow or infinity or NaN as argument. */
|
2012-05-05 19:34:31 +00:00
|
|
|
fstsw %ax
|
|
|
|
movb $0x45, %dh
|
|
|
|
andb %ah, %dh
|
|
|
|
cmpb $0x05, %dh
|
|
|
|
je 1f /* Is +-Inf, jump. */
|
2012-05-05 19:37:39 +00:00
|
|
|
cmpb $0x01, %dh
|
2016-06-08 21:55:06 +00:00
|
|
|
je 6f /* Is +-NaN, jump. */
|
2012-05-05 19:37:39 +00:00
|
|
|
/* Overflow or underflow; saturate. */
|
|
|
|
fstp %st
|
|
|
|
fldt MO(csat)
|
|
|
|
andb $2, %ah
|
|
|
|
jz 3f
|
|
|
|
fchs
|
2012-05-07 19:13:08 +00:00
|
|
|
#endif
|
2012-07-06 11:17:41 +00:00
|
|
|
3: FLDLOG /* 1 log2(base) */
|
2012-05-06 18:23:44 +00:00
|
|
|
fmul %st(1), %st /* 1 x log2(base) */
|
2013-12-19 13:36:10 +00:00
|
|
|
/* Set round-to-nearest temporarily. */
|
|
|
|
subl $8, %esp
|
|
|
|
cfi_adjust_cfa_offset (8)
|
|
|
|
fstcw 4(%esp)
|
|
|
|
movl $0xf3ff, %edx
|
|
|
|
andl 4(%esp), %edx
|
|
|
|
movl %edx, (%esp)
|
|
|
|
fldcw (%esp)
|
2012-05-05 19:34:31 +00:00
|
|
|
frndint /* 1 i */
|
|
|
|
fld %st(1) /* 2 x */
|
|
|
|
frndint /* 2 xi */
|
2013-12-19 13:36:10 +00:00
|
|
|
fldcw 4(%esp)
|
|
|
|
addl $8, %esp
|
|
|
|
cfi_adjust_cfa_offset (-8)
|
2012-05-05 19:34:31 +00:00
|
|
|
fld %st(1) /* 3 i */
|
|
|
|
fldt MO(c0) /* 4 c0 */
|
|
|
|
fld %st(2) /* 5 xi */
|
|
|
|
fmul %st(1), %st /* 5 c0 xi */
|
|
|
|
fsubp %st, %st(2) /* 4 f = c0 xi - i */
|
|
|
|
fld %st(4) /* 5 x */
|
|
|
|
fsub %st(3), %st /* 5 xf = x - xi */
|
|
|
|
fmulp %st, %st(1) /* 4 c0 xf */
|
|
|
|
faddp %st, %st(1) /* 3 f = f + c0 xf */
|
|
|
|
fldt MO(c1) /* 4 */
|
|
|
|
fmul %st(4), %st /* 4 c1 * x */
|
|
|
|
faddp %st, %st(1) /* 3 f = f + c1 * x */
|
2012-05-06 18:23:44 +00:00
|
|
|
f2xm1 /* 3 2^(fract(x * log2(base))) - 1 */
|
2012-05-07 19:13:08 +00:00
|
|
|
#ifdef USE_AS_EXPM1L
|
|
|
|
fstp %st(1) /* 2 */
|
|
|
|
fscale /* 2 scale factor is st(1); base^x - 2^i */
|
|
|
|
fxch /* 2 i */
|
|
|
|
fld1 /* 3 1.0 */
|
|
|
|
fscale /* 3 2^i */
|
|
|
|
fld1 /* 4 1.0 */
|
|
|
|
fsubrp %st, %st(1) /* 3 2^i - 1.0 */
|
|
|
|
fstp %st(1) /* 2 */
|
|
|
|
faddp %st, %st(1) /* 1 base^x - 1.0 */
|
|
|
|
#else
|
2012-05-05 19:34:31 +00:00
|
|
|
fld1 /* 4 1.0 */
|
2012-05-06 18:23:44 +00:00
|
|
|
faddp /* 3 2^(fract(x * log2(base))) */
|
2012-05-05 19:34:31 +00:00
|
|
|
fstp %st(1) /* 2 */
|
2012-05-06 18:23:44 +00:00
|
|
|
fscale /* 2 scale factor is st(1); base^x */
|
2012-05-05 19:34:31 +00:00
|
|
|
fstp %st(1) /* 1 */
|
Refactor i386 libm code forcing underflow exceptions.
This patch refactors code in sysdeps/i386/fpu that forces underflow
exceptions to use common macros for that purpose as far as possible.
(Although some of the macros end up used in only one place, I think
it's cleanest to define all these macros together so that all the code
forcing underflow uses such macros. Some more uses of such macros
will also be introduced when fixing remaining bugs about missing
underflow exceptions, and it would be possible to do further
refactoring of the macros in i386-math-asm.h to share more code by
using other macros internally. Places that test for underflow by
examining the representation of the argument with integer operations,
rather that using floating-point comparisons on the argument or
result, are unchanged by this patch.)
Most of this code uses a macro MO to abstract away the differences
between PIC and non-PIC memory references to constants. log1p
functions, however, hardcoded PIC conditionals for this. Because the
common macros rely on the use of MO, I changed the log1p functions to
use the normal style here, and, for consistency, also made that change
to log1pl which is otherwise unaffected by this patch.
Tested for x86.
* sysdeps/i386/fpu/i386-math-asm.h (DEFINE_LDBL_MIN): New macro.
(FLT_CHECK_FORCE_UFLOW): Likewise.
(DBL_CHECK_FORCE_UFLOW): Likewise.
(FLT_CHECK_FORCE_UFLOW_NARROW): Likewise.
(DBL_CHECK_FORCE_UFLOW_NARROW): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
* sysdeps/i386/fpu/e_asin.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_asin): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_asinf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_asinf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_atan2.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atan2): Use DBL_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atan2f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atan2f): Use FLT_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atanh.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atanh): Use DBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_atanhf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atanhf): Use FLT_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_exp2l.S: Include <i386-math-asm.h>.
(ldbl_min): Replace with use of DEFINE_LDBL_MIN.
(__ieee754_exp2l): Use LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN.
* sysdeps/i386/fpu/e_expl.S: Include <i386-math-asm.h>.
[!USE_AS_EXPM1L] (cmin): Replace with use of DEFINE_LDBL_MIN.
(IEEE754_EXPL): Use LDBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/s_atan.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__atan): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_atanf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__atanf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_expm1.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__expm1): Use DBL_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_expm1f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__expm1f): Use FLT_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_log1p.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(MO): New macro.
(__log1p): Use MO. Use DBL_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(MO): New macro.
(__log1pf): Use MO. Use FLT_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pl.S (MO): New macro.
(__log1pl): Use MO.
2015-09-24 21:41:00 +00:00
|
|
|
LDBL_CHECK_FORCE_UFLOW_NONNEG
|
2012-05-07 19:13:08 +00:00
|
|
|
#endif
|
Refactor i386 libm code forcing underflow exceptions.
This patch refactors code in sysdeps/i386/fpu that forces underflow
exceptions to use common macros for that purpose as far as possible.
(Although some of the macros end up used in only one place, I think
it's cleanest to define all these macros together so that all the code
forcing underflow uses such macros. Some more uses of such macros
will also be introduced when fixing remaining bugs about missing
underflow exceptions, and it would be possible to do further
refactoring of the macros in i386-math-asm.h to share more code by
using other macros internally. Places that test for underflow by
examining the representation of the argument with integer operations,
rather that using floating-point comparisons on the argument or
result, are unchanged by this patch.)
Most of this code uses a macro MO to abstract away the differences
between PIC and non-PIC memory references to constants. log1p
functions, however, hardcoded PIC conditionals for this. Because the
common macros rely on the use of MO, I changed the log1p functions to
use the normal style here, and, for consistency, also made that change
to log1pl which is otherwise unaffected by this patch.
Tested for x86.
* sysdeps/i386/fpu/i386-math-asm.h (DEFINE_LDBL_MIN): New macro.
(FLT_CHECK_FORCE_UFLOW): Likewise.
(DBL_CHECK_FORCE_UFLOW): Likewise.
(FLT_CHECK_FORCE_UFLOW_NARROW): Likewise.
(DBL_CHECK_FORCE_UFLOW_NARROW): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNAN): Likewise.
(FLT_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(DBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
(LDBL_CHECK_FORCE_UFLOW_NONNEG): Likewise.
* sysdeps/i386/fpu/e_asin.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_asin): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_asinf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_asinf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/e_atan2.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atan2): Use DBL_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atan2f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atan2f): Use FLT_CHECK_FORCE_UFLOW_NARROW.
* sysdeps/i386/fpu/e_atanh.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__ieee754_atanh): Use DBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_atanhf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__ieee754_atanhf): Use FLT_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/e_exp2l.S: Include <i386-math-asm.h>.
(ldbl_min): Replace with use of DEFINE_LDBL_MIN.
(__ieee754_exp2l): Use LDBL_CHECK_FORCE_UFLOW_NONNEG_NAN.
* sysdeps/i386/fpu/e_expl.S: Include <i386-math-asm.h>.
[!USE_AS_EXPM1L] (cmin): Replace with use of DEFINE_LDBL_MIN.
(IEEE754_EXPL): Use LDBL_CHECK_FORCE_UFLOW_NONNEG.
* sysdeps/i386/fpu/s_atan.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__atan): Use DBL_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_atanf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__atanf): Use FLT_CHECK_FORCE_UFLOW.
* sysdeps/i386/fpu/s_expm1.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(__expm1): Use DBL_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_expm1f.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(__expm1f): Use FLT_CHECK_FORCE_UFLOW. Move underflow check after
main computation.
* sysdeps/i386/fpu/s_log1p.S: Include <i386-math-asm.h>.
(dbl_min): Replace with use of DEFINE_DBL_MIN.
(MO): New macro.
(__log1p): Use MO. Use DBL_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pf.S: Include <i386-math-asm.h>.
(flt_min): Replace with use of DEFINE_FLT_MIN.
(MO): New macro.
(__log1pf): Use MO. Use FLT_CHECK_FORCE_UFLOW_NONNAN.
* sysdeps/i386/fpu/s_log1pl.S (MO): New macro.
(__log1pl): Use MO.
2015-09-24 21:41:00 +00:00
|
|
|
fstp %st(1) /* 0 */
|
2012-05-05 19:34:31 +00:00
|
|
|
jmp 2f
|
2012-07-06 11:17:41 +00:00
|
|
|
1:
|
2012-05-07 19:13:08 +00:00
|
|
|
#ifdef USE_AS_EXPM1L
|
2012-07-06 11:17:41 +00:00
|
|
|
/* For expm1l, only negative sign gets here. */
|
|
|
|
fstp %st
|
2012-05-07 19:13:08 +00:00
|
|
|
fld1
|
|
|
|
fchs
|
|
|
|
#else
|
2012-07-06 11:17:41 +00:00
|
|
|
testl $0x200, %eax /* Test sign. */
|
|
|
|
jz 2f /* If positive, jump. */
|
|
|
|
fstp %st
|
2012-05-05 19:34:31 +00:00
|
|
|
fldz /* Set result to 0. */
|
2012-05-07 19:13:08 +00:00
|
|
|
#endif
|
2012-05-05 19:34:31 +00:00
|
|
|
2: ret
|
2016-06-08 21:55:06 +00:00
|
|
|
6: /* NaN argument. */
|
|
|
|
fadd %st
|
|
|
|
ret
|
2012-05-06 18:23:44 +00:00
|
|
|
END(IEEE754_EXPL)
|
2012-05-07 19:13:08 +00:00
|
|
|
#ifdef USE_AS_EXPM1L
|
|
|
|
libm_hidden_def (__expm1l)
|
2017-11-17 22:54:39 +00:00
|
|
|
libm_alias_ldouble (__expm1, expm1)
|
2012-05-07 19:13:08 +00:00
|
|
|
#else
|
2012-05-06 18:23:44 +00:00
|
|
|
strong_alias (IEEE754_EXPL, EXPL_FINITE)
|
2012-05-07 19:13:08 +00:00
|
|
|
#endif
|