diff --git a/compiler-rt/lib/builtins/floatsidf.c b/compiler-rt/lib/builtins/floatsidf.c --- a/compiler-rt/lib/builtins/floatsidf.c +++ b/compiler-rt/lib/builtins/floatsidf.c @@ -27,20 +27,21 @@ // All other cases begin by extracting the sign and absolute value of a rep_t sign = 0; + su_int aAbs = (su_int)a; if (a < 0) { sign = signBit; - a = -a; + aAbs = -(su_int)a; } // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - clzsi(a); + const int exponent = (aWidth - 1) - clzsi(aAbs); rep_t result; // 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)(su_int)a << shift ^ implicitBit; + result = (rep_t)aAbs << shift ^ implicitBit; // Insert the exponent result += (rep_t)(exponent + exponentBias) << significandBits; diff --git a/compiler-rt/lib/builtins/floatsisf.c b/compiler-rt/lib/builtins/floatsisf.c --- a/compiler-rt/lib/builtins/floatsisf.c +++ b/compiler-rt/lib/builtins/floatsisf.c @@ -27,23 +27,24 @@ // All other cases begin by extracting the sign and absolute value of a rep_t sign = 0; + su_int aAbs = (su_int)a; if (a < 0) { sign = signBit; - a = -a; + aAbs = -(su_int)a; } // Exponent of (fp_t)a is the width of abs(a). - const int exponent = (aWidth - 1) - clzsi(a); + const int exponent = (aWidth - 1) - clzsi(aAbs); 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; + result = (rep_t)aAbs << shift ^ implicitBit; } else { const int shift = exponent - significandBits; - result = (rep_t)a >> shift ^ implicitBit; - rep_t round = (rep_t)a << (typeWidth - shift); + result = (rep_t)aAbs >> shift ^ implicitBit; + rep_t round = (rep_t)aAbs << (typeWidth - shift); if (round > signBit) result++; if (round == signBit) diff --git a/compiler-rt/lib/builtins/floatsitf.c b/compiler-rt/lib/builtins/floatsitf.c --- a/compiler-rt/lib/builtins/floatsitf.c +++ b/compiler-rt/lib/builtins/floatsitf.c @@ -29,7 +29,7 @@ su_int aAbs = (su_int)a; if (a < 0) { sign = signBit; - aAbs = ~(su_int)a + (su_int)1U; + aAbs = -(su_int)a; } // Exponent of (fp_t)a is the width of abs(a).