mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-29 14:01:20 +00:00
94ced920a9
i386 scalb / scalbn / scalbln (and thus ldexp) functions for float and double can return results with excess range (and consequently excess precision for subnormal results). As the results of these functions are fully determined by reference to IEEE 754 operations, this is unambiguously a bug, apart from the testsuite failures it causes. This patch makes those functions store their results on the stack and load them back to eliminate the excess range. Double rounding is not a problem, as the only cases where it could occur are when the result overflows or underflows for extended precision, and then the double-rounded results are the same as the single-rounded results. The new macros will be used for more functions, more such macros added, and existing code refactored to use such macros, in subsequent patches. Tested for x86. Committed. [BZ #18981] * sysdeps/i386/fpu/i386-math-asm.h: New file. * sysdeps/i386/fpu/e_scalb.S: Include <i386-math-asm.h>. (__ieee754_scalb): Use DBL_NARROW_EVAL. * sysdeps/i386/fpu/e_scalbf.S: Include <i386-math-asm.h>. (__ieee754_scalbf): Use FLT_NARROW_EVAL. * sysdeps/i386/fpu/s_scalbn.S: Include <i386-math-asm.h>. (__scalbn): Use DBL_NARROW_EVAL. * sysdeps/i386/fpu/s_scalbnf.S: Include <i386-math-asm.h>. (__scalbnf): Use FLT_NARROW_EVAL.
101 lines
1.5 KiB
ArmAsm
101 lines
1.5 KiB
ArmAsm
/*
|
|
* Written by J.T. Conklin <jtc@netbsd.org>.
|
|
* Public domain.
|
|
*
|
|
* Correct handling of y==-inf <drepper@gnu>
|
|
*/
|
|
|
|
#include <machine/asm.h>
|
|
#include <i386-math-asm.h>
|
|
|
|
.section .rodata
|
|
|
|
.align ALIGNARG(4)
|
|
.type zero_nan,@object
|
|
zero_nan:
|
|
.double 0.0
|
|
nan: .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
|
|
.byte 0, 0, 0, 0, 0, 0, 0, 0x80
|
|
.byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
|
|
ASM_SIZE_DIRECTIVE(zero_nan)
|
|
|
|
|
|
#ifdef PIC
|
|
# define MO(op) op##@GOTOFF(%ecx)
|
|
# define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
|
|
#else
|
|
# define MO(op) op
|
|
# define MOX(op,x,f) op(,x,f)
|
|
#endif
|
|
|
|
.text
|
|
ENTRY(__ieee754_scalb)
|
|
fldl 12(%esp)
|
|
fxam
|
|
fnstsw
|
|
fldl 4(%esp)
|
|
andl $0x4700, %eax
|
|
cmpl $0x0700, %eax
|
|
je 1f
|
|
andl $0x4500, %eax
|
|
cmpl $0x0100, %eax
|
|
je 2f
|
|
fxam
|
|
fnstsw
|
|
andl $0x4500, %eax
|
|
cmpl $0x0100, %eax
|
|
je 3f
|
|
fld %st(1)
|
|
frndint
|
|
fcomp %st(2)
|
|
fnstsw
|
|
sahf
|
|
jne 4f
|
|
fscale
|
|
fstp %st(1)
|
|
DBL_NARROW_EVAL
|
|
ret
|
|
|
|
/* y is -inf */
|
|
1: fxam
|
|
#ifdef PIC
|
|
LOAD_PIC_REG (cx)
|
|
#endif
|
|
fnstsw
|
|
movl 8(%esp), %edx
|
|
shrl $5, %eax
|
|
fstp %st
|
|
fstp %st
|
|
andl $0x80000000, %edx
|
|
andl $0x0228, %eax
|
|
cmpl $0x0028, %eax
|
|
je 4f
|
|
andl $8, %eax
|
|
shrl $27, %edx
|
|
addl %edx, %eax
|
|
fldl MOX(zero_nan, %eax, 1)
|
|
ret
|
|
|
|
/* The result is NaN, but we must not raise an exception.
|
|
So use a variable. */
|
|
2: fstp %st
|
|
fstp %st
|
|
#ifdef PIC
|
|
LOAD_PIC_REG (cx)
|
|
#endif
|
|
fldl MO(nan)
|
|
ret
|
|
|
|
/* The first parameter is a NaN. Return it. */
|
|
3: fstp %st(1)
|
|
ret
|
|
|
|
/* Return NaN and raise the invalid exception. */
|
|
4: fstp %st
|
|
fstp %st
|
|
fldz
|
|
fdiv %st
|
|
ret
|
|
END(__ieee754_scalb)
|
|
strong_alias (__ieee754_scalb, __scalb_finite)
|