llvm.org GIT mirror llvm / cc9aca6
[APInt] Reformat tc functions to put opening curly braces on the end of the previous line. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298900 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
1 changed file(s) with 45 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
23612361
23622362 /* Returns the integer part with the least significant BITS set.
23632363 BITS cannot be zero. */
2364 static inline integerPart
2365 lowBitMask(unsigned bits)
2366 {
2364 static inline integerPart lowBitMask(unsigned bits) {
23672365 assert(bits != 0 && bits <= integerPartWidth);
23682366
23692367 return ~(integerPart) 0 >> (integerPartWidth - bits);
23702368 }
23712369
23722370 /* Returns the value of the lower half of PART. */
2373 static inline integerPart
2374 lowHalf(integerPart part)
2375 {
2371 static inline integerPart lowHalf(integerPart part) {
23762372 return part & lowBitMask(integerPartWidth / 2);
23772373 }
23782374
23792375 /* Returns the value of the upper half of PART. */
2380 static inline integerPart
2381 highHalf(integerPart part)
2382 {
2376 static inline integerPart highHalf(integerPart part) {
23832377 return part >> (integerPartWidth / 2);
23842378 }
23852379
23862380 /* Returns the bit number of the most significant set bit of a part.
23872381 If the input number has no bits set -1U is returned. */
2388 static unsigned
2389 partMSB(integerPart value)
2390 {
2382 static unsigned partMSB(integerPart value) {
23912383 return findLastSet(value, ZB_Max);
23922384 }
23932385
23942386 /* Returns the bit number of the least significant set bit of a
23952387 part. If the input number has no bits set -1U is returned. */
2396 static unsigned
2397 partLSB(integerPart value)
2398 {
2388 static unsigned partLSB(integerPart value) {
23992389 return findFirstSet(value, ZB_Max);
24002390 }
24012391
24022392 /* Sets the least significant part of a bignum to the input value, and
24032393 zeroes out higher parts. */
2404 void
2405 APInt::tcSet(integerPart *dst, integerPart part, unsigned parts)
2406 {
2394 void APInt::tcSet(integerPart *dst, integerPart part, unsigned parts) {
24072395 assert(parts > 0);
24082396
24092397 dst[0] = part;
24122400 }
24132401
24142402 /* Assign one bignum to another. */
2415 void
2416 APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned parts)
2417 {
2403 void APInt::tcAssign(integerPart *dst, const integerPart *src, unsigned parts) {
24182404 for (unsigned i = 0; i < parts; i++)
24192405 dst[i] = src[i];
24202406 }
24212407
24222408 /* Returns true if a bignum is zero, false otherwise. */
2423 bool
2424 APInt::tcIsZero(const integerPart *src, unsigned parts)
2425 {
2409 bool APInt::tcIsZero(const integerPart *src, unsigned parts) {
24262410 for (unsigned i = 0; i < parts; i++)
24272411 if (src[i])
24282412 return false;
24312415 }
24322416
24332417 /* Extract the given bit of a bignum; returns 0 or 1. */
2434 int
2435 APInt::tcExtractBit(const integerPart *parts, unsigned bit)
2436 {
2418 int APInt::tcExtractBit(const integerPart *parts, unsigned bit) {
24372419 return (parts[bit / integerPartWidth] &
24382420 ((integerPart) 1 << bit % integerPartWidth)) != 0;
24392421 }
24402422
24412423 /* Set the given bit of a bignum. */
2442 void
2443 APInt::tcSetBit(integerPart *parts, unsigned bit)
2444 {
2424 void APInt::tcSetBit(integerPart *parts, unsigned bit) {
24452425 parts[bit / integerPartWidth] |= (integerPart) 1 << (bit % integerPartWidth);
24462426 }
24472427
24482428 /* Clears the given bit of a bignum. */
2449 void
2450 APInt::tcClearBit(integerPart *parts, unsigned bit)
2451 {
2429 void APInt::tcClearBit(integerPart *parts, unsigned bit) {
24522430 parts[bit / integerPartWidth] &=
24532431 ~((integerPart) 1 << (bit % integerPartWidth));
24542432 }
24552433
24562434 /* Returns the bit number of the least significant set bit of a
24572435 number. If the input number has no bits set -1U is returned. */
2458 unsigned
2459 APInt::tcLSB(const integerPart *parts, unsigned n)
2460 {
2436 unsigned APInt::tcLSB(const integerPart *parts, unsigned n) {
24612437 for (unsigned i = 0; i < n; i++) {
24622438 if (parts[i] != 0) {
24632439 unsigned lsb = partLSB(parts[i]);
24712447
24722448 /* Returns the bit number of the most significant set bit of a number.
24732449 If the input number has no bits set -1U is returned. */
2474 unsigned
2475 APInt::tcMSB(const integerPart *parts, unsigned n)
2476 {
2450 unsigned APInt::tcMSB(const integerPart *parts, unsigned n) {
24772451 do {
24782452 --n;
24792453
24922466 the least significant bit of DST. All high bits above srcBITS in
24932467 DST are zero-filled. */
24942468 void
2495 APInt::tcExtract(integerPart *dst, unsigned dstCount,const integerPart *src,
2496 unsigned srcBits, unsigned srcLSB)
2497 {
2469 APInt::tcExtract(integerPart *dst, unsigned dstCount, const integerPart *src,
2470 unsigned srcBits, unsigned srcLSB) {
24982471 unsigned dstParts = (srcBits + integerPartWidth - 1) / integerPartWidth;
24992472 assert(dstParts <= dstCount);
25002473
25232496 }
25242497
25252498 /* DST += RHS + C where C is zero or one. Returns the carry flag. */
2526 integerPart
2527 APInt::tcAdd(integerPart *dst, const integerPart *rhs,
2528 integerPart c, unsigned parts)
2529 {
2499 integerPart APInt::tcAdd(integerPart *dst, const integerPart *rhs,
2500 integerPart c, unsigned parts) {
25302501 assert(c <= 1);
25312502
25322503 for (unsigned i = 0; i < parts; i++) {
25462517 }
25472518
25482519 /* DST -= RHS + C where C is zero or one. Returns the carry flag. */
2549 integerPart
2550 APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
2551 integerPart c, unsigned parts)
2520 integerPart APInt::tcSubtract(integerPart *dst, const integerPart *rhs,
2521 integerPart c, unsigned parts)
25522522 {
25532523 assert(c <= 1);
25542524
25692539 }
25702540
25712541 /* Negate a bignum in-place. */
2572 void
2573 APInt::tcNegate(integerPart *dst, unsigned parts)
2574 {
2542 void APInt::tcNegate(integerPart *dst, unsigned parts) {
25752543 tcComplement(dst, parts);
25762544 tcIncrement(dst, parts);
25772545 }
25872555 DSTPARTS parts of the result, and if all of the omitted higher
25882556 parts were zero return zero, otherwise overflow occurred and
25892557 return one. */
2590 int
2591 APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
2592 integerPart multiplier, integerPart carry,
2593 unsigned srcParts, unsigned dstParts,
2594 bool add)
2595 {
2558 int APInt::tcMultiplyPart(integerPart *dst, const integerPart *src,
2559 integerPart multiplier, integerPart carry,
2560 unsigned srcParts, unsigned dstParts,
2561 bool add) {
25962562 /* Otherwise our writes of DST kill our later reads of SRC. */
25972563 assert(dst <= src || dst >= src + srcParts);
25982564 assert(dstParts <= srcParts + 1);
26142580
26152581 srcPart = src[i];
26162582
2617 if (multiplier == 0 || srcPart == 0) {
2583 if (multiplier == 0 || srcPart == 0) {
26182584 low = carry;
26192585 high = 0;
26202586 } else {
26792645 is filled with the least significant parts of the result. Returns
26802646 one if overflow occurred, otherwise zero. DST must be disjoint
26812647 from both operands. */
2682 int
2683 APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
2684 const integerPart *rhs, unsigned parts)
2685 {
2648 int APInt::tcMultiply(integerPart *dst, const integerPart *lhs,
2649 const integerPart *rhs, unsigned parts) {
26862650 assert(dst != lhs && dst != rhs);
26872651
26882652 int overflow = 0;
26992663 operands. No overflow occurs. DST must be disjoint from both
27002664 operands. Returns the number of parts required to hold the
27012665 result. */
2702 unsigned
2703 APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
2704 const integerPart *rhs, unsigned lhsParts,
2705 unsigned rhsParts)
2706 {
2666 unsigned APInt::tcFullMultiply(integerPart *dst, const integerPart *lhs,
2667 const integerPart *rhs, unsigned lhsParts,
2668 unsigned rhsParts) {
27072669 /* Put the narrower number on the LHS for less loops below. */
27082670 if (lhsParts > rhsParts) {
27092671 return tcFullMultiply (dst, rhs, lhs, rhsParts, lhsParts);
27312693 use by the routine; its contents need not be initialized and are
27322694 destroyed. LHS, REMAINDER and SCRATCH must be distinct.
27332695 */
2734 int
2735 APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
2736 integerPart *remainder, integerPart *srhs,
2737 unsigned parts)
2738 {
2696 int APInt::tcDivide(integerPart *lhs, const integerPart *rhs,
2697 integerPart *remainder, integerPart *srhs,
2698 unsigned parts) {
27392699 assert(lhs != remainder && lhs != srhs && remainder != srhs);
27402700
27412701 unsigned shiftCount = tcMSB(rhs, parts) + 1;
27772737
27782738 /* Shift a bignum left COUNT bits in-place. Shifted in bits are zero.
27792739 There are no restrictions on COUNT. */
2780 void
2781 APInt::tcShiftLeft(integerPart *dst, unsigned parts, unsigned count)
2782 {
2740 void APInt::tcShiftLeft(integerPart *dst, unsigned parts, unsigned count) {
27832741 if (count) {
27842742 /* Jump is the inter-part jump; shift is is intra-part shift. */
27852743 unsigned jump = count / integerPartWidth;
28092767
28102768 /* Shift a bignum right COUNT bits in-place. Shifted in bits are
28112769 zero. There are no restrictions on COUNT. */
2812 void
2813 APInt::tcShiftRight(integerPart *dst, unsigned parts, unsigned count)
2814 {
2770 void APInt::tcShiftRight(integerPart *dst, unsigned parts, unsigned count) {
28152771 if (count) {
28162772 /* Jump is the inter-part jump; shift is is intra-part shift. */
28172773 unsigned jump = count / integerPartWidth;
28392795 }
28402796
28412797 /* Bitwise and of two bignums. */
2842 void
2843 APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned parts)
2844 {
2798 void APInt::tcAnd(integerPart *dst, const integerPart *rhs, unsigned parts) {
28452799 for (unsigned i = 0; i < parts; i++)
28462800 dst[i] &= rhs[i];
28472801 }
28482802
28492803 /* Bitwise inclusive or of two bignums. */
2850 void
2851 APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned parts)
2852 {
2804 void APInt::tcOr(integerPart *dst, const integerPart *rhs, unsigned parts) {
28532805 for (unsigned i = 0; i < parts; i++)
28542806 dst[i] |= rhs[i];
28552807 }
28562808
28572809 /* Bitwise exclusive or of two bignums. */
2858 void
2859 APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned parts)
2860 {
2810 void APInt::tcXor(integerPart *dst, const integerPart *rhs, unsigned parts) {
28612811 for (unsigned i = 0; i < parts; i++)
28622812 dst[i] ^= rhs[i];
28632813 }
28642814
28652815 /* Complement a bignum in-place. */
2866 void
2867 APInt::tcComplement(integerPart *dst, unsigned parts)
2868 {
2816 void APInt::tcComplement(integerPart *dst, unsigned parts) {
28692817 for (unsigned i = 0; i < parts; i++)
28702818 dst[i] = ~dst[i];
28712819 }
28722820
28732821 /* Comparison (unsigned) of two bignums. */
2874 int
2875 APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
2876 unsigned parts)
2877 {
2822 int APInt::tcCompare(const integerPart *lhs, const integerPart *rhs,
2823 unsigned parts) {
28782824 while (parts) {
28792825 parts--;
28802826 if (lhs[parts] == rhs[parts])
28902836 }
28912837
28922838 /* Increment a bignum in-place, return the carry flag. */
2893 integerPart
2894 APInt::tcIncrement(integerPart *dst, unsigned parts)
2895 {
2839 integerPart APInt::tcIncrement(integerPart *dst, unsigned parts) {
28962840 unsigned i;
28972841 for (i = 0; i < parts; i++)
28982842 if (++dst[i] != 0)
29022846 }
29032847
29042848 /* Decrement a bignum in-place, return the borrow flag. */
2905 integerPart
2906 APInt::tcDecrement(integerPart *dst, unsigned parts) {
2849 integerPart APInt::tcDecrement(integerPart *dst, unsigned parts) {
29072850 for (unsigned i = 0; i < parts; i++) {
29082851 // If the current word is non-zero, then the decrement has no effect on the
29092852 // higher-order words of the integer and no borrow can occur. Exit early.
29172860
29182861 /* Set the least significant BITS bits of a bignum, clear the
29192862 rest. */
2920 void
2921 APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned parts,
2922 unsigned bits)
2923 {
2863 void APInt::tcSetLeastSignificantBits(integerPart *dst, unsigned parts,
2864 unsigned bits) {
29242865 unsigned i = 0;
29252866 while (bits > integerPartWidth) {
29262867 dst[i++] = ~(integerPart) 0;