mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-04 21:31:03 +00:00
APInt: udivrem should use machine instructions for single-word APInts
This mirrors the behavior of APInt::udiv and APInt::urem. Some architectures, like X86, have a single instruction which can compute both division and remainder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224217 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fabf5cc5d9
commit
a53d2268a9
@ -1956,6 +1956,18 @@ APInt APInt::srem(const APInt &RHS) const {
|
||||
|
||||
void APInt::udivrem(const APInt &LHS, const APInt &RHS,
|
||||
APInt &Quotient, APInt &Remainder) {
|
||||
assert(LHS.BitWidth == RHS.BitWidth && "Bit widths must be the same");
|
||||
|
||||
// First, deal with the easy case
|
||||
if (LHS.isSingleWord()) {
|
||||
assert(RHS.VAL != 0 && "Divide by zero?");
|
||||
uint64_t QuotVal = LHS.VAL / RHS.VAL;
|
||||
uint64_t RemVal = LHS.VAL % RHS.VAL;
|
||||
Quotient = APInt(LHS.BitWidth, QuotVal);
|
||||
Remainder = APInt(LHS.BitWidth, RemVal);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get some size facts about the dividend and divisor
|
||||
unsigned lhsBits = LHS.getActiveBits();
|
||||
unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user