Flutter Engine
The Flutter Engine
utils_test.cc
Go to the documentation of this file.
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 "platform/globals.h"
8#include "vm/unit_test.h"
9
10namespace dart {
11
12VM_UNIT_TEST_CASE(StringHash) {
13 auto hash_created_string = [](intptr_t length,
14 intptr_t misalignment) -> uint32_t {
15 const intptr_t capacity = length + misalignment + kInt32Size;
16 char* str = new char[capacity];
17 const intptr_t alloc_misalignment =
18 reinterpret_cast<intptr_t>(str) % kInt32Size;
19 const intptr_t first_aligned_position =
20 alloc_misalignment > 0 ? kInt32Size - alloc_misalignment : 0;
21 const intptr_t start = first_aligned_position + misalignment;
22 for (intptr_t n = 0; n < start; n++) {
23 str[n] = 0xFF;
24 }
25 for (intptr_t n = 0; n < length; n++) {
26 // Fill the important string positions with uppercase letters.
27 str[start + n] = 0x40 + (n % 26);
28 }
29 for (intptr_t n = start + length; n < capacity; n++) {
30 str[n] = 0xFF;
31 }
32 const uint32_t hash = Utils::StringHash(str + start, length);
33 delete[] str;
34 return hash;
35 };
36
37 const intptr_t kMaxLength = 100;
38 ASSERT(kMaxLength >= kInt64Size);
39 uint32_t last_hash = hash_created_string(0, 0);
40 bool identical_hashes = true;
41 // Check the same string at different (mis)alignments has the same hash.
42 for (intptr_t len = 0; len < kMaxLength; len++) {
43 const uint32_t hash = hash_created_string(len, 0);
44 for (intptr_t misalignment = 1; misalignment < kInt64Size; misalignment++) {
45 EXPECT_EQ(hash, hash_created_string(len, misalignment));
46 }
47 if (hash != last_hash) {
48 identical_hashes = false;
49 }
50 last_hash = hash;
51 }
52 // Make sure at least some of the hashes were different from each other.
53 EXPECT(!identical_hashes);
54}
55
57 EXPECT_EQ(0, Utils::Minimum(0, 1));
58 EXPECT_EQ(0, Utils::Minimum(1, 0));
59
60 EXPECT_EQ(1, Utils::Minimum(1, 2));
61 EXPECT_EQ(1, Utils::Minimum(2, 1));
62
63 EXPECT_EQ(-1, Utils::Minimum(-1, 1));
64 EXPECT_EQ(-1, Utils::Minimum(1, -1));
65
66 EXPECT_EQ(-2, Utils::Minimum(-1, -2));
67 EXPECT_EQ(-2, Utils::Minimum(-2, -1));
68}
69
71 EXPECT_EQ(1, Utils::Maximum(0, 1));
72 EXPECT_EQ(1, Utils::Maximum(1, 0));
73
74 EXPECT_EQ(2, Utils::Maximum(1, 2));
75 EXPECT_EQ(2, Utils::Maximum(2, 1));
76
77 EXPECT_EQ(1, Utils::Maximum(-1, 1));
78 EXPECT_EQ(1, Utils::Maximum(1, -1));
79
80 EXPECT_EQ(-1, Utils::Maximum(-1, -2));
81 EXPECT_EQ(-1, Utils::Maximum(-2, -1));
82}
83
84VM_UNIT_TEST_CASE(IsPowerOfTwo) {
91
94}
95
96VM_UNIT_TEST_CASE(ShiftForPowerOfTwo) {
97 EXPECT_EQ(1, Utils::ShiftForPowerOfTwo(2));
98 EXPECT_EQ(2, Utils::ShiftForPowerOfTwo(4));
99 EXPECT_EQ(8, Utils::ShiftForPowerOfTwo(256));
100}
101
105
107 EXPECT(!Utils::IsAligned(1, 2));
109
110 EXPECT(Utils::IsAligned(32, 8));
111 EXPECT(!Utils::IsAligned(33, 8));
112 EXPECT(Utils::IsAligned(40, 8));
113
114 EXPECT(!Utils::IsAligned(0, 8, 4));
115 EXPECT(!Utils::IsAligned(1, 8, 4));
116 EXPECT(Utils::IsAligned(4, 8, 4));
117 EXPECT(!Utils::IsAligned(8, 8, 4));
118 EXPECT(!Utils::IsAligned(9, 8, 4));
119 EXPECT(Utils::IsAligned(12, 8, 4));
120}
121
123 EXPECT_EQ(0, Utils::RoundDown(22, 32));
124 EXPECT_EQ(32, Utils::RoundDown(33, 32));
125 EXPECT_EQ(32, Utils::RoundDown(63, 32));
126 uword* address = reinterpret_cast<uword*>(63);
127 uword* rounddown_address = reinterpret_cast<uword*>(32);
128 EXPECT_EQ(rounddown_address, Utils::RoundDown(address, 32));
129}
130
132 EXPECT_EQ(32, Utils::RoundUp(22, 32));
133 EXPECT_EQ(64, Utils::RoundUp(33, 32));
134 EXPECT_EQ(64, Utils::RoundUp(63, 32));
135 uword* address = reinterpret_cast<uword*>(63);
136 uword* roundup_address = reinterpret_cast<uword*>(64);
137 EXPECT_EQ(roundup_address, Utils::RoundUp(address, 32));
138
139 EXPECT_EQ(4, Utils::RoundUp(0, 8, 4));
140 EXPECT_EQ(4, Utils::RoundUp(1, 8, 4));
141 EXPECT_EQ(4, Utils::RoundUp(4, 8, 4));
142 EXPECT_EQ(12, Utils::RoundUp(8, 8, 4));
143 EXPECT_EQ(12, Utils::RoundUp(9, 8, 4));
144 EXPECT_EQ(12, Utils::RoundUp(12, 8, 4));
145}
146
147VM_UNIT_TEST_CASE(RoundUpToPowerOfTwo) {
148 EXPECT_EQ(0U, Utils::RoundUpToPowerOfTwo(0));
149 EXPECT_EQ(1U, Utils::RoundUpToPowerOfTwo(1));
150 EXPECT_EQ(2U, Utils::RoundUpToPowerOfTwo(2));
151 EXPECT_EQ(4U, Utils::RoundUpToPowerOfTwo(3));
152 EXPECT_EQ(4U, Utils::RoundUpToPowerOfTwo(4));
153 EXPECT_EQ(8U, Utils::RoundUpToPowerOfTwo(5));
154 EXPECT_EQ(8U, Utils::RoundUpToPowerOfTwo(7));
155 EXPECT_EQ(16U, Utils::RoundUpToPowerOfTwo(9));
156 EXPECT_EQ(16U, Utils::RoundUpToPowerOfTwo(16));
157 EXPECT_EQ(0x10000000U, Utils::RoundUpToPowerOfTwo(0x08765432));
158}
159
160VM_UNIT_TEST_CASE(CountOneBits32) {
161 EXPECT_EQ(0, Utils::CountOneBits32(0));
162 EXPECT_EQ(1, Utils::CountOneBits32(0x00000010));
163 EXPECT_EQ(1, Utils::CountOneBits32(0x00010000));
164 EXPECT_EQ(1, Utils::CountOneBits32(0x10000000));
165 EXPECT_EQ(4, Utils::CountOneBits32(0x10101010));
166 EXPECT_EQ(8, Utils::CountOneBits32(0x03030303));
167 EXPECT_EQ(32, Utils::CountOneBits32(0xFFFFFFFF));
168}
169
170VM_UNIT_TEST_CASE(CountOneBits64) {
171 EXPECT_EQ(0, Utils::CountOneBits64(DART_UINT64_C(0)));
172 EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x00000010)));
173 EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x00010000)));
174 EXPECT_EQ(1, Utils::CountOneBits64(DART_UINT64_C(0x10000000)));
175 EXPECT_EQ(4, Utils::CountOneBits64(DART_UINT64_C(0x10101010)));
176 EXPECT_EQ(8, Utils::CountOneBits64(DART_UINT64_C(0x03030303)));
177 EXPECT_EQ(32, Utils::CountOneBits64(DART_UINT64_C(0xFFFFFFFF)));
178 EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x0000001000000010)));
179 EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x0001000000010000)));
180 EXPECT_EQ(2, Utils::CountOneBits64(DART_UINT64_C(0x1000000010000000)));
181 EXPECT_EQ(8, Utils::CountOneBits64(DART_UINT64_C(0x1010101010101010)));
182 EXPECT_EQ(16, Utils::CountOneBits64(DART_UINT64_C(0x0303030303030303)));
183 EXPECT_EQ(64, Utils::CountOneBits64(DART_UINT64_C(0xFFFFFFFFFFFFFFFF)));
184}
185
186VM_UNIT_TEST_CASE(CountOneBitsWord) {
187 EXPECT_EQ(0, Utils::CountOneBitsWord(0));
188 EXPECT_EQ(1, Utils::CountOneBitsWord(0x00000010));
189 EXPECT_EQ(1, Utils::CountOneBitsWord(0x00010000));
190 EXPECT_EQ(1, Utils::CountOneBitsWord(0x10000000));
191 EXPECT_EQ(4, Utils::CountOneBitsWord(0x10101010));
192 EXPECT_EQ(8, Utils::CountOneBitsWord(0x03030303));
193 EXPECT_EQ(32, Utils::CountOneBitsWord(0xFFFFFFFF));
194#if defined(ARCH_IS_64_BIT)
195 EXPECT_EQ(2, Utils::CountOneBitsWord(0x0000001000000010));
196 EXPECT_EQ(2, Utils::CountOneBitsWord(0x0001000000010000));
197 EXPECT_EQ(2, Utils::CountOneBitsWord(0x1000000010000000));
198 EXPECT_EQ(8, Utils::CountOneBitsWord(0x1010101010101010));
199 EXPECT_EQ(16, Utils::CountOneBitsWord(0x0303030303030303));
200 EXPECT_EQ(64, Utils::CountOneBitsWord(0xFFFFFFFFFFFFFFFF));
201#endif
202}
203
204VM_UNIT_TEST_CASE(CountTrailingZeros32) {
205 EXPECT_EQ(0, Utils::CountTrailingZeros32(0x1));
206 EXPECT_EQ(1, Utils::CountTrailingZeros32(0x2));
207 EXPECT_EQ(4, Utils::CountTrailingZeros32(0x0f0f0));
208 EXPECT_EQ(31, Utils::CountTrailingZeros32(0x80000000));
209 EXPECT_EQ(32, Utils::CountTrailingZeros32(0x0));
210}
211
212VM_UNIT_TEST_CASE(CountTrailingZeros64) {
213 EXPECT_EQ(0, Utils::CountTrailingZeros64(0x1));
214 EXPECT_EQ(1, Utils::CountTrailingZeros64(0x2));
215 EXPECT_EQ(4, Utils::CountTrailingZeros64(0x0f0f0));
216 EXPECT_EQ(63, Utils::CountTrailingZeros64(0x8000000000000000LLU));
217 EXPECT_EQ(64, Utils::CountTrailingZeros64(0x0));
218}
219
220VM_UNIT_TEST_CASE(CountLeadingZeros32) {
221 EXPECT_EQ(32, Utils::CountLeadingZeros32(0x0));
222 EXPECT_EQ(31, Utils::CountLeadingZeros32(0x1));
223 EXPECT_EQ(4, Utils::CountLeadingZeros32(0x0F0F0000));
224 EXPECT_EQ(1, Utils::CountLeadingZeros32(0x7FFFFFFF));
225 EXPECT_EQ(0, Utils::CountLeadingZeros32(0xFFFFFFFF));
226}
227
228VM_UNIT_TEST_CASE(CountLeadingZeros64) {
229 EXPECT_EQ(64, Utils::CountLeadingZeros64(0x0));
230 EXPECT_EQ(63, Utils::CountLeadingZeros64(0x1));
231 EXPECT_EQ(4, Utils::CountLeadingZeros64(0x0F0F000000000000LLU));
232 EXPECT_EQ(1, Utils::CountLeadingZeros64(0x7FFFFFFFFFFFFFFFLLU));
233 EXPECT_EQ(0, Utils::CountLeadingZeros64(0xFFFFFFFFFFFFFFFFLLU));
234}
235
236VM_UNIT_TEST_CASE(CountZerosWord) {
239 EXPECT_EQ(0, Utils::CountTrailingZerosWord(0x1));
240 EXPECT_EQ(kBitsPerWord - 1, Utils::CountLeadingZerosWord(0x1));
241 EXPECT_EQ(1, Utils::CountTrailingZerosWord(0x2));
242 EXPECT_EQ(kBitsPerWord - 2, Utils::CountLeadingZerosWord(0x2));
243 EXPECT_EQ(0, Utils::CountTrailingZerosWord(0x3));
244 EXPECT_EQ(kBitsPerWord - 2, Utils::CountLeadingZerosWord(0x3));
245 EXPECT_EQ(2, Utils::CountTrailingZerosWord(0x4));
246 EXPECT_EQ(kBitsPerWord - 3, Utils::CountLeadingZerosWord(0x4));
249 const uword kTopBit = static_cast<uword>(1) << (kBitsPerWord - 1);
250 EXPECT_EQ(kBitsPerWord - 1, Utils::CountTrailingZerosWord(kTopBit));
251 EXPECT_EQ(0, Utils::CountLeadingZerosWord(kTopBit));
252}
253
254VM_UNIT_TEST_CASE(ReverseBits32) {
255 EXPECT_EQ(0xffffffffU, Utils::ReverseBits32(0xffffffffU));
256 EXPECT_EQ(0xf0000000U, Utils::ReverseBits32(0x0000000fU));
257 EXPECT_EQ(0x00000001U, Utils::ReverseBits32(0x80000000U));
258 EXPECT_EQ(0x22222222U, Utils::ReverseBits32(0x44444444U));
259 EXPECT_EQ(0x1E6A2C48U, Utils::ReverseBits32(0x12345678U));
260}
261
262VM_UNIT_TEST_CASE(ReverseBits64) {
263 EXPECT_EQ(0xffffffffffffffffLLU, Utils::ReverseBits64(0xffffffffffffffffLLU));
264 EXPECT_EQ(0xf000000000000000LLU, Utils::ReverseBits64(0x000000000000000fLLU));
265 EXPECT_EQ(0x0000000000000001LLU, Utils::ReverseBits64(0x8000000000000000LLU));
266 EXPECT_EQ(0x2222222222222222LLU, Utils::ReverseBits64(0x4444444444444444LLU));
267 EXPECT_EQ(0x8f7b3d591e6a2c48LLU, Utils::ReverseBits64(0x123456789abcdef1LLU));
268}
269
270VM_UNIT_TEST_CASE(ReverseBitsWord) {
271 const uword kOne = static_cast<uword>(1);
272 const uword kTopBit = kOne << (kBitsPerWord - 1);
273 EXPECT_EQ(kTopBit, Utils::ReverseBitsWord(kOne));
274 EXPECT_EQ(kOne, Utils::ReverseBitsWord(kTopBit));
275}
276
278 EXPECT(Utils::IsInt(8, 16));
279 EXPECT(Utils::IsInt(8, 16U));
280 EXPECT(Utils::IsInt(8, 127));
281 EXPECT(Utils::IsInt(8, 127U));
282 EXPECT(Utils::IsInt(8, -128));
283 EXPECT(!Utils::IsInt(8, static_cast<unsigned int>(-128)));
284 EXPECT(!Utils::IsInt(8, 255));
285 EXPECT(!Utils::IsInt(8, 255U));
286 EXPECT(Utils::IsInt(16, 16));
287 EXPECT(Utils::IsInt(16, 16U));
288 EXPECT(!Utils::IsInt(16, 65535));
289 EXPECT(!Utils::IsInt(16, 65535U));
290 EXPECT(Utils::IsInt(16, 32767));
291 EXPECT(Utils::IsInt(16, 32767U));
292 EXPECT(Utils::IsInt(16, -32768));
293 EXPECT(!Utils::IsInt(16, static_cast<unsigned int>(-32768)));
294 EXPECT(Utils::IsInt(32, 16LL));
295 EXPECT(Utils::IsInt(32, 16ULL));
296 EXPECT(Utils::IsInt(32, 2147483647LL));
297 EXPECT(Utils::IsInt(32, 2147483647ULL));
298 EXPECT(Utils::IsInt(32, -2147483648LL));
299 EXPECT(!Utils::IsInt(32, static_cast<uint64_t>(-2147483648LL)));
300 EXPECT(!Utils::IsInt(32, 4294967295LL));
301 EXPECT(!Utils::IsInt(32, 4294967295ULL));
302}
303
305 EXPECT(Utils::IsUint(8, 16));
306 EXPECT(Utils::IsUint(8, 16U));
307 EXPECT(Utils::IsUint(8, 0));
308 EXPECT(Utils::IsUint(8, 0U));
309 EXPECT(Utils::IsUint(8, 255));
310 EXPECT(Utils::IsUint(8, 255U));
311 EXPECT(!Utils::IsUint(8, 256));
312 EXPECT(!Utils::IsUint(8, 256U));
313 EXPECT(Utils::IsUint(16, 16));
314 EXPECT(Utils::IsUint(16, 16U));
315 EXPECT(Utils::IsUint(16, 0));
316 EXPECT(Utils::IsUint(16, 0U));
317 EXPECT(Utils::IsUint(16, 65535));
318 EXPECT(Utils::IsUint(16, 65535U));
319 EXPECT(!Utils::IsUint(16, 65536));
320 EXPECT(!Utils::IsUint(16, 65536U));
321 EXPECT(Utils::IsUint(32, 16LL));
322 EXPECT(Utils::IsUint(32, 16ULL));
323 EXPECT(Utils::IsUint(32, 0LL));
324 EXPECT(Utils::IsUint(32, 0ULL));
325 EXPECT(Utils::IsUint(32, 4294967295LL));
326 EXPECT(Utils::IsUint(32, 4294967295ULL));
327 EXPECT(!Utils::IsUint(32, 4294967296LL));
328 EXPECT(!Utils::IsUint(32, 4294967296ULL));
329}
330
331VM_UNIT_TEST_CASE(MagnitudeIsUint) {
337 EXPECT(!Utils::MagnitudeIsUint(8, static_cast<unsigned int>(-128)));
343 EXPECT(Utils::MagnitudeIsUint(12, 4095U));
344 EXPECT(Utils::MagnitudeIsUint(12, -4095));
345 EXPECT(!Utils::MagnitudeIsUint(12, static_cast<unsigned int>(-4095)));
346 EXPECT(!Utils::MagnitudeIsUint(12, 4096));
347 EXPECT(!Utils::MagnitudeIsUint(12, 4096U));
348 EXPECT(!Utils::MagnitudeIsUint(12, -4096));
349 EXPECT(!Utils::MagnitudeIsUint(12, static_cast<unsigned int>(-4096)));
354 EXPECT(Utils::MagnitudeIsUint(16, 65535));
355 EXPECT(Utils::MagnitudeIsUint(16, 65535U));
356 EXPECT(Utils::MagnitudeIsUint(16, -32768));
357 EXPECT(!Utils::MagnitudeIsUint(16, static_cast<unsigned int>(-32768)));
358 EXPECT(!Utils::MagnitudeIsUint(16, 65536));
359 EXPECT(!Utils::MagnitudeIsUint(16, 65536U));
361 EXPECT(Utils::MagnitudeIsUint(32, 16ULL));
364 EXPECT(Utils::MagnitudeIsUint(32, -2147483648LL));
365 EXPECT(!Utils::MagnitudeIsUint(32, static_cast<uint64_t>(-2147483648LL)));
366 EXPECT(Utils::MagnitudeIsUint(32, 4294967295LL));
367 EXPECT(Utils::MagnitudeIsUint(32, 4294967295ULL));
368 EXPECT(!Utils::MagnitudeIsUint(32, 4294967296LL));
369 EXPECT(!Utils::MagnitudeIsUint(32, 4294967296ULL));
370}
371
373 EXPECT_EQ(0xff00, Utils::Low16Bits(0xffff00));
374 EXPECT_EQ(0xff, Utils::High16Bits(0xffff00));
375 EXPECT_EQ(0xff00, Utils::Low32Bits(0xff0000ff00LL));
376 EXPECT_EQ(0xff, Utils::High32Bits(0xff0000ff00LL));
377 EXPECT_EQ(0x00ff0000ff00LL, Utils::LowHighTo64Bits(0xff00, 0x00ff));
378}
379
381 uint16_t value16be = Utils::HostToBigEndian16(0xf1);
382 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16be)[0]);
383 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16be)[1]);
384
385 uint16_t value16le = Utils::HostToLittleEndian16(0xf1);
386 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16le)[0]);
387 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16le)[1]);
388
389 uint32_t value32be = Utils::HostToBigEndian32(0xf1f2);
390 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[0]);
391 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[1]);
392 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32be)[2]);
393 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32be)[3]);
394 EXPECT_EQ(0xf1f2u, Utils::BigEndianToHost32(value32be));
395
396 uint32_t value32le = Utils::HostToLittleEndian32(0xf1f2);
397 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32le)[0]);
398 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32le)[1]);
399 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[2]);
400 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[3]);
401
402 uint64_t value64be = Utils::HostToBigEndian64(0xf1f2f3f4);
403 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[0]);
404 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[1]);
405 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[2]);
406 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[3]);
407 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64be)[4]);
408 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64be)[5]);
409 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64be)[6]);
410 EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64be)[7]);
411
412 uint64_t value64le = Utils::HostToLittleEndian64(0xf1f2f3f4);
413 EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64le)[0]);
414 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]);
415 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]);
416 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]);
417 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]);
418 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]);
419 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]);
420 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]);
421 EXPECT_EQ(0xf1f2f3f4ul, Utils::LittleEndianToHost64(value64le));
422}
423
424VM_UNIT_TEST_CASE(DoublesBitEqual) {
426 EXPECT(!Utils::DoublesBitEqual(1.0, -1.0));
428 EXPECT(!Utils::DoublesBitEqual(0.0, -0.0));
430}
431
433#if defined(ARCH_IS_64_BIT)
434 EXPECT_EQ(0ull, Utils::NBitMask(0));
435 EXPECT_EQ(0x1ull, Utils::NBitMask(1));
436 EXPECT_EQ(0x3ull, Utils::NBitMask(2));
437 EXPECT_EQ(0xfull, Utils::NBitMask(4));
438 EXPECT_EQ(0xffull, Utils::NBitMask(8));
439 EXPECT_EQ(0xffffull, Utils::NBitMask(16));
440 EXPECT_EQ(0x1ffffull, Utils::NBitMask(17));
441 EXPECT_EQ(0x7fffffffull, Utils::NBitMask(31));
442 EXPECT_EQ(0xffffffffull, Utils::NBitMask(32));
443 EXPECT_EQ(0x1ffffffffull, Utils::NBitMask(33));
444 EXPECT_EQ(0x7fffffffffffffffull, Utils::NBitMask(kBitsPerWord - 1));
445 EXPECT_EQ(0xffffffffffffffffull, Utils::NBitMask(kBitsPerWord));
446#else
447 EXPECT_EQ(0u, Utils::NBitMask(0));
448 EXPECT_EQ(0x1u, Utils::NBitMask(1));
449 EXPECT_EQ(0x3u, Utils::NBitMask(2));
450 EXPECT_EQ(0xfu, Utils::NBitMask(4));
451 EXPECT_EQ(0xffu, Utils::NBitMask(8));
452 EXPECT_EQ(0xffffu, Utils::NBitMask(16));
453 EXPECT_EQ(0x1ffffu, Utils::NBitMask(17));
454 EXPECT_EQ(0x7fffffffu, Utils::NBitMask(kBitsPerWord - 1));
455 EXPECT_EQ(0xffffffffu, Utils::NBitMask(kBitsPerWord));
456#endif
457}
458
459} // namespace dart
static uint32_t hash(const SkShaderBase::GradientInfo &v)
#define EXPECT(type, expectedAlignment, expectedSize)
static uint64_t HostToBigEndian64(uint64_t host_value)
Definition: utils_android.h:24
static bool IsInt(intptr_t N, T value)
Definition: utils.h:313
static int CountLeadingZeros64(uint64_t x)
Definition: utils.h:229
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
Definition: utils.h:135
static uint64_t HostToLittleEndian64(uint64_t host_value)
Definition: utils_android.h:36
static int32_t Low32Bits(int64_t value)
Definition: utils.h:369
static int32_t Low16Bits(int32_t value)
Definition: utils.h:361
static uword ReverseBitsWord(uword x)
Definition: utils.h:292
static constexpr int CountOneBitsWord(uword x)
Definition: utils.h:176
static constexpr T Maximum(T x, T y)
Definition: utils.h:41
static bool MagnitudeIsUint(intptr_t N, T value)
Definition: utils.h:352
static constexpr int ShiftForPowerOfTwo(T x)
Definition: utils.h:81
static int CountLeadingZeros32(uint32_t x)
Definition: utils.h:219
static int CountTrailingZeros64(uint64_t x)
Definition: utils.h:264
static constexpr T NBitMask(size_t n)
Definition: utils.h:548
static uint64_t LittleEndianToHost64(uint64_t le_value)
Definition: utils.h:521
static int CountTrailingZeros32(uint32_t x)
Definition: utils.h:255
static int32_t High32Bits(int64_t value)
Definition: utils.h:373
static T Minimum(T x, T y)
Definition: utils.h:36
static uint16_t HostToLittleEndian16(uint16_t host_value)
Definition: utils_android.h:28
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition: utils.h:120
static uint32_t StringHash(const void *data, int length)
Definition: utils.cc:114
static int CountLeadingZerosWord(uword x)
Definition: utils.h:247
static int64_t LowHighTo64Bits(uint32_t low, int32_t high)
Definition: utils.h:377
static uint32_t BigEndianToHost32(uint32_t be_value)
Definition: utils.h:518
static constexpr int CountOneBits32(uint32_t x)
Definition: utils.h:160
static bool IsUint(intptr_t N, T value)
Definition: utils.h:328
static int CountTrailingZerosWord(uword x)
Definition: utils.h:281
static uint32_t HostToLittleEndian32(uint32_t host_value)
Definition: utils_android.h:32
static constexpr int CountOneBits64(uint64_t x)
Definition: utils.h:148
static constexpr T RoundDown(T x, intptr_t alignment)
Definition: utils.h:108
static int32_t High16Bits(int32_t value)
Definition: utils.h:365
static constexpr bool IsAligned(T x, uintptr_t alignment, uintptr_t offset=0)
Definition: utils.h:92
static bool DoublesBitEqual(const double a, const double b)
Definition: utils.h:525
static uint16_t HostToBigEndian16(uint16_t host_value)
Definition: utils_android.h:16
static uint32_t HostToBigEndian32(uint32_t host_value)
Definition: utils_android.h:20
static uint32_t ReverseBits32(uint32_t x)
Definition: utils.cc:27
static uint64_t ReverseBits64(uint64_t x)
Definition: utils.cc:17
static constexpr bool IsPowerOfTwo(T x)
Definition: utils.h:76
#define ASSERT(E)
size_t length
Definition: dart_vm.cc:33
constexpr intptr_t kBitsPerWord
Definition: globals.h:514
constexpr intptr_t kInt64Size
Definition: globals.h:453
constexpr uword kUwordMax
Definition: globals.h:519
uintptr_t uword
Definition: globals.h:501
constexpr intptr_t kInt32Size
Definition: globals.h:450
VM_UNIT_TEST_CASE(DirectoryCurrentNoScope)
static void RoundUp(Vector< char > buffer, int *length, int *decimal_point)
Definition: fixed-dtoa.cc:189
#define DART_UINT64_C(x)
Definition: globals.h:434