OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 #ifndef V8_ARM64_UTILS_ARM64_H_ | 5 #ifndef V8_ARM64_UTILS_ARM64_H_ |
6 #define V8_ARM64_UTILS_ARM64_H_ | 6 #define V8_ARM64_UTILS_ARM64_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/arm64/constants-arm64.h" | 10 #include "src/arm64/constants-arm64.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Bit counting. | 48 // Bit counting. |
49 int CountLeadingZeros(uint64_t value, int width); | 49 int CountLeadingZeros(uint64_t value, int width); |
50 int CountLeadingSignBits(int64_t value, int width); | 50 int CountLeadingSignBits(int64_t value, int width); |
51 int CountTrailingZeros(uint64_t value, int width); | 51 int CountTrailingZeros(uint64_t value, int width); |
52 int CountSetBits(uint64_t value, int width); | 52 int CountSetBits(uint64_t value, int width); |
53 uint64_t LargestPowerOf2Divisor(uint64_t value); | 53 uint64_t LargestPowerOf2Divisor(uint64_t value); |
54 int MaskToBit(uint64_t mask); | 54 int MaskToBit(uint64_t mask); |
55 | 55 |
56 | 56 |
57 template <typename T> | 57 template <typename T> |
58 T ReverseBits(T value) { | |
59 DCHECK((sizeof(value) == 1) || (sizeof(value) == 2) || (sizeof(value) == 4) || | |
60 (sizeof(value) == 8)); | |
61 T result = 0; | |
62 for (unsigned i = 0; i < (sizeof(value) * 8); i++) { | |
63 result = (result << 1) | (value & 1); | |
64 value >>= 1; | |
65 } | |
66 return result; | |
67 } | |
68 | |
69 | |
70 template <typename T> | |
71 T ReverseBytes(T value, int block_bytes_log2) { | 58 T ReverseBytes(T value, int block_bytes_log2) { |
72 DCHECK((sizeof(value) == 4) || (sizeof(value) == 8)); | 59 DCHECK((sizeof(value) == 4) || (sizeof(value) == 8)); |
73 DCHECK((1U << block_bytes_log2) <= sizeof(value)); | 60 DCHECK((1U << block_bytes_log2) <= sizeof(value)); |
74 // Split the 64-bit value into an 8-bit array, where b[0] is the least | 61 // Split the 64-bit value into an 8-bit array, where b[0] is the least |
75 // significant byte, and b[7] is the most significant. | 62 // significant byte, and b[7] is the most significant. |
76 uint8_t bytes[8]; | 63 uint8_t bytes[8]; |
77 uint64_t mask = 0xff00000000000000; | 64 uint64_t mask = 0xff00000000000000; |
78 for (int i = 7; i >= 0; i--) { | 65 for (int i = 7; i >= 0; i--) { |
79 bytes[i] = (static_cast<uint64_t>(value) & mask) >> (i * 8); | 66 bytes[i] = (static_cast<uint64_t>(value) & mask) >> (i * 8); |
80 mask >>= 8; | 67 mask >>= 8; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 129 |
143 | 130 |
144 inline float FusedMultiplyAdd(float op1, float op2, float a) { | 131 inline float FusedMultiplyAdd(float op1, float op2, float a) { |
145 return fmaf(op1, op2, a); | 132 return fmaf(op1, op2, a); |
146 } | 133 } |
147 | 134 |
148 } // namespace internal | 135 } // namespace internal |
149 } // namespace v8 | 136 } // namespace v8 |
150 | 137 |
151 #endif // V8_ARM64_UTILS_ARM64_H_ | 138 #endif // V8_ARM64_UTILS_ARM64_H_ |
OLD | NEW |