diff options
author | Joerg Sonnenberger <joerg@bec.de> | 2015-03-11 21:13:56 +0000 |
---|---|---|
committer | Joerg Sonnenberger <joerg@bec.de> | 2015-03-11 21:13:56 +0000 |
commit | 6c015134aead1e20986ebbda8d75e9125e0eeed9 (patch) | |
tree | 087bc7b4667f73e29e18876318fc024c41091346 /lib/builtins/fixunsxfsi.c | |
parent | 4779d3501762b1c89b54dd852787e410d1dc3e5e (diff) |
Refactor float to integer conversion to share the same code.
80bit Intel/PPC long double is excluded due to lacking support
for the abstraction. Consistently provide saturation logic.
Extend to long double on 128bit IEEE extended platforms.
Initial patch with test cases from GuanHong Liu.
Reviewed by Steve Canon.
Differential Revision: http://reviews.llvm.org/D2804
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@231965 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/fixunsxfsi.c')
-rw-r--r-- | lib/builtins/fixunsxfsi.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/builtins/fixunsxfsi.c b/lib/builtins/fixunsxfsi.c index df0a18e2c..c3c70f743 100644 --- a/lib/builtins/fixunsxfsi.c +++ b/lib/builtins/fixunsxfsi.c @@ -23,7 +23,6 @@ /* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes * su_int is a 32 bit integral type * value in long double is representable in su_int or is negative - * (no range checking performed) */ /* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | @@ -38,6 +37,8 @@ __fixunsxfsi(long double a) int e = (fb.u.high.s.low & 0x00007FFF) - 16383; if (e < 0 || (fb.u.high.s.low & 0x00008000)) return 0; + if ((unsigned)e > sizeof(su_int) * CHAR_BIT) + return ~(su_int)0; return fb.u.low.s.high >> (31 - e); } |