diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h --- a/libc/src/__support/UInt.h +++ b/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) { diff --git a/libc/test/src/__support/uint_test.cpp b/libc/test/src/__support/uint_test.cpp --- a/libc/test/src/__support/uint_test.cpp +++ b/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) {