glibc/soft-fp/extendxftf2.c

54 lines
1.8 KiB
C
Raw Normal View History

2013-10-11 07:57:22 +08:00
/* Software floating-point emulation.
Return a converted to IEEE quad
Copyright (C) 2007-2018 Free Software Foundation, Inc.
2013-10-11 07:57:22 +08:00
This file is part of the GNU C Library.
Contributed by Uros Bizjak (ubizjak@gmail.com).
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.
In addition to the permissions in the GNU Lesser General Public
License, the Free Software Foundation gives you unlimited
permission to link the compiled version of this file into
combinations with other programs, and to distribute those
combinations without any restriction coming from the use of this
file. (The Lesser General Public License restrictions do apply in
other respects; for example, they cover modification of the file,
and distribution when not linked into a combine executable.)
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
<http://www.gnu.org/licenses/>. */
2013-10-11 07:57:22 +08:00
#include "soft-fp.h"
#include "extended.h"
#include "quad.h"
TFtype
2013-10-16 09:22:21 +08:00
__extendxftf2 (XFtype a)
2013-10-11 07:57:22 +08:00
{
FP_DECL_EX;
2013-10-16 09:22:21 +08:00
FP_DECL_E (A);
FP_DECL_Q (R);
2013-10-11 07:57:22 +08:00
TFtype r;
soft-fp: Make extensions of subnormals from XFmode to TFmode signal underflow if traps enabled. This patch fixes a soft-fp corner case I previously noted in <https://sourceware.org/ml/libc-alpha/2013-10/msg00349.html>: when trapping on underflow is enabled, extensions of subnormals from XFmode to TFmode need to signal underflow because the result is tiny (but exact, so the underflow flag is not raised unless trapping is enabled). To avoid any excess initialization or tests for other cases of floating-point extensions, a new FP_INIT_TRAPPING_EXCEPTIONS is added that does the initialization required for this particular case (more than FP_INIT_EXCEPTIONS, less than FP_INIT_ROUNDMODE, in general), and FP_NO_EXACT_UNDERFLOW is added to stub out FP_TRAPPING_EXCEPTIONS tests for those cases of extensions where the test would be dead code, to avoid any uninitialized variable warnings. As the relevant case only applies in libgcc, not to any use of soft-fp in glibc, there is no bug report in Bugzilla and no non-default definitions of FP_INIT_TRAPPING_EXCEPTIONS are added by the patch. A testcase will be added to GCC as part of an update of soft-fp in libgcc once this patch is in libc. Tested for powerpc-nofpu that the disassembly of installed shared libraries is unchanged by this patch. Bootstrapped GCC with updated soft-fp with no regressions on x86_64-unknown-linux-gnu and verified that a test of the relevant case passes where it failed before. * soft-fp/op-common.h (FP_EXTEND): When a subnormal input produces a subnormal result, set the underflow exception if trapping on underflow is enabled. * soft-fp/soft-fp.h (FP_INIT_TRAPPING_EXCEPTIONS): New macro. (FP_INIT_EXCEPTIONS): Default to FP_INIT_TRAPPING_EXCEPTIONS. [FP_NO_EXACT_UNDERFLOW] (FP_TRAPPING_EXCEPTIONS): Undefine and redefine to 0. * soft-fp/extenddftf2.c (FP_NO_EXACT_UNDERFLOW): Define. * soft-fp/extendsfdf2.c (FP_NO_EXACT_UNDERFLOW): Likewise. * soft-fp/extendsftf2.c (FP_NO_EXACT_UNDERFLOW): Likewise. * soft-fp/extendxftf2.c (__extendxftf2): Use FP_INIT_TRAPPING_EXCEPTIONS instead of FP_INIT_ROUNDMODE.
2014-10-09 09:00:41 +08:00
FP_INIT_TRAPPING_EXCEPTIONS;
2013-10-16 09:22:21 +08:00
FP_UNPACK_RAW_E (A, a);
2013-10-11 07:57:22 +08:00
#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q
2013-10-16 09:22:21 +08:00
FP_EXTEND (Q, E, 4, 4, R, A);
2013-10-11 07:57:22 +08:00
#else
2013-10-16 09:22:21 +08:00
FP_EXTEND (Q, E, 2, 2, R, A);
2013-10-11 07:57:22 +08:00
#endif
2013-10-16 09:22:21 +08:00
FP_PACK_RAW_Q (r, R);
2013-10-11 07:57:22 +08:00
FP_HANDLE_EXCEPTIONS;
return r;
}