summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-12-22 03:15:35 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-12-22 03:15:35 +0000
commit2aae94fa709128e4a11fceea8467715ad3e7c292 (patch)
tree6032807c6da756c64cbbc19e490732ca5ee180a2 /llvm/lib/Support/APInt.cpp
parent1dc45d8df4194cebf3dd6843e429499c27579773 (diff)
downloadbcm5719-llvm-2aae94fa709128e4a11fceea8467715ad3e7c292.tar.gz
bcm5719-llvm-2aae94fa709128e4a11fceea8467715ad3e7c292.zip
Fix APInt::rotl and APInt::rotr so that they work correctly. Found while writing some code that tried to use them.
llvm-svn: 147134
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 143ded920e2..b5411bec9d4 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1338,14 +1338,10 @@ APInt APInt::rotl(const APInt &rotateAmt) const {
}
APInt APInt::rotl(unsigned rotateAmt) const {
+ rotateAmt %= BitWidth;
if (rotateAmt == 0)
return *this;
- // Don't get too fancy, just use existing shift/or facilities
- APInt hi(*this);
- APInt lo(*this);
- hi.shl(rotateAmt);
- lo.lshr(BitWidth - rotateAmt);
- return hi | lo;
+ return shl(rotateAmt) | lshr(BitWidth - rotateAmt);
}
APInt APInt::rotr(const APInt &rotateAmt) const {
@@ -1353,14 +1349,10 @@ APInt APInt::rotr(const APInt &rotateAmt) const {
}
APInt APInt::rotr(unsigned rotateAmt) const {
+ rotateAmt %= BitWidth;
if (rotateAmt == 0)
return *this;
- // Don't get too fancy, just use existing shift/or facilities
- APInt hi(*this);
- APInt lo(*this);
- lo.lshr(rotateAmt);
- hi.shl(BitWidth - rotateAmt);
- return hi | lo;
+ return lshr(rotateAmt) | shl(BitWidth - rotateAmt);
}
// Square Root - this method computes and returns the square root of "this".
OpenPOWER on IntegriCloud