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 RUNTIME_PLATFORM_UTILS_WIN_H_ | 5 #ifndef RUNTIME_PLATFORM_UTILS_WIN_H_ |
6 #define RUNTIME_PLATFORM_UTILS_WIN_H_ | 6 #define RUNTIME_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) { | 13 inline int Utils::CountLeadingZeros(uword x) { |
14 unsigned long position; // NOLINT | 14 unsigned long position; // NOLINT |
15 #if defined(ARCH_IS_32_BIT) | 15 #if defined(ARCH_IS_32_BIT) |
16 _BitScanReverse(&position, x); | 16 _BitScanReverse(&position, x); |
17 #elif defined(ARCH_IS_64_BIT) | 17 #elif defined(ARCH_IS_64_BIT) |
18 _BitScanReverse64(&position, x); | 18 _BitScanReverse64(&position, x); |
19 #else | 19 #else |
20 #error Architecture is not 32-bit or 64-bit. | 20 #error Architecture is not 32-bit or 64-bit. |
21 #endif | 21 #endif |
22 return kBitsPerWord - static_cast<int>(position) - 1; | 22 return kBitsPerWord - static_cast<int>(position) - 1; |
23 } | 23 } |
24 | 24 |
25 | |
26 inline int Utils::CountTrailingZeros(uword x) { | 25 inline int Utils::CountTrailingZeros(uword x) { |
27 unsigned long result; // NOLINT | 26 unsigned long result; // NOLINT |
28 #if defined(ARCH_IS_32_BIT) | 27 #if defined(ARCH_IS_32_BIT) |
29 _BitScanForward(&result, x); | 28 _BitScanForward(&result, x); |
30 #elif defined(ARCH_IS_64_BIT) | 29 #elif defined(ARCH_IS_64_BIT) |
31 _BitScanForward64(&result, x); | 30 _BitScanForward64(&result, x); |
32 #else | 31 #else |
33 #error Architecture is not 32-bit or 64-bit. | 32 #error Architecture is not 32-bit or 64-bit. |
34 #endif | 33 #endif |
35 return static_cast<int>(result); | 34 return static_cast<int>(result); |
36 } | 35 } |
37 | 36 |
38 | |
39 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { | 37 inline uint16_t Utils::HostToBigEndian16(uint16_t value) { |
40 return _byteswap_ushort(value); | 38 return _byteswap_ushort(value); |
41 } | 39 } |
42 | 40 |
43 | |
44 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { | 41 inline uint32_t Utils::HostToBigEndian32(uint32_t value) { |
45 return _byteswap_ulong(value); | 42 return _byteswap_ulong(value); |
46 } | 43 } |
47 | 44 |
48 | |
49 inline uint64_t Utils::HostToBigEndian64(uint64_t value) { | 45 inline uint64_t Utils::HostToBigEndian64(uint64_t value) { |
50 return _byteswap_uint64(value); | 46 return _byteswap_uint64(value); |
51 } | 47 } |
52 | 48 |
53 | |
54 inline uint16_t Utils::HostToLittleEndian16(uint16_t value) { | 49 inline uint16_t Utils::HostToLittleEndian16(uint16_t value) { |
55 return value; | 50 return value; |
56 } | 51 } |
57 | 52 |
58 | |
59 inline uint32_t Utils::HostToLittleEndian32(uint32_t value) { | 53 inline uint32_t Utils::HostToLittleEndian32(uint32_t value) { |
60 return value; | 54 return value; |
61 } | 55 } |
62 | 56 |
63 | |
64 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { | 57 inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { |
65 return value; | 58 return value; |
66 } | 59 } |
67 | 60 |
68 } // namespace dart | 61 } // namespace dart |
69 | 62 |
70 #endif // RUNTIME_PLATFORM_UTILS_WIN_H_ | 63 #endif // RUNTIME_PLATFORM_UTILS_WIN_H_ |
OLD | NEW |