[APInt] Add support for dividing or remainder by a uint64_t or int64_t.

Authored by craig.topper on May 17 2017, 11:26 PM.



This patch adds udiv/sdiv/urem/srem/udivrem/sdivrem methods that can divide by a uint64_t. This makes division consistent with all the other arithmetic operations.

This modifies the interface of the divide helper method to work on raw arrays instead of APInts. This way we can pass the uint64_t in for the RHS without wrapping it in an APInt. This required moving all the Quotient and Remainder allocation handling up to the callers. For udiv/urem this was as simple as just creating the Quotient/Remainder with the right size when they were declared. For udivrem we have to rely on reallocate not changing the contents of the variable LHS or RHS is aliased with the Quotient or Remainder APInts. We also have to zero the upper bits of Remainder and Quotient that divide doesn't write to if lhsWords/rhsWords is smaller than the width.

I've update the toString method to use the new udivrem.

Diff Detail

craig.topper created this revision.May 17 2017, 11:26 PM

Forgot to mention, we should look into merging divide and tcDivide in the future.

Add extra tests?

1568 ↗(On Diff #99398)


Add tests. Remove braces.

RKSimon accepted this revision.May 19 2017, 6:44 AM


This revision is now accepted and ready to land.May 19 2017, 6:44 AM
This revision was automatically updated to reflect the committed changes.