[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. llvm-svn: 364599
This commit is contained in:
parent
4a8dc61534
commit
a59cf87822
|
@ -2505,4 +2505,21 @@ TEST(APIntTest, SolveQuadraticEquationWrap) {
|
||||||
Iterate(i);
|
Iterate(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(APIntTest, MultiplicativeInverseExaustive) {
|
||||||
|
for (unsigned BitWidth = 1; BitWidth <= 16; ++BitWidth) {
|
||||||
|
for (unsigned Value = 0; Value < (1 << BitWidth); ++Value) {
|
||||||
|
APInt V = APInt(BitWidth, Value);
|
||||||
|
APInt MulInv =
|
||||||
|
V.zext(BitWidth + 1)
|
||||||
|
.multiplicativeInverse(APInt::getSignedMinValue(BitWidth + 1))
|
||||||
|
.trunc(BitWidth);
|
||||||
|
APInt One = V * MulInv;
|
||||||
|
EXPECT_TRUE(MulInv.isNullValue() || One.isOneValue())
|
||||||
|
<< " bitwidth = " << BitWidth << ", value = " << Value
|
||||||
|
<< ", computed multiplicative inverse = " << MulInv
|
||||||
|
<< ", value * multiplicative inverse = " << One << " (should be 1)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
Loading…
Reference in New Issue