llvm.org GIT mirror llvm / 48e8c80
Suppress -Wshorten-64-to-32 warnings for 64-bit hosts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50590 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 11 years ago
3 changed file(s) with 52 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
3030 typedef uint64_t integerPart;
3131
3232 const unsigned int host_char_bit = 8;
33 const unsigned int integerPartWidth = host_char_bit * sizeof(integerPart);
33 const unsigned int integerPartWidth = host_char_bit *
34 static_cast(sizeof(integerPart));
3435
3536 //===----------------------------------------------------------------------===//
3637 // APInt Class
7576
7677 /// This enum is used to hold the constants we needed for APInt.
7778 enum {
78 APINT_BITS_PER_WORD = sizeof(uint64_t) * 8, ///< Bits in a word
79 APINT_WORD_SIZE = sizeof(uint64_t) ///< Byte size of a word
79 /// Bits in a word
80 APINT_BITS_PER_WORD = static_cast(sizeof(uint64_t)) * 8,
81 /// Byte size of a word
82 APINT_WORD_SIZE = static_cast(sizeof(uint64_t))
8083 };
8184
8285 /// This constructor is used only internally for speed of construction of
162162 static int
163163 totalExponent(const char *p, int exponentAdjustment)
164164 {
165 integerPart unsignedExponent;
165 int unsignedExponent;
166166 bool negative, overflow;
167 long exponent;
167 int exponent;
168168
169169 /* Move past the exponent letter and sign to the digits. */
170170 p++;
279279 while (*p == '.');
280280
281281 /* Adjust the exponents for any decimal point. */
282 D->exponent += (dot - p) - (dot > p);
283 D->normalizedExponent = (D->exponent + (p - D->firstSigDigit)
284 - (dot > D->firstSigDigit && dot < p));
282 D->exponent += static_cast((dot - p) - (dot > p));
283 D->normalizedExponent = (D->exponent +
284 static_cast((p - D->firstSigDigit)
285 - (dot > D->firstSigDigit && dot < p)));
285286 }
286287
287288 D->lastSigDigit = p;
20012002 firstSignificantDigit = p;
20022003
20032004 for(;;) {
2004 integerPart hex_value;
2005 unsigned int hex_value;
20052006
20062007 if(*p == '.') {
20072008 assert(dot == 0);
20422043
20432044 /* Calculate the exponent adjustment implicit in the number of
20442045 significant digits. */
2045 expAdjustment = dot - firstSignificantDigit;
2046 expAdjustment = static_cast(dot - firstSignificantDigit);
20462047 if(expAdjustment < 0)
20472048 expAdjustment++;
20482049 expAdjustment = expAdjustment * 4 - 1;
20962097 decSig.exponent += exp;
20972098
20982099 lostFraction calcLostFraction;
2099 integerPart HUerr, HUdistance, powHUerr;
2100 integerPart HUerr, HUdistance;
2101 unsigned int powHUerr;
21002102
21012103 if (exp >= 0) {
21022104 /* multiplySignificand leaves the precision-th bit set to 1. */
21122114 excessPrecision = calcSemantics.precision;
21132115 }
21142116 /* Extra half-ulp lost in reciprocal of exponent. */
2115 powHUerr = (powStatus == opOK && calcLostFraction == lfExactlyZero) ? 0: 2;
2117 powHUerr = (powStatus == opOK && calcLostFraction == lfExactlyZero) ? 0:2;
21162118 }
21172119
21182120 /* Both multiplySignificand and divideSignificand return the
21892191 N-digit decimal integer is N * 196 / 59. Allocate enough space
21902192 to hold the full significand, and an extra part required by
21912193 tcMultiplyPart. */
2192 partCount = (D.lastSigDigit - D.firstSigDigit) + 1;
2194 partCount = static_cast(D.lastSigDigit - D.firstSigDigit) + 1;
21932195 partCount = partCountForBits(1 + 196 * partCount / 59);
21942196 decSignificand = new integerPart[partCount + 1];
21952197 partCount = 0;
23192321
23202322 *dst = 0;
23212323
2322 return dst - p;
2324 return static_cast(dst - p);
23232325 }
23242326
23252327 /* Does the hard work of outputting the correctly rounded hexadecimal
24422444 uint32_t hash = sign<<11 | semantics->precision | exponent<<12;
24432445 const integerPart* p = significandParts();
24442446 for (int i=partCount(); i>0; i--, p++)
2445 hash ^= ((uint32_t)*p) ^ (*p)>>32;
2447 hash ^= ((uint32_t)*p) ^ (uint32_t)((*p)>>32);
24462448 return hash;
24472449 }
24482450 }
24822484 }
24832485
24842486 uint64_t words[2];
2485 words[0] = (((uint64_t)sign & 1) << 63) |
2486 ((myexponent & 0x7fff) << 48) |
2487 words[0] = ((uint64_t)(sign & 1) << 63) |
2488 ((myexponent & 0x7fffLL) << 48) |
24872489 ((mysignificand >>16) & 0xffffffffffffLL);
24882490 words[1] = mysignificand & 0xffff;
24892491 return APInt(80, 2, words);
25252527 }
25262528
25272529 uint64_t words[2];
2528 words[0] = (((uint64_t)sign & 1) << 63) |
2530 words[0] = ((uint64_t)(sign & 1) << 63) |
25292531 ((myexponent & 0x7ff) << 52) |
25302532 (mysignificand & 0xfffffffffffffLL);
2531 words[1] = (((uint64_t)sign2 & 1) << 63) |
2533 words[1] = ((uint64_t)(sign2 & 1) << 63) |
25322534 ((myexponent2 & 0x7ff) << 52) |
25332535 (mysignificand2 & 0xfffffffffffffLL);
25342536 return APInt(128, 2, words);
25592561 mysignificand = *significandParts();
25602562 }
25612563
2562 return APInt(64, (((((uint64_t)sign & 1) << 63) |
2564 return APInt(64, ((((uint64_t)(sign & 1) << 63) |
25632565 ((myexponent & 0x7ff) << 52) |
25642566 (mysignificand & 0xfffffffffffffLL))));
25652567 }
25742576
25752577 if (category==fcNormal) {
25762578 myexponent = exponent+127; //bias
2577 mysignificand = *significandParts();
2579 mysignificand = (uint32_t)*significandParts();
25782580 if (myexponent == 1 && !(mysignificand & 0x800000))
25792581 myexponent = 0; // denormal
25802582 } else if (category==fcZero) {
25862588 } else {
25872589 assert(category == fcNaN && "Unknown category!");
25882590 myexponent = 0xff;
2589 mysignificand = *significandParts();
2591 mysignificand = (uint32_t)*significandParts();
25902592 }
25912593
25922594 return APInt(32, (((sign&1) << 31) | ((myexponent&0xff) << 23) |
26482650 initialize(&APFloat::x87DoubleExtended);
26492651 assert(partCount()==2);
26502652
2651 sign = i1>>63;
2653 sign = static_cast(i1>>63);
26522654 if (myexponent==0 && mysignificand==0) {
26532655 // exponent, significand meaningless
26542656 category = fcZero;
26842686 initialize(&APFloat::PPCDoubleDouble);
26852687 assert(partCount()==2);
26862688
2687 sign = i1>>63;
2688 sign2 = i2>>63;
2689 sign = static_cast(i1>>63);
2690 sign2 = static_cast(i2>>63);
26892691 if (myexponent==0 && mysignificand==0) {
26902692 // exponent, significand meaningless
26912693 // exponent2 and significand2 are required to be 0; we don't check
27312733 initialize(&APFloat::IEEEdouble);
27322734 assert(partCount()==1);
27332735
2734 sign = i>>63;
2736 sign = static_cast(i>>63);
27352737 if (myexponent==0 && mysignificand==0) {
27362738 // exponent, significand meaningless
27372739 category = fcZero;
9898 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
9999 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
100100 assert(!Val.empty() && "String empty?");
101 fromString(numbits, Val.c_str(), Val.size(), radix);
101 fromString(numbits, Val.c_str(), (uint32_t)Val.size(), radix);
102102 }
103103
104104 APInt::APInt(const APInt& that)
904904
905905 // Otherwise, we have to shift the mantissa bits up to the right location
906906 APInt Tmp(width, mantissa);
907 Tmp = Tmp.shl(exp - 52);
907 Tmp = Tmp.shl((uint32_t)exp - 52);
908908 return isNeg ? -Tmp : Tmp;
909909 }
910910
10851085 /// Arithmetic right-shift this APInt by shiftAmt.
10861086 /// @brief Arithmetic right-shift function.
10871087 APInt APInt::ashr(const APInt &shiftAmt) const {
1088 return ashr(shiftAmt.getLimitedValue(BitWidth));
1088 return ashr((uint32_t)shiftAmt.getLimitedValue(BitWidth));
10891089 }
10901090
10911091 /// Arithmetic right-shift this APInt by shiftAmt.
11741174 /// Logical right-shift this APInt by shiftAmt.
11751175 /// @brief Logical right-shift function.
11761176 APInt APInt::lshr(const APInt &shiftAmt) const {
1177 return lshr(shiftAmt.getLimitedValue(BitWidth));
1177 return lshr((uint32_t)shiftAmt.getLimitedValue(BitWidth));
11781178 }
11791179
11801180 /// Logical right-shift this APInt by shiftAmt.
12431243 /// @brief Left-shift function.
12441244 APInt APInt::shl(const APInt &shiftAmt) const {
12451245 // It's undefined behavior in C to shift by BitWidth or greater, but
1246 return shl(shiftAmt.getLimitedValue(BitWidth));
1246 return shl((uint32_t)shiftAmt.getLimitedValue(BitWidth));
12471247 }
12481248
12491249 /// Left-shift this APInt by shiftAmt.
13061306 }
13071307
13081308 APInt APInt::rotl(const APInt &rotateAmt) const {
1309 return rotl(rotateAmt.getLimitedValue(BitWidth));
1309 return rotl((uint32_t)rotateAmt.getLimitedValue(BitWidth));
13101310 }
13111311
13121312 APInt APInt::rotl(uint32_t rotateAmt) const {
13211321 }
13221322
13231323 APInt APInt::rotr(const APInt &rotateAmt) const {
1324 return rotr(rotateAmt.getLimitedValue(BitWidth));
1324 return rotr((uint32_t)rotateAmt.getLimitedValue(BitWidth));
13251325 }
13261326
13271327 APInt APInt::rotr(uint32_t rotateAmt) const {
15161516
15171517 uint64_t result = u_tmp - subtrahend;
15181518 uint32_t k = j + i;
1519 u[k++] = result & (b-1); // subtract low word
1520 u[k++] = result >> 32; // subtract high word
1519 u[k++] = (uint32_t)(result & (b-1)); // subtract low word
1520 u[k++] = (uint32_t)(result >> 32); // subtract high word
15211521 while (borrow && k <= m+n) { // deal with borrow to the left
15221522 borrow = u[k] == 0;
15231523 u[k]--;
15481548
15491549 // D5. [Test remainder.] Set q[j] = qp. If the result of step D4 was
15501550 // negative, go to step D6; otherwise go on to step D7.
1551 q[j] = qp;
1551 q[j] = (uint32_t)qp;
15521552 if (isNeg) {
15531553 // D6. [Add back]. The probability that this step is necessary is very
15541554 // small, on the order of only 2/b. Make sure that test data accounts for
16441644 memset(U, 0, (m+n+1)*sizeof(uint32_t));
16451645 for (unsigned i = 0; i < lhsWords; ++i) {
16461646 uint64_t tmp = (LHS.getNumWords() == 1 ? LHS.VAL : LHS.pVal[i]);
1647 U[i * 2] = tmp & mask;
1648 U[i * 2 + 1] = tmp >> (sizeof(uint32_t)*8);
1647 U[i * 2] = (uint32_t)(tmp & mask);
1648 U[i * 2 + 1] = (uint32_t)(tmp >> (sizeof(uint32_t)*8));
16491649 }
16501650 U[m+n] = 0; // this extra word is for "spill" in the Knuth algorithm.
16511651
16531653 memset(V, 0, (n)*sizeof(uint32_t));
16541654 for (unsigned i = 0; i < rhsWords; ++i) {
16551655 uint64_t tmp = (RHS.getNumWords() == 1 ? RHS.VAL : RHS.pVal[i]);
1656 V[i * 2] = tmp & mask;
1657 V[i * 2 + 1] = tmp >> (sizeof(uint32_t)*8);
1656 V[i * 2] = (uint32_t)(tmp & mask);
1657 V[i * 2 + 1] = (uint32_t)(tmp >> (sizeof(uint32_t)*8));
16581658 }
16591659
16601660 // initialize the quotient and remainder
16901690 remainder = 0;
16911691 } else if (partial_dividend < divisor) {
16921692 Q[i] = 0;
1693 remainder = partial_dividend;
1693 remainder = (uint32_t)partial_dividend;
16941694 } else if (partial_dividend == divisor) {
16951695 Q[i] = 1;
16961696 remainder = 0;
16971697 } else {
1698 Q[i] = partial_dividend / divisor;
1699 remainder = partial_dividend - (Q[i] * divisor);
1698 Q[i] = (uint32_t)(partial_dividend / divisor);
1699 remainder = (uint32_t)(partial_dividend - (Q[i] * divisor));
17001700 }
17011701 }
17021702 if (R)
19901990 memset(buf, 0, 65);
19911991 uint64_t v = VAL;
19921992 while (bits_used) {
1993 uint32_t bit = v & 1;
1993 uint32_t bit = (uint32_t)v & 1;
19941994 bits_used--;
19951995 buf[bits_used] = digits[bit][0];
19961996 v >>=1;
20252025 uint64_t mask = radix - 1;
20262026 APInt zero(tmp.getBitWidth(), 0);
20272027 while (tmp.ne(zero)) {
2028 unsigned digit = (tmp.isSingleWord() ? tmp.VAL : tmp.pVal[0]) & mask;
2028 unsigned digit =
2029 (unsigned)((tmp.isSingleWord() ? tmp.VAL : tmp.pVal[0]) & mask);
20292030 result.insert(insert_at, digits[digit]);
20302031 tmp = tmp.lshr(shift);
20312032 }
20532054 APInt tmp2(tmp.getBitWidth(), 0);
20542055 divide(tmp, tmp.getNumWords(), divisor, divisor.getNumWords(), &tmp2,
20552056 &APdigit);
2056 uint32_t digit = APdigit.getZExtValue();
2057 uint32_t digit = (uint32_t)APdigit.getZExtValue();
20572058 assert(digit < radix && "divide failed");
20582059 result.insert(insert_at,digits[digit]);
20592060 tmp = tmp2;