diff options
author | Eli Friedman <efriedma@quicinc.com> | 2019-03-19 21:55:58 +0000 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2019-03-19 21:55:58 +0000 |
commit | ef821f937fff68b0fe9cd71c116ad2cb387b8e5b (patch) | |
tree | 3255ee4cdc5a7208bd6a955507a4e2a034c782e9 /lib/builtins/divsf3.c | |
parent | 9342558f6da1f6c5644040e3cecfc42be66b181a (diff) | |
download | compiler-rt-ef821f937fff68b0fe9cd71c116ad2cb387b8e5b.tar.gz |
[builtins] Divide shouldn't underflow if rounded result would be normal.
We were treating certain edge cases that are actually normal as denormal
results, and flushing them to zero; we shouldn't do that. Not sure this
is the cleanest way to implement this edge case, but I wanted to avoid
adding any code on the common path.
Differential Revision: https://reviews.llvm.org/D59070
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@356529 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/divsf3.c')
-rw-r--r-- | lib/builtins/divsf3.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/builtins/divsf3.c b/lib/builtins/divsf3.c index 97cbcc196..944524749 100644 --- a/lib/builtins/divsf3.c +++ b/lib/builtins/divsf3.c @@ -147,6 +147,18 @@ __divsf3(fp_t a, fp_t b) { } else if (writtenExponent < 1) { + if (writtenExponent == 0) { + // Check whether the rounded result is normal. + const bool round = (residual << 1) > bSignificand; + // Clear the implicit bit. + rep_t absResult = quotient & significandMask; + // Round. + absResult += round; + if (absResult & ~significandMask) { + // The rounded result is normal; return it. + return fromRep(absResult | quotientSign); + } + } // Flush denormals to zero. In the future, it would be nice to add // code to round them correctly. return fromRep(quotientSign); |