This is an archive of the discontinued LLVM Phabricator instance.

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

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

Details

Summary

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

Event Timeline

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.

RKSimon edited edge metadata.May 18 2017, 3:15 AM

Add extra tests?

lib/Support/APInt.cpp
1568

braces

Add tests. Remove braces.

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

LGTM

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.