MCPcopy Create free account
hub / github.com/ablab/spades / udiv

Method udiv

ext/src/llvm/APInt.cpp:1599–1635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1597}
1598
1599APInt APInt::udiv(const APInt &RHS) const {
1600 assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
1601
1602 // First, deal with the easy case
1603 if (isSingleWord()) {
1604 assert(RHS.U.VAL != 0 && "Divide by zero?");
1605 return APInt(BitWidth, U.VAL / RHS.U.VAL);
1606 }
1607
1608 // Get some facts about the LHS and RHS number of bits and words
1609 unsigned lhsWords = getNumWords(getActiveBits());
1610 unsigned rhsBits = RHS.getActiveBits();
1611 unsigned rhsWords = getNumWords(rhsBits);
1612 assert(rhsWords && "Divided by zero???");
1613
1614 // Deal with some degenerate cases
1615 if (!lhsWords)
1616 // 0 / X ===> 0
1617 return APInt(BitWidth, 0);
1618 if (rhsBits == 1)
1619 // X / 1 ===> X
1620 return *this;
1621 if (lhsWords < rhsWords || this->ult(RHS))
1622 // X / Y ===> 0, iff X < Y
1623 return APInt(BitWidth, 0);
1624 if (*this == RHS)
1625 // X / X ===> 1
1626 return APInt(BitWidth, 1);
1627 if (lhsWords == 1) // rhsWords is 1 if lhsWords is 1.
1628 // All high words are zero, just use native divide
1629 return APInt(BitWidth, this->U.pVal[0] / RHS.U.pVal[0]);
1630
1631 // We have to compute it the hard way. Invoke the Knuth divide algorithm.
1632 APInt Quotient(BitWidth, 0); // to hold result.
1633 divide(U.pVal, lhsWords, RHS.U.pVal, rhsWords, Quotient.U.pVal, nullptr);
1634 return Quotient;
1635}
1636
1637APInt APInt::udiv(uint64_t RHS) const {
1638 assert(RHS != 0 && "Divide by zero?");

Callers 7

sqrtMethod · 0.95
sdivMethod · 0.95
AdjustToPrecisionFunction · 0.80
magicMethod · 0.80
magicuMethod · 0.80
RoundingUDivMethod · 0.80

Calls 5

assertClass · 0.85
isSingleWordFunction · 0.85
getNumWordsFunction · 0.85
getActiveBitsFunction · 0.85
APIntFunction · 0.50

Tested by

no test coverage detected