OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef PLATFORM_UTILS_WIN_H_ | 5 #ifndef PLATFORM_UTILS_WIN_H_ |
6 #define PLATFORM_UTILS_WIN_H_ | 6 #define PLATFORM_UTILS_WIN_H_ |
7 | 7 |
8 #include <intrin.h> | 8 #include <intrin.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
| 13 inline int Utils::CountLeadingZeros(uword x) { |
| 14 unsigned long result; // NOLINT |
| 15 #if defined(ARCH_IS_32_BIT) |
| 16 _BitScanForward(&result, x); |
| 17 #elif defined(ARCH_IS_64_BIT) |
| 18 _BitScanForward64(&result, x); |
| 19 #else |
| 20 #error Architecture is not 32-bit or 64-bit. |
| 21 #endif |
| 22 return static_cast<int>(result); |
| 23 } |
| 24 |
| 25 |
13 inline int Utils::CountTrailingZeros(uword x) { | 26 inline int Utils::CountTrailingZeros(uword x) { |
14 unsigned long result; // NOLINT | 27 unsigned long result; // NOLINT |
15 #if defined(ARCH_IS_32_BIT) | 28 #if defined(ARCH_IS_32_BIT) |
16 _BitScanReverse(&result, x); | 29 _BitScanReverse(&result, x); |
17 #elif defined(ARCH_IS_64_BIT) | 30 #elif defined(ARCH_IS_64_BIT) |
18 _BitScanReverse64(&result, x); | 31 _BitScanReverse64(&result, x); |
19 #else | 32 #else |
20 #error Architecture is not 32-bit or 64-bit. | 33 #error Architecture is not 32-bit or 64-bit. |
21 #endif | 34 #endif |
22 return static_cast<int>(result); | 35 return static_cast<int>(result); |
23 }; | 36 } |
24 | 37 |
25 | 38 |
26 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { | 39 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { |
27 return _byteswap_ushort(value); | 40 return _byteswap_ushort(value); |
28 } | 41 } |
29 | 42 |
30 | 43 |
31 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { | 44 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { |
32 return _byteswap_ulong(value); | 45 return _byteswap_ulong(value); |
33 } | 46 } |
(...skipping 14 matching lines...) Expand all Loading... |
48 } | 61 } |
49 | 62 |
50 | 63 |
51 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { | 64 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { |
52 return value; | 65 return value; |
53 } | 66 } |
54 | 67 |
55 } // namespace dart | 68 } // namespace dart |
56 | 69 |
57 #endif // PLATFORM_UTILS_WIN_H_ | 70 #endif // PLATFORM_UTILS_WIN_H_ |
OLD | NEW |