[llvm-commits] [llvm] r147134 - /llvm/trunk/lib/Support/APInt.cpp
Eli Friedman
eli.friedman at gmail.com
Wed Dec 21 19:15:35 PST 2011
Author: efriedma
Date: Wed Dec 21 21:15:35 2011
New Revision: 147134
URL: http://llvm.org/viewvc/llvm-project?rev=147134&view=rev
Log:
Fix APInt::rotl and APInt::rotr so that they work correctly. Found while writing some code that tried to use them.
Modified:
llvm/trunk/lib/Support/APInt.cpp
Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=147134&r1=147133&r2=147134&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Wed Dec 21 21:15:35 2011
@@ -1338,14 +1338,10 @@
}
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(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".
More information about the llvm-commits
mailing list