Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 4d055d5

Browse files
committed
Adds an extra explicit cast to fix Bug 7931 and removes codepaths that were never used
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@111269 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 86d0ba4 commit 4d055d5

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

lib/floatsidf.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,11 @@ fp_t __floatsidf(int a) {
3535
const int exponent = (aWidth - 1) - __builtin_clz(a);
3636
rep_t result;
3737

38-
// Shift a into the significand field, rounding if it is a right-shift
39-
if (exponent <= significandBits) {
40-
const int shift = significandBits - exponent;
41-
result = (rep_t)a << shift ^ implicitBit;
42-
} else {
43-
const int shift = exponent - significandBits;
44-
result = (rep_t)a >> shift ^ implicitBit;
45-
rep_t round = (rep_t)a << (typeWidth - shift);
46-
if (round > signBit) result++;
47-
if (round == signBit) result += result & 1;
48-
}
38+
// Shift a into the significand field and clear the implicit bit. Extra
39+
// cast to unsigned int is necessary to get the correct behavior for
40+
// the input INT_MIN.
41+
const int shift = significandBits - exponent;
42+
result = (rep_t)(unsigned int)a << shift ^ implicitBit;
4943

5044
// Insert the exponent
5145
result += (rep_t)(exponent + exponentBias) << significandBits;

lib/floatunsidf.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,9 @@ fp_t __floatunsidf(unsigned int a) {
2727
const int exponent = (aWidth - 1) - __builtin_clz(a);
2828
rep_t result;
2929

30-
// Shift a into the significand field, rounding if it is a right-shift
31-
if (exponent <= significandBits) {
32-
const int shift = significandBits - exponent;
33-
result = (rep_t)a << shift ^ implicitBit;
34-
} else {
35-
const int shift = exponent - significandBits;
36-
result = (rep_t)a >> shift ^ implicitBit;
37-
rep_t round = (rep_t)a << (typeWidth - shift);
38-
if (round > signBit) result++;
39-
if (round == signBit) result += result & 1;
40-
}
30+
// Shift a into the significand field and clear the implicit bit.
31+
const int shift = significandBits - exponent;
32+
result = (rep_t)a << shift ^ implicitBit;
4133

4234
// Insert the exponent
4335
result += (rep_t)(exponent + exponentBias) << significandBits;

0 commit comments

Comments
 (0)