Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: test/base-unittests/bits-unittest.cc

Issue 494633002: Fix implementation of bit count functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mips64/simulator-mips64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « src/mips64/simulator-mips64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698