[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
Thu Jan 5 04:46:30 PST 2017
joey updated this revision to Diff 83216.
joey added a comment.
Updated the code to use 'urem' to get the remainder, rather than calling getZExtValue.
Should the APInt rotateAmt need to have the same bitwidth as the APInt the rotl is being called on? urem and a few other methods need that.
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(33, 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,9 @@
}
APInt APInt::rotl(const APInt &rotateAmt) const {
- return rotl((unsigned)rotateAmt.getLimitedValue(BitWidth));
+ unsigned rotBitWidth = rotateAmt.getBitWidth();
+ APInt rem(rotateAmt.urem(APInt(rotBitWidth, BitWidth)));
+ return rotl((unsigned)rem.getLimitedValue(BitWidth));
}
APInt APInt::rotl(unsigned rotateAmt) const {
@@ -1256,7 +1258,9 @@
}
APInt APInt::rotr(const APInt &rotateAmt) const {
- return rotr((unsigned)rotateAmt.getLimitedValue(BitWidth));
+ unsigned rotBitWidth = rotateAmt.getBitWidth();
+ APInt rem(rotateAmt.urem(APInt(rotBitWidth, BitWidth)));
+ return rotr((unsigned)rem.getLimitedValue(BitWidth));
}
APInt APInt::rotr(unsigned rotateAmt) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27749.83216.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/5a7fb43f/attachment.bin>
More information about the llvm-commits
mailing list