summaryrefslogtreecommitdiff
path: root/lib/builtins/fp_extend_impl.inc
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2015-05-12 18:33:42 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2015-05-12 18:33:42 +0000
commitd982553daf42bbedf3373c35d8db2d3fd323f9b0 (patch)
tree9faab0a3c213100c9b3c783c052601f78ae2f165 /lib/builtins/fp_extend_impl.inc
parent4901406799702394d9ca0b820852d850ed187f6e (diff)
[Builtins] Implement half-precision conversions.
Mostly uninteresting, except: - in __extendXfYf2, when checking if the number is normal, the old code relied on the unsignedness of src_rep_t, which is a problem when sizeof(src_rep_t) < sizeof(int): the result gets promoted to int, the signedness of which breaks the comparison. I added an explicit cast; it shouldn't affect other types. - we can't pass __fp16, so src_t and src_rep_t are the same. - the gnu_*_ieee symbols are simply duplicated definitions, as aliases are problematic on mach-o (where only weak aliases are supported; that's not what we want). Differential Revision: http://reviews.llvm.org/D9693 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@237161 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/fp_extend_impl.inc')
-rw-r--r--lib/builtins/fp_extend_impl.inc4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/builtins/fp_extend_impl.inc b/lib/builtins/fp_extend_impl.inc
index f6953ff4b..edcfa8d23 100644
--- a/lib/builtins/fp_extend_impl.inc
+++ b/lib/builtins/fp_extend_impl.inc
@@ -66,7 +66,9 @@ static inline dst_t __extendXfYf2__(src_t a) {
const src_rep_t sign = aRep & srcSignMask;
dst_rep_t absResult;
- if (aAbs - srcMinNormal < srcInfinity - srcMinNormal) {
+ // If sizeof(src_rep_t) < sizeof(int), the subtraction result is promoted
+ // to (signed) int. To avoid that, explicitly cast to src_rep_t.
+ if ((src_rep_t)(aAbs - srcMinNormal) < srcInfinity - srcMinNormal) {
// a is a normal number.
// Extend to the destination type by shifting the significand and
// exponent into the proper position and rebiasing the exponent.