#endif
TEST(APIntTest, i65_Count) {
+ APInt i65(65, 0, true);
+ EXPECT_EQ(65u, i65.countLeadingZeros());
+ EXPECT_EQ(0u, i65.countLeadingOnes());
+ EXPECT_EQ(0u, i65.getActiveBits());
+ EXPECT_EQ(1u, i65.getActiveWords());
+ EXPECT_EQ(65u, i65.countTrailingZeros());
+ EXPECT_EQ(0u, i65.countPopulation());
+
APInt i65minus(65, 0, true);
i65minus.setBit(64);
EXPECT_EQ(0u, i65minus.countLeadingZeros());
EXPECT_EQ(Rot, Big.rotr(144));
}
+TEST(APIntTest, Splat) {
+ APInt ValA(8, 0x01);
+ EXPECT_EQ(ValA, APInt::getSplat(8, ValA));
+ EXPECT_EQ(APInt(64, 0x0101010101010101ULL), APInt::getSplat(64, ValA));
+
+ APInt ValB(3, 5);
+ EXPECT_EQ(APInt(4, 0xD), APInt::getSplat(4, ValB));
+ EXPECT_EQ(APInt(15, 0xDB6D), APInt::getSplat(15, ValB));
+}
+
+TEST(APIntTest, tcDecrement) {
+ // Test single word decrement.
+
+ // No out borrow.
+ {
+ integerPart singleWord = ~integerPart(0) << (integerPartWidth - 1);
+ integerPart carry = APInt::tcDecrement(&singleWord, 1);
+ EXPECT_EQ(carry, integerPart(0));
+ EXPECT_EQ(singleWord, ~integerPart(0) >> 1);
+ }
+
+ // With out borrow.
+ {
+ integerPart singleWord = 0;
+ integerPart carry = APInt::tcDecrement(&singleWord, 1);
+ EXPECT_EQ(carry, integerPart(1));
+ EXPECT_EQ(singleWord, ~integerPart(0));
+ }
+
+ // Test multiword decrement.
+
+ // No across word borrow, no out borrow.
+ {
+ integerPart test[4] = {0x1, 0x1, 0x1, 0x1};
+ integerPart expected[4] = {0x0, 0x1, 0x1, 0x1};
+ APInt::tcDecrement(test, 4);
+ EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
+ }
+
+ // 1 across word borrow, no out borrow.
+ {
+ integerPart test[4] = {0x0, 0xF, 0x1, 0x1};
+ integerPart expected[4] = {~integerPart(0), 0xE, 0x1, 0x1};
+ integerPart carry = APInt::tcDecrement(test, 4);
+ EXPECT_EQ(carry, integerPart(0));
+ EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
+ }
+
+ // 2 across word borrow, no out borrow.
+ {
+ integerPart test[4] = {0x0, 0x0, 0xC, 0x1};
+ integerPart expected[4] = {~integerPart(0), ~integerPart(0), 0xB, 0x1};
+ integerPart carry = APInt::tcDecrement(test, 4);
+ EXPECT_EQ(carry, integerPart(0));
+ EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
+ }
+
+ // 3 across word borrow, no out borrow.
+ {
+ integerPart test[4] = {0x0, 0x0, 0x0, 0x1};
+ integerPart expected[4] = {~integerPart(0), ~integerPart(0), ~integerPart(0), 0x0};
+ integerPart carry = APInt::tcDecrement(test, 4);
+ EXPECT_EQ(carry, integerPart(0));
+ EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
+ }
+
+ // 3 across word borrow, with out borrow.
+ {
+ integerPart test[4] = {0x0, 0x0, 0x0, 0x0};
+ integerPart expected[4] = {~integerPart(0), ~integerPart(0), ~integerPart(0), ~integerPart(0)};
+ integerPart carry = APInt::tcDecrement(test, 4);
+ EXPECT_EQ(carry, integerPart(1));
+ EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
+ }
+}
}