From: Marcus Shawcroft <marcus.shawcroft@linaro.org>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: libc-ports@sourceware.org
Subject: Re: [PATCH 1/2] AArch64 glibc port
Date: Wed, 07 Nov 2012 12:35:00 -0000 [thread overview]
Message-ID: <CABXK9ndfSEpyP40xo8MPnv9zA7hp=Tp+dMg6QcqqcKf3TzYn1w@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1211051746530.21662@digraph.polyomino.org.uk>
[-- Attachment #1: Type: text/plain, Size: 1763 bytes --]
> 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).
>
This resolves the majority of the outstanding issues. The solution
above is not quite sufficient because given a true 0, FP_ROUND may set
working bits resulting in the underflow test failing. I resolved this
by adjusting FP_ROUND such that it does not attempt to round a true
zero, is that sane? I've attached my current patch. The patch is
against glibc/soft-fp but I've actually be using it applied to
libgcc/soft-fp. What is the recommend way to test patches to soft-fp
in glibc?
/Marcus
[-- Attachment #2: glibc-v3-underflow-patch.txt --]
[-- Type: text/plain, Size: 2575 bytes --]
diff --git a/soft-fp/op-common.h b/soft-fp/op-common.h
index db75af5..12fb16e 100644
--- a/soft-fp/op-common.h
+++ b/soft-fp/op-common.h
@@ -134,6 +134,12 @@ do { \
#define _FP_PACK_SEMIRAW(fs, wc, X) \
do { \
_FP_ROUND(wc, X); \
+ if (X##_e == 0 && !_FP_FRAC_ZEROP_##wc(X)) \
+ { \
+ if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) \
+ || (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)) \
+ FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
+ } \
if (_FP_FRAC_HIGH_##fs(X) \
& (_FP_OVERFLOW_##fs >> 1)) \
{ \
@@ -143,24 +149,15 @@ do { \
_FP_OVERFLOW_SEMIRAW(fs, wc, X); \
} \
_FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
- if (!_FP_EXP_NORMAL(fs, wc, X) && !_FP_FRAC_ZEROP_##wc(X)) \
+ if (X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
{ \
- if (X##_e == 0) \
+ if (!_FP_KEEPNANFRACP) \
{ \
- if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) \
- || (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)) \
- FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
+ _FP_FRAC_SET_##wc(X, _FP_NANFRAC_##fs); \
+ X##_s = _FP_NANSIGN_##fs; \
} \
else \
- { \
- if (!_FP_KEEPNANFRACP) \
- { \
- _FP_FRAC_SET_##wc(X, _FP_NANFRAC_##fs); \
- X##_s = _FP_NANSIGN_##fs; \
- } \
- else \
- _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_QNANBIT_##fs; \
- } \
+ _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_QNANBIT_##fs; \
} \
} while (0)
diff --git a/soft-fp/soft-fp.h b/soft-fp/soft-fp.h
index 750c7fe..62bd27a 100644
--- a/soft-fp/soft-fp.h
+++ b/soft-fp/soft-fp.h
@@ -159,21 +159,22 @@ do { \
do { \
if (_FP_FRAC_LOW_##wc(X) & 7) \
FP_SET_EXCEPTION(FP_EX_INEXACT); \
- switch (FP_ROUNDMODE) \
- { \
- case FP_RND_NEAREST: \
- _FP_ROUND_NEAREST(wc,X); \
- break; \
- case FP_RND_ZERO: \
- _FP_ROUND_ZERO(wc,X); \
- break; \
- case FP_RND_PINF: \
- _FP_ROUND_PINF(wc,X); \
- break; \
- case FP_RND_MINF: \
- _FP_ROUND_MINF(wc,X); \
- break; \
- } \
+ if (_FP_FRAC_LOW_##wc(X)) \
+ switch (FP_ROUNDMODE) \
+ { \
+ case FP_RND_NEAREST: \
+ _FP_ROUND_NEAREST(wc,X); \
+ break; \
+ case FP_RND_ZERO: \
+ _FP_ROUND_ZERO(wc,X); \
+ break; \
+ case FP_RND_PINF: \
+ _FP_ROUND_PINF(wc,X); \
+ break; \
+ case FP_RND_MINF: \
+ _FP_ROUND_MINF(wc,X); \
+ break; \
+ } \
} while (0)
#define FP_CLS_NORMAL 0
next prev parent reply other threads:[~2012-11-07 12:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CABXK9nfac4O=A0SMe_3FvTnqjpTDF0bDkd6inTBeSbK6DUtWOw@mail.gmail.com>
2012-10-03 22:11 ` Joseph S. Myers
2012-11-02 17:27 ` Marcus Shawcroft
2012-11-03 18:17 ` Joseph S. Myers
2012-11-05 17:02 ` Marcus Shawcroft
2012-11-05 18:06 ` Joseph S. Myers
2012-11-07 12:35 ` Marcus Shawcroft [this message]
2012-11-07 13:09 ` Joseph S. Myers
[not found] ` <CABXK9nfUuGCf2d8L4+ZnAMS+jdm_uMDcgTL619nbdHdpNEw_FQ@mail.gmail.com>
2012-11-07 15:16 ` Joseph S. Myers
2012-11-08 8:09 ` Fwd: " Marcus Shawcroft
2012-11-08 18:14 ` Joseph S. Myers
2012-11-08 21:26 ` Richard Henderson
2012-11-08 23:13 ` Joseph S. Myers
2012-11-09 18:07 ` Marcus Shawcroft
2012-11-09 19:35 ` Andreas Jaeger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABXK9ndfSEpyP40xo8MPnv9zA7hp=Tp+dMg6QcqqcKf3TzYn1w@mail.gmail.com' \
--to=marcus.shawcroft@linaro.org \
--cc=joseph@codesourcery.com \
--cc=libc-ports@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).