OSDN Git Service

[APInt] Add support for dividing or remainder by a uint64_t or int64_t.
authorCraig Topper <craig.topper@gmail.com>
Fri, 19 May 2017 16:43:54 +0000 (16:43 +0000)
committerCraig Topper <craig.topper@gmail.com>
Fri, 19 May 2017 16:43:54 +0000 (16:43 +0000)
commit47c969db7e087df37e4a882d49b8a52886aa5728
tree16c519d2fa4fa4250e61c7d2712ea9a11f33766a
parent519ca370237eb5db4e31208c4a4e0df2cf5b5bea
[APInt] Add support for dividing or remainder by a uint64_t or int64_t.

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.

Reviewers: hans, dblaikie, RKSimon

Reviewed By: RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D33310

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303431 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/APInt.h
lib/Support/APInt.cpp
unittests/ADT/APIntTest.cpp