llvm.org GIT mirror llvm / 5b5948d
[NFC][APInt] Add (exhaustive) test for multiplicativeInverse() Else there is no direct test coverage at all. The function should either return '0' or precise answer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364599 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev a month ago
1 changed file(s) with 17 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
25042504 Iterate(i);
25052505 }
25062506
2507 TEST(APIntTest, MultiplicativeInverseExaustive) {
2508 for (unsigned BitWidth = 1; BitWidth <= 16; ++BitWidth) {
2509 for (unsigned Value = 0; Value < (1 << BitWidth); ++Value) {
2510 APInt V = APInt(BitWidth, Value);
2511 APInt MulInv =
2512 V.zext(BitWidth + 1)
2513 .multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
2514 .trunc(BitWidth);
2515 APInt One = V * MulInv;
2516 EXPECT_TRUE(MulInv.isNullValue() || One.isOneValue())
2517 << " bitwidth = " << BitWidth << ", value = " << Value
2518 << ", computed multiplicative inverse = " << MulInv
2519 << ", value * multiplicative inverse = " << One << " (should be 1)";
2520 }
2521 }
2522 }
2523
25072524 } // end anonymous namespace