summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-03-17 20:39:06 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-03-17 20:39:06 +0000
commit09a51bab5d12e688f4145d6fb8654fc13c7ce4d9 (patch)
treeee64614cc32bcba99e27b619c7fce2557e00c3f6 /llvm/lib
parent8630840c30a99e54414c0ee9b39928813301dcfc (diff)
downloadbcm5719-llvm-09a51bab5d12e688f4145d6fb8654fc13c7ce4d9.tar.gz
bcm5719-llvm-09a51bab5d12e688f4145d6fb8654fc13c7ce4d9.zip
Add an argument to APInt's magic udiv calculation to specify the number of bits that are known zero in the divided number.
This will come in handy soon. llvm-svn: 127828
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/APInt.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 08f36d2af3a..f4aae72ecaf 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1517,13 +1517,15 @@ APInt::ms APInt::magic() const {
/// division by a constant as a sequence of multiplies, adds and shifts.
/// Requires that the divisor not be 0. Taken from "Hacker's Delight", Henry
/// S. Warren, Jr., chapter 10.
-APInt::mu APInt::magicu() const {
+/// LeadingZeros can be used to simplify the calculation if the upper bits
+/// of the devided value are known zero.
+APInt::mu APInt::magicu(unsigned LeadingZeros) const {
const APInt& d = *this;
unsigned p;
APInt nc, delta, q1, r1, q2, r2;
struct mu magu;
magu.a = 0; // initialize "add" indicator
- APInt allOnes = APInt::getAllOnesValue(d.getBitWidth());
+ APInt allOnes = APInt::getAllOnesValue(d.getBitWidth()).lshr(LeadingZeros);
APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
OpenPOWER on IntegriCloud