[llvm] [ADT] Add signed and unsigned mulHi and mulLo to APInt (PR #84719)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 10 22:43:21 PDT 2024
================
@@ -2805,6 +2806,89 @@ TEST(APIntTest, multiply) {
EXPECT_EQ(64U, i96.countr_zero());
}
+TEST(APIntOpsTest, MulHiLo) {
+
+ // Unsigned
+
+ // 32 bits
+ APInt i32a(32, 0x0001'E235);
+ APInt i32b(32, 0xF623'55AD);
+ EXPECT_EQ(0x0001'CFA1, APIntOps::mulHiU(i32a, i32b));
+ EXPECT_EQ(0x7CA0'76D1, APIntOps::mulLoU(i32a, i32b));
+
+ // 64 bits
+ APInt i64a(64, 0x1234'5678'90AB'CDEF);
+ APInt i64b(64, 0xFEDC'BA09'8765'4321);
+ EXPECT_EQ(0x121F'A000'A372'3A57, APIntOps::mulHiU(i64a, i64b));
+ EXPECT_EQ(0xC24A'442F'E556'18CF, APIntOps::mulLoU(i64a, i64b));
+
+ // 128 bits
+ APInt i128a(128, "1234567890ABCDEF1234567890ABCDEF", 16);
+ APInt i128b(128, "FEDCBA0987654321FEDCBA0987654321", 16);
+ APInt i128ResHi = APIntOps::mulHiU(i128a, i128b);
+ std::string strResHi = toString(i128ResHi, 16, false, true, true, true);
+ EXPECT_STREQ("0x121F'A000'A372'3A57'E689'8431'2C3A'8D7E", strResHi.c_str());
----------------
arsenm wrote:
Why not regular EXPECT_EQ and avoid the .c_str?
https://github.com/llvm/llvm-project/pull/84719
More information about the llvm-commits
mailing list