[libc-commits] [PATCH] D140070: [libc] fix shifting exact multiples of 64 in uint
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Dec 15 11:30:21 PST 2022
michaelrj updated this revision to Diff 483262.
michaelrj marked 2 inline comments as done.
michaelrj added a comment.
move check for shift of 0 outside of loop for shift_left
remove redundant check in shift right
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140070/new/
https://reviews.llvm.org/D140070
Files:
libc/src/__support/UInt.h
libc/test/src/__support/uint_test.cpp
Index: libc/test/src/__support/uint_test.cpp
===================================================================
--- libc/test/src/__support/uint_test.cpp
+++ libc/test/src/__support/uint_test.cpp
@@ -326,6 +326,10 @@
LL_UInt128 result6({0, 0});
EXPECT_EQ((val2 << 128), result6);
EXPECT_EQ((val2 << 256), result6);
+
+ LL_UInt192 val3({1, 0, 0});
+ LL_UInt192 result7({0, 1, 0});
+ EXPECT_EQ((val3 << 64), result7);
}
TEST(LlvmLibcUIntClassTest, ShiftRightTests) {
@@ -363,6 +367,10 @@
EXPECT_EQ((v2 >> 64), r2);
EXPECT_EQ((v2 >> 128), r3);
EXPECT_EQ((r2 >> 64), r3);
+
+ LL_UInt192 val3({0, 0, 1});
+ LL_UInt192 result7({0, 1, 0});
+ EXPECT_EQ((val3 >> 64), result7);
}
TEST(LlvmLibcUIntClassTest, AndTests) {
Index: libc/src/__support/UInt.h
===================================================================
--- libc/src/__support/UInt.h
+++ libc/src/__support/UInt.h
@@ -364,7 +364,7 @@
val[1] = uint64_t(tmp >> 64);
return;
}
-#endif // __SIZEOF_INT128__
+#endif // __SIZEOF_INT128__
if (unlikely(s == 0))
return;
@@ -374,11 +374,17 @@
if (drop < WordCount) {
i = WordCount - 1;
- size_t j = WordCount - 1 - drop;
- for (; j > 0; --i, --j) {
- val[i] = (val[j] << shift) | (val[j - 1] >> (64 - shift));
+ if (shift > 0) {
+ for (size_t j = WordCount - 1 - drop; j > 0; --i, --j) {
+ val[i] = (val[j] << shift) | (val[j - 1] >> (64 - shift));
+ }
+ val[i] = val[0] << shift;
+ } else {
+ for (size_t j = WordCount - 1 - drop; j > 0; --i, --j) {
+ val[i] = val[j];
+ }
+ val[i] = val[0];
}
- val[i] = val[0] << shift;
}
for (size_t j = 0; j < i; ++j) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140070.483262.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221215/75e6c838/attachment-0001.bin>
More information about the libc-commits
mailing list