Index: compiler-rt/lib/builtins/ppc/fixunstfti.c =================================================================== --- compiler-rt/lib/builtins/ppc/fixunstfti.c +++ compiler-rt/lib/builtins/ppc/fixunstfti.c @@ -15,6 +15,19 @@ #include "../int_math.h" #define BIAS 1023 +/* Macro to scale either the high or low doubles (CASE 2) + * when the high or low doubles do not fit within an int64. */ +#define SCALE_DOUBLE(exponent, result, doubleType) \ + shift = exponent - 54; \ + ldStructure.doubleBitPatterns[doubleType] &= 0x800FFFFFFFFFFFFFll; \ + ldStructure.doubleBitPatterns[doubleType] |= 0x4350000000000000ll; \ + if (doubleType == 0) { \ + result = (unsigned long long)ldStructure.doublePairs[doubleType]; \ + } else { \ + result = (long long)ldStructure.doublePairs[doubleType]; \ + } \ + result = result << shift; + __uint128_t __fixunstfti(long double input) { /* If we are trying to convert a NaN, return the NaN bit pattern. */ @@ -65,11 +78,7 @@ hiResult = (unsigned long long)ldStructure.doublePairs[0]; } else if (hiExponent < 128) { /* CASE 2 - High double does not fit in int64, scale it. */ - shift = hiExponent - 54; - ldStructure.doubleBitPatterns[0] &= 0x800FFFFFFFFFFFFFll; - ldStructure.doubleBitPatterns[0] |= 0x4350000000000000ll; - hiResult = (unsigned long long)ldStructure.doublePairs[0]; - hiResult = hiResult << shift; + SCALE_DOUBLE(hiExponent, hiResult, 0); } else { /* Detect cases for overflow. When the exponent of the high * double is greater than 128 bits and when the long double @@ -89,11 +98,7 @@ loResult = (long long)ldStructure.doublePairs[1]; } else { /* CASE 2 - Low double does not fit in int64, scale it. */ - shift = loExponent - 54; - ldStructure.doubleBitPatterns[1] &= 0x800FFFFFFFFFFFFFll; - ldStructure.doubleBitPatterns[1] |= 0x4350000000000000ll; - loResult = (long long)ldStructure.doublePairs[1]; - loResult = loResult << shift; + SCALE_DOUBLE(loExponent, loResult, 1); } /* Add the high and low doublewords together to form a 128 bit integer. */