This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Re: [PATCH 1/2] AArch64 glibc port
On Mon, 5 Nov 2012, Marcus Shawcroft wrote:
> Digging into the behaviour of trunctfdf2 (provided by libgcc) on the
> value LDBL_MIN, I expected to see INEXACT and UNDERFLOW but only get
> INEXACT.
I'm looking at the current soft-fp code in glibc rather than the older
version in libgcc (which will need updating from glibc once this issue is
resolved [*]) but don't see any relevant differences.
There are two places in op-common.h handling underflow, _FP_PACK_SEMIRAW
and _FP_PACK_CANONICAL.
Looking first at the latter (not the one involved in the present issue),
it seems OK on the basis of tininess-before-rounding.
(Tininess-after-rounding would need extra work. 32-bit ARM is
tininess-before-rounding, so I'll guess that AArch64 is as well.) That
is, it will raise the underflow flag for all inexact underflow cases,
including underflow to zero.
For the former, there are two issues with the underflow handling: it's
determined based on the exponent after rounding (which is not correct for
either "before rounding" or "after rounding" tininess detection - "after
rounding" tininess detection means after rounding to the normal precision
rather than after rounding to an actual representable value), and it has
the test you note for whether the mantissa, after shifting, is nonzero. I
think the correct thing to do would be to have a test "if (X##_e == 0 &&
!_FP_FRAC_ZEROP_##wc(X))" (which then has the existing exception-setting
logic) immediately after the _FP_ROUND call. That way, (a) the logic is
before-rounding tininess, which at least is consistent with
_FP_PACK_CANONICAL, (b) the INEXACT exception has been set by _FP_ROUND if
applicable, as required for the logic determining whether to raise the
underflow flag and (c) the low bits haven't yet been shifted out, so an
exact zero can be distinguished from an inexact one by the mantissa.
The code that now has "if (!_FP_EXP_NORMAL(fs, wc, X) &&
!_FP_FRAC_ZEROP_##wc(X))" might then better test "(X##_e ==
_FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X))" (i.e., the value is a NaN,
the only remaining case there).
After-rounding tininess detection would be more complicated, but as I note
above it's probably irrelevant to AArch64 (though relevant to complete
correctness for Alpha and MIPS, and for the use of soft-fp for __float128
in libgcc for x86 / x86_64 / IA64).
[*] See what I said in
<http://gcc.gnu.org/ml/gcc-patches/2012-10/msg02963.html> regarding asking
architecture maintainers to help provide FP_TRAPPING_EXCEPTIONS
definitions after such an update.
--
Joseph S. Myers
joseph@codesourcery.com