[llvm-commits] [llvm] r47741 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/Support/APInt.cpp
Dan Gohman
gohman at apple.com
Thu Feb 28 17:40:47 PST 2008
Author: djg
Date: Thu Feb 28 19:40:47 2008
New Revision: 47741
URL: http://llvm.org/viewvc/llvm-project?rev=47741&view=rev
Log:
Add support to APInt for shift and rotate operations with APInt
instead of uint32_t for the shift/rotate count operand type.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/lib/Support/APInt.cpp
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=47741&r1=47740&r2=47741&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Thu Feb 28 19:40:47 2008
@@ -584,6 +584,10 @@
return shl(Bits);
}
+ APInt operator<<(const APInt &Bits) const {
+ return shl(Bits);
+ }
+
/// Arithmetic right-shift this APInt by shiftAmt.
/// @brief Arithmetic right-shift function.
APInt ashr(uint32_t shiftAmt) const;
@@ -602,6 +606,24 @@
/// @brief Rotate right by rotateAmt.
APInt rotr(uint32_t rotateAmt) const;
+ /// Arithmetic right-shift this APInt by shiftAmt.
+ /// @brief Arithmetic right-shift function.
+ APInt ashr(const APInt &shiftAmt) const;
+
+ /// Logical right-shift this APInt by shiftAmt.
+ /// @brief Logical right-shift function.
+ APInt lshr(const APInt &shiftAmt) const;
+
+ /// Left-shift this APInt by shiftAmt.
+ /// @brief Left-shift function.
+ APInt shl(const APInt &shiftAmt) const;
+
+ /// @brief Rotate left by rotateAmt.
+ APInt rotl(const APInt &rotateAmt) const;
+
+ /// @brief Rotate right by rotateAmt.
+ APInt rotr(const APInt &rotateAmt) const;
+
/// Perform an unsigned divide operation on this APInt by RHS. Both this and
/// RHS are treated as unsigned quantities for purposes of this division.
/// @returns a new APInt value containing the division result
Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=47741&r1=47740&r2=47741&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Thu Feb 28 19:40:47 2008
@@ -1085,6 +1085,12 @@
/// Arithmetic right-shift this APInt by shiftAmt.
/// @brief Arithmetic right-shift function.
+APInt APInt::ashr(const APInt &shiftAmt) const {
+ return ashr(shiftAmt.getLimitedValue(BitWidth));
+}
+
+/// Arithmetic right-shift this APInt by shiftAmt.
+/// @brief Arithmetic right-shift function.
APInt APInt::ashr(uint32_t shiftAmt) const {
assert(shiftAmt <= BitWidth && "Invalid shift amount");
// Handle a degenerate case
@@ -1168,6 +1174,12 @@
/// Logical right-shift this APInt by shiftAmt.
/// @brief Logical right-shift function.
+APInt APInt::lshr(const APInt &shiftAmt) const {
+ return ashr(shiftAmt.getLimitedValue(BitWidth));
+}
+
+/// Logical right-shift this APInt by shiftAmt.
+/// @brief Logical right-shift function.
APInt APInt::lshr(uint32_t shiftAmt) const {
if (isSingleWord()) {
if (shiftAmt == BitWidth)
@@ -1230,6 +1242,13 @@
/// Left-shift this APInt by shiftAmt.
/// @brief Left-shift function.
+APInt APInt::shl(const APInt &shiftAmt) const {
+ // It's undefined behavior in C to shift by BitWidth or greater, but
+ return shl(shiftAmt.getLimitedValue(BitWidth));
+}
+
+/// Left-shift this APInt by shiftAmt.
+/// @brief Left-shift function.
APInt APInt::shl(uint32_t shiftAmt) const {
assert(shiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) {
@@ -1287,6 +1306,10 @@
return APInt(val, BitWidth).clearUnusedBits();
}
+APInt APInt::rotl(const APInt &rotateAmt) const {
+ return rotl(rotateAmt.getLimitedValue(BitWidth));
+}
+
APInt APInt::rotl(uint32_t rotateAmt) const {
if (rotateAmt == 0)
return *this;
@@ -1298,6 +1321,10 @@
return hi | lo;
}
+APInt APInt::rotr(const APInt &rotateAmt) const {
+ return rotr(rotateAmt.getLimitedValue(BitWidth));
+}
+
APInt APInt::rotr(uint32_t rotateAmt) const {
if (rotateAmt == 0)
return *this;
More information about the llvm-commits
mailing list