Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | // Copyright 2015, VIXL authors |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 | // used to endorse or promote products derived from this software without |
| 14 | // specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | #ifndef VIXL_UTILS_H |
| 28 | #define VIXL_UTILS_H |
| 29 | |
armvixl | 6e2c827 | 2015-03-31 11:04:14 +0100 | [diff] [blame] | 30 | #include <cmath> |
Pierre Langlois | 78973f2 | 2016-08-10 14:35:56 +0100 | [diff] [blame] | 31 | #include <cstring> |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 32 | #include <limits> |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 33 | #include <type_traits> |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 34 | #include <vector> |
Alexandre Rames | b68bacb | 2016-05-24 08:56:23 +0100 | [diff] [blame] | 35 | |
Alexandre Rames | 1f9074d | 2016-05-23 15:50:01 +0100 | [diff] [blame] | 36 | #include "compiler-intrinsics-vixl.h" |
Alexandre Rames | b68bacb | 2016-05-24 08:56:23 +0100 | [diff] [blame] | 37 | #include "globals-vixl.h" |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 38 | |
| 39 | namespace vixl { |
| 40 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 41 | // Macros for compile-time format checking. |
armvixl | 788c84f | 2015-12-08 17:05:23 +0000 | [diff] [blame] | 42 | #if GCC_VERSION_OR_NEWER(4, 4, 0) |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 43 | #define PRINTF_CHECK(format_index, varargs_index) \ |
armvixl | 788c84f | 2015-12-08 17:05:23 +0000 | [diff] [blame] | 44 | __attribute__((format(gnu_printf, format_index, varargs_index))) |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 45 | #else |
| 46 | #define PRINTF_CHECK(format_index, varargs_index) |
| 47 | #endif |
| 48 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 49 | #ifdef __GNUC__ |
| 50 | #define VIXL_HAS_DEPRECATED_WITH_MSG |
| 51 | #elif defined(__clang__) |
| 52 | #ifdef __has_extension(attribute_deprecated_with_message) |
| 53 | #define VIXL_HAS_DEPRECATED_WITH_MSG |
| 54 | #endif |
| 55 | #endif |
| 56 | |
| 57 | #ifdef VIXL_HAS_DEPRECATED_WITH_MSG |
| 58 | #define VIXL_DEPRECATED(replaced_by, declarator) \ |
| 59 | __attribute__((deprecated("Use \"" replaced_by "\" instead"))) declarator |
| 60 | #else |
| 61 | #define VIXL_DEPRECATED(replaced_by, declarator) declarator |
| 62 | #endif |
| 63 | |
| 64 | #ifdef VIXL_DEBUG |
| 65 | #define VIXL_UNREACHABLE_OR_FALLTHROUGH() VIXL_UNREACHABLE() |
| 66 | #else |
| 67 | #define VIXL_UNREACHABLE_OR_FALLTHROUGH() VIXL_FALLTHROUGH() |
| 68 | #endif |
| 69 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 70 | template <typename T, size_t n> |
TatWai Chong | 2cb1b61 | 2020-03-04 23:51:21 -0800 | [diff] [blame] | 71 | constexpr size_t ArrayLength(const T (&)[n]) { |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 72 | return n; |
| 73 | } |
| 74 | |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 75 | inline uint64_t GetUintMask(unsigned bits) { |
| 76 | VIXL_ASSERT(bits <= 64); |
| 77 | uint64_t base = (bits >= 64) ? 0 : (UINT64_C(1) << bits); |
| 78 | return base - 1; |
| 79 | } |
| 80 | |
TatWai Chong | 29a0c43 | 2019-11-06 22:20:44 -0800 | [diff] [blame] | 81 | inline uint64_t GetSignMask(unsigned bits) { |
| 82 | VIXL_ASSERT(bits <= 64); |
| 83 | return UINT64_C(1) << (bits - 1); |
| 84 | } |
| 85 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 86 | // Check number width. |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 87 | // TODO: Refactor these using templates. |
| 88 | inline bool IsIntN(unsigned n, uint32_t x) { |
Jacob Bramley | 6069fd4 | 2019-06-24 10:20:45 +0100 | [diff] [blame] | 89 | VIXL_ASSERT((0 < n) && (n <= 32)); |
| 90 | return x <= static_cast<uint32_t>(INT32_MAX >> (32 - n)); |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 91 | } |
| 92 | inline bool IsIntN(unsigned n, int32_t x) { |
Jacob Bramley | 6069fd4 | 2019-06-24 10:20:45 +0100 | [diff] [blame] | 93 | VIXL_ASSERT((0 < n) && (n <= 32)); |
| 94 | if (n == 32) return true; |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 95 | int32_t limit = INT32_C(1) << (n - 1); |
| 96 | return (-limit <= x) && (x < limit); |
| 97 | } |
| 98 | inline bool IsIntN(unsigned n, uint64_t x) { |
Jacob Bramley | 6069fd4 | 2019-06-24 10:20:45 +0100 | [diff] [blame] | 99 | VIXL_ASSERT((0 < n) && (n <= 64)); |
| 100 | return x <= static_cast<uint64_t>(INT64_MAX >> (64 - n)); |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 101 | } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 102 | inline bool IsIntN(unsigned n, int64_t x) { |
Jacob Bramley | 6069fd4 | 2019-06-24 10:20:45 +0100 | [diff] [blame] | 103 | VIXL_ASSERT((0 < n) && (n <= 64)); |
| 104 | if (n == 64) return true; |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 105 | int64_t limit = INT64_C(1) << (n - 1); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 106 | return (-limit <= x) && (x < limit); |
| 107 | } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 108 | VIXL_DEPRECATED("IsIntN", inline bool is_intn(unsigned n, int64_t x)) { |
| 109 | return IsIntN(n, x); |
| 110 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 111 | |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 112 | inline bool IsUintN(unsigned n, uint32_t x) { |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 113 | VIXL_ASSERT((0 < n) && (n <= 32)); |
| 114 | if (n >= 32) return true; |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 115 | return !(x >> n); |
| 116 | } |
| 117 | inline bool IsUintN(unsigned n, int32_t x) { |
| 118 | VIXL_ASSERT((0 < n) && (n < 32)); |
| 119 | // Convert to an unsigned integer to avoid implementation-defined behavior. |
| 120 | return !(static_cast<uint32_t>(x) >> n); |
| 121 | } |
| 122 | inline bool IsUintN(unsigned n, uint64_t x) { |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 123 | VIXL_ASSERT((0 < n) && (n <= 64)); |
| 124 | if (n >= 64) return true; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 125 | return !(x >> n); |
| 126 | } |
Pierre Langlois | efe0c1f | 2016-11-24 11:54:47 +0000 | [diff] [blame] | 127 | inline bool IsUintN(unsigned n, int64_t x) { |
| 128 | VIXL_ASSERT((0 < n) && (n < 64)); |
| 129 | // Convert to an unsigned integer to avoid implementation-defined behavior. |
| 130 | return !(static_cast<uint64_t>(x) >> n); |
| 131 | } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 132 | VIXL_DEPRECATED("IsUintN", inline bool is_uintn(unsigned n, int64_t x)) { |
| 133 | return IsUintN(n, x); |
| 134 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 135 | |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 136 | inline uint64_t TruncateToUintN(unsigned n, uint64_t x) { |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 137 | VIXL_ASSERT((0 < n) && (n < 64)); |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 138 | return static_cast<uint64_t>(x) & ((UINT64_C(1) << n) - 1); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 139 | } |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 140 | VIXL_DEPRECATED("TruncateToUintN", |
| 141 | inline uint64_t truncate_to_intn(unsigned n, int64_t x)) { |
| 142 | return TruncateToUintN(n, x); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 143 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 144 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 145 | // clang-format off |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 146 | #define INT_1_TO_32_LIST(V) \ |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 147 | V(1) V(2) V(3) V(4) V(5) V(6) V(7) V(8) \ |
| 148 | V(9) V(10) V(11) V(12) V(13) V(14) V(15) V(16) \ |
| 149 | V(17) V(18) V(19) V(20) V(21) V(22) V(23) V(24) \ |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 150 | V(25) V(26) V(27) V(28) V(29) V(30) V(31) V(32) |
| 151 | |
| 152 | #define INT_33_TO_63_LIST(V) \ |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 153 | V(33) V(34) V(35) V(36) V(37) V(38) V(39) V(40) \ |
| 154 | V(41) V(42) V(43) V(44) V(45) V(46) V(47) V(48) \ |
| 155 | V(49) V(50) V(51) V(52) V(53) V(54) V(55) V(56) \ |
| 156 | V(57) V(58) V(59) V(60) V(61) V(62) V(63) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 157 | |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 158 | #define INT_1_TO_63_LIST(V) INT_1_TO_32_LIST(V) INT_33_TO_63_LIST(V) |
| 159 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 160 | // clang-format on |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 161 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 162 | #define DECLARE_IS_INT_N(N) \ |
| 163 | inline bool IsInt##N(int64_t x) { return IsIntN(N, x); } \ |
| 164 | VIXL_DEPRECATED("IsInt" #N, inline bool is_int##N(int64_t x)) { \ |
| 165 | return IsIntN(N, x); \ |
| 166 | } |
| 167 | |
| 168 | #define DECLARE_IS_UINT_N(N) \ |
| 169 | inline bool IsUint##N(int64_t x) { return IsUintN(N, x); } \ |
| 170 | VIXL_DEPRECATED("IsUint" #N, inline bool is_uint##N(int64_t x)) { \ |
| 171 | return IsUintN(N, x); \ |
| 172 | } |
| 173 | |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 174 | #define DECLARE_TRUNCATE_TO_UINT_32(N) \ |
| 175 | inline uint32_t TruncateToUint##N(uint64_t x) { \ |
| 176 | return static_cast<uint32_t>(TruncateToUintN(N, x)); \ |
| 177 | } \ |
| 178 | VIXL_DEPRECATED("TruncateToUint" #N, \ |
| 179 | inline uint32_t truncate_to_int##N(int64_t x)) { \ |
| 180 | return TruncateToUint##N(x); \ |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 181 | } |
| 182 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 183 | INT_1_TO_63_LIST(DECLARE_IS_INT_N) |
| 184 | INT_1_TO_63_LIST(DECLARE_IS_UINT_N) |
Jacob Bramley | 3976edb | 2016-10-18 10:51:43 +0100 | [diff] [blame] | 185 | INT_1_TO_32_LIST(DECLARE_TRUNCATE_TO_UINT_32) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 186 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 187 | #undef DECLARE_IS_INT_N |
| 188 | #undef DECLARE_IS_UINT_N |
| 189 | #undef DECLARE_TRUNCATE_TO_INT_N |
| 190 | |
| 191 | // Bit field extraction. |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 192 | inline uint64_t ExtractUnsignedBitfield64(int msb, int lsb, uint64_t x) { |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 193 | VIXL_ASSERT((static_cast<size_t>(msb) < sizeof(x) * 8) && (lsb >= 0) && |
| 194 | (msb >= lsb)); |
| 195 | if ((msb == 63) && (lsb == 0)) return x; |
armvixl | 578645f | 2013-08-15 17:21:42 +0100 | [diff] [blame] | 196 | return (x >> lsb) & ((static_cast<uint64_t>(1) << (1 + msb - lsb)) - 1); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 199 | |
Jacob Bramley | 199339d | 2019-08-05 18:49:13 +0100 | [diff] [blame] | 200 | inline uint32_t ExtractUnsignedBitfield32(int msb, int lsb, uint64_t x) { |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 201 | VIXL_ASSERT((static_cast<size_t>(msb) < sizeof(x) * 8) && (lsb >= 0) && |
| 202 | (msb >= lsb)); |
| 203 | return TruncateToUint32(ExtractUnsignedBitfield64(msb, lsb, x)); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 206 | |
Jacob Bramley | 6069fd4 | 2019-06-24 10:20:45 +0100 | [diff] [blame] | 207 | inline int64_t ExtractSignedBitfield64(int msb, int lsb, uint64_t x) { |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 208 | VIXL_ASSERT((static_cast<size_t>(msb) < sizeof(x) * 8) && (lsb >= 0) && |
| 209 | (msb >= lsb)); |
| 210 | uint64_t temp = ExtractUnsignedBitfield64(msb, lsb, x); |
| 211 | // If the highest extracted bit is set, sign extend. |
| 212 | if ((temp >> (msb - lsb)) == 1) { |
| 213 | temp |= ~UINT64_C(0) << (msb - lsb); |
| 214 | } |
| 215 | int64_t result; |
| 216 | memcpy(&result, &temp, sizeof(result)); |
| 217 | return result; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Jacob Bramley | 199339d | 2019-08-05 18:49:13 +0100 | [diff] [blame] | 220 | inline int32_t ExtractSignedBitfield32(int msb, int lsb, uint64_t x) { |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 221 | VIXL_ASSERT((static_cast<size_t>(msb) < sizeof(x) * 8) && (lsb >= 0) && |
| 222 | (msb >= lsb)); |
| 223 | uint32_t temp = TruncateToUint32(ExtractSignedBitfield64(msb, lsb, x)); |
| 224 | int32_t result; |
| 225 | memcpy(&result, &temp, sizeof(result)); |
| 226 | return result; |
| 227 | } |
| 228 | |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 229 | inline uint64_t RotateRight(uint64_t value, |
| 230 | unsigned int rotate, |
| 231 | unsigned int width) { |
| 232 | VIXL_ASSERT((width > 0) && (width <= 64)); |
| 233 | uint64_t width_mask = ~UINT64_C(0) >> (64 - width); |
| 234 | rotate &= 63; |
| 235 | if (rotate > 0) { |
| 236 | value &= width_mask; |
| 237 | value = (value << (width - rotate)) | (value >> rotate); |
| 238 | } |
| 239 | return value & width_mask; |
| 240 | } |
| 241 | |
| 242 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 243 | // Wrapper class for passing FP16 values through the assembler. |
| 244 | // This is purely to aid with type checking/casting. |
| 245 | class Float16 { |
| 246 | public: |
| 247 | explicit Float16(double dvalue); |
| 248 | Float16() : rawbits_(0x0) {} |
| 249 | friend uint16_t Float16ToRawbits(Float16 value); |
| 250 | friend Float16 RawbitsToFloat16(uint16_t bits); |
| 251 | |
| 252 | protected: |
| 253 | uint16_t rawbits_; |
| 254 | }; |
| 255 | |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 256 | // Floating point representation. |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 257 | uint16_t Float16ToRawbits(Float16 value); |
Carey Williams | d8bb357 | 2018-04-10 11:58:07 +0100 | [diff] [blame] | 258 | |
| 259 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 260 | uint32_t FloatToRawbits(float value); |
| 261 | VIXL_DEPRECATED("FloatToRawbits", |
| 262 | inline uint32_t float_to_rawbits(float value)) { |
| 263 | return FloatToRawbits(value); |
| 264 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 265 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 266 | uint64_t DoubleToRawbits(double value); |
| 267 | VIXL_DEPRECATED("DoubleToRawbits", |
| 268 | inline uint64_t double_to_rawbits(double value)) { |
| 269 | return DoubleToRawbits(value); |
| 270 | } |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 271 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 272 | Float16 RawbitsToFloat16(uint16_t bits); |
Carey Williams | d8bb357 | 2018-04-10 11:58:07 +0100 | [diff] [blame] | 273 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 274 | float RawbitsToFloat(uint32_t bits); |
| 275 | VIXL_DEPRECATED("RawbitsToFloat", |
| 276 | inline float rawbits_to_float(uint32_t bits)) { |
| 277 | return RawbitsToFloat(bits); |
| 278 | } |
| 279 | |
| 280 | double RawbitsToDouble(uint64_t bits); |
| 281 | VIXL_DEPRECATED("RawbitsToDouble", |
| 282 | inline double rawbits_to_double(uint64_t bits)) { |
| 283 | return RawbitsToDouble(bits); |
| 284 | } |
| 285 | |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 286 | // Some compilers dislike negating unsigned integers, |
| 287 | // so we provide an equivalent. |
| 288 | template <typename T> |
| 289 | T UnsignedNegate(T value) { |
| 290 | VIXL_STATIC_ASSERT(std::is_unsigned<T>::value); |
| 291 | return ~value + 1; |
| 292 | } |
| 293 | |
mmc28a | b5c57c9 | 2023-03-16 16:26:31 +0000 | [diff] [blame^] | 294 | // An absolute operation for signed integers that is defined for results outside |
| 295 | // the representable range. Specifically, Abs(MIN_INT) is MIN_INT. |
| 296 | template <typename T> |
| 297 | T Abs(T val) { |
| 298 | // TODO: this static assertion is for signed integer inputs, as that's the |
| 299 | // only type tested. However, the code should work for all numeric inputs. |
| 300 | // Remove the assertion and this comment when more tests are available. |
| 301 | VIXL_STATIC_ASSERT(std::is_signed<T>::value && std::is_integral<T>::value); |
| 302 | return ((val >= -std::numeric_limits<T>::max()) && (val < 0)) ? -val : val; |
| 303 | } |
| 304 | |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 305 | // Convert unsigned to signed numbers in a well-defined way (using two's |
| 306 | // complement representations). |
| 307 | inline int64_t RawbitsToInt64(uint64_t bits) { |
| 308 | return (bits >= UINT64_C(0x8000000000000000)) |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 309 | ? (-static_cast<int64_t>(UnsignedNegate(bits) - 1) - 1) |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 310 | : static_cast<int64_t>(bits); |
| 311 | } |
| 312 | |
| 313 | inline int32_t RawbitsToInt32(uint32_t bits) { |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 314 | return (bits >= UINT64_C(0x80000000)) |
| 315 | ? (-static_cast<int32_t>(UnsignedNegate(bits) - 1) - 1) |
| 316 | : static_cast<int32_t>(bits); |
Jacob Bramley | 03c0b51 | 2019-02-22 16:42:06 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 319 | namespace internal { |
| 320 | |
| 321 | // Internal simulation class used solely by the simulator to |
| 322 | // provide an abstraction layer for any half-precision arithmetic. |
| 323 | class SimFloat16 : public Float16 { |
| 324 | public: |
| 325 | // TODO: We should investigate making this constructor explicit. |
| 326 | // This is currently difficult to do due to a number of templated |
| 327 | // functions in the simulator which rely on returning double values. |
| 328 | SimFloat16(double dvalue) : Float16(dvalue) {} // NOLINT(runtime/explicit) |
| 329 | SimFloat16(Float16 f) { // NOLINT(runtime/explicit) |
| 330 | this->rawbits_ = Float16ToRawbits(f); |
| 331 | } |
| 332 | SimFloat16() : Float16() {} |
| 333 | SimFloat16 operator-() const; |
| 334 | SimFloat16 operator+(SimFloat16 rhs) const; |
| 335 | SimFloat16 operator-(SimFloat16 rhs) const; |
| 336 | SimFloat16 operator*(SimFloat16 rhs) const; |
| 337 | SimFloat16 operator/(SimFloat16 rhs) const; |
| 338 | bool operator<(SimFloat16 rhs) const; |
| 339 | bool operator>(SimFloat16 rhs) const; |
| 340 | bool operator==(SimFloat16 rhs) const; |
| 341 | bool operator!=(SimFloat16 rhs) const; |
Josh Soref | b43d6ef | 2022-08-03 12:47:14 -0400 | [diff] [blame] | 342 | // This is necessary for conversions performed in (macro asm) Fmov. |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 343 | bool operator==(double rhs) const; |
| 344 | operator double() const; |
| 345 | }; |
| 346 | } // namespace internal |
| 347 | |
| 348 | uint32_t Float16Sign(internal::SimFloat16 value); |
| 349 | |
| 350 | uint32_t Float16Exp(internal::SimFloat16 value); |
| 351 | |
| 352 | uint32_t Float16Mantissa(internal::SimFloat16 value); |
| 353 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 354 | uint32_t FloatSign(float value); |
| 355 | VIXL_DEPRECATED("FloatSign", inline uint32_t float_sign(float value)) { |
| 356 | return FloatSign(value); |
| 357 | } |
| 358 | |
| 359 | uint32_t FloatExp(float value); |
| 360 | VIXL_DEPRECATED("FloatExp", inline uint32_t float_exp(float value)) { |
| 361 | return FloatExp(value); |
| 362 | } |
| 363 | |
| 364 | uint32_t FloatMantissa(float value); |
| 365 | VIXL_DEPRECATED("FloatMantissa", inline uint32_t float_mantissa(float value)) { |
| 366 | return FloatMantissa(value); |
| 367 | } |
| 368 | |
| 369 | uint32_t DoubleSign(double value); |
| 370 | VIXL_DEPRECATED("DoubleSign", inline uint32_t double_sign(double value)) { |
| 371 | return DoubleSign(value); |
| 372 | } |
| 373 | |
| 374 | uint32_t DoubleExp(double value); |
| 375 | VIXL_DEPRECATED("DoubleExp", inline uint32_t double_exp(double value)) { |
| 376 | return DoubleExp(value); |
| 377 | } |
| 378 | |
| 379 | uint64_t DoubleMantissa(double value); |
| 380 | VIXL_DEPRECATED("DoubleMantissa", |
| 381 | inline uint64_t double_mantissa(double value)) { |
| 382 | return DoubleMantissa(value); |
| 383 | } |
| 384 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 385 | internal::SimFloat16 Float16Pack(uint16_t sign, |
| 386 | uint16_t exp, |
| 387 | uint16_t mantissa); |
| 388 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 389 | float FloatPack(uint32_t sign, uint32_t exp, uint32_t mantissa); |
| 390 | VIXL_DEPRECATED("FloatPack", |
| 391 | inline float float_pack(uint32_t sign, |
| 392 | uint32_t exp, |
| 393 | uint32_t mantissa)) { |
| 394 | return FloatPack(sign, exp, mantissa); |
| 395 | } |
| 396 | |
| 397 | double DoublePack(uint64_t sign, uint64_t exp, uint64_t mantissa); |
| 398 | VIXL_DEPRECATED("DoublePack", |
| 399 | inline double double_pack(uint32_t sign, |
| 400 | uint32_t exp, |
| 401 | uint64_t mantissa)) { |
| 402 | return DoublePack(sign, exp, mantissa); |
| 403 | } |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 404 | |
| 405 | // An fpclassify() function for 16-bit half-precision floats. |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 406 | int Float16Classify(Float16 value); |
| 407 | VIXL_DEPRECATED("Float16Classify", inline int float16classify(uint16_t value)) { |
| 408 | return Float16Classify(RawbitsToFloat16(value)); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 409 | } |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 410 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 411 | bool IsZero(Float16 value); |
Carey Williams | d8bb357 | 2018-04-10 11:58:07 +0100 | [diff] [blame] | 412 | |
Jacob Bramley | f48172b | 2020-07-13 14:47:15 +0100 | [diff] [blame] | 413 | inline bool IsPositiveZero(double value) { |
| 414 | return (value == 0.0) && (copysign(1.0, value) > 0.0); |
| 415 | } |
| 416 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 417 | inline bool IsNaN(float value) { return std::isnan(value); } |
| 418 | |
| 419 | inline bool IsNaN(double value) { return std::isnan(value); } |
| 420 | |
| 421 | inline bool IsNaN(Float16 value) { return Float16Classify(value) == FP_NAN; } |
| 422 | |
| 423 | inline bool IsInf(float value) { return std::isinf(value); } |
| 424 | |
| 425 | inline bool IsInf(double value) { return std::isinf(value); } |
| 426 | |
| 427 | inline bool IsInf(Float16 value) { |
| 428 | return Float16Classify(value) == FP_INFINITE; |
| 429 | } |
Carey Williams | d8bb357 | 2018-04-10 11:58:07 +0100 | [diff] [blame] | 430 | |
| 431 | |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 432 | // NaN tests. |
| 433 | inline bool IsSignallingNaN(double num) { |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 434 | const uint64_t kFP64QuietNaNMask = UINT64_C(0x0008000000000000); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 435 | uint64_t raw = DoubleToRawbits(num); |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 436 | if (IsNaN(num) && ((raw & kFP64QuietNaNMask) == 0)) { |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 437 | return true; |
| 438 | } |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | inline bool IsSignallingNaN(float num) { |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 444 | const uint32_t kFP32QuietNaNMask = 0x00400000; |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 445 | uint32_t raw = FloatToRawbits(num); |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 446 | if (IsNaN(num) && ((raw & kFP32QuietNaNMask) == 0)) { |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 447 | return true; |
| 448 | } |
| 449 | return false; |
| 450 | } |
| 451 | |
| 452 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 453 | inline bool IsSignallingNaN(Float16 num) { |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 454 | const uint16_t kFP16QuietNaNMask = 0x0200; |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 455 | return IsNaN(num) && ((Float16ToRawbits(num) & kFP16QuietNaNMask) == 0); |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 459 | template <typename T> |
| 460 | inline bool IsQuietNaN(T num) { |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 461 | return IsNaN(num) && !IsSignallingNaN(num); |
armvixl | f37fdc0 | 2014-02-05 13:22:16 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 465 | // Convert the NaN in 'num' to a quiet NaN. |
| 466 | inline double ToQuietNaN(double num) { |
armvixl | 5799d6c | 2014-05-01 11:05:00 +0100 | [diff] [blame] | 467 | const uint64_t kFP64QuietNaNMask = UINT64_C(0x0008000000000000); |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 468 | VIXL_ASSERT(IsNaN(num)); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 469 | return RawbitsToDouble(DoubleToRawbits(num) | kFP64QuietNaNMask); |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | |
| 473 | inline float ToQuietNaN(float num) { |
| 474 | const uint32_t kFP32QuietNaNMask = 0x00400000; |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 475 | VIXL_ASSERT(IsNaN(num)); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 476 | return RawbitsToFloat(FloatToRawbits(num) | kFP32QuietNaNMask); |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 480 | inline internal::SimFloat16 ToQuietNaN(internal::SimFloat16 num) { |
| 481 | const uint16_t kFP16QuietNaNMask = 0x0200; |
| 482 | VIXL_ASSERT(IsNaN(num)); |
| 483 | return internal::SimFloat16( |
| 484 | RawbitsToFloat16(Float16ToRawbits(num) | kFP16QuietNaNMask)); |
| 485 | } |
| 486 | |
| 487 | |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 488 | // Fused multiply-add. |
| 489 | inline double FusedMultiplyAdd(double op1, double op2, double a) { |
| 490 | return fma(op1, op2, a); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | inline float FusedMultiplyAdd(float op1, float op2, float a) { |
| 495 | return fmaf(op1, op2, a); |
| 496 | } |
| 497 | |
| 498 | |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 499 | inline uint64_t LowestSetBit(uint64_t value) { |
| 500 | return value & UnsignedNegate(value); |
| 501 | } |
armvixl | 6e2c827 | 2015-03-31 11:04:14 +0100 | [diff] [blame] | 502 | |
| 503 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 504 | template <typename T> |
armvixl | 6e2c827 | 2015-03-31 11:04:14 +0100 | [diff] [blame] | 505 | inline int HighestSetBitPosition(T value) { |
| 506 | VIXL_ASSERT(value != 0); |
| 507 | return (sizeof(value) * 8 - 1) - CountLeadingZeros(value); |
| 508 | } |
| 509 | |
| 510 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 511 | template <typename V> |
armvixl | 6e2c827 | 2015-03-31 11:04:14 +0100 | [diff] [blame] | 512 | inline int WhichPowerOf2(V value) { |
| 513 | VIXL_ASSERT(IsPowerOf2(value)); |
| 514 | return CountTrailingZeros(value); |
| 515 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 516 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 517 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 518 | unsigned CountClearHalfWords(uint64_t imm, unsigned reg_size); |
| 519 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 520 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 521 | int BitCount(uint64_t value); |
| 522 | |
| 523 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 524 | template <typename T> |
| 525 | T ReverseBits(T value) { |
| 526 | VIXL_ASSERT((sizeof(value) == 1) || (sizeof(value) == 2) || |
| 527 | (sizeof(value) == 4) || (sizeof(value) == 8)); |
| 528 | T result = 0; |
| 529 | for (unsigned i = 0; i < (sizeof(value) * 8); i++) { |
| 530 | result = (result << 1) | (value & 1); |
| 531 | value >>= 1; |
| 532 | } |
| 533 | return result; |
| 534 | } |
| 535 | |
| 536 | |
| 537 | template <typename T> |
Jacob Bramley | acd32aa | 2019-12-12 18:08:20 +0000 | [diff] [blame] | 538 | inline T SignExtend(T val, int size_in_bits) { |
| 539 | VIXL_ASSERT(size_in_bits > 0); |
| 540 | T mask = (T(2) << (size_in_bits - 1)) - T(1); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 541 | val &= mask; |
Jacob Bramley | acd32aa | 2019-12-12 18:08:20 +0000 | [diff] [blame] | 542 | T sign_bits = -((val >> (size_in_bits - 1)) << size_in_bits); |
Vincent Belliard | 4e52d4d | 2018-04-03 13:34:44 -0700 | [diff] [blame] | 543 | val |= sign_bits; |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 544 | return val; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | template <typename T> |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 549 | T ReverseBytes(T value, int block_bytes_log2) { |
| 550 | VIXL_ASSERT((sizeof(value) == 4) || (sizeof(value) == 8)); |
| 551 | VIXL_ASSERT((1U << block_bytes_log2) <= sizeof(value)); |
| 552 | // Split the 64-bit value into an 8-bit array, where b[0] is the least |
| 553 | // significant byte, and b[7] is the most significant. |
| 554 | uint8_t bytes[8]; |
armvixl | 788c84f | 2015-12-08 17:05:23 +0000 | [diff] [blame] | 555 | uint64_t mask = UINT64_C(0xff00000000000000); |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 556 | for (int i = 7; i >= 0; i--) { |
| 557 | bytes[i] = (static_cast<uint64_t>(value) & mask) >> (i * 8); |
| 558 | mask >>= 8; |
| 559 | } |
| 560 | |
| 561 | // Permutation tables for REV instructions. |
| 562 | // permute_table[0] is used by REV16_x, REV16_w |
| 563 | // permute_table[1] is used by REV32_x, REV_w |
| 564 | // permute_table[2] is used by REV_x |
| 565 | VIXL_ASSERT((0 < block_bytes_log2) && (block_bytes_log2 < 4)); |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 566 | static const uint8_t permute_table[3][8] = {{6, 7, 4, 5, 2, 3, 0, 1}, |
| 567 | {4, 5, 6, 7, 0, 1, 2, 3}, |
| 568 | {0, 1, 2, 3, 4, 5, 6, 7}}; |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 569 | uint64_t temp = 0; |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 570 | for (int i = 0; i < 8; i++) { |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 571 | temp <<= 8; |
| 572 | temp |= bytes[permute_table[block_bytes_log2 - 1][i]]; |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 573 | } |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 574 | |
| 575 | T result; |
| 576 | VIXL_STATIC_ASSERT(sizeof(result) <= sizeof(temp)); |
| 577 | memcpy(&result, &temp, sizeof(result)); |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 578 | return result; |
| 579 | } |
| 580 | |
Vincent Belliard | 96ff2a4 | 2016-10-27 08:51:55 -0700 | [diff] [blame] | 581 | template <unsigned MULTIPLE, typename T> |
| 582 | inline bool IsMultiple(T value) { |
| 583 | VIXL_ASSERT(IsPowerOf2(MULTIPLE)); |
| 584 | return (value & (MULTIPLE - 1)) == 0; |
| 585 | } |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 586 | |
Martyn Capewell | fb8e3df | 2016-11-03 15:50:19 +0000 | [diff] [blame] | 587 | template <typename T> |
| 588 | inline bool IsMultiple(T value, unsigned multiple) { |
| 589 | VIXL_ASSERT(IsPowerOf2(multiple)); |
| 590 | return (value & (multiple - 1)) == 0; |
| 591 | } |
| 592 | |
Georgia Kouveli | 1cb7144 | 2017-01-30 13:35:28 +0000 | [diff] [blame] | 593 | template <typename T> |
| 594 | inline bool IsAligned(T pointer, int alignment) { |
| 595 | VIXL_ASSERT(IsPowerOf2(alignment)); |
| 596 | return (pointer & (alignment - 1)) == 0; |
| 597 | } |
| 598 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 599 | // Pointer alignment |
| 600 | // TODO: rename/refactor to make it specific to instructions. |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 601 | template <unsigned ALIGN, typename T> |
| 602 | inline bool IsAligned(T pointer) { |
| 603 | VIXL_ASSERT(sizeof(pointer) == sizeof(intptr_t)); // NOLINT(runtime/sizeof) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 604 | // Use C-style casts to get static_cast behaviour for integral types (T), and |
| 605 | // reinterpret_cast behaviour for other types. |
Georgia Kouveli | 1cb7144 | 2017-01-30 13:35:28 +0000 | [diff] [blame] | 606 | return IsAligned((intptr_t)(pointer), ALIGN); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 607 | } |
| 608 | |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 609 | template <typename T> |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 610 | bool IsWordAligned(T pointer) { |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 611 | return IsAligned<4>(pointer); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 612 | } |
| 613 | |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 614 | // Increment a pointer until it has the specified alignment. The alignment must |
| 615 | // be a power of two. |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 616 | template <class T> |
Pierre Langlois | 0ad8a6f | 2017-05-16 08:58:34 +0100 | [diff] [blame] | 617 | T AlignUp(T pointer, |
| 618 | typename Unsigned<sizeof(T) * kBitsPerByte>::type alignment) { |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 619 | VIXL_ASSERT(IsPowerOf2(alignment)); |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 620 | // Use C-style casts to get static_cast behaviour for integral types (T), and |
| 621 | // reinterpret_cast behaviour for other types. |
| 622 | |
Pierre Langlois | 0ad8a6f | 2017-05-16 08:58:34 +0100 | [diff] [blame] | 623 | typename Unsigned<sizeof(T)* kBitsPerByte>::type pointer_raw = |
Jacob Bramley | 2fe55ec | 2020-03-20 17:03:48 +0000 | [diff] [blame] | 624 | (typename Unsigned<sizeof(T) * kBitsPerByte>::type) pointer; |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 625 | VIXL_STATIC_ASSERT(sizeof(pointer) <= sizeof(pointer_raw)); |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 626 | |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 627 | size_t mask = alignment - 1; |
| 628 | T result = (T)((pointer_raw + mask) & ~mask); |
Alexandre Rames | 47ed265 | 2016-11-09 14:44:06 +0000 | [diff] [blame] | 629 | VIXL_ASSERT(result >= pointer); |
| 630 | |
| 631 | return result; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 632 | } |
| 633 | |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 634 | // Decrement a pointer until it has the specified alignment. The alignment must |
| 635 | // be a power of two. |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 636 | template <class T> |
Pierre Langlois | 0ad8a6f | 2017-05-16 08:58:34 +0100 | [diff] [blame] | 637 | T AlignDown(T pointer, |
| 638 | typename Unsigned<sizeof(T) * kBitsPerByte>::type alignment) { |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 639 | VIXL_ASSERT(IsPowerOf2(alignment)); |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 640 | // Use C-style casts to get static_cast behaviour for integral types (T), and |
| 641 | // reinterpret_cast behaviour for other types. |
| 642 | |
Pierre Langlois | 0ad8a6f | 2017-05-16 08:58:34 +0100 | [diff] [blame] | 643 | typename Unsigned<sizeof(T)* kBitsPerByte>::type pointer_raw = |
Jacob Bramley | 2fe55ec | 2020-03-20 17:03:48 +0000 | [diff] [blame] | 644 | (typename Unsigned<sizeof(T) * kBitsPerByte>::type) pointer; |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 645 | VIXL_STATIC_ASSERT(sizeof(pointer) <= sizeof(pointer_raw)); |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 646 | |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 647 | size_t mask = alignment - 1; |
| 648 | return (T)(pointer_raw & ~mask); |
armvixl | b0c8ae2 | 2014-03-21 14:03:59 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Georgia Kouveli | bbd09d6 | 2017-05-03 17:23:47 +0100 | [diff] [blame] | 651 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 652 | template <typename T> |
| 653 | inline T ExtractBit(T value, unsigned bit) { |
| 654 | return (value >> bit) & T(1); |
| 655 | } |
| 656 | |
| 657 | template <typename Ts, typename Td> |
| 658 | inline Td ExtractBits(Ts value, int least_significant_bit, Td mask) { |
| 659 | return Td((value >> least_significant_bit) & Ts(mask)); |
| 660 | } |
| 661 | |
| 662 | template <typename Ts, typename Td> |
Vincent Belliard | 60241a5 | 2016-11-10 12:41:11 -0800 | [diff] [blame] | 663 | inline void AssignBit(Td& dst, // NOLINT(runtime/references) |
| 664 | int bit, |
| 665 | Ts value) { |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 666 | VIXL_ASSERT((value == Ts(0)) || (value == Ts(1))); |
| 667 | VIXL_ASSERT(bit >= 0); |
| 668 | VIXL_ASSERT(bit < static_cast<int>(sizeof(Td) * 8)); |
| 669 | Td mask(1); |
| 670 | dst &= ~(mask << bit); |
| 671 | dst |= Td(value) << bit; |
| 672 | } |
| 673 | |
| 674 | template <typename Td, typename Ts> |
Vincent Belliard | 60241a5 | 2016-11-10 12:41:11 -0800 | [diff] [blame] | 675 | inline void AssignBits(Td& dst, // NOLINT(runtime/references) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 676 | int least_significant_bit, |
| 677 | Ts mask, |
| 678 | Ts value) { |
| 679 | VIXL_ASSERT(least_significant_bit >= 0); |
| 680 | VIXL_ASSERT(least_significant_bit < static_cast<int>(sizeof(Td) * 8)); |
| 681 | VIXL_ASSERT(((Td(mask) << least_significant_bit) >> least_significant_bit) == |
| 682 | Td(mask)); |
| 683 | VIXL_ASSERT((value & mask) == value); |
| 684 | dst &= ~(Td(mask) << least_significant_bit); |
| 685 | dst |= Td(value) << least_significant_bit; |
| 686 | } |
| 687 | |
| 688 | class VFP { |
| 689 | public: |
| 690 | static uint32_t FP32ToImm8(float imm) { |
| 691 | // bits: aBbb.bbbc.defg.h000.0000.0000.0000.0000 |
| 692 | uint32_t bits = FloatToRawbits(imm); |
| 693 | // bit7: a000.0000 |
| 694 | uint32_t bit7 = ((bits >> 31) & 0x1) << 7; |
| 695 | // bit6: 0b00.0000 |
| 696 | uint32_t bit6 = ((bits >> 29) & 0x1) << 6; |
| 697 | // bit5_to_0: 00cd.efgh |
| 698 | uint32_t bit5_to_0 = (bits >> 19) & 0x3f; |
| 699 | return static_cast<uint32_t>(bit7 | bit6 | bit5_to_0); |
| 700 | } |
| 701 | static uint32_t FP64ToImm8(double imm) { |
| 702 | // bits: aBbb.bbbb.bbcd.efgh.0000.0000.0000.0000 |
| 703 | // 0000.0000.0000.0000.0000.0000.0000.0000 |
| 704 | uint64_t bits = DoubleToRawbits(imm); |
| 705 | // bit7: a000.0000 |
| 706 | uint64_t bit7 = ((bits >> 63) & 0x1) << 7; |
| 707 | // bit6: 0b00.0000 |
| 708 | uint64_t bit6 = ((bits >> 61) & 0x1) << 6; |
| 709 | // bit5_to_0: 00cd.efgh |
| 710 | uint64_t bit5_to_0 = (bits >> 48) & 0x3f; |
| 711 | |
| 712 | return static_cast<uint32_t>(bit7 | bit6 | bit5_to_0); |
| 713 | } |
| 714 | static float Imm8ToFP32(uint32_t imm8) { |
| 715 | // Imm8: abcdefgh (8 bits) |
| 716 | // Single: aBbb.bbbc.defg.h000.0000.0000.0000.0000 (32 bits) |
| 717 | // where B is b ^ 1 |
| 718 | uint32_t bits = imm8; |
| 719 | uint32_t bit7 = (bits >> 7) & 0x1; |
| 720 | uint32_t bit6 = (bits >> 6) & 0x1; |
| 721 | uint32_t bit5_to_0 = bits & 0x3f; |
| 722 | uint32_t result = (bit7 << 31) | ((32 - bit6) << 25) | (bit5_to_0 << 19); |
| 723 | |
| 724 | return RawbitsToFloat(result); |
| 725 | } |
| 726 | static double Imm8ToFP64(uint32_t imm8) { |
| 727 | // Imm8: abcdefgh (8 bits) |
| 728 | // Double: aBbb.bbbb.bbcd.efgh.0000.0000.0000.0000 |
| 729 | // 0000.0000.0000.0000.0000.0000.0000.0000 (64 bits) |
| 730 | // where B is b ^ 1 |
| 731 | uint32_t bits = imm8; |
| 732 | uint64_t bit7 = (bits >> 7) & 0x1; |
| 733 | uint64_t bit6 = (bits >> 6) & 0x1; |
| 734 | uint64_t bit5_to_0 = bits & 0x3f; |
| 735 | uint64_t result = (bit7 << 63) | ((256 - bit6) << 54) | (bit5_to_0 << 48); |
| 736 | return RawbitsToDouble(result); |
| 737 | } |
| 738 | static bool IsImmFP32(float imm) { |
| 739 | // Valid values will have the form: |
| 740 | // aBbb.bbbc.defg.h000.0000.0000.0000.0000 |
| 741 | uint32_t bits = FloatToRawbits(imm); |
| 742 | // bits[19..0] are cleared. |
| 743 | if ((bits & 0x7ffff) != 0) { |
| 744 | return false; |
| 745 | } |
| 746 | |
| 747 | |
| 748 | // bits[29..25] are all set or all cleared. |
| 749 | uint32_t b_pattern = (bits >> 16) & 0x3e00; |
| 750 | if (b_pattern != 0 && b_pattern != 0x3e00) { |
| 751 | return false; |
| 752 | } |
| 753 | // bit[30] and bit[29] are opposite. |
| 754 | if (((bits ^ (bits << 1)) & 0x40000000) == 0) { |
| 755 | return false; |
| 756 | } |
| 757 | return true; |
| 758 | } |
| 759 | static bool IsImmFP64(double imm) { |
| 760 | // Valid values will have the form: |
| 761 | // aBbb.bbbb.bbcd.efgh.0000.0000.0000.0000 |
| 762 | // 0000.0000.0000.0000.0000.0000.0000.0000 |
| 763 | uint64_t bits = DoubleToRawbits(imm); |
| 764 | // bits[47..0] are cleared. |
| 765 | if ((bits & 0x0000ffffffffffff) != 0) { |
| 766 | return false; |
| 767 | } |
| 768 | // bits[61..54] are all set or all cleared. |
| 769 | uint32_t b_pattern = (bits >> 48) & 0x3fc0; |
| 770 | if ((b_pattern != 0) && (b_pattern != 0x3fc0)) { |
| 771 | return false; |
| 772 | } |
| 773 | // bit[62] and bit[61] are opposite. |
| 774 | if (((bits ^ (bits << 1)) & (UINT64_C(1) << 62)) == 0) { |
| 775 | return false; |
| 776 | } |
| 777 | return true; |
| 778 | } |
| 779 | }; |
| 780 | |
| 781 | class BitField { |
| 782 | // ForEachBitHelper is a functor that will call |
| 783 | // bool ForEachBitHelper::execute(ElementType id) const |
| 784 | // and expects a boolean in return whether to continue (if true) |
| 785 | // or stop (if false) |
| 786 | // check_set will check if the bits are on (true) or off(false) |
| 787 | template <typename ForEachBitHelper, bool check_set> |
| 788 | bool ForEachBit(const ForEachBitHelper& helper) { |
| 789 | for (int i = 0; static_cast<size_t>(i) < bitfield_.size(); i++) { |
| 790 | if (bitfield_[i] == check_set) |
| 791 | if (!helper.execute(i)) return false; |
| 792 | } |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | public: |
| 797 | explicit BitField(unsigned size) : bitfield_(size, 0) {} |
| 798 | |
| 799 | void Set(int i) { |
| 800 | VIXL_ASSERT((i >= 0) && (static_cast<size_t>(i) < bitfield_.size())); |
| 801 | bitfield_[i] = true; |
| 802 | } |
| 803 | |
| 804 | void Unset(int i) { |
| 805 | VIXL_ASSERT((i >= 0) && (static_cast<size_t>(i) < bitfield_.size())); |
| 806 | bitfield_[i] = true; |
| 807 | } |
| 808 | |
| 809 | bool IsSet(int i) const { return bitfield_[i]; } |
| 810 | |
| 811 | // For each bit not set in the bitfield call the execute functor |
| 812 | // execute. |
| 813 | // ForEachBitSetHelper::execute returns true if the iteration through |
| 814 | // the bits can continue, otherwise it will stop. |
| 815 | // struct ForEachBitSetHelper { |
| 816 | // bool execute(int /*id*/) { return false; } |
| 817 | // }; |
| 818 | template <typename ForEachBitNotSetHelper> |
| 819 | bool ForEachBitNotSet(const ForEachBitNotSetHelper& helper) { |
| 820 | return ForEachBit<ForEachBitNotSetHelper, false>(helper); |
| 821 | } |
| 822 | |
| 823 | // For each bit set in the bitfield call the execute functor |
| 824 | // execute. |
| 825 | template <typename ForEachBitSetHelper> |
| 826 | bool ForEachBitSet(const ForEachBitSetHelper& helper) { |
| 827 | return ForEachBit<ForEachBitSetHelper, true>(helper); |
| 828 | } |
| 829 | |
| 830 | private: |
| 831 | std::vector<bool> bitfield_; |
| 832 | }; |
| 833 | |
Pierre Langlois | d82faf6 | 2018-04-04 13:06:58 +0100 | [diff] [blame] | 834 | namespace internal { |
| 835 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 836 | typedef int64_t Int64; |
| 837 | class Uint64; |
| 838 | class Uint128; |
| 839 | |
| 840 | class Uint32 { |
| 841 | uint32_t data_; |
| 842 | |
| 843 | public: |
| 844 | // Unlike uint32_t, Uint32 has a default constructor. |
| 845 | Uint32() { data_ = 0; } |
| 846 | explicit Uint32(uint32_t data) : data_(data) {} |
| 847 | inline explicit Uint32(Uint64 data); |
| 848 | uint32_t Get() const { return data_; } |
| 849 | template <int N> |
| 850 | int32_t GetSigned() const { |
| 851 | return ExtractSignedBitfield32(N - 1, 0, data_); |
| 852 | } |
| 853 | int32_t GetSigned() const { return data_; } |
| 854 | Uint32 operator~() const { return Uint32(~data_); } |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 855 | Uint32 operator-() const { return Uint32(UnsignedNegate(data_)); } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 856 | bool operator==(Uint32 value) const { return data_ == value.data_; } |
| 857 | bool operator!=(Uint32 value) const { return data_ != value.data_; } |
| 858 | bool operator>(Uint32 value) const { return data_ > value.data_; } |
| 859 | Uint32 operator+(Uint32 value) const { return Uint32(data_ + value.data_); } |
| 860 | Uint32 operator-(Uint32 value) const { return Uint32(data_ - value.data_); } |
| 861 | Uint32 operator&(Uint32 value) const { return Uint32(data_ & value.data_); } |
| 862 | Uint32 operator&=(Uint32 value) { |
| 863 | data_ &= value.data_; |
| 864 | return *this; |
| 865 | } |
| 866 | Uint32 operator^(Uint32 value) const { return Uint32(data_ ^ value.data_); } |
| 867 | Uint32 operator^=(Uint32 value) { |
| 868 | data_ ^= value.data_; |
| 869 | return *this; |
| 870 | } |
| 871 | Uint32 operator|(Uint32 value) const { return Uint32(data_ | value.data_); } |
| 872 | Uint32 operator|=(Uint32 value) { |
| 873 | data_ |= value.data_; |
| 874 | return *this; |
| 875 | } |
| 876 | // Unlike uint32_t, the shift functions can accept negative shift and |
| 877 | // return 0 when the shift is too big. |
| 878 | Uint32 operator>>(int shift) const { |
| 879 | if (shift == 0) return *this; |
| 880 | if (shift < 0) { |
| 881 | int tmp = -shift; |
| 882 | if (tmp >= 32) return Uint32(0); |
| 883 | return Uint32(data_ << tmp); |
| 884 | } |
| 885 | int tmp = shift; |
| 886 | if (tmp >= 32) return Uint32(0); |
| 887 | return Uint32(data_ >> tmp); |
| 888 | } |
| 889 | Uint32 operator<<(int shift) const { |
| 890 | if (shift == 0) return *this; |
| 891 | if (shift < 0) { |
| 892 | int tmp = -shift; |
| 893 | if (tmp >= 32) return Uint32(0); |
| 894 | return Uint32(data_ >> tmp); |
| 895 | } |
| 896 | int tmp = shift; |
| 897 | if (tmp >= 32) return Uint32(0); |
| 898 | return Uint32(data_ << tmp); |
| 899 | } |
| 900 | }; |
| 901 | |
| 902 | class Uint64 { |
| 903 | uint64_t data_; |
| 904 | |
| 905 | public: |
| 906 | // Unlike uint64_t, Uint64 has a default constructor. |
| 907 | Uint64() { data_ = 0; } |
| 908 | explicit Uint64(uint64_t data) : data_(data) {} |
| 909 | explicit Uint64(Uint32 data) : data_(data.Get()) {} |
| 910 | inline explicit Uint64(Uint128 data); |
| 911 | uint64_t Get() const { return data_; } |
| 912 | int64_t GetSigned(int N) const { |
| 913 | return ExtractSignedBitfield64(N - 1, 0, data_); |
| 914 | } |
| 915 | int64_t GetSigned() const { return data_; } |
| 916 | Uint32 ToUint32() const { |
| 917 | VIXL_ASSERT((data_ >> 32) == 0); |
Pierre Langlois | f5348ce | 2016-09-22 11:15:35 +0100 | [diff] [blame] | 918 | return Uint32(static_cast<uint32_t>(data_)); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 919 | } |
| 920 | Uint32 GetHigh32() const { return Uint32(data_ >> 32); } |
Pierre Langlois | f5348ce | 2016-09-22 11:15:35 +0100 | [diff] [blame] | 921 | Uint32 GetLow32() const { return Uint32(data_ & 0xffffffff); } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 922 | Uint64 operator~() const { return Uint64(~data_); } |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 923 | Uint64 operator-() const { return Uint64(UnsignedNegate(data_)); } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 924 | bool operator==(Uint64 value) const { return data_ == value.data_; } |
| 925 | bool operator!=(Uint64 value) const { return data_ != value.data_; } |
| 926 | Uint64 operator+(Uint64 value) const { return Uint64(data_ + value.data_); } |
| 927 | Uint64 operator-(Uint64 value) const { return Uint64(data_ - value.data_); } |
| 928 | Uint64 operator&(Uint64 value) const { return Uint64(data_ & value.data_); } |
| 929 | Uint64 operator&=(Uint64 value) { |
| 930 | data_ &= value.data_; |
| 931 | return *this; |
| 932 | } |
| 933 | Uint64 operator^(Uint64 value) const { return Uint64(data_ ^ value.data_); } |
| 934 | Uint64 operator^=(Uint64 value) { |
| 935 | data_ ^= value.data_; |
| 936 | return *this; |
| 937 | } |
| 938 | Uint64 operator|(Uint64 value) const { return Uint64(data_ | value.data_); } |
| 939 | Uint64 operator|=(Uint64 value) { |
| 940 | data_ |= value.data_; |
| 941 | return *this; |
| 942 | } |
| 943 | // Unlike uint64_t, the shift functions can accept negative shift and |
| 944 | // return 0 when the shift is too big. |
| 945 | Uint64 operator>>(int shift) const { |
| 946 | if (shift == 0) return *this; |
| 947 | if (shift < 0) { |
| 948 | int tmp = -shift; |
| 949 | if (tmp >= 64) return Uint64(0); |
| 950 | return Uint64(data_ << tmp); |
| 951 | } |
| 952 | int tmp = shift; |
| 953 | if (tmp >= 64) return Uint64(0); |
| 954 | return Uint64(data_ >> tmp); |
| 955 | } |
| 956 | Uint64 operator<<(int shift) const { |
| 957 | if (shift == 0) return *this; |
| 958 | if (shift < 0) { |
| 959 | int tmp = -shift; |
| 960 | if (tmp >= 64) return Uint64(0); |
| 961 | return Uint64(data_ >> tmp); |
| 962 | } |
| 963 | int tmp = shift; |
| 964 | if (tmp >= 64) return Uint64(0); |
| 965 | return Uint64(data_ << tmp); |
| 966 | } |
| 967 | }; |
| 968 | |
| 969 | class Uint128 { |
| 970 | uint64_t data_high_; |
| 971 | uint64_t data_low_; |
| 972 | |
| 973 | public: |
| 974 | Uint128() : data_high_(0), data_low_(0) {} |
| 975 | explicit Uint128(uint64_t data_low) : data_high_(0), data_low_(data_low) {} |
| 976 | explicit Uint128(Uint64 data_low) |
| 977 | : data_high_(0), data_low_(data_low.Get()) {} |
| 978 | Uint128(uint64_t data_high, uint64_t data_low) |
| 979 | : data_high_(data_high), data_low_(data_low) {} |
| 980 | Uint64 ToUint64() const { |
| 981 | VIXL_ASSERT(data_high_ == 0); |
| 982 | return Uint64(data_low_); |
| 983 | } |
| 984 | Uint64 GetHigh64() const { return Uint64(data_high_); } |
| 985 | Uint64 GetLow64() const { return Uint64(data_low_); } |
| 986 | Uint128 operator~() const { return Uint128(~data_high_, ~data_low_); } |
| 987 | bool operator==(Uint128 value) const { |
| 988 | return (data_high_ == value.data_high_) && (data_low_ == value.data_low_); |
| 989 | } |
| 990 | Uint128 operator&(Uint128 value) const { |
| 991 | return Uint128(data_high_ & value.data_high_, data_low_ & value.data_low_); |
| 992 | } |
| 993 | Uint128 operator&=(Uint128 value) { |
| 994 | data_high_ &= value.data_high_; |
| 995 | data_low_ &= value.data_low_; |
| 996 | return *this; |
| 997 | } |
| 998 | Uint128 operator|=(Uint128 value) { |
| 999 | data_high_ |= value.data_high_; |
| 1000 | data_low_ |= value.data_low_; |
| 1001 | return *this; |
| 1002 | } |
| 1003 | Uint128 operator>>(int shift) const { |
| 1004 | VIXL_ASSERT((shift >= 0) && (shift < 128)); |
| 1005 | if (shift == 0) return *this; |
| 1006 | if (shift >= 64) { |
| 1007 | return Uint128(0, data_high_ >> (shift - 64)); |
| 1008 | } |
| 1009 | uint64_t tmp = (data_high_ << (64 - shift)) | (data_low_ >> shift); |
| 1010 | return Uint128(data_high_ >> shift, tmp); |
| 1011 | } |
| 1012 | Uint128 operator<<(int shift) const { |
| 1013 | VIXL_ASSERT((shift >= 0) && (shift < 128)); |
| 1014 | if (shift == 0) return *this; |
| 1015 | if (shift >= 64) { |
| 1016 | return Uint128(data_low_ << (shift - 64), 0); |
| 1017 | } |
| 1018 | uint64_t tmp = (data_high_ << shift) | (data_low_ >> (64 - shift)); |
| 1019 | return Uint128(tmp, data_low_ << shift); |
| 1020 | } |
| 1021 | }; |
| 1022 | |
| 1023 | Uint32::Uint32(Uint64 data) : data_(data.ToUint32().Get()) {} |
| 1024 | Uint64::Uint64(Uint128 data) : data_(data.ToUint64().Get()) {} |
| 1025 | |
| 1026 | Int64 BitCount(Uint32 value); |
| 1027 | |
TatWai Chong | 1363476 | 2019-07-16 16:20:45 -0700 | [diff] [blame] | 1028 | // The algorithm used is adapted from the one described in section 8.2 of |
| 1029 | // Hacker's Delight, by Henry S. Warren, Jr. |
| 1030 | template <unsigned N, typename T> |
| 1031 | int64_t MultiplyHigh(T u, T v) { |
| 1032 | uint64_t u0, v0, w0, u1, v1, w1, w2, t; |
| 1033 | VIXL_STATIC_ASSERT((N == 8) || (N == 16) || (N == 32) || (N == 64)); |
| 1034 | uint64_t sign_mask = UINT64_C(1) << (N - 1); |
| 1035 | uint64_t sign_ext = 0; |
| 1036 | unsigned half_bits = N / 2; |
| 1037 | uint64_t half_mask = GetUintMask(half_bits); |
| 1038 | if (std::numeric_limits<T>::is_signed) { |
| 1039 | sign_ext = UINT64_C(0xffffffffffffffff) << half_bits; |
| 1040 | } |
| 1041 | |
| 1042 | VIXL_ASSERT(sizeof(u) == sizeof(uint64_t)); |
| 1043 | VIXL_ASSERT(sizeof(u) == sizeof(u0)); |
| 1044 | |
| 1045 | u0 = u & half_mask; |
| 1046 | u1 = u >> half_bits | (((u & sign_mask) != 0) ? sign_ext : 0); |
| 1047 | v0 = v & half_mask; |
| 1048 | v1 = v >> half_bits | (((v & sign_mask) != 0) ? sign_ext : 0); |
| 1049 | |
| 1050 | w0 = u0 * v0; |
| 1051 | t = u1 * v0 + (w0 >> half_bits); |
| 1052 | |
| 1053 | w1 = t & half_mask; |
| 1054 | w2 = t >> half_bits | (((t & sign_mask) != 0) ? sign_ext : 0); |
| 1055 | w1 = u0 * v1 + w1; |
| 1056 | w1 = w1 >> half_bits | (((w1 & sign_mask) != 0) ? sign_ext : 0); |
| 1057 | |
| 1058 | uint64_t value = u1 * v1 + w2 + w1; |
| 1059 | int64_t result; |
| 1060 | memcpy(&result, &value, sizeof(result)); |
| 1061 | return result; |
| 1062 | } |
| 1063 | |
Pierre Langlois | d82faf6 | 2018-04-04 13:06:58 +0100 | [diff] [blame] | 1064 | } // namespace internal |
| 1065 | |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 1066 | // The default NaN values (for FPCR.DN=1). |
| 1067 | extern const double kFP64DefaultNaN; |
| 1068 | extern const float kFP32DefaultNaN; |
| 1069 | extern const Float16 kFP16DefaultNaN; |
| 1070 | |
| 1071 | // Floating-point infinity values. |
| 1072 | extern const Float16 kFP16PositiveInfinity; |
| 1073 | extern const Float16 kFP16NegativeInfinity; |
| 1074 | extern const float kFP32PositiveInfinity; |
| 1075 | extern const float kFP32NegativeInfinity; |
| 1076 | extern const double kFP64PositiveInfinity; |
| 1077 | extern const double kFP64NegativeInfinity; |
| 1078 | |
| 1079 | // Floating-point zero values. |
| 1080 | extern const Float16 kFP16PositiveZero; |
| 1081 | extern const Float16 kFP16NegativeZero; |
| 1082 | |
| 1083 | // AArch64 floating-point specifics. These match IEEE-754. |
| 1084 | const unsigned kDoubleMantissaBits = 52; |
| 1085 | const unsigned kDoubleExponentBits = 11; |
| 1086 | const unsigned kFloatMantissaBits = 23; |
| 1087 | const unsigned kFloatExponentBits = 8; |
| 1088 | const unsigned kFloat16MantissaBits = 10; |
| 1089 | const unsigned kFloat16ExponentBits = 5; |
| 1090 | |
| 1091 | enum FPRounding { |
| 1092 | // The first four values are encodable directly by FPCR<RMode>. |
| 1093 | FPTieEven = 0x0, |
| 1094 | FPPositiveInfinity = 0x1, |
| 1095 | FPNegativeInfinity = 0x2, |
| 1096 | FPZero = 0x3, |
| 1097 | |
| 1098 | // The final rounding modes are only available when explicitly specified by |
| 1099 | // the instruction (such as with fcvta). It cannot be set in FPCR. |
| 1100 | FPTieAway, |
| 1101 | FPRoundOdd |
| 1102 | }; |
| 1103 | |
| 1104 | enum UseDefaultNaN { kUseDefaultNaN, kIgnoreDefaultNaN }; |
| 1105 | |
| 1106 | // Assemble the specified IEEE-754 components into the target type and apply |
| 1107 | // appropriate rounding. |
| 1108 | // sign: 0 = positive, 1 = negative |
| 1109 | // exponent: Unbiased IEEE-754 exponent. |
| 1110 | // mantissa: The mantissa of the input. The top bit (which is not encoded for |
| 1111 | // normal IEEE-754 values) must not be omitted. This bit has the |
| 1112 | // value 'pow(2, exponent)'. |
| 1113 | // |
| 1114 | // The input value is assumed to be a normalized value. That is, the input may |
| 1115 | // not be infinity or NaN. If the source value is subnormal, it must be |
| 1116 | // normalized before calling this function such that the highest set bit in the |
| 1117 | // mantissa has the value 'pow(2, exponent)'. |
| 1118 | // |
| 1119 | // Callers should use FPRoundToFloat or FPRoundToDouble directly, rather than |
| 1120 | // calling a templated FPRound. |
| 1121 | template <class T, int ebits, int mbits> |
| 1122 | T FPRound(int64_t sign, |
| 1123 | int64_t exponent, |
| 1124 | uint64_t mantissa, |
| 1125 | FPRounding round_mode) { |
| 1126 | VIXL_ASSERT((sign == 0) || (sign == 1)); |
| 1127 | |
| 1128 | // Only FPTieEven and FPRoundOdd rounding modes are implemented. |
| 1129 | VIXL_ASSERT((round_mode == FPTieEven) || (round_mode == FPRoundOdd)); |
| 1130 | |
| 1131 | // Rounding can promote subnormals to normals, and normals to infinities. For |
| 1132 | // example, a double with exponent 127 (FLT_MAX_EXP) would appear to be |
| 1133 | // encodable as a float, but rounding based on the low-order mantissa bits |
| 1134 | // could make it overflow. With ties-to-even rounding, this value would become |
| 1135 | // an infinity. |
| 1136 | |
| 1137 | // ---- Rounding Method ---- |
| 1138 | // |
| 1139 | // The exponent is irrelevant in the rounding operation, so we treat the |
| 1140 | // lowest-order bit that will fit into the result ('onebit') as having |
| 1141 | // the value '1'. Similarly, the highest-order bit that won't fit into |
| 1142 | // the result ('halfbit') has the value '0.5'. The 'point' sits between |
| 1143 | // 'onebit' and 'halfbit': |
| 1144 | // |
| 1145 | // These bits fit into the result. |
| 1146 | // |---------------------| |
| 1147 | // mantissa = 0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| 1148 | // || |
| 1149 | // / | |
| 1150 | // / halfbit |
| 1151 | // onebit |
| 1152 | // |
| 1153 | // For subnormal outputs, the range of representable bits is smaller and |
| 1154 | // the position of onebit and halfbit depends on the exponent of the |
| 1155 | // input, but the method is otherwise similar. |
| 1156 | // |
| 1157 | // onebit(frac) |
| 1158 | // | |
| 1159 | // | halfbit(frac) halfbit(adjusted) |
| 1160 | // | / / |
| 1161 | // | | | |
| 1162 | // 0b00.0 (exact) -> 0b00.0 (exact) -> 0b00 |
| 1163 | // 0b00.0... -> 0b00.0... -> 0b00 |
| 1164 | // 0b00.1 (exact) -> 0b00.0111..111 -> 0b00 |
| 1165 | // 0b00.1... -> 0b00.1... -> 0b01 |
| 1166 | // 0b01.0 (exact) -> 0b01.0 (exact) -> 0b01 |
| 1167 | // 0b01.0... -> 0b01.0... -> 0b01 |
| 1168 | // 0b01.1 (exact) -> 0b01.1 (exact) -> 0b10 |
| 1169 | // 0b01.1... -> 0b01.1... -> 0b10 |
| 1170 | // 0b10.0 (exact) -> 0b10.0 (exact) -> 0b10 |
| 1171 | // 0b10.0... -> 0b10.0... -> 0b10 |
| 1172 | // 0b10.1 (exact) -> 0b10.0111..111 -> 0b10 |
| 1173 | // 0b10.1... -> 0b10.1... -> 0b11 |
| 1174 | // 0b11.0 (exact) -> 0b11.0 (exact) -> 0b11 |
| 1175 | // ... / | / | |
| 1176 | // / | / | |
| 1177 | // / | |
| 1178 | // adjusted = frac - (halfbit(mantissa) & ~onebit(frac)); / | |
| 1179 | // |
| 1180 | // mantissa = (mantissa >> shift) + halfbit(adjusted); |
| 1181 | |
| 1182 | static const int mantissa_offset = 0; |
| 1183 | static const int exponent_offset = mantissa_offset + mbits; |
| 1184 | static const int sign_offset = exponent_offset + ebits; |
| 1185 | VIXL_ASSERT(sign_offset == (sizeof(T) * 8 - 1)); |
| 1186 | |
| 1187 | // Bail out early for zero inputs. |
| 1188 | if (mantissa == 0) { |
| 1189 | return static_cast<T>(sign << sign_offset); |
| 1190 | } |
| 1191 | |
| 1192 | // If all bits in the exponent are set, the value is infinite or NaN. |
| 1193 | // This is true for all binary IEEE-754 formats. |
| 1194 | static const int infinite_exponent = (1 << ebits) - 1; |
| 1195 | static const int max_normal_exponent = infinite_exponent - 1; |
| 1196 | |
| 1197 | // Apply the exponent bias to encode it for the result. Doing this early makes |
| 1198 | // it easy to detect values that will be infinite or subnormal. |
| 1199 | exponent += max_normal_exponent >> 1; |
| 1200 | |
| 1201 | if (exponent > max_normal_exponent) { |
| 1202 | // Overflow: the input is too large for the result type to represent. |
| 1203 | if (round_mode == FPTieEven) { |
| 1204 | // FPTieEven rounding mode handles overflows using infinities. |
| 1205 | exponent = infinite_exponent; |
| 1206 | mantissa = 0; |
| 1207 | } else { |
| 1208 | VIXL_ASSERT(round_mode == FPRoundOdd); |
| 1209 | // FPRoundOdd rounding mode handles overflows using the largest magnitude |
| 1210 | // normal number. |
| 1211 | exponent = max_normal_exponent; |
| 1212 | mantissa = (UINT64_C(1) << exponent_offset) - 1; |
| 1213 | } |
| 1214 | return static_cast<T>((sign << sign_offset) | |
| 1215 | (exponent << exponent_offset) | |
| 1216 | (mantissa << mantissa_offset)); |
| 1217 | } |
| 1218 | |
| 1219 | // Calculate the shift required to move the top mantissa bit to the proper |
| 1220 | // place in the destination type. |
| 1221 | const int highest_significant_bit = 63 - CountLeadingZeros(mantissa); |
| 1222 | int shift = highest_significant_bit - mbits; |
| 1223 | |
| 1224 | if (exponent <= 0) { |
| 1225 | // The output will be subnormal (before rounding). |
| 1226 | // For subnormal outputs, the shift must be adjusted by the exponent. The +1 |
| 1227 | // is necessary because the exponent of a subnormal value (encoded as 0) is |
| 1228 | // the same as the exponent of the smallest normal value (encoded as 1). |
Anton Kirilov | 088b01f | 2022-09-27 14:27:38 +0100 | [diff] [blame] | 1229 | shift += static_cast<int>(-exponent + 1); |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 1230 | |
| 1231 | // Handle inputs that would produce a zero output. |
| 1232 | // |
| 1233 | // Shifts higher than highest_significant_bit+1 will always produce a zero |
| 1234 | // result. A shift of exactly highest_significant_bit+1 might produce a |
| 1235 | // non-zero result after rounding. |
| 1236 | if (shift > (highest_significant_bit + 1)) { |
| 1237 | if (round_mode == FPTieEven) { |
| 1238 | // The result will always be +/-0.0. |
| 1239 | return static_cast<T>(sign << sign_offset); |
| 1240 | } else { |
| 1241 | VIXL_ASSERT(round_mode == FPRoundOdd); |
| 1242 | VIXL_ASSERT(mantissa != 0); |
| 1243 | // For FPRoundOdd, if the mantissa is too small to represent and |
| 1244 | // non-zero return the next "odd" value. |
| 1245 | return static_cast<T>((sign << sign_offset) | 1); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // Properly encode the exponent for a subnormal output. |
| 1250 | exponent = 0; |
| 1251 | } else { |
| 1252 | // Clear the topmost mantissa bit, since this is not encoded in IEEE-754 |
| 1253 | // normal values. |
| 1254 | mantissa &= ~(UINT64_C(1) << highest_significant_bit); |
| 1255 | } |
| 1256 | |
| 1257 | // The casts below are only well-defined for unsigned integers. |
| 1258 | VIXL_STATIC_ASSERT(std::numeric_limits<T>::is_integer); |
| 1259 | VIXL_STATIC_ASSERT(!std::numeric_limits<T>::is_signed); |
| 1260 | |
| 1261 | if (shift > 0) { |
| 1262 | if (round_mode == FPTieEven) { |
| 1263 | // We have to shift the mantissa to the right. Some precision is lost, so |
| 1264 | // we need to apply rounding. |
| 1265 | uint64_t onebit_mantissa = (mantissa >> (shift)) & 1; |
| 1266 | uint64_t halfbit_mantissa = (mantissa >> (shift - 1)) & 1; |
| 1267 | uint64_t adjustment = (halfbit_mantissa & ~onebit_mantissa); |
| 1268 | uint64_t adjusted = mantissa - adjustment; |
| 1269 | T halfbit_adjusted = (adjusted >> (shift - 1)) & 1; |
| 1270 | |
| 1271 | T result = |
| 1272 | static_cast<T>((sign << sign_offset) | (exponent << exponent_offset) | |
| 1273 | ((mantissa >> shift) << mantissa_offset)); |
| 1274 | |
| 1275 | // A very large mantissa can overflow during rounding. If this happens, |
| 1276 | // the exponent should be incremented and the mantissa set to 1.0 |
| 1277 | // (encoded as 0). Applying halfbit_adjusted after assembling the float |
| 1278 | // has the nice side-effect that this case is handled for free. |
| 1279 | // |
| 1280 | // This also handles cases where a very large finite value overflows to |
| 1281 | // infinity, or where a very large subnormal value overflows to become |
| 1282 | // normal. |
| 1283 | return result + halfbit_adjusted; |
| 1284 | } else { |
| 1285 | VIXL_ASSERT(round_mode == FPRoundOdd); |
| 1286 | // If any bits at position halfbit or below are set, onebit (ie. the |
| 1287 | // bottom bit of the resulting mantissa) must be set. |
| 1288 | uint64_t fractional_bits = mantissa & ((UINT64_C(1) << shift) - 1); |
| 1289 | if (fractional_bits != 0) { |
| 1290 | mantissa |= UINT64_C(1) << shift; |
| 1291 | } |
| 1292 | |
| 1293 | return static_cast<T>((sign << sign_offset) | |
| 1294 | (exponent << exponent_offset) | |
| 1295 | ((mantissa >> shift) << mantissa_offset)); |
| 1296 | } |
| 1297 | } else { |
| 1298 | // We have to shift the mantissa to the left (or not at all). The input |
| 1299 | // mantissa is exactly representable in the output mantissa, so apply no |
| 1300 | // rounding correction. |
| 1301 | return static_cast<T>((sign << sign_offset) | |
| 1302 | (exponent << exponent_offset) | |
| 1303 | ((mantissa << -shift) << mantissa_offset)); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | // See FPRound for a description of this function. |
| 1309 | inline double FPRoundToDouble(int64_t sign, |
| 1310 | int64_t exponent, |
| 1311 | uint64_t mantissa, |
| 1312 | FPRounding round_mode) { |
| 1313 | uint64_t bits = |
| 1314 | FPRound<uint64_t, kDoubleExponentBits, kDoubleMantissaBits>(sign, |
| 1315 | exponent, |
| 1316 | mantissa, |
| 1317 | round_mode); |
| 1318 | return RawbitsToDouble(bits); |
| 1319 | } |
| 1320 | |
| 1321 | |
| 1322 | // See FPRound for a description of this function. |
| 1323 | inline Float16 FPRoundToFloat16(int64_t sign, |
| 1324 | int64_t exponent, |
| 1325 | uint64_t mantissa, |
| 1326 | FPRounding round_mode) { |
| 1327 | return RawbitsToFloat16( |
Jacob Bramley | 2fe55ec | 2020-03-20 17:03:48 +0000 | [diff] [blame] | 1328 | FPRound<uint16_t, kFloat16ExponentBits, kFloat16MantissaBits>( |
| 1329 | sign, exponent, mantissa, round_mode)); |
Jacob Bramley | ca78974 | 2018-09-13 14:25:46 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | // See FPRound for a description of this function. |
| 1334 | static inline float FPRoundToFloat(int64_t sign, |
| 1335 | int64_t exponent, |
| 1336 | uint64_t mantissa, |
| 1337 | FPRounding round_mode) { |
| 1338 | uint32_t bits = |
| 1339 | FPRound<uint32_t, kFloatExponentBits, kFloatMantissaBits>(sign, |
| 1340 | exponent, |
| 1341 | mantissa, |
| 1342 | round_mode); |
| 1343 | return RawbitsToFloat(bits); |
| 1344 | } |
| 1345 | |
| 1346 | |
| 1347 | float FPToFloat(Float16 value, UseDefaultNaN DN, bool* exception = NULL); |
| 1348 | float FPToFloat(double value, |
| 1349 | FPRounding round_mode, |
| 1350 | UseDefaultNaN DN, |
| 1351 | bool* exception = NULL); |
| 1352 | |
| 1353 | double FPToDouble(Float16 value, UseDefaultNaN DN, bool* exception = NULL); |
| 1354 | double FPToDouble(float value, UseDefaultNaN DN, bool* exception = NULL); |
| 1355 | |
| 1356 | Float16 FPToFloat16(float value, |
| 1357 | FPRounding round_mode, |
| 1358 | UseDefaultNaN DN, |
| 1359 | bool* exception = NULL); |
| 1360 | |
| 1361 | Float16 FPToFloat16(double value, |
| 1362 | FPRounding round_mode, |
| 1363 | UseDefaultNaN DN, |
| 1364 | bool* exception = NULL); |
Jacob Bramley | 0f62eab | 2019-10-23 17:07:47 +0100 | [diff] [blame] | 1365 | |
| 1366 | // Like static_cast<T>(value), but with specialisations for the Float16 type. |
| 1367 | template <typename T, typename F> |
| 1368 | T StaticCastFPTo(F value) { |
| 1369 | return static_cast<T>(value); |
| 1370 | } |
| 1371 | |
| 1372 | template <> |
| 1373 | inline float StaticCastFPTo<float, Float16>(Float16 value) { |
| 1374 | return FPToFloat(value, kIgnoreDefaultNaN); |
| 1375 | } |
| 1376 | |
| 1377 | template <> |
| 1378 | inline double StaticCastFPTo<double, Float16>(Float16 value) { |
| 1379 | return FPToDouble(value, kIgnoreDefaultNaN); |
| 1380 | } |
| 1381 | |
| 1382 | template <> |
| 1383 | inline Float16 StaticCastFPTo<Float16, float>(float value) { |
| 1384 | return FPToFloat16(value, FPTieEven, kIgnoreDefaultNaN); |
| 1385 | } |
| 1386 | |
| 1387 | template <> |
| 1388 | inline Float16 StaticCastFPTo<Float16, double>(double value) { |
| 1389 | return FPToFloat16(value, FPTieEven, kIgnoreDefaultNaN); |
| 1390 | } |
| 1391 | |
| 1392 | template <typename T> |
| 1393 | uint64_t FPToRawbitsWithSize(unsigned size_in_bits, T value) { |
| 1394 | switch (size_in_bits) { |
| 1395 | case 16: |
| 1396 | return Float16ToRawbits(StaticCastFPTo<Float16>(value)); |
| 1397 | case 32: |
| 1398 | return FloatToRawbits(StaticCastFPTo<float>(value)); |
| 1399 | case 64: |
| 1400 | return DoubleToRawbits(StaticCastFPTo<double>(value)); |
| 1401 | } |
| 1402 | VIXL_UNREACHABLE(); |
| 1403 | return 0; |
| 1404 | } |
TatWai Chong | db7437c | 2020-01-09 17:44:10 -0800 | [diff] [blame] | 1405 | |
| 1406 | template <typename T> |
| 1407 | T RawbitsWithSizeToFP(unsigned size_in_bits, uint64_t value) { |
| 1408 | VIXL_ASSERT(IsUintN(size_in_bits, value)); |
| 1409 | switch (size_in_bits) { |
| 1410 | case 16: |
| 1411 | return StaticCastFPTo<T>(RawbitsToFloat16(static_cast<uint16_t>(value))); |
| 1412 | case 32: |
| 1413 | return StaticCastFPTo<T>(RawbitsToFloat(static_cast<uint32_t>(value))); |
| 1414 | case 64: |
| 1415 | return StaticCastFPTo<T>(RawbitsToDouble(value)); |
| 1416 | } |
| 1417 | VIXL_UNREACHABLE(); |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
Martyn Capewell | 6bf2875 | 2020-08-05 11:57:06 +0100 | [diff] [blame] | 1421 | // Jenkins one-at-a-time hash, based on |
| 1422 | // https://en.wikipedia.org/wiki/Jenkins_hash_function citing |
| 1423 | // https://www.drdobbs.com/database/algorithm-alley/184410284. |
| 1424 | constexpr uint32_t Hash(const char* str, uint32_t hash = 0) { |
| 1425 | if (*str == '\0') { |
| 1426 | hash += hash << 3; |
| 1427 | hash ^= hash >> 11; |
| 1428 | hash += hash << 15; |
| 1429 | return hash; |
| 1430 | } else { |
| 1431 | hash += *str; |
| 1432 | hash += hash << 10; |
| 1433 | hash ^= hash >> 6; |
| 1434 | return Hash(str + 1, hash); |
| 1435 | } |
| 1436 | } |
| 1437 | |
Martyn Capewell | 8afff39 | 2022-04-19 18:08:39 +0100 | [diff] [blame] | 1438 | constexpr uint32_t operator"" _h(const char* x, size_t) { return Hash(x); } |
| 1439 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 1440 | } // namespace vixl |
| 1441 | |
| 1442 | #endif // VIXL_UTILS_H |