diff options
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/floatsidf.c | 16 | ||||
-rw-r--r-- | compiler-rt/lib/floatunsidf.c | 14 |
2 files changed, 8 insertions, 22 deletions
diff --git a/compiler-rt/lib/floatsidf.c b/compiler-rt/lib/floatsidf.c index ebd1a6b6037..a13ab8fbcfb 100644 --- a/compiler-rt/lib/floatsidf.c +++ b/compiler-rt/lib/floatsidf.c @@ -35,17 +35,11 @@ fp_t __floatsidf(int a) { const int exponent = (aWidth - 1) - __builtin_clz(a); rep_t result; - // Shift a into the significand field, rounding if it is a right-shift - if (exponent <= significandBits) { - const int shift = significandBits - exponent; - result = (rep_t)a << shift ^ implicitBit; - } else { - const int shift = exponent - significandBits; - result = (rep_t)a >> shift ^ implicitBit; - rep_t round = (rep_t)a << (typeWidth - shift); - if (round > signBit) result++; - if (round == signBit) result += result & 1; - } + // Shift a into the significand field and clear the implicit bit. Extra + // cast to unsigned int is necessary to get the correct behavior for + // the input INT_MIN. + const int shift = significandBits - exponent; + result = (rep_t)(unsigned int)a << shift ^ implicitBit; // Insert the exponent result += (rep_t)(exponent + exponentBias) << significandBits; diff --git a/compiler-rt/lib/floatunsidf.c b/compiler-rt/lib/floatunsidf.c index 1342c3c45c6..05242c18ab3 100644 --- a/compiler-rt/lib/floatunsidf.c +++ b/compiler-rt/lib/floatunsidf.c @@ -27,17 +27,9 @@ fp_t __floatunsidf(unsigned int a) { const int exponent = (aWidth - 1) - __builtin_clz(a); rep_t result; - // Shift a into the significand field, rounding if it is a right-shift - if (exponent <= significandBits) { - const int shift = significandBits - exponent; - result = (rep_t)a << shift ^ implicitBit; - } else { - const int shift = exponent - significandBits; - result = (rep_t)a >> shift ^ implicitBit; - rep_t round = (rep_t)a << (typeWidth - shift); - if (round > signBit) result++; - if (round == signBit) result += result & 1; - } + // Shift a into the significand field and clear the implicit bit. + const int shift = significandBits - exponent; + result = (rep_t)a << shift ^ implicitBit; // Insert the exponent result += (rep_t)(exponent + exponentBias) << significandBits; |