mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 21:10:07 +00:00
26b0bf9600
As discussed in <https://sourceware.org/ml/libc-alpha/2016-05/msg00577.html>, TS 18661-1 disallows ceil, floor, round and trunc functions from raising the "inexact" exception, in accordance with general IEEE 754 semantics for when that exception is raised. Fixing this for x87 floating point is more complicated than for the other versions of these functions, because they use the frndint instruction that raises "inexact" and this can only be avoided by saving and restoring the whole floating-point environment. As I noted in <https://sourceware.org/ml/libc-alpha/2016-06/msg00128.html>, I have now implemented a GCC option -fno-fp-int-builtin-inexact for GCC 7, such that GCC will inline these functions on x86, without caring about "inexact", when the default -ffp-int-builtin-inexact is in effect. This allows users to get optimized code depending on the options they pass to the compiler, while making the out-of-line functions follow TS 18661-1 semantics and avoid "inexact". This patch duly fixes the out-of-line ceil function implementations to avoid "inexact", in the same way as the nearbyint implementations. I do not know how the performance of implementations such as these based on saving the environment and changing the rounding mode temporarily compares to that of the C versions or SSE 4.1 versions (of course, for 32-bit x86 SSE implementations still need to get the return value in an x87 register); it's entirely possible other implementations could be faster in some cases. Tested for x86_64 and x86. [BZ #15479] * sysdeps/i386/fpu/s_ceil.S (__ceil): Save and restore floating-point environment rather than just control word. * sysdeps/i386/fpu/s_ceilf.S (__ceilf): Likewise. * sysdeps/i386/fpu/s_ceill.S (__ceill): Save and restore floating-point environment, with "invalid" exceptions merged in, rather than just control word. * sysdeps/x86_64/fpu/s_ceill.S (__ceill): Likewise. * math/libm-test.inc (ceil_test_data): Do not allow spurious "inexact" exceptions.
37 lines
843 B
ArmAsm
37 lines
843 B
ArmAsm
/*
|
|
* Written by J.T. Conklin <jtc@netbsd.org>.
|
|
* Changes for long double by Ulrich Drepper <drepper@cygnus.com>
|
|
* Changes for x86-64 by Andreas Jaeger <aj@suse.de>
|
|
* Public domain.
|
|
*/
|
|
|
|
#include <machine/asm.h>
|
|
|
|
|
|
ENTRY(__ceill)
|
|
fldt 8(%rsp)
|
|
|
|
fnstenv -28(%rsp) /* store fpu environment */
|
|
|
|
/* We use here %edx although only the low 1 bits are defined.
|
|
But none of the operations should care and they are faster
|
|
than the 16 bit operations. */
|
|
movl $0x0800,%edx /* round towards +oo */
|
|
orl -28(%rsp),%edx
|
|
andl $0xfbff,%edx
|
|
movl %edx,-32(%rsp)
|
|
fldcw -32(%rsp) /* load modified control word */
|
|
|
|
frndint /* round */
|
|
|
|
/* Preserve "invalid" exceptions from sNaN input. */
|
|
fnstsw
|
|
andl $0x1, %eax
|
|
orl %eax, -24(%rsp)
|
|
|
|
fldenv -28(%rsp) /* restore original environment */
|
|
|
|
ret
|
|
END (__ceill)
|
|
weak_alias (__ceill, ceill)
|