1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "platform/utils.h" |
6 | #include "platform/assert.h" |
7 | #include "vm/unit_test.h" |
8 | |
9 | namespace dart { |
10 | |
11 | VM_UNIT_TEST_CASE(Minimum) { |
12 | EXPECT_EQ(0, Utils::Minimum(0, 1)); |
13 | EXPECT_EQ(0, Utils::Minimum(1, 0)); |
14 | |
15 | EXPECT_EQ(1, Utils::Minimum(1, 2)); |
16 | EXPECT_EQ(1, Utils::Minimum(2, 1)); |
17 | |
18 | EXPECT_EQ(-1, Utils::Minimum(-1, 1)); |
19 | EXPECT_EQ(-1, Utils::Minimum(1, -1)); |
20 | |
21 | EXPECT_EQ(-2, Utils::Minimum(-1, -2)); |
22 | EXPECT_EQ(-2, Utils::Minimum(-2, -1)); |
23 | } |
24 | |
25 | VM_UNIT_TEST_CASE(Maximum) { |
26 | EXPECT_EQ(1, Utils::Maximum(0, 1)); |
27 | EXPECT_EQ(1, Utils::Maximum(1, 0)); |
28 | |
29 | EXPECT_EQ(2, Utils::Maximum(1, 2)); |
30 | EXPECT_EQ(2, Utils::Maximum(2, 1)); |
31 | |
32 | EXPECT_EQ(1, Utils::Maximum(-1, 1)); |
33 | EXPECT_EQ(1, Utils::Maximum(1, -1)); |
34 | |
35 | EXPECT_EQ(-1, Utils::Maximum(-1, -2)); |
36 | EXPECT_EQ(-1, Utils::Maximum(-2, -1)); |
37 | } |
38 | |
39 | VM_UNIT_TEST_CASE(IsPowerOfTwo) { |
40 | EXPECT(!Utils::IsPowerOfTwo(0)); |
41 | EXPECT(Utils::IsPowerOfTwo(1)); |
42 | EXPECT(Utils::IsPowerOfTwo(2)); |
43 | EXPECT(!Utils::IsPowerOfTwo(3)); |
44 | EXPECT(Utils::IsPowerOfTwo(4)); |
45 | EXPECT(Utils::IsPowerOfTwo(256)); |
46 | |
47 | EXPECT(!Utils::IsPowerOfTwo(-1)); |
48 | EXPECT(!Utils::IsPowerOfTwo(-2)); |
49 | } |
50 | |
51 | VM_UNIT_TEST_CASE(ShiftForPowerOfTwo) { |
52 | EXPECT_EQ(1, Utils::ShiftForPowerOfTwo(2)); |
53 | EXPECT_EQ(2, Utils::ShiftForPowerOfTwo(4)); |
54 | EXPECT_EQ(8, Utils::ShiftForPowerOfTwo(256)); |
55 | } |
56 | |
57 | VM_UNIT_TEST_CASE(IsAligned) { |
58 | EXPECT(Utils::IsAligned(0, 1)); |
59 | EXPECT(Utils::IsAligned(1, 1)); |
60 | |
61 | EXPECT(Utils::IsAligned(0, 2)); |
62 | EXPECT(!Utils::IsAligned(1, 2)); |
63 | EXPECT(Utils::IsAligned(2, 2)); |
64 | |
65 | EXPECT(Utils::IsAligned(32, 8)); |
66 | EXPECT(!Utils::IsAligned(33, 8)); |
67 | EXPECT(Utils::IsAligned(40, 8)); |
68 | } |
69 | |
70 | VM_UNIT_TEST_CASE(RoundDown) { |
71 | EXPECT_EQ(0, Utils::RoundDown(22, 32)); |
72 | EXPECT_EQ(32, Utils::RoundDown(33, 32)); |
73 | EXPECT_EQ(32, Utils::RoundDown(63, 32)); |
74 | uword* address = reinterpret_cast<uword*>(63); |
75 | uword* rounddown_address = reinterpret_cast<uword*>(32); |
76 | EXPECT_EQ(rounddown_address, Utils::RoundDown(address, 32)); |
77 | } |
78 | |
79 | VM_UNIT_TEST_CASE(RoundUp) { |
80 | EXPECT_EQ(32, Utils::RoundUp(22, 32)); |
81 | EXPECT_EQ(64, Utils::RoundUp(33, 32)); |
82 | EXPECT_EQ(64, Utils::RoundUp(63, 32)); |
83 | uword* address = reinterpret_cast<uword*>(63); |
84 | uword* roundup_address = reinterpret_cast<uword*>(64); |
85 | EXPECT_EQ(roundup_address, Utils::RoundUp(address, 32)); |
86 | } |
87 | |
88 | VM_UNIT_TEST_CASE(RoundUpToPowerOfTwo) { |
89 | EXPECT_EQ(0U, Utils::RoundUpToPowerOfTwo(0)); |
90 | EXPECT_EQ(1U, Utils::RoundUpToPowerOfTwo(1)); |
91 | EXPECT_EQ(2U, Utils::RoundUpToPowerOfTwo(2)); |
92 | EXPECT_EQ(4U, Utils::RoundUpToPowerOfTwo(3)); |
93 | EXPECT_EQ(4U, Utils::RoundUpToPowerOfTwo(4)); |
94 | EXPECT_EQ(8U, Utils::RoundUpToPowerOfTwo(5)); |
95 | EXPECT_EQ(8U, Utils::RoundUpToPowerOfTwo(7)); |
96 | EXPECT_EQ(16U, Utils::RoundUpToPowerOfTwo(9)); |
97 | EXPECT_EQ(16U, Utils::RoundUpToPowerOfTwo(16)); |
98 | EXPECT_EQ(0x10000000U, Utils::RoundUpToPowerOfTwo(0x08765432)); |
99 | } |
100 | |
101 | VM_UNIT_TEST_CASE(CountOneBits32) { |
102 | EXPECT_EQ(0, Utils::CountOneBits32(0)); |
103 | EXPECT_EQ(1, Utils::CountOneBits32(0x00000010)); |
104 | EXPECT_EQ(1, Utils::CountOneBits32(0x00010000)); |
105 | EXPECT_EQ(1, Utils::CountOneBits32(0x10000000)); |
106 | EXPECT_EQ(4, Utils::CountOneBits32(0x10101010)); |
107 | EXPECT_EQ(8, Utils::CountOneBits32(0x03030303)); |
108 | EXPECT_EQ(32, Utils::CountOneBits32(0xFFFFFFFF)); |
109 | } |
110 | |
111 | VM_UNIT_TEST_CASE(CountOneBits64) { |
112 | EXPECT_EQ(0, Utils::CountOneBits64(DART_UINT64_C(0))); |
113 | EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x00000010))); |
114 | EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x00010000))); |
115 | EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x10000000))); |
116 | EXPECT_EQ(4, Utils::CountOneBits64(DART_UINT64_C(0x10101010))); |
117 | EXPECT_EQ(8, Utils::CountOneBits64(DART_UINT64_C(0x03030303))); |
118 | EXPECT_EQ(32, Utils::CountOneBits64(DART_UINT64_C(0xFFFFFFFF))); |
119 | EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x0000001000000010))); |
120 | EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x0001000000010000))); |
121 | EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x1000000010000000))); |
122 | EXPECT_EQ(8, Utils::CountOneBits64(DART_UINT64_C(0x1010101010101010))); |
123 | EXPECT_EQ(16, Utils::CountOneBits64(DART_UINT64_C(0x0303030303030303))); |
124 | EXPECT_EQ(64, Utils::CountOneBits64(DART_UINT64_C(0xFFFFFFFFFFFFFFFF))); |
125 | } |
126 | |
127 | VM_UNIT_TEST_CASE(CountOneBitsWord) { |
128 | EXPECT_EQ(0, Utils::CountOneBitsWord(0)); |
129 | EXPECT_EQ(1, Utils::CountOneBitsWord(0x00000010)); |
130 | EXPECT_EQ(1, Utils::CountOneBitsWord(0x00010000)); |
131 | EXPECT_EQ(1, Utils::CountOneBitsWord(0x10000000)); |
132 | EXPECT_EQ(4, Utils::CountOneBitsWord(0x10101010)); |
133 | EXPECT_EQ(8, Utils::CountOneBitsWord(0x03030303)); |
134 | EXPECT_EQ(32, Utils::CountOneBitsWord(0xFFFFFFFF)); |
135 | #if defined(ARCH_IS_64_BIT) |
136 | EXPECT_EQ(2, Utils::CountOneBitsWord(0x0000001000000010)); |
137 | EXPECT_EQ(2, Utils::CountOneBitsWord(0x0001000000010000)); |
138 | EXPECT_EQ(2, Utils::CountOneBitsWord(0x1000000010000000)); |
139 | EXPECT_EQ(8, Utils::CountOneBitsWord(0x1010101010101010)); |
140 | EXPECT_EQ(16, Utils::CountOneBitsWord(0x0303030303030303)); |
141 | EXPECT_EQ(64, Utils::CountOneBitsWord(0xFFFFFFFFFFFFFFFF)); |
142 | #endif |
143 | } |
144 | |
145 | VM_UNIT_TEST_CASE(CountTrailingZeros32) { |
146 | EXPECT_EQ(0, Utils::CountTrailingZeros32(0x1)); |
147 | EXPECT_EQ(1, Utils::CountTrailingZeros32(0x2)); |
148 | EXPECT_EQ(4, Utils::CountTrailingZeros32(0x0f0f0)); |
149 | EXPECT_EQ(31, Utils::CountTrailingZeros32(0x80000000)); |
150 | EXPECT_EQ(32, Utils::CountTrailingZeros32(0x0)); |
151 | } |
152 | |
153 | VM_UNIT_TEST_CASE(CountTrailingZeros64) { |
154 | EXPECT_EQ(0, Utils::CountTrailingZeros64(0x1)); |
155 | EXPECT_EQ(1, Utils::CountTrailingZeros64(0x2)); |
156 | EXPECT_EQ(4, Utils::CountTrailingZeros64(0x0f0f0)); |
157 | EXPECT_EQ(63, Utils::CountTrailingZeros64(0x8000000000000000LLU)); |
158 | EXPECT_EQ(64, Utils::CountTrailingZeros64(0x0)); |
159 | } |
160 | |
161 | VM_UNIT_TEST_CASE(CountLeadingZeros32) { |
162 | EXPECT_EQ(32, Utils::CountLeadingZeros32(0x0)); |
163 | EXPECT_EQ(31, Utils::CountLeadingZeros32(0x1)); |
164 | EXPECT_EQ(4, Utils::CountLeadingZeros32(0x0F0F0000)); |
165 | EXPECT_EQ(1, Utils::CountLeadingZeros32(0x7FFFFFFF)); |
166 | EXPECT_EQ(0, Utils::CountLeadingZeros32(0xFFFFFFFF)); |
167 | } |
168 | |
169 | VM_UNIT_TEST_CASE(CountLeadingZeros64) { |
170 | EXPECT_EQ(64, Utils::CountLeadingZeros64(0x0)); |
171 | EXPECT_EQ(63, Utils::CountLeadingZeros64(0x1)); |
172 | EXPECT_EQ(4, Utils::CountLeadingZeros64(0x0F0F000000000000LLU)); |
173 | EXPECT_EQ(1, Utils::CountLeadingZeros64(0x7FFFFFFFFFFFFFFFLLU)); |
174 | EXPECT_EQ(0, Utils::CountLeadingZeros64(0xFFFFFFFFFFFFFFFFLLU)); |
175 | } |
176 | |
177 | VM_UNIT_TEST_CASE(CountZerosWord) { |
178 | EXPECT_EQ(kBitsPerWord, Utils::CountTrailingZerosWord(0x0)); |
179 | EXPECT_EQ(kBitsPerWord, Utils::CountLeadingZerosWord(0x0)); |
180 | EXPECT_EQ(0, Utils::CountTrailingZerosWord(0x1)); |
181 | EXPECT_EQ(kBitsPerWord - 1, Utils::CountLeadingZerosWord(0x1)); |
182 | EXPECT_EQ(1, Utils::CountTrailingZerosWord(0x2)); |
183 | EXPECT_EQ(kBitsPerWord - 2, Utils::CountLeadingZerosWord(0x2)); |
184 | EXPECT_EQ(0, Utils::CountTrailingZerosWord(0x3)); |
185 | EXPECT_EQ(kBitsPerWord - 2, Utils::CountLeadingZerosWord(0x3)); |
186 | EXPECT_EQ(2, Utils::CountTrailingZerosWord(0x4)); |
187 | EXPECT_EQ(kBitsPerWord - 3, Utils::CountLeadingZerosWord(0x4)); |
188 | EXPECT_EQ(0, Utils::CountTrailingZerosWord(kUwordMax)); |
189 | EXPECT_EQ(0, Utils::CountLeadingZerosWord(kUwordMax)); |
190 | static const uword kTopBit = static_cast<uword>(1) << (kBitsPerWord - 1); |
191 | EXPECT_EQ(kBitsPerWord - 1, Utils::CountTrailingZerosWord(kTopBit)); |
192 | EXPECT_EQ(0, Utils::CountLeadingZerosWord(kTopBit)); |
193 | } |
194 | |
195 | VM_UNIT_TEST_CASE(ReverseBits32) { |
196 | EXPECT_EQ(0xffffffffU, Utils::ReverseBits32(0xffffffffU)); |
197 | EXPECT_EQ(0xf0000000U, Utils::ReverseBits32(0x0000000fU)); |
198 | EXPECT_EQ(0x00000001U, Utils::ReverseBits32(0x80000000U)); |
199 | EXPECT_EQ(0x22222222U, Utils::ReverseBits32(0x44444444U)); |
200 | EXPECT_EQ(0x1E6A2C48U, Utils::ReverseBits32(0x12345678U)); |
201 | } |
202 | |
203 | VM_UNIT_TEST_CASE(ReverseBits64) { |
204 | EXPECT_EQ(0xffffffffffffffffLLU, Utils::ReverseBits64(0xffffffffffffffffLLU)); |
205 | EXPECT_EQ(0xf000000000000000LLU, Utils::ReverseBits64(0x000000000000000fLLU)); |
206 | EXPECT_EQ(0x0000000000000001LLU, Utils::ReverseBits64(0x8000000000000000LLU)); |
207 | EXPECT_EQ(0x2222222222222222LLU, Utils::ReverseBits64(0x4444444444444444LLU)); |
208 | EXPECT_EQ(0x8f7b3d591e6a2c48LLU, Utils::ReverseBits64(0x123456789abcdef1LLU)); |
209 | } |
210 | |
211 | VM_UNIT_TEST_CASE(ReverseBitsWord) { |
212 | const uword kOne = static_cast<uword>(1); |
213 | const uword kTopBit = kOne << (kBitsPerWord - 1); |
214 | EXPECT_EQ(kTopBit, Utils::ReverseBitsWord(kOne)); |
215 | EXPECT_EQ(kOne, Utils::ReverseBitsWord(kTopBit)); |
216 | } |
217 | |
218 | VM_UNIT_TEST_CASE(IsInt) { |
219 | EXPECT(Utils::IsInt(8, 16)); |
220 | EXPECT(Utils::IsInt(8, 127)); |
221 | EXPECT(Utils::IsInt(8, -128)); |
222 | EXPECT(!Utils::IsInt(8, 255)); |
223 | EXPECT(Utils::IsInt(16, 16)); |
224 | EXPECT(!Utils::IsInt(16, 65535)); |
225 | EXPECT(Utils::IsInt(16, 32767)); |
226 | EXPECT(Utils::IsInt(16, -32768)); |
227 | EXPECT(Utils::IsInt(32, 16LL)); |
228 | EXPECT(Utils::IsInt(32, 2147483647LL)); |
229 | EXPECT(Utils::IsInt(32, -2147483648LL)); |
230 | EXPECT(!Utils::IsInt(32, 4294967295LL)); |
231 | } |
232 | |
233 | VM_UNIT_TEST_CASE(IsUint) { |
234 | EXPECT(Utils::IsUint(8, 16)); |
235 | EXPECT(Utils::IsUint(8, 0)); |
236 | EXPECT(Utils::IsUint(8, 255)); |
237 | EXPECT(!Utils::IsUint(8, 256)); |
238 | EXPECT(Utils::IsUint(16, 16)); |
239 | EXPECT(Utils::IsUint(16, 0)); |
240 | EXPECT(Utils::IsUint(16, 65535)); |
241 | EXPECT(!Utils::IsUint(16, 65536)); |
242 | EXPECT(Utils::IsUint(32, 16LL)); |
243 | EXPECT(Utils::IsUint(32, 0LL)); |
244 | EXPECT(Utils::IsUint(32, 4294967295LL)); |
245 | EXPECT(!Utils::IsUint(32, 4294967296LL)); |
246 | } |
247 | |
248 | VM_UNIT_TEST_CASE(IsAbsoluteUint) { |
249 | EXPECT(Utils::IsAbsoluteUint(8, 16)); |
250 | EXPECT(Utils::IsAbsoluteUint(8, 0)); |
251 | EXPECT(Utils::IsAbsoluteUint(8, -128)); |
252 | EXPECT(Utils::IsAbsoluteUint(8, 255)); |
253 | EXPECT(!Utils::IsAbsoluteUint(8, 256)); |
254 | EXPECT(Utils::IsAbsoluteUint(16, 16)); |
255 | EXPECT(Utils::IsAbsoluteUint(16, 0)); |
256 | EXPECT(Utils::IsAbsoluteUint(16, 65535)); |
257 | EXPECT(Utils::IsAbsoluteUint(16, -32768)); |
258 | EXPECT(!Utils::IsAbsoluteUint(16, 65536)); |
259 | EXPECT(Utils::IsAbsoluteUint(32, 16LL)); |
260 | EXPECT(Utils::IsAbsoluteUint(32, 0LL)); |
261 | EXPECT(Utils::IsAbsoluteUint(32, -2147483648LL)); |
262 | EXPECT(Utils::IsAbsoluteUint(32, 4294967295LL)); |
263 | EXPECT(!Utils::IsAbsoluteUint(32, 4294967296LL)); |
264 | } |
265 | |
266 | VM_UNIT_TEST_CASE(LowBits) { |
267 | EXPECT_EQ(0xff00, Utils::Low16Bits(0xffff00)); |
268 | EXPECT_EQ(0xff, Utils::High16Bits(0xffff00)); |
269 | EXPECT_EQ(0xff00, Utils::Low32Bits(0xff0000ff00LL)); |
270 | EXPECT_EQ(0xff, Utils::High32Bits(0xff0000ff00LL)); |
271 | EXPECT_EQ(0x00ff0000ff00LL, Utils::LowHighTo64Bits(0xff00, 0x00ff)); |
272 | } |
273 | |
274 | VM_UNIT_TEST_CASE(Endianity) { |
275 | uint16_t value16be = Utils::HostToBigEndian16(0xf1); |
276 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16be)[0]); |
277 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16be)[1]); |
278 | |
279 | uint16_t value16le = Utils::HostToLittleEndian16(0xf1); |
280 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16le)[0]); |
281 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16le)[1]); |
282 | |
283 | uint32_t value32be = Utils::HostToBigEndian32(0xf1f2); |
284 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[0]); |
285 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[1]); |
286 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32be)[2]); |
287 | EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32be)[3]); |
288 | EXPECT_EQ(0xf1f2u, Utils::BigEndianToHost32(value32be)); |
289 | |
290 | uint32_t value32le = Utils::HostToLittleEndian32(0xf1f2); |
291 | EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32le)[0]); |
292 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32le)[1]); |
293 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[2]); |
294 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[3]); |
295 | |
296 | uint64_t value64be = Utils::HostToBigEndian64(0xf1f2f3f4); |
297 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[0]); |
298 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[1]); |
299 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[2]); |
300 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[3]); |
301 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64be)[4]); |
302 | EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64be)[5]); |
303 | EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64be)[6]); |
304 | EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64be)[7]); |
305 | |
306 | uint64_t value64le = Utils::HostToLittleEndian64(0xf1f2f3f4); |
307 | EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64le)[0]); |
308 | EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]); |
309 | EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]); |
310 | EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]); |
311 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]); |
312 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]); |
313 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]); |
314 | EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]); |
315 | EXPECT_EQ(0xf1f2f3f4ul, Utils::LittleEndianToHost64(value64le)); |
316 | } |
317 | |
318 | VM_UNIT_TEST_CASE(DoublesBitEqual) { |
319 | EXPECT(Utils::DoublesBitEqual(1.0, 1.0)); |
320 | EXPECT(!Utils::DoublesBitEqual(1.0, -1.0)); |
321 | EXPECT(Utils::DoublesBitEqual(0.0, 0.0)); |
322 | EXPECT(!Utils::DoublesBitEqual(0.0, -0.0)); |
323 | EXPECT(Utils::DoublesBitEqual(NAN, NAN)); |
324 | } |
325 | |
326 | VM_UNIT_TEST_CASE(NBitMask) { |
327 | #if defined(ARCH_IS_64_BIT) |
328 | EXPECT_EQ(0ull, Utils::NBitMask(0)); |
329 | EXPECT_EQ(0x1ull, Utils::NBitMask(1)); |
330 | EXPECT_EQ(0x3ull, Utils::NBitMask(2)); |
331 | EXPECT_EQ(0xfull, Utils::NBitMask(4)); |
332 | EXPECT_EQ(0xffull, Utils::NBitMask(8)); |
333 | EXPECT_EQ(0xffffull, Utils::NBitMask(16)); |
334 | EXPECT_EQ(0x1ffffull, Utils::NBitMask(17)); |
335 | EXPECT_EQ(0x7fffffffull, Utils::NBitMask(31)); |
336 | EXPECT_EQ(0xffffffffull, Utils::NBitMask(32)); |
337 | EXPECT_EQ(0x1ffffffffull, Utils::NBitMask(33)); |
338 | EXPECT_EQ(0x7fffffffffffffffull, Utils::NBitMask(kBitsPerWord - 1)); |
339 | EXPECT_EQ(0xffffffffffffffffull, Utils::NBitMask(kBitsPerWord)); |
340 | #else |
341 | EXPECT_EQ(0u, Utils::NBitMask(0)); |
342 | EXPECT_EQ(0x1u, Utils::NBitMask(1)); |
343 | EXPECT_EQ(0x3u, Utils::NBitMask(2)); |
344 | EXPECT_EQ(0xfu, Utils::NBitMask(4)); |
345 | EXPECT_EQ(0xffu, Utils::NBitMask(8)); |
346 | EXPECT_EQ(0xffffu, Utils::NBitMask(16)); |
347 | EXPECT_EQ(0x1ffffu, Utils::NBitMask(17)); |
348 | EXPECT_EQ(0x7fffffffu, Utils::NBitMask(kBitsPerWord - 1)); |
349 | EXPECT_EQ(0xffffffffu, Utils::NBitMask(kBitsPerWord)); |
350 | #endif |
351 | } |
352 | |
353 | } // namespace dart |
354 | |