OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains the unit tests for the bit utilities. | 5 // This file contains the unit tests for the bit utilities. |
6 | 6 |
7 #include "base/bits.h" | 7 #include "base/bits.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 EXPECT_EQ(0ul, Align(0, 4)); | 54 EXPECT_EQ(0ul, Align(0, 4)); |
55 EXPECT_EQ(4ul, Align(1, 4)); | 55 EXPECT_EQ(4ul, Align(1, 4)); |
56 EXPECT_EQ(4096ul, Align(1, 4096)); | 56 EXPECT_EQ(4096ul, Align(1, 4096)); |
57 EXPECT_EQ(4096ul, Align(4096, 4096)); | 57 EXPECT_EQ(4096ul, Align(4096, 4096)); |
58 EXPECT_EQ(4096ul, Align(4095, 4096)); | 58 EXPECT_EQ(4096ul, Align(4095, 4096)); |
59 EXPECT_EQ(8192ul, Align(4097, 4096)); | 59 EXPECT_EQ(8192ul, Align(4097, 4096)); |
60 EXPECT_EQ(kSizeTMax - 31, Align(kSizeTMax - 62, 32)); | 60 EXPECT_EQ(kSizeTMax - 31, Align(kSizeTMax - 62, 32)); |
61 EXPECT_EQ(kSizeTMax / 2 + 1, Align(1, kSizeTMax / 2 + 1)); | 61 EXPECT_EQ(kSizeTMax / 2 + 1, Align(1, kSizeTMax / 2 + 1)); |
62 } | 62 } |
63 | 63 |
| 64 TEST(BitsTest, CLZWorks) { |
| 65 EXPECT_EQ(32u, CountLeadingZeroBits32(0u)); |
| 66 EXPECT_EQ(31u, CountLeadingZeroBits32(1u)); |
| 67 EXPECT_EQ(1u, CountLeadingZeroBits32(1u << 30)); |
| 68 EXPECT_EQ(0u, CountLeadingZeroBits32(1u << 31)); |
| 69 |
| 70 #if defined(ARCH_CPU_64_BITS) |
| 71 EXPECT_EQ(64u, CountLeadingZeroBitsSizeT(0ull)); |
| 72 EXPECT_EQ(63u, CountLeadingZeroBitsSizeT(1ull)); |
| 73 EXPECT_EQ(32u, CountLeadingZeroBitsSizeT(1ull << 31)); |
| 74 EXPECT_EQ(1u, CountLeadingZeroBitsSizeT(1ull << 62)); |
| 75 EXPECT_EQ(0u, CountLeadingZeroBitsSizeT(1ull << 63)); |
| 76 #else |
| 77 EXPECT_EQ(32u, CountLeadingZeroBitsSizeT(0u)); |
| 78 EXPECT_EQ(31u, CountLeadingZeroBitsSizeT(1u)); |
| 79 EXPECT_EQ(1u, CountLeadingZeroBitsSizeT(1u << 30)); |
| 80 EXPECT_EQ(0u, CountLeadingZeroBitsSizeT(1u << 31)); |
| 81 #endif |
| 82 } |
| 83 |
64 } // namespace bits | 84 } // namespace bits |
65 } // namespace base | 85 } // namespace base |
OLD | NEW |