}
}
-TEST(APIntTest, extractBit) {
+TEST(APIntTest, arrayAccess) {
// Single word check.
uint64_t E1 = 0x2CA7F46BF6569915ULL;
APInt A1(64, E1);
- for (unsigned i = 0, e = 64; i < e; ++i) {
+ for (unsigned i = 0, e = 64; i < e; ++i) {
EXPECT_EQ(bool(E1 & (1ULL << i)),
- A1.extractBit(i));
+ A1[i]);
}
// Multiword check.
integerPart E2[4] = {
- 0xeb6eb136591cba21ULL,
- 0x7b9358bd6a33f10aULL,
- 0x7e7ffa5eadd8846ULL,
- 0x305f341ca00b613dULL
+ 0xEB6EB136591CBA21ULL,
+ 0x7B9358BD6A33F10AULL,
+ 0x7E7FFA5EADD8846ULL,
+ 0x305F341CA00B613DULL
};
- APInt A2(integerPartWidth*4, ArrayRef<integerPart>(E2, 4));
+ APInt A2(integerPartWidth*4, E2);
for (unsigned i = 0; i < 4; ++i) {
for (unsigned j = 0; j < integerPartWidth; ++j) {
EXPECT_EQ(bool(E2[i] & (1ULL << j)),
- A2.extractBit(i*integerPartWidth + j));
+ A2[i*integerPartWidth + j]);
}
}
}
+TEST(APIntTest, LargeAPIntConstruction) {
+ // Check that we can properly construct very large APInt. It is very
+ // unlikely that people will ever do this, but it is a legal input,
+ // so we should not crash on it.
+ APInt A9(UINT32_MAX, 0);
+ EXPECT_FALSE(A9.getBoolValue());
+}
+
+TEST(APIntTest, nearestLogBase2) {
+ // Single word check.
+
+ // Test round up.
+ uint64_t I1 = 0x1800001;
+ APInt A1(64, I1);
+ EXPECT_EQ(A1.nearestLogBase2(), A1.ceilLogBase2());
+
+ // Test round down.
+ uint64_t I2 = 0x1000011;
+ APInt A2(64, I2);
+ EXPECT_EQ(A2.nearestLogBase2(), A2.logBase2());
+
+ // Test ties round up.
+ uint64_t I3 = 0x1800000;
+ APInt A3(64, I3);
+ EXPECT_EQ(A3.nearestLogBase2(), A3.ceilLogBase2());
+
+ // Multiple word check.
+
+ // Test round up.
+ integerPart I4[4] = {0x0, 0xF, 0x18, 0x0};
+ APInt A4(integerPartWidth*4, I4);
+ EXPECT_EQ(A4.nearestLogBase2(), A4.ceilLogBase2());
+
+ // Test round down.
+ integerPart I5[4] = {0x0, 0xF, 0x10, 0x0};
+ APInt A5(integerPartWidth*4, I5);
+ EXPECT_EQ(A5.nearestLogBase2(), A5.logBase2());
+
+ // Test ties round up.
+ uint64_t I6[4] = {0x0, 0x0, 0x0, 0x18};
+ APInt A6(integerPartWidth*4, I6);
+ EXPECT_EQ(A6.nearestLogBase2(), A6.ceilLogBase2());
+
+ // Test BitWidth == 1 special cases.
+ APInt A7(1, 1);
+ EXPECT_EQ(A7.nearestLogBase2(), 0ULL);
+ APInt A8(1, 0);
+ EXPECT_EQ(A8.nearestLogBase2(), UINT32_MAX);
+
+ // Test the zero case when we have a bit width large enough such
+ // that the bit width is larger than UINT32_MAX-1.
+ APInt A9(UINT32_MAX, 0);
+ EXPECT_EQ(A9.nearestLogBase2(), UINT32_MAX);
+}
+
+TEST(APIntTest, SelfMoveAssignment) {
+ APInt X(32, 0xdeadbeef);
+ X = std::move(X);
+ EXPECT_EQ(32u, X.getBitWidth());
+ EXPECT_EQ(0xdeadbeefULL, X.getLimitedValue());
+
+ uint64_t Bits[] = {0xdeadbeefdeadbeefULL, 0xdeadbeefdeadbeefULL};
+ APInt Y(128, Bits);
+ Y = std::move(Y);
+ EXPECT_EQ(128u, Y.getBitWidth());
+ EXPECT_EQ(~0ULL, Y.getLimitedValue());
+ const uint64_t *Raw = Y.getRawData();
+ EXPECT_EQ(2u, Y.getNumWords());
+ EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[0]);
+ EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[1]);
+}
+
}