llvm.org GIT mirror llvm / a77792d
[APInt] Combine variable declaration and initialization where possible in the tc functions. NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298898 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
1 changed file(s) with 39 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
24062406 void
24072407 APInt::tcSet(integerPart *dst, integerPart part, unsigned parts)
24082408 {
2409 unsigned int i;
2410
24112409 assert(parts > 0);
24122410
24132411 dst[0] = part;
2414 for (i = 1; i < parts; i++)
2412 for (unsigned i = 1; i < parts; i++)
24152413 dst[i] = 0;
24162414 }
24172415
24192417 void
24202418 APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned parts)
24212419 {
2422 unsigned int i;
2423
2424 for (i = 0; i < parts; i++)
2420 for (unsigned i = 0; i < parts; i++)
24252421 dst[i] = src[i];
24262422 }
24272423
24292425 bool
24302426 APInt::tcIsZero(const integerPart *src, unsigned parts)
24312427 {
2432 unsigned int i;
2433
2434 for (i = 0; i < parts; i++)
2428 for (unsigned i = 0; i < parts; i++)
24352429 if (src[i])
24362430 return false;
24372431
24662460 unsigned
24672461 APInt::tcLSB(const integerPart *parts, unsigned n)
24682462 {
2469 unsigned int i, lsb;
2470
2471 for (i = 0; i < n; i++) {
2472 if (parts[i] != 0) {
2473 lsb = partLSB(parts[i]);
2474
2475 return lsb + i * integerPartWidth;
2476 }
2463 for (unsigned i = 0; i < n; i++) {
2464 if (parts[i] != 0) {
2465 unsigned lsb = partLSB(parts[i]);
2466
2467 return lsb + i * integerPartWidth;
2468 }
24772469 }
24782470
24792471 return -1U;
24842476 unsigned
24852477 APInt::tcMSB(const integerPart *parts, unsigned n)
24862478 {
2487 unsigned int msb;
2488
24892479 do {
24902480 --n;
24912481
24922482 if (parts[n] != 0) {
2493 msb = partMSB(parts[n]);
2483 unsigned msb = partMSB(parts[n]);
24942484
24952485 return msb + n * integerPartWidth;
24962486 }
25072497 APInt::tcExtract(integerPart *dst, unsigned dstCount,const integerPart *src,
25082498 unsigned srcBits, unsigned srcLSB)
25092499 {
2510 unsigned int firstSrcPart, dstParts, shift, n;
2511
2512 dstParts = (srcBits + integerPartWidth - 1) / integerPartWidth;
2500 unsigned dstParts = (srcBits + integerPartWidth - 1) / integerPartWidth;
25132501 assert(dstParts <= dstCount);
25142502
2515 firstSrcPart = srcLSB / integerPartWidth;
2503 unsigned firstSrcPart = srcLSB / integerPartWidth;
25162504 tcAssign (dst, src + firstSrcPart, dstParts);
25172505
2518 shift = srcLSB % integerPartWidth;
2506 unsigned shift = srcLSB % integerPartWidth;
25192507 tcShiftRight (dst, dstParts, shift);
25202508
25212509 /* We now have (dstParts * integerPartWidth - shift) bits from SRC
25222510 in DST. If this is less that srcBits, append the rest, else
25232511 clear the high bits. */
2524 n = dstParts * integerPartWidth - shift;
2512 unsigned n = dstParts * integerPartWidth - shift;
25252513 if (n < srcBits) {
25262514 integerPart mask = lowBitMask (srcBits - n);
25272515 dst[dstParts - 1] |= ((src[firstSrcPart + dstParts] & mask)
25412529 APInt::tcAdd(integerPart *dst, const integerPart *rhs,
25422530 integerPart c, unsigned parts)
25432531 {
2544 unsigned int i;
2545
25462532 assert(c <= 1);
25472533
2548 for (i = 0; i < parts; i++) {
2534 for (unsigned i = 0; i < parts; i++) {
25492535 integerPart l;
25502536
25512537 l = dst[i];
25662552 APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
25672553 integerPart c, unsigned parts)
25682554 {
2569 unsigned int i;
2570
25712555 assert(c <= 1);
25722556
2573 for (i = 0; i < parts; i++) {
2557 for (unsigned i = 0; i < parts; i++) {
25742558 integerPart l;
25752559
25762560 l = dst[i];
26112595 unsigned srcParts, unsigned dstParts,
26122596 bool add)
26132597 {
2614 unsigned int i, n;
2615
26162598 /* Otherwise our writes of DST kill our later reads of SRC. */
26172599 assert(dst <= src || dst >= src + srcParts);
26182600 assert(dstParts <= srcParts + 1);
26192601
26202602 /* N loops; minimum of dstParts and srcParts. */
2621 n = dstParts < srcParts ? dstParts: srcParts;
2622
2603 unsigned n = dstParts < srcParts ? dstParts: srcParts;
2604
2605 unsigned i;
26232606 for (i = 0; i < n; i++) {
26242607 integerPart low, mid, high, srcPart;
26252608
27022685 APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
27032686 const integerPart *rhs, unsigned parts)
27042687 {
2705 unsigned int i;
2706 int overflow;
2707
27082688 assert(dst != lhs && dst != rhs);
27092689
2710 overflow = 0;
2690 int overflow = 0;
27112691 tcSet(dst, 0, parts);
27122692
2713 for (i = 0; i < parts; i++)
2693 for (unsigned i = 0; i < parts; i++)
27142694 overflow |= tcMultiplyPart(&dst[i], lhs, rhs[i], 0, parts,
27152695 parts - i, true);
27162696
27302710 if (lhsParts > rhsParts) {
27312711 return tcFullMultiply (dst, rhs, lhs, rhsParts, lhsParts);
27322712 } else {
2733 unsigned int n;
2734
27352713 assert(dst != lhs && dst != rhs);
27362714
27372715 tcSet(dst, 0, rhsParts);
27382716
2739 for (n = 0; n < lhsParts; n++)
2740 tcMultiplyPart(&dst[n], rhs, lhs[n], 0, rhsParts, rhsParts + 1, true);
2741
2742 n = lhsParts + rhsParts;
2717 for (unsigned i = 0; i < lhsParts; i++)
2718 tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1, true);
2719
2720 unsigned n = lhsParts + rhsParts;
27432721
27442722 return n - (dst[n - 1] == 0);
27452723 }
27602738 integerPart *remainder, integerPart *srhs,
27612739 unsigned parts)
27622740 {
2763 unsigned int n, shiftCount;
2764 integerPart mask;
2765
27662741 assert(lhs != remainder && lhs != srhs && remainder != srhs);
27672742
2768 shiftCount = tcMSB(rhs, parts) + 1;
2743 unsigned shiftCount = tcMSB(rhs, parts) + 1;
27692744 if (shiftCount == 0)
27702745 return true;
27712746
27722747 shiftCount = parts * integerPartWidth - shiftCount;
2773 n = shiftCount / integerPartWidth;
2774 mask = (integerPart) 1 << (shiftCount % integerPartWidth);
2748 unsigned n = shiftCount / integerPartWidth;
2749 integerPart mask = (integerPart) 1 << (shiftCount % integerPartWidth);
27752750
27762751 tcAssign(srhs, rhs, parts);
27772752 tcShiftLeft(srhs, parts, shiftCount);
28082783 APInt::tcShiftLeft(integerPart *dst, unsigned parts, unsigned count)
28092784 {
28102785 if (count) {
2811 unsigned int jump, shift;
2812
28132786 /* Jump is the inter-part jump; shift is is intra-part shift. */
2814 jump = count / integerPartWidth;
2815 shift = count % integerPartWidth;
2787 unsigned jump = count / integerPartWidth;
2788 unsigned shift = count % integerPartWidth;
28162789
28172790 while (parts > jump) {
28182791 integerPart part;
28422815 APInt::tcShiftRight(integerPart *dst, unsigned parts, unsigned count)
28432816 {
28442817 if (count) {
2845 unsigned int i, jump, shift;
2846
28472818 /* Jump is the inter-part jump; shift is is intra-part shift. */
2848 jump = count / integerPartWidth;
2849 shift = count % integerPartWidth;
2819 unsigned jump = count / integerPartWidth;
2820 unsigned shift = count % integerPartWidth;
28502821
28512822 /* Perform the shift. This leaves the most significant COUNT bits
28522823 of the result at zero. */
2853 for (i = 0; i < parts; i++) {
2824 for (unsigned i = 0; i < parts; i++) {
28542825 integerPart part;
28552826
28562827 if (i + jump >= parts) {
28732844 void
28742845 APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned parts)
28752846 {
2876 unsigned int i;
2877
2878 for (i = 0; i < parts; i++)
2847 for (unsigned i = 0; i < parts; i++)
28792848 dst[i] &= rhs[i];
28802849 }
28812850
28832852 void
28842853 APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned parts)
28852854 {
2886 unsigned int i;
2887
2888 for (i = 0; i < parts; i++)
2855 for (unsigned i = 0; i < parts; i++)
28892856 dst[i] |= rhs[i];
28902857 }
28912858
28932860 void
28942861 APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned parts)
28952862 {
2896 unsigned int i;
2897
2898 for (i = 0; i < parts; i++)
2863 for (unsigned i = 0; i < parts; i++)
28992864 dst[i] ^= rhs[i];
29002865 }
29012866
29032868 void
29042869 APInt::tcComplement(integerPart *dst, unsigned parts)
29052870 {
2906 unsigned int i;
2907
2908 for (i = 0; i < parts; i++)
2871 for (unsigned i = 0; i < parts; i++)
29092872 dst[i] = ~dst[i];
29102873 }
29112874
29322895 integerPart
29332896 APInt::tcIncrement(integerPart *dst, unsigned parts)
29342897 {
2935 unsigned int i;
2936
2898 unsigned i;
29372899 for (i = 0; i < parts; i++)
29382900 if (++dst[i] != 0)
29392901 break;
29612923 APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned parts,
29622924 unsigned bits)
29632925 {
2964 unsigned int i;
2965
2966 i = 0;
2926 unsigned i = 0;
29672927 while (bits > integerPartWidth) {
29682928 dst[i++] = ~(integerPart) 0;
29692929 bits -= integerPartWidth;