Index: test/base-unittests/bits-unittest.cc |
diff --git a/test/base-unittests/bits-unittest.cc b/test/base-unittests/bits-unittest.cc |
index 689fb41daece31dffb2a3298dee66f3f903b3bf4..56d3d9261beb9aaab847de70f31e03d7b71b751f 100644 |
--- a/test/base-unittests/bits-unittest.cc |
+++ b/test/base-unittests/bits-unittest.cc |
@@ -10,6 +10,36 @@ namespace v8 { |
namespace base { |
namespace bits { |
+TEST(BitsTest, CountSetBits32) { |
+ EXPECT_EQ(0u, CountSetBits32(0)); |
+ EXPECT_EQ(1u, CountSetBits32(1)); |
+ EXPECT_EQ(8u, CountSetBits32(0x11111111)); |
+ EXPECT_EQ(16u, CountSetBits32(0xf0f0f0f0)); |
+ EXPECT_EQ(24u, CountSetBits32(0xfff0f0ff)); |
+ EXPECT_EQ(32u, CountSetBits32(0xffffffff)); |
+} |
+ |
+ |
+TEST(BitsTest, CountLeadingZeros32) { |
+ EXPECT_EQ(32u, CountLeadingZeros32(0)); |
+ EXPECT_EQ(31u, CountLeadingZeros32(1)); |
+ TRACED_FORRANGE(uint32_t, shift, 0, 31) { |
+ EXPECT_EQ(31u - shift, CountLeadingZeros32(1u << shift)); |
+ } |
+ EXPECT_EQ(4u, CountLeadingZeros32(0x0f0f0f0f)); |
+} |
+ |
+ |
+TEST(BitsTest, CountTrailingZeros32) { |
+ EXPECT_EQ(32u, CountTrailingZeros32(0)); |
+ EXPECT_EQ(31u, CountTrailingZeros32(0x80000000)); |
+ TRACED_FORRANGE(uint32_t, shift, 0, 31) { |
+ EXPECT_EQ(shift, CountTrailingZeros32(1u << shift)); |
+ } |
+ EXPECT_EQ(4u, CountTrailingZeros32(0xf0f0f0f0)); |
+} |
+ |
+ |
TEST(BitsTest, RotateRight32) { |
TRACED_FORRANGE(uint32_t, shift, 0, 31) { |
EXPECT_EQ(0u, RotateRight32(0u, shift)); |