[PATCH] D27749: [APFloat] Fix rotl/rotr when the shift amount is greater than the total bit width.
Joey Gouly via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 14 03:33:20 PST 2016
joey created this revision.
joey added a subscriber: llvm-commits.
joey set the repository for this revision to rL LLVM.
As per the title, fix the rotation by not truncating the shift amount to the bit width.
Add a unit test to check that 1 << 33 produces 2.
Repository:
rL LLVM
https://reviews.llvm.org/D27749
Files:
lib/Support/APInt.cpp
unittests/ADT/APIntTest.cpp
Index: unittests/ADT/APIntTest.cpp
===================================================================
--- unittests/ADT/APIntTest.cpp
+++ unittests/ADT/APIntTest.cpp
@@ -978,6 +978,9 @@
EXPECT_EQ(APInt(8, 1), APInt(8, 16).rotl(4));
EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotl(8));
+ EXPECT_EQ(APInt(32, 2), APInt(32, 1).rotl(33));
+ EXPECT_EQ(APInt(32, 2), APInt(32, 1).rotl(APInt(32, 33)));
+
EXPECT_EQ(APInt(8, 16), APInt(8, 16).rotr(0));
EXPECT_EQ(APInt(8, 8), APInt(8, 16).rotr(1));
EXPECT_EQ(APInt(8, 4), APInt(8, 16).rotr(2));
@@ -990,6 +993,9 @@
EXPECT_EQ(APInt(8, 16), APInt(8, 1).rotr(4));
EXPECT_EQ(APInt(8, 1), APInt(8, 1).rotr(8));
+ EXPECT_EQ(APInt(32, (1 << 31)), APInt(32, 1).rotr(33));
+ EXPECT_EQ(APInt(32, (1 << 31)), APInt(32, 1).rotr(APInt(32, 33)));
+
APInt Big(256, "00004000800000000000000000003fff8000000000000000", 16);
APInt Rot(256, "3fff80000000000000000000000000000000000040008000", 16);
EXPECT_EQ(Rot, Big.rotr(144));
Index: lib/Support/APInt.cpp
===================================================================
--- lib/Support/APInt.cpp
+++ lib/Support/APInt.cpp
@@ -1245,7 +1245,7 @@
}
APInt APInt::rotl(const APInt &rotateAmt) const {
- return rotl((unsigned)rotateAmt.getLimitedValue(BitWidth));
+ return rotl((unsigned)rotateAmt.getZExtValue());
}
APInt APInt::rotl(unsigned rotateAmt) const {
@@ -1256,7 +1256,7 @@
}
APInt APInt::rotr(const APInt &rotateAmt) const {
- return rotr((unsigned)rotateAmt.getLimitedValue(BitWidth));
+ return rotr((unsigned)rotateAmt.getZExtValue());
}
APInt APInt::rotr(unsigned rotateAmt) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27749.81355.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161214/5c391abf/attachment.bin>
More information about the llvm-commits
mailing list