llvm.org GIT mirror
Add an argument to APInt's magic udiv calculation to specify the number of bits that are known zero in the divided number. This will come in handy soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127828 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 9 years ago
3 changed file(s) with 7 addition(s) and 3 deletion(s).
 1371 1371 1372 1372 /// Calculate the magic number for unsigned division by a constant. 1373 1373 struct mu; 1374 mu magicu() const;⏎ 1374 mu magicu(unsigned LeadingZeros = 0) const;⏎ 1375 1375 1376 1376 /// @} 1377 1377 /// @name Building-block Operations for APInt and APFloat
 1516 1516 /// division by a constant as a sequence of multiplies, adds and shifts. 1517 1517 /// Requires that the divisor not be 0. Taken from "Hacker's Delight", Henry 1518 1518 /// S. Warren, Jr., chapter 10. 1519 APInt::mu APInt::magicu() const {⏎ 1519 /// LeadingZeros can be used to simplify the calculation if the upper bits⏎ 1520 /// of the devided value are known zero. 1521 APInt::mu APInt::magicu(unsigned LeadingZeros) const { 1520 1522 const APInt& d = *this; 1521 1523 unsigned p; 1522 1524 APInt nc, delta, q1, r1, q2, r2; 1523 1525 struct mu magu; 1524 1526 magu.a = 0; // initialize "add" indicator 1525 APInt allOnes = APInt::getAllOnesValue(d.getBitWidth());⏎ 1527 APInt allOnes = APInt::getAllOnesValue(d.getBitWidth()).lshr(LeadingZeros);⏎ 1526 1528 APInt signedMin = APInt::getSignedMinValue(d.getBitWidth()); 1527 1529 APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth()); 1528 1530
 347 347 EXPECT_EQ(APInt(32, 5).magicu().s, 2U); 348 348 EXPECT_EQ(APInt(32, 7).magicu().m, APInt(32, "24924925", 16)); 349 349 EXPECT_EQ(APInt(32, 7).magicu().s, 3U); 350 EXPECT_EQ(APInt(64, 25).magicu(1).m, APInt(64, "A3D70A3D70A3D70B", 16)); 351 EXPECT_EQ(APInt(64, 25).magicu(1).s, 4U); 350 352 } 351 353 352 354 #ifdef GTEST_HAS_DEATH_TEST