Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_ |
| 18 | #define ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_ |
| 19 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 20 | #include <deque> |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 21 | #include <utility> |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 24 | #include "arch/mips64/instruction_set_features_mips64.h" |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 26 | #include "base/enums.h" |
David Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 27 | #include "base/globals.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 28 | #include "base/macros.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 29 | #include "base/stl_util_identity.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 30 | #include "constants_mips64.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 31 | #include "heap_poisoning.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 32 | #include "managed_register_mips64.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 33 | #include "offsets.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 34 | #include "utils/assembler.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 35 | #include "utils/jni_macro_assembler.h" |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 36 | #include "utils/label.h" |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 37 | |
| 38 | namespace art { |
| 39 | namespace mips64 { |
| 40 | |
Chris Larsen | c733dca | 2016-05-13 16:11:47 -0700 | [diff] [blame] | 41 | enum LoadConst64Path { |
| 42 | kLoadConst64PathZero = 0x0, |
| 43 | kLoadConst64PathOri = 0x1, |
| 44 | kLoadConst64PathDaddiu = 0x2, |
| 45 | kLoadConst64PathLui = 0x4, |
| 46 | kLoadConst64PathLuiOri = 0x8, |
| 47 | kLoadConst64PathOriDahi = 0x10, |
| 48 | kLoadConst64PathOriDati = 0x20, |
| 49 | kLoadConst64PathLuiDahi = 0x40, |
| 50 | kLoadConst64PathLuiDati = 0x80, |
| 51 | kLoadConst64PathDaddiuDsrlX = 0x100, |
| 52 | kLoadConst64PathOriDsllX = 0x200, |
| 53 | kLoadConst64PathDaddiuDsllX = 0x400, |
| 54 | kLoadConst64PathLuiOriDsllX = 0x800, |
| 55 | kLoadConst64PathOriDsllXOri = 0x1000, |
| 56 | kLoadConst64PathDaddiuDsllXOri = 0x2000, |
| 57 | kLoadConst64PathDaddiuDahi = 0x4000, |
| 58 | kLoadConst64PathDaddiuDati = 0x8000, |
| 59 | kLoadConst64PathDinsu1 = 0x10000, |
| 60 | kLoadConst64PathDinsu2 = 0x20000, |
| 61 | kLoadConst64PathCatchAll = 0x40000, |
| 62 | kLoadConst64PathAllPaths = 0x7ffff, |
| 63 | }; |
| 64 | |
| 65 | template <typename Asm> |
| 66 | void TemplateLoadConst32(Asm* a, GpuRegister rd, int32_t value) { |
| 67 | if (IsUint<16>(value)) { |
| 68 | // Use OR with (unsigned) immediate to encode 16b unsigned int. |
| 69 | a->Ori(rd, ZERO, value); |
| 70 | } else if (IsInt<16>(value)) { |
| 71 | // Use ADD with (signed) immediate to encode 16b signed int. |
| 72 | a->Addiu(rd, ZERO, value); |
| 73 | } else { |
| 74 | // Set 16 most significant bits of value. The "lui" instruction |
| 75 | // also clears the 16 least significant bits to zero. |
| 76 | a->Lui(rd, value >> 16); |
| 77 | if (value & 0xFFFF) { |
| 78 | // If the 16 least significant bits are non-zero, set them |
| 79 | // here. |
| 80 | a->Ori(rd, rd, value); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static inline int InstrCountForLoadReplicatedConst32(int64_t value) { |
| 86 | int32_t x = Low32Bits(value); |
| 87 | int32_t y = High32Bits(value); |
| 88 | |
| 89 | if (x == y) { |
Chris Larsen | 8859cec | 2017-08-30 16:40:02 -0700 | [diff] [blame] | 90 | return (IsUint<16>(x) || IsInt<16>(x) || ((x & 0xFFFF) == 0)) ? 2 : 3; |
Chris Larsen | c733dca | 2016-05-13 16:11:47 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return INT_MAX; |
| 94 | } |
| 95 | |
| 96 | template <typename Asm, typename Rtype, typename Vtype> |
| 97 | void TemplateLoadConst64(Asm* a, Rtype rd, Vtype value) { |
| 98 | int bit31 = (value & UINT64_C(0x80000000)) != 0; |
| 99 | int rep32_count = InstrCountForLoadReplicatedConst32(value); |
| 100 | |
| 101 | // Loads with 1 instruction. |
| 102 | if (IsUint<16>(value)) { |
| 103 | // 64-bit value can be loaded as an unsigned 16-bit number. |
| 104 | a->RecordLoadConst64Path(kLoadConst64PathOri); |
| 105 | a->Ori(rd, ZERO, value); |
| 106 | } else if (IsInt<16>(value)) { |
| 107 | // 64-bit value can be loaded as an signed 16-bit number. |
| 108 | a->RecordLoadConst64Path(kLoadConst64PathDaddiu); |
| 109 | a->Daddiu(rd, ZERO, value); |
| 110 | } else if ((value & 0xFFFF) == 0 && IsInt<16>(value >> 16)) { |
| 111 | // 64-bit value can be loaded as an signed 32-bit number which has all |
| 112 | // of its 16 least significant bits set to zero. |
| 113 | a->RecordLoadConst64Path(kLoadConst64PathLui); |
| 114 | a->Lui(rd, value >> 16); |
| 115 | } else if (IsInt<32>(value)) { |
| 116 | // Loads with 2 instructions. |
| 117 | // 64-bit value can be loaded as an signed 32-bit number which has some |
| 118 | // or all of its 16 least significant bits set to one. |
| 119 | a->RecordLoadConst64Path(kLoadConst64PathLuiOri); |
| 120 | a->Lui(rd, value >> 16); |
| 121 | a->Ori(rd, rd, value); |
| 122 | } else if ((value & 0xFFFF0000) == 0 && IsInt<16>(value >> 32)) { |
| 123 | // 64-bit value which consists of an unsigned 16-bit value in its |
| 124 | // least significant 32-bits, and a signed 16-bit value in its |
| 125 | // most significant 32-bits. |
| 126 | a->RecordLoadConst64Path(kLoadConst64PathOriDahi); |
| 127 | a->Ori(rd, ZERO, value); |
| 128 | a->Dahi(rd, value >> 32); |
| 129 | } else if ((value & UINT64_C(0xFFFFFFFF0000)) == 0) { |
| 130 | // 64-bit value which consists of an unsigned 16-bit value in its |
| 131 | // least significant 48-bits, and a signed 16-bit value in its |
| 132 | // most significant 16-bits. |
| 133 | a->RecordLoadConst64Path(kLoadConst64PathOriDati); |
| 134 | a->Ori(rd, ZERO, value); |
| 135 | a->Dati(rd, value >> 48); |
| 136 | } else if ((value & 0xFFFF) == 0 && |
| 137 | (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) { |
| 138 | // 16 LSBs (Least Significant Bits) all set to zero. |
| 139 | // 48 MSBs (Most Significant Bits) hold a signed 32-bit value. |
| 140 | a->RecordLoadConst64Path(kLoadConst64PathLuiDahi); |
| 141 | a->Lui(rd, value >> 16); |
| 142 | a->Dahi(rd, (value >> 32) + bit31); |
| 143 | } else if ((value & 0xFFFF) == 0 && ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) { |
| 144 | // 16 LSBs all set to zero. |
| 145 | // 48 MSBs hold a signed value which can't be represented by signed |
| 146 | // 32-bit number, and the middle 16 bits are all zero, or all one. |
| 147 | a->RecordLoadConst64Path(kLoadConst64PathLuiDati); |
| 148 | a->Lui(rd, value >> 16); |
| 149 | a->Dati(rd, (value >> 48) + bit31); |
| 150 | } else if (IsInt<16>(static_cast<int32_t>(value)) && |
| 151 | (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) { |
| 152 | // 32 LSBs contain an unsigned 16-bit number. |
| 153 | // 32 MSBs contain a signed 16-bit number. |
| 154 | a->RecordLoadConst64Path(kLoadConst64PathDaddiuDahi); |
| 155 | a->Daddiu(rd, ZERO, value); |
| 156 | a->Dahi(rd, (value >> 32) + bit31); |
| 157 | } else if (IsInt<16>(static_cast<int32_t>(value)) && |
| 158 | ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) { |
| 159 | // 48 LSBs contain an unsigned 16-bit number. |
| 160 | // 16 MSBs contain a signed 16-bit number. |
| 161 | a->RecordLoadConst64Path(kLoadConst64PathDaddiuDati); |
| 162 | a->Daddiu(rd, ZERO, value); |
| 163 | a->Dati(rd, (value >> 48) + bit31); |
| 164 | } else if (IsPowerOfTwo(value + UINT64_C(1))) { |
| 165 | // 64-bit values which have their "n" MSBs set to one, and their |
| 166 | // "64-n" LSBs set to zero. "n" must meet the restrictions 0 < n < 64. |
| 167 | int shift_cnt = 64 - CTZ(value + UINT64_C(1)); |
| 168 | a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsrlX); |
| 169 | a->Daddiu(rd, ZERO, -1); |
| 170 | if (shift_cnt < 32) { |
| 171 | a->Dsrl(rd, rd, shift_cnt); |
| 172 | } else { |
| 173 | a->Dsrl32(rd, rd, shift_cnt & 31); |
| 174 | } |
| 175 | } else { |
| 176 | int shift_cnt = CTZ(value); |
| 177 | int64_t tmp = value >> shift_cnt; |
| 178 | a->RecordLoadConst64Path(kLoadConst64PathOriDsllX); |
| 179 | if (IsUint<16>(tmp)) { |
| 180 | // Value can be computed by loading a 16-bit unsigned value, and |
| 181 | // then shifting left. |
| 182 | a->Ori(rd, ZERO, tmp); |
| 183 | if (shift_cnt < 32) { |
| 184 | a->Dsll(rd, rd, shift_cnt); |
| 185 | } else { |
| 186 | a->Dsll32(rd, rd, shift_cnt & 31); |
| 187 | } |
| 188 | } else if (IsInt<16>(tmp)) { |
| 189 | // Value can be computed by loading a 16-bit signed value, and |
| 190 | // then shifting left. |
| 191 | a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllX); |
| 192 | a->Daddiu(rd, ZERO, tmp); |
| 193 | if (shift_cnt < 32) { |
| 194 | a->Dsll(rd, rd, shift_cnt); |
| 195 | } else { |
| 196 | a->Dsll32(rd, rd, shift_cnt & 31); |
| 197 | } |
| 198 | } else if (rep32_count < 3) { |
| 199 | // Value being loaded has 32 LSBs equal to the 32 MSBs, and the |
| 200 | // value loaded into the 32 LSBs can be loaded with a single |
| 201 | // MIPS instruction. |
| 202 | a->LoadConst32(rd, value); |
| 203 | a->Dinsu(rd, rd, 32, 32); |
| 204 | a->RecordLoadConst64Path(kLoadConst64PathDinsu1); |
| 205 | } else if (IsInt<32>(tmp)) { |
| 206 | // Loads with 3 instructions. |
| 207 | // Value can be computed by loading a 32-bit signed value, and |
| 208 | // then shifting left. |
| 209 | a->RecordLoadConst64Path(kLoadConst64PathLuiOriDsllX); |
| 210 | a->Lui(rd, tmp >> 16); |
| 211 | a->Ori(rd, rd, tmp); |
| 212 | if (shift_cnt < 32) { |
| 213 | a->Dsll(rd, rd, shift_cnt); |
| 214 | } else { |
| 215 | a->Dsll32(rd, rd, shift_cnt & 31); |
| 216 | } |
| 217 | } else { |
| 218 | shift_cnt = 16 + CTZ(value >> 16); |
| 219 | tmp = value >> shift_cnt; |
| 220 | if (IsUint<16>(tmp)) { |
| 221 | // Value can be computed by loading a 16-bit unsigned value, |
| 222 | // shifting left, and "or"ing in another 16-bit unsigned value. |
| 223 | a->RecordLoadConst64Path(kLoadConst64PathOriDsllXOri); |
| 224 | a->Ori(rd, ZERO, tmp); |
| 225 | if (shift_cnt < 32) { |
| 226 | a->Dsll(rd, rd, shift_cnt); |
| 227 | } else { |
| 228 | a->Dsll32(rd, rd, shift_cnt & 31); |
| 229 | } |
| 230 | a->Ori(rd, rd, value); |
| 231 | } else if (IsInt<16>(tmp)) { |
| 232 | // Value can be computed by loading a 16-bit signed value, |
| 233 | // shifting left, and "or"ing in a 16-bit unsigned value. |
| 234 | a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllXOri); |
| 235 | a->Daddiu(rd, ZERO, tmp); |
| 236 | if (shift_cnt < 32) { |
| 237 | a->Dsll(rd, rd, shift_cnt); |
| 238 | } else { |
| 239 | a->Dsll32(rd, rd, shift_cnt & 31); |
| 240 | } |
| 241 | a->Ori(rd, rd, value); |
| 242 | } else if (rep32_count < 4) { |
| 243 | // Value being loaded has 32 LSBs equal to the 32 MSBs, and the |
| 244 | // value in the 32 LSBs requires 2 MIPS instructions to load. |
| 245 | a->LoadConst32(rd, value); |
| 246 | a->Dinsu(rd, rd, 32, 32); |
| 247 | a->RecordLoadConst64Path(kLoadConst64PathDinsu2); |
| 248 | } else { |
| 249 | // Loads with 3-4 instructions. |
| 250 | // Catch-all case to get any other 64-bit values which aren't |
| 251 | // handled by special cases above. |
| 252 | uint64_t tmp2 = value; |
| 253 | a->RecordLoadConst64Path(kLoadConst64PathCatchAll); |
| 254 | a->LoadConst32(rd, value); |
| 255 | if (bit31) { |
| 256 | tmp2 += UINT64_C(0x100000000); |
| 257 | } |
| 258 | if (((tmp2 >> 32) & 0xFFFF) != 0) { |
| 259 | a->Dahi(rd, tmp2 >> 32); |
| 260 | } |
| 261 | if (tmp2 & UINT64_C(0x800000000000)) { |
| 262 | tmp2 += UINT64_C(0x1000000000000); |
| 263 | } |
| 264 | if ((tmp2 >> 48) != 0) { |
| 265 | a->Dati(rd, tmp2 >> 48); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 272 | static constexpr size_t kMips64HalfwordSize = 2; |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 273 | static constexpr size_t kMips64WordSize = 4; |
| 274 | static constexpr size_t kMips64DoublewordSize = 8; |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 275 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 276 | enum LoadOperandType { |
| 277 | kLoadSignedByte, |
| 278 | kLoadUnsignedByte, |
| 279 | kLoadSignedHalfword, |
| 280 | kLoadUnsignedHalfword, |
| 281 | kLoadWord, |
Douglas Leung | d90957f | 2015-04-30 19:22:49 -0700 | [diff] [blame] | 282 | kLoadUnsignedWord, |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 283 | kLoadDoubleword, |
| 284 | kLoadQuadword |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | enum StoreOperandType { |
| 288 | kStoreByte, |
| 289 | kStoreHalfword, |
| 290 | kStoreWord, |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 291 | kStoreDoubleword, |
| 292 | kStoreQuadword |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
Chris Larsen | 1450082 | 2015-10-01 11:35:18 -0700 | [diff] [blame] | 295 | // Used to test the values returned by ClassS/ClassD. |
| 296 | enum FPClassMaskType { |
| 297 | kSignalingNaN = 0x001, |
| 298 | kQuietNaN = 0x002, |
| 299 | kNegativeInfinity = 0x004, |
| 300 | kNegativeNormal = 0x008, |
| 301 | kNegativeSubnormal = 0x010, |
| 302 | kNegativeZero = 0x020, |
| 303 | kPositiveInfinity = 0x040, |
| 304 | kPositiveNormal = 0x080, |
| 305 | kPositiveSubnormal = 0x100, |
| 306 | kPositiveZero = 0x200, |
| 307 | }; |
| 308 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 309 | class Mips64Label : public Label { |
| 310 | public: |
| 311 | Mips64Label() : prev_branch_id_plus_one_(0) {} |
| 312 | |
| 313 | Mips64Label(Mips64Label&& src) |
| 314 | : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {} |
| 315 | |
| 316 | private: |
| 317 | uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any. |
| 318 | |
| 319 | friend class Mips64Assembler; |
| 320 | DISALLOW_COPY_AND_ASSIGN(Mips64Label); |
| 321 | }; |
| 322 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 323 | // Assembler literal is a value embedded in code, retrieved using a PC-relative load. |
| 324 | class Literal { |
| 325 | public: |
| 326 | static constexpr size_t kMaxSize = 8; |
| 327 | |
| 328 | Literal(uint32_t size, const uint8_t* data) |
| 329 | : label_(), size_(size) { |
| 330 | DCHECK_LE(size, Literal::kMaxSize); |
| 331 | memcpy(data_, data, size); |
| 332 | } |
| 333 | |
| 334 | template <typename T> |
| 335 | T GetValue() const { |
| 336 | DCHECK_EQ(size_, sizeof(T)); |
| 337 | T value; |
| 338 | memcpy(&value, data_, sizeof(T)); |
| 339 | return value; |
| 340 | } |
| 341 | |
| 342 | uint32_t GetSize() const { |
| 343 | return size_; |
| 344 | } |
| 345 | |
| 346 | const uint8_t* GetData() const { |
| 347 | return data_; |
| 348 | } |
| 349 | |
| 350 | Mips64Label* GetLabel() { |
| 351 | return &label_; |
| 352 | } |
| 353 | |
| 354 | const Mips64Label* GetLabel() const { |
| 355 | return &label_; |
| 356 | } |
| 357 | |
| 358 | private: |
| 359 | Mips64Label label_; |
| 360 | const uint32_t size_; |
| 361 | uint8_t data_[kMaxSize]; |
| 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(Literal); |
| 364 | }; |
| 365 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 366 | // Jump table: table of labels emitted after the code and before the literals. Similar to literals. |
| 367 | class JumpTable { |
| 368 | public: |
| 369 | explicit JumpTable(std::vector<Mips64Label*>&& labels) |
| 370 | : label_(), labels_(std::move(labels)) { |
| 371 | } |
| 372 | |
| 373 | size_t GetSize() const { |
| 374 | return labels_.size() * sizeof(uint32_t); |
| 375 | } |
| 376 | |
| 377 | const std::vector<Mips64Label*>& GetData() const { |
| 378 | return labels_; |
| 379 | } |
| 380 | |
| 381 | Mips64Label* GetLabel() { |
| 382 | return &label_; |
| 383 | } |
| 384 | |
| 385 | const Mips64Label* GetLabel() const { |
| 386 | return &label_; |
| 387 | } |
| 388 | |
| 389 | private: |
| 390 | Mips64Label label_; |
| 391 | std::vector<Mips64Label*> labels_; |
| 392 | |
| 393 | DISALLOW_COPY_AND_ASSIGN(JumpTable); |
| 394 | }; |
| 395 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 396 | // Slowpath entered when Thread::Current()->_exception is non-null. |
| 397 | class Mips64ExceptionSlowPath { |
| 398 | public: |
| 399 | explicit Mips64ExceptionSlowPath(Mips64ManagedRegister scratch, size_t stack_adjust) |
| 400 | : scratch_(scratch), stack_adjust_(stack_adjust) {} |
| 401 | |
| 402 | Mips64ExceptionSlowPath(Mips64ExceptionSlowPath&& src) |
| 403 | : scratch_(src.scratch_), |
| 404 | stack_adjust_(src.stack_adjust_), |
| 405 | exception_entry_(std::move(src.exception_entry_)) {} |
| 406 | |
| 407 | private: |
| 408 | Mips64Label* Entry() { return &exception_entry_; } |
| 409 | const Mips64ManagedRegister scratch_; |
| 410 | const size_t stack_adjust_; |
| 411 | Mips64Label exception_entry_; |
| 412 | |
| 413 | friend class Mips64Assembler; |
| 414 | DISALLOW_COPY_AND_ASSIGN(Mips64ExceptionSlowPath); |
| 415 | }; |
| 416 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 417 | class Mips64Assembler final : public Assembler, public JNIMacroAssembler<PointerSize::k64> { |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 418 | public: |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 419 | using JNIBase = JNIMacroAssembler<PointerSize::k64>; |
| 420 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 421 | explicit Mips64Assembler(ArenaAllocator* allocator, |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 422 | const Mips64InstructionSetFeatures* instruction_set_features = nullptr) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 423 | : Assembler(allocator), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 424 | overwriting_(false), |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 425 | overwrite_location_(0), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 426 | literals_(allocator->Adapter(kArenaAllocAssembler)), |
| 427 | long_literals_(allocator->Adapter(kArenaAllocAssembler)), |
| 428 | jump_tables_(allocator->Adapter(kArenaAllocAssembler)), |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 429 | last_position_adjustment_(0), |
| 430 | last_old_position_(0), |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 431 | last_branch_id_(0), |
| 432 | has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false) { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 433 | cfi().DelayEmittingAdvancePCs(); |
| 434 | } |
| 435 | |
| 436 | virtual ~Mips64Assembler() { |
| 437 | for (auto& branch : branches_) { |
| 438 | CHECK(branch.IsResolved()); |
| 439 | } |
| 440 | } |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 441 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 442 | size_t CodeSize() const override { return Assembler::CodeSize(); } |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 443 | DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); } |
| 444 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 445 | // Emit Machine Instructions. |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 446 | void Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 447 | void Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 448 | void Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 449 | void Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 450 | void Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 451 | void Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 452 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 453 | void MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 454 | void MuhR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 455 | void DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 456 | void ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 457 | void DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 458 | void ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 459 | void Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 460 | void Dmuh(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 461 | void Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 462 | void Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 463 | void Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
| 464 | void Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 465 | |
| 466 | void And(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 467 | void Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 468 | void Or(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 469 | void Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 470 | void Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 471 | void Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 472 | void Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 473 | |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 474 | void Bitswap(GpuRegister rd, GpuRegister rt); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 475 | void Dbitswap(GpuRegister rd, GpuRegister rt); // MIPS64 |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 476 | void Seb(GpuRegister rd, GpuRegister rt); |
| 477 | void Seh(GpuRegister rd, GpuRegister rt); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 478 | void Dsbh(GpuRegister rd, GpuRegister rt); // MIPS64 |
| 479 | void Dshd(GpuRegister rd, GpuRegister rt); // MIPS64 |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 480 | void Dext(GpuRegister rs, GpuRegister rt, int pos, int size); // MIPS64 |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 481 | void Ins(GpuRegister rt, GpuRegister rs, int pos, int size); |
| 482 | void Dins(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64 |
| 483 | void Dinsm(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64 |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 484 | void Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64 |
Lena Djokic | a556e6b | 2017-12-13 12:09:42 +0100 | [diff] [blame] | 485 | void DblIns(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64 |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 486 | void Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); |
| 487 | void Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); // MIPS64 |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 488 | void Wsbh(GpuRegister rd, GpuRegister rt); |
| 489 | void Sc(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 490 | void Scd(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64 |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 491 | void Ll(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 492 | void Lld(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64 |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 493 | |
| 494 | void Sll(GpuRegister rd, GpuRegister rt, int shamt); |
| 495 | void Srl(GpuRegister rd, GpuRegister rt, int shamt); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 496 | void Rotr(GpuRegister rd, GpuRegister rt, int shamt); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 497 | void Sra(GpuRegister rd, GpuRegister rt, int shamt); |
| 498 | void Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); |
| 499 | void Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); |
Chris Larsen | 9aebff2 | 2015-09-22 17:54:15 -0700 | [diff] [blame] | 500 | void Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 501 | void Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs); |
| 502 | void Dsll(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
| 503 | void Dsrl(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 504 | void Drotr(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 505 | void Dsra(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
| 506 | void Dsll32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
| 507 | void Dsrl32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
Chris Larsen | 9aebff2 | 2015-09-22 17:54:15 -0700 | [diff] [blame] | 508 | void Drotr32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 509 | void Dsra32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64 |
| 510 | void Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64 |
| 511 | void Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64 |
Chris Larsen | 9aebff2 | 2015-09-22 17:54:15 -0700 | [diff] [blame] | 512 | void Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64 |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 513 | void Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 514 | |
| 515 | void Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 516 | void Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 517 | void Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 518 | void Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 519 | void Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 520 | void Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 521 | void Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64 |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 522 | void Lwpc(GpuRegister rs, uint32_t imm19); |
| 523 | void Lwupc(GpuRegister rs, uint32_t imm19); // MIPS64 |
| 524 | void Ldpc(GpuRegister rs, uint32_t imm18); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 525 | void Lui(GpuRegister rt, uint16_t imm16); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 526 | void Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 527 | void Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64 |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 528 | void Dahi(GpuRegister rs, uint16_t imm16); // MIPS64 |
| 529 | void Dati(GpuRegister rs, uint16_t imm16); // MIPS64 |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 530 | void Sync(uint32_t stype); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 531 | |
| 532 | void Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 533 | void Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 534 | void Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 535 | void Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 536 | |
| 537 | void Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 538 | void Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 539 | void Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
| 540 | void Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 541 | void Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 542 | void Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt); |
| 543 | void Clz(GpuRegister rd, GpuRegister rs); |
| 544 | void Clo(GpuRegister rd, GpuRegister rs); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 545 | void Dclz(GpuRegister rd, GpuRegister rs); // MIPS64 |
| 546 | void Dclo(GpuRegister rd, GpuRegister rs); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 547 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 548 | void Jalr(GpuRegister rd, GpuRegister rs); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 549 | void Jalr(GpuRegister rs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 550 | void Jr(GpuRegister rs); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 551 | void Auipc(GpuRegister rs, uint16_t imm16); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 552 | void Addiupc(GpuRegister rs, uint32_t imm19); |
| 553 | void Bc(uint32_t imm26); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 554 | void Balc(uint32_t imm26); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 555 | void Jic(GpuRegister rt, uint16_t imm16); |
| 556 | void Jialc(GpuRegister rt, uint16_t imm16); |
| 557 | void Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 558 | void Bltzc(GpuRegister rt, uint16_t imm16); |
| 559 | void Bgtzc(GpuRegister rt, uint16_t imm16); |
| 560 | void Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 561 | void Bgezc(GpuRegister rt, uint16_t imm16); |
| 562 | void Blezc(GpuRegister rt, uint16_t imm16); |
| 563 | void Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 564 | void Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 565 | void Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 566 | void Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16); |
| 567 | void Beqzc(GpuRegister rs, uint32_t imm21); |
| 568 | void Bnezc(GpuRegister rs, uint32_t imm21); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 569 | void Bc1eqz(FpuRegister ft, uint16_t imm16); |
| 570 | void Bc1nez(FpuRegister ft, uint16_t imm16); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 571 | void Beq(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2 |
| 572 | void Bne(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2 |
| 573 | void Beqz(GpuRegister rt, uint16_t imm16); // R2 |
| 574 | void Bnez(GpuRegister rt, uint16_t imm16); // R2 |
| 575 | void Bltz(GpuRegister rt, uint16_t imm16); // R2 |
| 576 | void Bgez(GpuRegister rt, uint16_t imm16); // R2 |
| 577 | void Blez(GpuRegister rt, uint16_t imm16); // R2 |
| 578 | void Bgtz(GpuRegister rt, uint16_t imm16); // R2 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 579 | |
| 580 | void AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 581 | void SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 582 | void MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 583 | void DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 584 | void AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 585 | void SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 586 | void MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 587 | void DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 588 | void SqrtS(FpuRegister fd, FpuRegister fs); |
| 589 | void SqrtD(FpuRegister fd, FpuRegister fs); |
| 590 | void AbsS(FpuRegister fd, FpuRegister fs); |
| 591 | void AbsD(FpuRegister fd, FpuRegister fs); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 592 | void MovS(FpuRegister fd, FpuRegister fs); |
| 593 | void MovD(FpuRegister fd, FpuRegister fs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 594 | void NegS(FpuRegister fd, FpuRegister fs); |
| 595 | void NegD(FpuRegister fd, FpuRegister fs); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 596 | void RoundLS(FpuRegister fd, FpuRegister fs); |
| 597 | void RoundLD(FpuRegister fd, FpuRegister fs); |
| 598 | void RoundWS(FpuRegister fd, FpuRegister fs); |
| 599 | void RoundWD(FpuRegister fd, FpuRegister fs); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 600 | void TruncLS(FpuRegister fd, FpuRegister fs); |
| 601 | void TruncLD(FpuRegister fd, FpuRegister fs); |
| 602 | void TruncWS(FpuRegister fd, FpuRegister fs); |
| 603 | void TruncWD(FpuRegister fd, FpuRegister fs); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 604 | void CeilLS(FpuRegister fd, FpuRegister fs); |
| 605 | void CeilLD(FpuRegister fd, FpuRegister fs); |
| 606 | void CeilWS(FpuRegister fd, FpuRegister fs); |
| 607 | void CeilWD(FpuRegister fd, FpuRegister fs); |
| 608 | void FloorLS(FpuRegister fd, FpuRegister fs); |
| 609 | void FloorLD(FpuRegister fd, FpuRegister fs); |
| 610 | void FloorWS(FpuRegister fd, FpuRegister fs); |
| 611 | void FloorWD(FpuRegister fd, FpuRegister fs); |
| 612 | void SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 613 | void SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
Goran Jakovljevic | 2dec927 | 2017-08-02 11:41:26 +0200 | [diff] [blame] | 614 | void SeleqzS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 615 | void SeleqzD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 616 | void SelnezS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 617 | void SelnezD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 618 | void RintS(FpuRegister fd, FpuRegister fs); |
| 619 | void RintD(FpuRegister fd, FpuRegister fs); |
| 620 | void ClassS(FpuRegister fd, FpuRegister fs); |
| 621 | void ClassD(FpuRegister fd, FpuRegister fs); |
| 622 | void MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 623 | void MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 624 | void MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 625 | void MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 626 | void CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 627 | void CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 628 | void CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 629 | void CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 630 | void CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 631 | void CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 632 | void CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 633 | void CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 634 | void CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 635 | void CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 636 | void CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 637 | void CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 638 | void CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 639 | void CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 640 | void CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 641 | void CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 642 | void CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 643 | void CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 644 | void CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
| 645 | void CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 646 | |
| 647 | void Cvtsw(FpuRegister fd, FpuRegister fs); |
| 648 | void Cvtdw(FpuRegister fd, FpuRegister fs); |
| 649 | void Cvtsd(FpuRegister fd, FpuRegister fs); |
| 650 | void Cvtds(FpuRegister fd, FpuRegister fs); |
Chris Larsen | 5141763 | 2015-10-02 13:24:25 -0700 | [diff] [blame] | 651 | void Cvtsl(FpuRegister fd, FpuRegister fs); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 652 | void Cvtdl(FpuRegister fd, FpuRegister fs); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 653 | |
| 654 | void Mfc1(GpuRegister rt, FpuRegister fs); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 655 | void Mfhc1(GpuRegister rt, FpuRegister fs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 656 | void Mtc1(GpuRegister rt, FpuRegister fs); |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 657 | void Mthc1(GpuRegister rt, FpuRegister fs); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 658 | void Dmfc1(GpuRegister rt, FpuRegister fs); // MIPS64 |
| 659 | void Dmtc1(GpuRegister rt, FpuRegister fs); // MIPS64 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 660 | void Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16); |
| 661 | void Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16); |
| 662 | void Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16); |
| 663 | void Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16); |
| 664 | |
| 665 | void Break(); |
| 666 | void Nop(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 667 | void Move(GpuRegister rd, GpuRegister rs); |
| 668 | void Clear(GpuRegister rd); |
| 669 | void Not(GpuRegister rd, GpuRegister rs); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 670 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 671 | // MSA instructions. |
| 672 | void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 673 | void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 674 | void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 675 | void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 676 | |
| 677 | void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 678 | void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 679 | void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 680 | void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 681 | void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 682 | void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 683 | void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 684 | void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Lena Djokic | 72aba71 | 2017-10-30 15:47:20 +0100 | [diff] [blame] | 685 | void Asub_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 686 | void Asub_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 687 | void Asub_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 688 | void Asub_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 689 | void Asub_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 690 | void Asub_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 691 | void Asub_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 692 | void Asub_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 693 | void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 694 | void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 695 | void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 696 | void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 697 | void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 698 | void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 699 | void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 700 | void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 701 | void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 702 | void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 703 | void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 704 | void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 705 | void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 706 | void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 707 | void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 708 | void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 709 | void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 710 | void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 711 | void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 712 | void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 80248d7 | 2017-04-20 11:55:47 +0200 | [diff] [blame] | 713 | void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 714 | void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 715 | void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 716 | void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 717 | void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 718 | void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 719 | void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 720 | void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 721 | void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 722 | void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 723 | void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 724 | void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 725 | void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 726 | void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 727 | void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 728 | void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 729 | void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 730 | void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 731 | void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 732 | void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 658263e | 2017-06-07 09:35:53 +0200 | [diff] [blame] | 733 | void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 734 | void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 735 | void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 736 | void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 737 | void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 738 | void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 739 | void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 740 | void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 741 | void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 742 | void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 743 | void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 744 | void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 745 | void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 746 | void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 747 | void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 748 | void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 749 | |
| 750 | void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 751 | void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 752 | void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 753 | void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 754 | void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 755 | void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 756 | void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 757 | void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 658263e | 2017-06-07 09:35:53 +0200 | [diff] [blame] | 758 | void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 759 | void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 760 | void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 761 | void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 762 | |
| 763 | void Ffint_sW(VectorRegister wd, VectorRegister ws); |
| 764 | void Ffint_sD(VectorRegister wd, VectorRegister ws); |
| 765 | void Ftint_sW(VectorRegister wd, VectorRegister ws); |
| 766 | void Ftint_sD(VectorRegister wd, VectorRegister ws); |
| 767 | |
| 768 | void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 769 | void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 770 | void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 771 | void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 772 | void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 773 | void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 774 | void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 775 | void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 776 | void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 777 | void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 778 | void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 779 | void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 780 | |
| 781 | // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1). |
| 782 | void SlliB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 783 | void SlliH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 784 | void SlliW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 785 | void SlliD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 786 | void SraiB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 787 | void SraiH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 788 | void SraiW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 789 | void SraiD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 790 | void SrliB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 791 | void SrliH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 792 | void SrliW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 793 | void SrliD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 794 | |
| 795 | void MoveV(VectorRegister wd, VectorRegister ws); |
| 796 | void SplatiB(VectorRegister wd, VectorRegister ws, int n4); |
| 797 | void SplatiH(VectorRegister wd, VectorRegister ws, int n3); |
| 798 | void SplatiW(VectorRegister wd, VectorRegister ws, int n2); |
| 799 | void SplatiD(VectorRegister wd, VectorRegister ws, int n1); |
Lena Djokic | 3309c01 | 2017-10-13 14:34:32 +0200 | [diff] [blame] | 800 | void Copy_sB(GpuRegister rd, VectorRegister ws, int n4); |
| 801 | void Copy_sH(GpuRegister rd, VectorRegister ws, int n3); |
| 802 | void Copy_sW(GpuRegister rd, VectorRegister ws, int n2); |
| 803 | void Copy_sD(GpuRegister rd, VectorRegister ws, int n1); |
| 804 | void Copy_uB(GpuRegister rd, VectorRegister ws, int n4); |
| 805 | void Copy_uH(GpuRegister rd, VectorRegister ws, int n3); |
| 806 | void Copy_uW(GpuRegister rd, VectorRegister ws, int n2); |
| 807 | void InsertB(VectorRegister wd, GpuRegister rs, int n4); |
| 808 | void InsertH(VectorRegister wd, GpuRegister rs, int n3); |
| 809 | void InsertW(VectorRegister wd, GpuRegister rs, int n2); |
| 810 | void InsertD(VectorRegister wd, GpuRegister rs, int n1); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 811 | void FillB(VectorRegister wd, GpuRegister rs); |
| 812 | void FillH(VectorRegister wd, GpuRegister rs); |
| 813 | void FillW(VectorRegister wd, GpuRegister rs); |
| 814 | void FillD(VectorRegister wd, GpuRegister rs); |
| 815 | |
Goran Jakovljevic | 3f44403 | 2017-03-31 14:38:20 +0200 | [diff] [blame] | 816 | void LdiB(VectorRegister wd, int imm8); |
| 817 | void LdiH(VectorRegister wd, int imm10); |
| 818 | void LdiW(VectorRegister wd, int imm10); |
| 819 | void LdiD(VectorRegister wd, int imm10); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 820 | void LdB(VectorRegister wd, GpuRegister rs, int offset); |
| 821 | void LdH(VectorRegister wd, GpuRegister rs, int offset); |
| 822 | void LdW(VectorRegister wd, GpuRegister rs, int offset); |
| 823 | void LdD(VectorRegister wd, GpuRegister rs, int offset); |
| 824 | void StB(VectorRegister wd, GpuRegister rs, int offset); |
| 825 | void StH(VectorRegister wd, GpuRegister rs, int offset); |
| 826 | void StW(VectorRegister wd, GpuRegister rs, int offset); |
| 827 | void StD(VectorRegister wd, GpuRegister rs, int offset); |
| 828 | |
Lena Djokic | 3309c01 | 2017-10-13 14:34:32 +0200 | [diff] [blame] | 829 | void IlvlB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 830 | void IlvlH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 831 | void IlvlW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 832 | void IlvlD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 3837011 | 2017-05-10 14:30:28 +0200 | [diff] [blame] | 833 | void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 834 | void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 835 | void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 836 | void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Lena Djokic | 3309c01 | 2017-10-13 14:34:32 +0200 | [diff] [blame] | 837 | void IlvevB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 838 | void IlvevH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 839 | void IlvevW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 840 | void IlvevD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 841 | void IlvodB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 842 | void IlvodH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 843 | void IlvodW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 844 | void IlvodD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
Goran Jakovljevic | 3837011 | 2017-05-10 14:30:28 +0200 | [diff] [blame] | 845 | |
Lena Djokic | b3d79e4 | 2017-07-25 11:20:52 +0200 | [diff] [blame] | 846 | void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 847 | void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 848 | void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 849 | void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 850 | void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 851 | void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 852 | void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 853 | void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 854 | void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 855 | void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 856 | void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 857 | void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 858 | |
Lena Djokic | 3309c01 | 2017-10-13 14:34:32 +0200 | [diff] [blame] | 859 | void Hadd_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 860 | void Hadd_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 861 | void Hadd_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 862 | void Hadd_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 863 | void Hadd_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 864 | void Hadd_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 865 | |
Lena Djokic | 0d2cab5 | 2018-03-06 15:20:45 +0100 | [diff] [blame] | 866 | void PcntB(VectorRegister wd, VectorRegister ws); |
| 867 | void PcntH(VectorRegister wd, VectorRegister ws); |
| 868 | void PcntW(VectorRegister wd, VectorRegister ws); |
| 869 | void PcntD(VectorRegister wd, VectorRegister ws); |
| 870 | |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 871 | // Helper for replicating floating point value in all destination elements. |
| 872 | void ReplicateFPToVectorRegister(VectorRegister dst, FpuRegister src, bool is_double); |
| 873 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 874 | // Higher level composite instructions. |
Chris Larsen | c733dca | 2016-05-13 16:11:47 -0700 | [diff] [blame] | 875 | int InstrCountForLoadReplicatedConst32(int64_t); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 876 | void LoadConst32(GpuRegister rd, int32_t value); |
| 877 | void LoadConst64(GpuRegister rd, int64_t value); // MIPS64 |
| 878 | |
Chris Larsen | c733dca | 2016-05-13 16:11:47 -0700 | [diff] [blame] | 879 | // This function is only used for testing purposes. |
| 880 | void RecordLoadConst64Path(int value); |
| 881 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 882 | void Addiu32(GpuRegister rt, GpuRegister rs, int32_t value); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 883 | void Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp = AT); // MIPS64 |
| 884 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 885 | // |
| 886 | // Heap poisoning. |
| 887 | // |
| 888 | |
| 889 | // Poison a heap reference contained in `src` and store it in `dst`. |
| 890 | void PoisonHeapReference(GpuRegister dst, GpuRegister src) { |
| 891 | // dst = -src. |
| 892 | // Negate the 32-bit ref. |
| 893 | Dsubu(dst, ZERO, src); |
| 894 | // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64. |
| 895 | Dext(dst, dst, 0, 32); |
| 896 | } |
| 897 | // Poison a heap reference contained in `reg`. |
| 898 | void PoisonHeapReference(GpuRegister reg) { |
| 899 | // reg = -reg. |
| 900 | PoisonHeapReference(reg, reg); |
| 901 | } |
| 902 | // Unpoison a heap reference contained in `reg`. |
| 903 | void UnpoisonHeapReference(GpuRegister reg) { |
| 904 | // reg = -reg. |
| 905 | // Negate the 32-bit ref. |
| 906 | Dsubu(reg, ZERO, reg); |
| 907 | // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64. |
| 908 | Dext(reg, reg, 0, 32); |
| 909 | } |
| 910 | // Poison a heap reference contained in `reg` if heap poisoning is enabled. |
| 911 | void MaybePoisonHeapReference(GpuRegister reg) { |
| 912 | if (kPoisonHeapReferences) { |
| 913 | PoisonHeapReference(reg); |
| 914 | } |
| 915 | } |
| 916 | // Unpoison a heap reference contained in `reg` if heap poisoning is enabled. |
| 917 | void MaybeUnpoisonHeapReference(GpuRegister reg) { |
| 918 | if (kPoisonHeapReferences) { |
| 919 | UnpoisonHeapReference(reg); |
| 920 | } |
| 921 | } |
| 922 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 923 | void Bind(Label* label) override { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 924 | Bind(down_cast<Mips64Label*>(label)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 925 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 926 | void Jump(Label* label ATTRIBUTE_UNUSED) override { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 927 | UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS64"; |
| 928 | } |
| 929 | |
| 930 | void Bind(Mips64Label* label); |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 931 | |
| 932 | // Don't warn about a different virtual Bind/Jump in the base class. |
| 933 | using JNIBase::Bind; |
| 934 | using JNIBase::Jump; |
| 935 | |
| 936 | // Create a new label that can be used with Jump/Bind calls. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 937 | std::unique_ptr<JNIMacroLabel> CreateLabel() override { |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 938 | LOG(FATAL) << "Not implemented on MIPS64"; |
| 939 | UNREACHABLE(); |
| 940 | } |
| 941 | // Emit an unconditional jump to the label. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 942 | void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) override { |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 943 | LOG(FATAL) << "Not implemented on MIPS64"; |
| 944 | UNREACHABLE(); |
| 945 | } |
| 946 | // Emit a conditional jump to the label by applying a unary condition test to the register. |
| 947 | void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED, |
| 948 | JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 949 | ManagedRegister test ATTRIBUTE_UNUSED) override { |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 950 | LOG(FATAL) << "Not implemented on MIPS64"; |
| 951 | UNREACHABLE(); |
| 952 | } |
| 953 | |
| 954 | // Code at this offset will serve as the target for the Jump call. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 955 | void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) override { |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 956 | LOG(FATAL) << "Not implemented on MIPS64"; |
| 957 | UNREACHABLE(); |
| 958 | } |
| 959 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 960 | // Create a new literal with a given value. |
| 961 | // NOTE: Force the template parameter to be explicitly specified. |
| 962 | template <typename T> |
| 963 | Literal* NewLiteral(typename Identity<T>::type value) { |
| 964 | static_assert(std::is_integral<T>::value, "T must be an integral type."); |
| 965 | return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value)); |
| 966 | } |
| 967 | |
| 968 | // Load label address using PC-relative loads. To be used with data labels in the literal / |
| 969 | // jump table area only and not with regular code labels. |
| 970 | void LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label); |
| 971 | |
| 972 | // Create a new literal with the given data. |
| 973 | Literal* NewLiteral(size_t size, const uint8_t* data); |
| 974 | |
| 975 | // Load literal using PC-relative loads. |
| 976 | void LoadLiteral(GpuRegister dest_reg, LoadOperandType load_type, Literal* literal); |
| 977 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 978 | // Create a jump table for the given labels that will be emitted when finalizing. |
| 979 | // When the table is emitted, offsets will be relative to the location of the table. |
| 980 | // The table location is determined by the location of its label (the label precedes |
| 981 | // the table data) and should be loaded using LoadLabelAddress(). |
| 982 | JumpTable* CreateJumpTable(std::vector<Mips64Label*>&& labels); |
| 983 | |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 984 | // When `is_bare` is false, the branches will promote to long (if the range |
| 985 | // of the individual branch instruction is insufficient) and the delay/ |
| 986 | // forbidden slots will be taken care of. |
| 987 | // Use `is_bare = false` when the branch target may be out of reach of the |
| 988 | // individual branch instruction. IOW, this is for general purpose use. |
| 989 | // |
| 990 | // When `is_bare` is true, just the branch instructions will be generated |
| 991 | // leaving delay/forbidden slot filling up to the caller and the branches |
| 992 | // won't promote to long if the range is insufficient (you'll get a |
| 993 | // compilation error when the range is exceeded). |
| 994 | // Use `is_bare = true` when the branch target is known to be within reach |
| 995 | // of the individual branch instruction. This is intended for small local |
| 996 | // optimizations around delay/forbidden slots. |
| 997 | // Also prefer using `is_bare = true` if the code near the branch is to be |
| 998 | // patched or analyzed at run time (e.g. introspection) to |
| 999 | // - show the intent and |
| 1000 | // - fail during compilation rather than during patching/execution if the |
| 1001 | // bare branch range is insufficent but the code size and layout are |
| 1002 | // expected to remain unchanged |
| 1003 | // |
| 1004 | // R6 compact branches without delay/forbidden slots. |
| 1005 | void Bc(Mips64Label* label, bool is_bare = false); |
| 1006 | void Balc(Mips64Label* label, bool is_bare = false); |
| 1007 | // R6 compact branches with forbidden slots. |
| 1008 | void Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1009 | void Bltzc(GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1010 | void Bgtzc(GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1011 | void Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1012 | void Bgezc(GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1013 | void Blezc(GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1014 | void Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1015 | void Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1016 | void Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1017 | void Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); |
| 1018 | void Beqzc(GpuRegister rs, Mips64Label* label, bool is_bare = false); |
| 1019 | void Bnezc(GpuRegister rs, Mips64Label* label, bool is_bare = false); |
| 1020 | // R6 branches with delay slots. |
| 1021 | void Bc1eqz(FpuRegister ft, Mips64Label* label, bool is_bare = false); |
| 1022 | void Bc1nez(FpuRegister ft, Mips64Label* label, bool is_bare = false); |
| 1023 | // R2 branches with delay slots that are also available on R6. |
| 1024 | // The `is_bare` parameter exists and is checked in these branches only to |
| 1025 | // prevent programming mistakes. These branches never promote to long, not |
| 1026 | // even if `is_bare` is false. |
| 1027 | void Bltz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1028 | void Bgtz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1029 | void Bgez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1030 | void Blez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1031 | void Beq(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1032 | void Bne(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2 |
| 1033 | void Beqz(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2 |
| 1034 | void Bnez(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2 |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1035 | |
| 1036 | void EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset, size_t size); |
Chris Larsen | c3fec0c | 2016-12-15 11:44:14 -0800 | [diff] [blame] | 1037 | void AdjustBaseAndOffset(GpuRegister& base, int32_t& offset, bool is_doubleword); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1038 | // If element_size_shift is negative at entry, its value will be calculated based on the offset. |
| 1039 | void AdjustBaseOffsetAndElementSizeShift(GpuRegister& base, |
| 1040 | int32_t& offset, |
| 1041 | int& element_size_shift); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1042 | |
| 1043 | private: |
| 1044 | // This will be used as an argument for loads/stores |
| 1045 | // when there is no need for implicit null checks. |
| 1046 | struct NoImplicitNullChecker { |
| 1047 | void operator()() const {} |
| 1048 | }; |
| 1049 | |
| 1050 | public: |
| 1051 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 1052 | void StoreConstToOffset(StoreOperandType type, |
| 1053 | int64_t value, |
| 1054 | GpuRegister base, |
| 1055 | int32_t offset, |
| 1056 | GpuRegister temp, |
| 1057 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 1058 | // We permit `base` and `temp` to coincide (however, we check that neither is AT), |
| 1059 | // in which case the `base` register may be overwritten in the process. |
| 1060 | CHECK_NE(temp, AT); // Must not use AT as temp, so as not to overwrite the adjusted base. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1061 | AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword)); |
Tijana Jakovljevic | ba89c34 | 2017-03-10 13:36:08 +0100 | [diff] [blame] | 1062 | GpuRegister reg; |
| 1063 | // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp` |
| 1064 | // to load and hold the value but we can use AT instead as AT hasn't been used yet. |
| 1065 | // Otherwise, `temp` can be used for the value. And if `temp` is the same as the |
| 1066 | // original `base` (that is, `base` prior to the adjustment), the original `base` |
| 1067 | // register will be overwritten. |
| 1068 | if (base == temp) { |
| 1069 | temp = AT; |
| 1070 | } |
| 1071 | |
| 1072 | if (type == kStoreDoubleword && IsAligned<kMips64DoublewordSize>(offset)) { |
| 1073 | if (value == 0) { |
| 1074 | reg = ZERO; |
| 1075 | } else { |
| 1076 | reg = temp; |
| 1077 | LoadConst64(reg, value); |
| 1078 | } |
| 1079 | Sd(reg, base, offset); |
| 1080 | null_checker(); |
| 1081 | } else { |
| 1082 | uint32_t low = Low32Bits(value); |
| 1083 | uint32_t high = High32Bits(value); |
| 1084 | if (low == 0) { |
| 1085 | reg = ZERO; |
| 1086 | } else { |
| 1087 | reg = temp; |
| 1088 | LoadConst32(reg, low); |
| 1089 | } |
| 1090 | switch (type) { |
| 1091 | case kStoreByte: |
| 1092 | Sb(reg, base, offset); |
| 1093 | break; |
| 1094 | case kStoreHalfword: |
| 1095 | Sh(reg, base, offset); |
| 1096 | break; |
| 1097 | case kStoreWord: |
| 1098 | Sw(reg, base, offset); |
| 1099 | break; |
| 1100 | case kStoreDoubleword: |
| 1101 | // not aligned to kMips64DoublewordSize |
| 1102 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1103 | Sw(reg, base, offset); |
| 1104 | null_checker(); |
| 1105 | if (high == 0) { |
| 1106 | reg = ZERO; |
| 1107 | } else { |
| 1108 | reg = temp; |
| 1109 | if (high != low) { |
| 1110 | LoadConst32(reg, high); |
| 1111 | } |
| 1112 | } |
| 1113 | Sw(reg, base, offset + kMips64WordSize); |
| 1114 | break; |
| 1115 | default: |
| 1116 | LOG(FATAL) << "UNREACHABLE"; |
| 1117 | } |
| 1118 | if (type != kStoreDoubleword) { |
| 1119 | null_checker(); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1125 | void LoadFromOffset(LoadOperandType type, |
| 1126 | GpuRegister reg, |
| 1127 | GpuRegister base, |
| 1128 | int32_t offset, |
| 1129 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1130 | AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kLoadDoubleword)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1131 | |
| 1132 | switch (type) { |
| 1133 | case kLoadSignedByte: |
| 1134 | Lb(reg, base, offset); |
| 1135 | break; |
| 1136 | case kLoadUnsignedByte: |
| 1137 | Lbu(reg, base, offset); |
| 1138 | break; |
| 1139 | case kLoadSignedHalfword: |
| 1140 | Lh(reg, base, offset); |
| 1141 | break; |
| 1142 | case kLoadUnsignedHalfword: |
| 1143 | Lhu(reg, base, offset); |
| 1144 | break; |
| 1145 | case kLoadWord: |
| 1146 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1147 | Lw(reg, base, offset); |
| 1148 | break; |
| 1149 | case kLoadUnsignedWord: |
| 1150 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1151 | Lwu(reg, base, offset); |
| 1152 | break; |
| 1153 | case kLoadDoubleword: |
| 1154 | if (!IsAligned<kMips64DoublewordSize>(offset)) { |
| 1155 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1156 | Lwu(reg, base, offset); |
| 1157 | null_checker(); |
| 1158 | Lwu(TMP2, base, offset + kMips64WordSize); |
| 1159 | Dinsu(reg, TMP2, 32, 32); |
| 1160 | } else { |
| 1161 | Ld(reg, base, offset); |
| 1162 | null_checker(); |
| 1163 | } |
| 1164 | break; |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1165 | default: |
| 1166 | LOG(FATAL) << "UNREACHABLE"; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1167 | } |
| 1168 | if (type != kLoadDoubleword) { |
| 1169 | null_checker(); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 1174 | void LoadFpuFromOffset(LoadOperandType type, |
| 1175 | FpuRegister reg, |
| 1176 | GpuRegister base, |
| 1177 | int32_t offset, |
| 1178 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1179 | int element_size_shift = -1; |
| 1180 | if (type != kLoadQuadword) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1181 | AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kLoadDoubleword)); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1182 | } else { |
| 1183 | AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift); |
| 1184 | } |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1185 | |
| 1186 | switch (type) { |
| 1187 | case kLoadWord: |
| 1188 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1189 | Lwc1(reg, base, offset); |
| 1190 | null_checker(); |
| 1191 | break; |
| 1192 | case kLoadDoubleword: |
| 1193 | if (!IsAligned<kMips64DoublewordSize>(offset)) { |
| 1194 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1195 | Lwc1(reg, base, offset); |
| 1196 | null_checker(); |
| 1197 | Lw(TMP2, base, offset + kMips64WordSize); |
| 1198 | Mthc1(TMP2, reg); |
| 1199 | } else { |
| 1200 | Ldc1(reg, base, offset); |
| 1201 | null_checker(); |
| 1202 | } |
| 1203 | break; |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1204 | case kLoadQuadword: |
| 1205 | switch (element_size_shift) { |
| 1206 | case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break; |
| 1207 | case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break; |
| 1208 | case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break; |
| 1209 | case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break; |
| 1210 | default: |
| 1211 | LOG(FATAL) << "UNREACHABLE"; |
| 1212 | } |
| 1213 | null_checker(); |
| 1214 | break; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1215 | default: |
| 1216 | LOG(FATAL) << "UNREACHABLE"; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 1221 | void StoreToOffset(StoreOperandType type, |
| 1222 | GpuRegister reg, |
| 1223 | GpuRegister base, |
| 1224 | int32_t offset, |
| 1225 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
Chris Larsen | c3fec0c | 2016-12-15 11:44:14 -0800 | [diff] [blame] | 1226 | // Must not use AT as `reg`, so as not to overwrite the value being stored |
| 1227 | // with the adjusted `base`. |
| 1228 | CHECK_NE(reg, AT); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1229 | AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword)); |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1230 | |
| 1231 | switch (type) { |
| 1232 | case kStoreByte: |
| 1233 | Sb(reg, base, offset); |
| 1234 | break; |
| 1235 | case kStoreHalfword: |
| 1236 | Sh(reg, base, offset); |
| 1237 | break; |
| 1238 | case kStoreWord: |
| 1239 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1240 | Sw(reg, base, offset); |
| 1241 | break; |
| 1242 | case kStoreDoubleword: |
| 1243 | if (!IsAligned<kMips64DoublewordSize>(offset)) { |
| 1244 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1245 | Sw(reg, base, offset); |
| 1246 | null_checker(); |
| 1247 | Dsrl32(TMP2, reg, 0); |
| 1248 | Sw(TMP2, base, offset + kMips64WordSize); |
| 1249 | } else { |
| 1250 | Sd(reg, base, offset); |
| 1251 | null_checker(); |
| 1252 | } |
| 1253 | break; |
| 1254 | default: |
| 1255 | LOG(FATAL) << "UNREACHABLE"; |
| 1256 | } |
| 1257 | if (type != kStoreDoubleword) { |
| 1258 | null_checker(); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 1263 | void StoreFpuToOffset(StoreOperandType type, |
| 1264 | FpuRegister reg, |
| 1265 | GpuRegister base, |
| 1266 | int32_t offset, |
| 1267 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1268 | int element_size_shift = -1; |
| 1269 | if (type != kStoreQuadword) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1270 | AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword)); |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1271 | } else { |
| 1272 | AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift); |
| 1273 | } |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1274 | |
| 1275 | switch (type) { |
| 1276 | case kStoreWord: |
| 1277 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1278 | Swc1(reg, base, offset); |
| 1279 | null_checker(); |
| 1280 | break; |
| 1281 | case kStoreDoubleword: |
| 1282 | if (!IsAligned<kMips64DoublewordSize>(offset)) { |
| 1283 | CHECK_ALIGNED(offset, kMips64WordSize); |
| 1284 | Mfhc1(TMP2, reg); |
| 1285 | Swc1(reg, base, offset); |
| 1286 | null_checker(); |
| 1287 | Sw(TMP2, base, offset + kMips64WordSize); |
| 1288 | } else { |
| 1289 | Sdc1(reg, base, offset); |
| 1290 | null_checker(); |
| 1291 | } |
| 1292 | break; |
Goran Jakovljevic | d8b6a53 | 2017-04-20 11:42:30 +0200 | [diff] [blame] | 1293 | case kStoreQuadword: |
| 1294 | switch (element_size_shift) { |
| 1295 | case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break; |
| 1296 | case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break; |
| 1297 | case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break; |
| 1298 | case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break; |
| 1299 | default: |
| 1300 | LOG(FATAL) << "UNREACHABLE"; |
| 1301 | } |
| 1302 | null_checker(); |
| 1303 | break; |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 1304 | default: |
| 1305 | LOG(FATAL) << "UNREACHABLE"; |
| 1306 | } |
| 1307 | } |
| 1308 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1309 | void LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base, int32_t offset); |
| 1310 | void LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base, int32_t offset); |
| 1311 | void StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base, int32_t offset); |
| 1312 | void StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base, int32_t offset); |
| 1313 | |
| 1314 | // Emit data (e.g. encoded instruction or immediate) to the instruction stream. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1315 | void Emit(uint32_t value); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1316 | |
| 1317 | // |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1318 | // Overridden common assembler high-level functionality. |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1319 | // |
| 1320 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1321 | // Emit code that will create an activation on the stack. |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 1322 | void BuildFrame(size_t frame_size, |
| 1323 | ManagedRegister method_reg, |
| 1324 | ArrayRef<const ManagedRegister> callee_save_regs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1325 | const ManagedRegisterEntrySpills& entry_spills) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1326 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1327 | // Emit code that will remove an activation from the stack. |
Roland Levillain | 0d127e1 | 2017-07-05 17:01:11 +0100 | [diff] [blame] | 1328 | void RemoveFrame(size_t frame_size, |
| 1329 | ArrayRef<const ManagedRegister> callee_save_regs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1330 | bool may_suspend) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1331 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1332 | void IncreaseFrameSize(size_t adjust) override; |
| 1333 | void DecreaseFrameSize(size_t adjust) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1334 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1335 | // Store routines. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1336 | void Store(FrameOffset offs, ManagedRegister msrc, size_t size) override; |
| 1337 | void StoreRef(FrameOffset dest, ManagedRegister msrc) override; |
| 1338 | void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1339 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1340 | void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1341 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1342 | void StoreStackOffsetToThread(ThreadOffset64 thr_offs, |
| 1343 | FrameOffset fr_offs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1344 | ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1345 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1346 | void StoreStackPointerToThread(ThreadOffset64 thr_offs) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1347 | |
| 1348 | void StoreSpanning(FrameOffset dest, ManagedRegister msrc, FrameOffset in_off, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1349 | ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1350 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1351 | // Load routines. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1352 | void Load(ManagedRegister mdest, FrameOffset src, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1354 | void LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1355 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1356 | void LoadRef(ManagedRegister dest, FrameOffset src) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1357 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1358 | void LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1359 | bool unpoison_reference) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1360 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1361 | void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1362 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1363 | void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1364 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1365 | // Copying routines. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1366 | void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1367 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1368 | void CopyRawPtrFromThread(FrameOffset fr_offs, |
| 1369 | ThreadOffset64 thr_offs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1370 | ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1371 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1372 | void CopyRawPtrToThread(ThreadOffset64 thr_offs, |
| 1373 | FrameOffset fr_offs, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1374 | ManagedRegister mscratch) override; |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1375 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1376 | void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1377 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1378 | void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1379 | |
| 1380 | void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister mscratch, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1381 | size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1382 | |
| 1383 | void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1384 | ManagedRegister mscratch, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1385 | |
| 1386 | void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister mscratch, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1387 | size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1388 | |
| 1389 | void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1390 | ManagedRegister mscratch, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1391 | |
| 1392 | void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1393 | ManagedRegister mscratch, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1394 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1395 | void MemoryBarrier(ManagedRegister) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1396 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1397 | // Sign extension. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1398 | void SignExtend(ManagedRegister mreg, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1399 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1400 | // Zero extension. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1401 | void ZeroExtend(ManagedRegister mreg, size_t size) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1402 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1403 | // Exploit fast access in managed code to Thread::Current(). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1404 | void GetCurrentThread(ManagedRegister tr) override; |
| 1405 | void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1406 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1407 | // Set up out_reg to hold a Object** into the handle scope, or to be null if the |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1408 | // value is null and null_allowed. in_reg holds a possibly stale reference |
| 1409 | // that can be used to avoid loading the handle scope entry to see if the value is |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1410 | // null. |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1411 | void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1412 | ManagedRegister in_reg, bool null_allowed) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1413 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1414 | // Set up out_off to hold a Object** into the handle scope, or to be null if the |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1415 | // value is null and null_allowed. |
| 1416 | void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset, ManagedRegister |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1417 | mscratch, bool null_allowed) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1418 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1419 | // src holds a handle scope entry (Object**) load this into dst. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1420 | void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1421 | |
| 1422 | // Heap::VerifyObject on src. In some cases (such as a reference to this) we |
| 1423 | // know that src may not be null. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1424 | void VerifyObject(ManagedRegister src, bool could_be_null) override; |
| 1425 | void VerifyObject(FrameOffset src, bool could_be_null) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1426 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1427 | // Call to address held at [base+offset]. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1428 | void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) override; |
| 1429 | void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) override; |
| 1430 | void CallFromThread(ThreadOffset64 offset, ManagedRegister mscratch) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1431 | |
| 1432 | // Generate code to check if Thread::Current()->exception_ is non-null |
| 1433 | // and branch to a ExceptionSlowPath if it is. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1434 | void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) override; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1435 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1436 | // Emit slow paths queued during assembly and promote short branches to long if needed. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1437 | void FinalizeCode() override; |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1438 | |
| 1439 | // Emit branches and finalize all instructions. |
| 1440 | void FinalizeInstructions(const MemoryRegion& region); |
| 1441 | |
| 1442 | // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS64, |
| 1443 | // must be used instead of Mips64Label::GetPosition()). |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1444 | uint32_t GetLabelLocation(const Mips64Label* label) const; |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1445 | |
| 1446 | // Get the final position of a label after local fixup based on the old position |
| 1447 | // recorded before FinalizeCode(). |
| 1448 | uint32_t GetAdjustedPosition(uint32_t old_position); |
| 1449 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1450 | // Note that PC-relative literal loads are handled as pseudo branches because they need very |
| 1451 | // similar relocation and may similarly expand in size to accomodate for larger offsets relative |
| 1452 | // to PC. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1453 | enum BranchCondition { |
| 1454 | kCondLT, |
| 1455 | kCondGE, |
| 1456 | kCondLE, |
| 1457 | kCondGT, |
| 1458 | kCondLTZ, |
| 1459 | kCondGEZ, |
| 1460 | kCondLEZ, |
| 1461 | kCondGTZ, |
| 1462 | kCondEQ, |
| 1463 | kCondNE, |
| 1464 | kCondEQZ, |
| 1465 | kCondNEZ, |
| 1466 | kCondLTU, |
| 1467 | kCondGEU, |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 1468 | kCondF, // Floating-point predicate false. |
| 1469 | kCondT, // Floating-point predicate true. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1470 | kUncond, |
| 1471 | }; |
| 1472 | friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs); |
| 1473 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1474 | private: |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1475 | class Branch { |
| 1476 | public: |
| 1477 | enum Type { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1478 | // R6 short branches (can be promoted to long). |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1479 | kUncondBranch, |
| 1480 | kCondBranch, |
| 1481 | kCall, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1482 | // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually. |
| 1483 | kBareUncondBranch, |
| 1484 | kBareCondBranch, |
| 1485 | kBareCall, |
| 1486 | // R2 short branches (can't be promoted to long), delay slots filled manually. |
| 1487 | kR2BareCondBranch, |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1488 | // Near label. |
| 1489 | kLabel, |
| 1490 | // Near literals. |
| 1491 | kLiteral, |
| 1492 | kLiteralUnsigned, |
| 1493 | kLiteralLong, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1494 | // Long branches. |
| 1495 | kLongUncondBranch, |
| 1496 | kLongCondBranch, |
| 1497 | kLongCall, |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1498 | // Far label. |
| 1499 | kFarLabel, |
| 1500 | // Far literals. |
| 1501 | kFarLiteral, |
| 1502 | kFarLiteralUnsigned, |
| 1503 | kFarLiteralLong, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1504 | }; |
| 1505 | |
| 1506 | // Bit sizes of offsets defined as enums to minimize chance of typos. |
| 1507 | enum OffsetBits { |
| 1508 | kOffset16 = 16, |
| 1509 | kOffset18 = 18, |
| 1510 | kOffset21 = 21, |
| 1511 | kOffset23 = 23, |
| 1512 | kOffset28 = 28, |
| 1513 | kOffset32 = 32, |
| 1514 | }; |
| 1515 | |
| 1516 | static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_ |
| 1517 | static constexpr int32_t kMaxBranchLength = 32; |
| 1518 | static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t); |
| 1519 | |
| 1520 | struct BranchInfo { |
| 1521 | // Branch length as a number of 4-byte-long instructions. |
| 1522 | uint32_t length; |
| 1523 | // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's |
| 1524 | // PC-relative offset (or its most significant 16-bit half, which goes first). |
| 1525 | uint32_t instr_offset; |
| 1526 | // Different MIPS instructions with PC-relative offsets apply said offsets to slightly |
| 1527 | // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte |
| 1528 | // instructions) from the instruction containing the offset. |
| 1529 | uint32_t pc_org; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1530 | // How large (in bits) a PC-relative offset can be for a given type of branch (kCondBranch |
| 1531 | // and kBareCondBranch are an exception: use kOffset23 for beqzc/bnezc). |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1532 | OffsetBits offset_size; |
| 1533 | // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift |
| 1534 | // count. |
| 1535 | int offset_shift; |
| 1536 | }; |
| 1537 | static const BranchInfo branch_info_[/* Type */]; |
| 1538 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1539 | // Unconditional branch or call. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1540 | Branch(uint32_t location, uint32_t target, bool is_call, bool is_bare); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1541 | // Conditional branch. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1542 | Branch(bool is_r6, |
| 1543 | uint32_t location, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1544 | uint32_t target, |
| 1545 | BranchCondition condition, |
| 1546 | GpuRegister lhs_reg, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1547 | GpuRegister rhs_reg, |
| 1548 | bool is_bare); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1549 | // Label address (in literal area) or literal. |
| 1550 | Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1551 | |
| 1552 | // Some conditional branches with lhs = rhs are effectively NOPs, while some |
| 1553 | // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs. |
| 1554 | // So, we need a way to identify such branches in order to emit no instructions for them |
| 1555 | // or change them to unconditional. |
| 1556 | static bool IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs); |
| 1557 | static bool IsUncond(BranchCondition condition, GpuRegister lhs, GpuRegister rhs); |
| 1558 | |
| 1559 | static BranchCondition OppositeCondition(BranchCondition cond); |
| 1560 | |
| 1561 | Type GetType() const; |
| 1562 | BranchCondition GetCondition() const; |
| 1563 | GpuRegister GetLeftRegister() const; |
| 1564 | GpuRegister GetRightRegister() const; |
| 1565 | uint32_t GetTarget() const; |
| 1566 | uint32_t GetLocation() const; |
| 1567 | uint32_t GetOldLocation() const; |
| 1568 | uint32_t GetLength() const; |
| 1569 | uint32_t GetOldLength() const; |
| 1570 | uint32_t GetSize() const; |
| 1571 | uint32_t GetOldSize() const; |
| 1572 | uint32_t GetEndLocation() const; |
| 1573 | uint32_t GetOldEndLocation() const; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1574 | bool IsBare() const; |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1575 | bool IsLong() const; |
| 1576 | bool IsResolved() const; |
| 1577 | |
| 1578 | // Returns the bit size of the signed offset that the branch instruction can handle. |
| 1579 | OffsetBits GetOffsetSize() const; |
| 1580 | |
| 1581 | // Calculates the distance between two byte locations in the assembler buffer and |
| 1582 | // returns the number of bits needed to represent the distance as a signed integer. |
| 1583 | // |
| 1584 | // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc), |
| 1585 | // and 26 (bc) bits, which are additionally shifted left 2 positions at run time. |
| 1586 | // |
| 1587 | // Composite branches (made of several instructions) with longer reach have 32-bit |
| 1588 | // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first). |
| 1589 | // The composite branches cover the range of PC + ~+/-2GB. The range is not end-to-end, |
| 1590 | // however. Consider the following implementation of a long unconditional branch, for |
| 1591 | // example: |
| 1592 | // |
| 1593 | // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16 |
| 1594 | // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0) |
| 1595 | // |
| 1596 | // Both of the above instructions take 16-bit signed offsets as immediate operands. |
| 1597 | // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000 |
| 1598 | // due to sign extension. This must be compensated for by incrementing offset_31_16 |
| 1599 | // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is |
| 1600 | // 0x7FFF, adding 1 will overflow the positive offset into the negative range. |
| 1601 | // Therefore, the long branch range is something like from PC - 0x80000000 to |
| 1602 | // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side. |
| 1603 | // |
| 1604 | // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special |
| 1605 | // case with the addiu instruction and a 16 bit offset. |
| 1606 | static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target); |
| 1607 | |
| 1608 | // Resolve a branch when the target is known. |
| 1609 | void Resolve(uint32_t target); |
| 1610 | |
| 1611 | // Relocate a branch by a given delta if needed due to expansion of this or another |
| 1612 | // branch at a given location by this delta (just changes location_ and target_). |
| 1613 | void Relocate(uint32_t expand_location, uint32_t delta); |
| 1614 | |
| 1615 | // If the branch is short, changes its type to long. |
| 1616 | void PromoteToLong(); |
| 1617 | |
| 1618 | // If necessary, updates the type by promoting a short branch to a long branch |
| 1619 | // based on the branch location and target. Returns the amount (in bytes) by |
| 1620 | // which the branch size has increased. |
| 1621 | // max_short_distance caps the maximum distance between location_ and target_ |
| 1622 | // that is allowed for short branches. This is for debugging/testing purposes. |
| 1623 | // max_short_distance = 0 forces all short branches to become long. |
| 1624 | // Use the implicit default argument when not debugging/testing. |
| 1625 | uint32_t PromoteIfNeeded(uint32_t max_short_distance = std::numeric_limits<uint32_t>::max()); |
| 1626 | |
| 1627 | // Returns the location of the instruction(s) containing the offset. |
| 1628 | uint32_t GetOffsetLocation() const; |
| 1629 | |
| 1630 | // Calculates and returns the offset ready for encoding in the branch instruction(s). |
| 1631 | uint32_t GetOffset() const; |
| 1632 | |
| 1633 | private: |
| 1634 | // Completes branch construction by determining and recording its type. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1635 | void InitializeType(Type initial_type, bool is_r6); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1636 | // Helper for the above. |
| 1637 | void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type); |
| 1638 | |
| 1639 | uint32_t old_location_; // Offset into assembler buffer in bytes. |
| 1640 | uint32_t location_; // Offset into assembler buffer in bytes. |
| 1641 | uint32_t target_; // Offset into assembler buffer in bytes. |
| 1642 | |
| 1643 | GpuRegister lhs_reg_; // Left-hand side register in conditional branches or |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1644 | // destination register in literals. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1645 | GpuRegister rhs_reg_; // Right-hand side register in conditional branches. |
| 1646 | BranchCondition condition_; // Condition for conditional branches. |
| 1647 | |
| 1648 | Type type_; // Current type of the branch. |
| 1649 | Type old_type_; // Initial type of the branch. |
| 1650 | }; |
| 1651 | friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs); |
| 1652 | friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs); |
| 1653 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1654 | void EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd, int shamt, int funct); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 1655 | void EmitRsd(int opcode, GpuRegister rs, GpuRegister rd, int shamt, int funct); |
| 1656 | void EmitRtd(int opcode, GpuRegister rt, GpuRegister rd, int shamt, int funct); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1657 | void EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 1658 | void EmitI21(int opcode, GpuRegister rs, uint32_t imm21); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1659 | void EmitI26(int opcode, uint32_t imm26); |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1660 | void EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd, int funct); |
| 1661 | void EmitFI(int opcode, int fmt, FpuRegister rt, uint16_t imm); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1662 | void EmitBcondR6(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint32_t imm16_21); |
| 1663 | void EmitBcondR2(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint16_t imm16); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 1664 | void EmitMsa3R(int operation, |
| 1665 | int df, |
| 1666 | VectorRegister wt, |
| 1667 | VectorRegister ws, |
| 1668 | VectorRegister wd, |
| 1669 | int minor_opcode); |
| 1670 | void EmitMsaBIT(int operation, int df_m, VectorRegister ws, VectorRegister wd, int minor_opcode); |
| 1671 | void EmitMsaELM(int operation, int df_n, VectorRegister ws, VectorRegister wd, int minor_opcode); |
| 1672 | void EmitMsaMI10(int s10, GpuRegister rs, VectorRegister wd, int minor_opcode, int df); |
Goran Jakovljevic | 3f44403 | 2017-03-31 14:38:20 +0200 | [diff] [blame] | 1673 | void EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame] | 1674 | void EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode); |
| 1675 | void EmitMsa2RF(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1676 | |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1677 | void Buncond(Mips64Label* label, bool is_bare); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1678 | void Bcond(Mips64Label* label, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1679 | bool is_r6, |
| 1680 | bool is_bare, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1681 | BranchCondition condition, |
| 1682 | GpuRegister lhs, |
| 1683 | GpuRegister rhs = ZERO); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1684 | void Call(Mips64Label* label, bool is_bare); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1685 | void FinalizeLabeledBranch(Mips64Label* label); |
| 1686 | |
| 1687 | Branch* GetBranch(uint32_t branch_id); |
| 1688 | const Branch* GetBranch(uint32_t branch_id) const; |
| 1689 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1690 | void EmitLiterals(); |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 1691 | void ReserveJumpTableSpace(); |
| 1692 | void EmitJumpTables(); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1693 | void PromoteBranches(); |
| 1694 | void EmitBranch(Branch* branch); |
| 1695 | void EmitBranches(); |
| 1696 | void PatchCFI(); |
| 1697 | |
| 1698 | // Emits exception block. |
| 1699 | void EmitExceptionPoll(Mips64ExceptionSlowPath* exception); |
| 1700 | |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 1701 | bool HasMsa() const { |
| 1702 | return has_msa_; |
| 1703 | } |
| 1704 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1705 | // List of exception blocks to generate at the end of the code cache. |
| 1706 | std::vector<Mips64ExceptionSlowPath> exception_blocks_; |
| 1707 | |
| 1708 | std::vector<Branch> branches_; |
| 1709 | |
| 1710 | // Whether appending instructions at the end of the buffer or overwriting the existing ones. |
| 1711 | bool overwriting_; |
| 1712 | // The current overwrite location. |
| 1713 | uint32_t overwrite_location_; |
| 1714 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 1715 | // Use std::deque<> for literal labels to allow insertions at the end |
| 1716 | // without invalidating pointers and references to existing elements. |
| 1717 | ArenaDeque<Literal> literals_; |
| 1718 | ArenaDeque<Literal> long_literals_; // 64-bit literals separated for alignment reasons. |
| 1719 | |
Alexey Frunze | 0960ac5 | 2016-12-20 17:24:59 -0800 | [diff] [blame] | 1720 | // Jump table list. |
| 1721 | ArenaDeque<JumpTable> jump_tables_; |
| 1722 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1723 | // Data for AdjustedPosition(), see the description there. |
| 1724 | uint32_t last_position_adjustment_; |
| 1725 | uint32_t last_old_position_; |
| 1726 | uint32_t last_branch_id_; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1727 | |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 1728 | const bool has_msa_; |
| 1729 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1730 | DISALLOW_COPY_AND_ASSIGN(Mips64Assembler); |
| 1731 | }; |
| 1732 | |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 1733 | } // namespace mips64 |
| 1734 | } // namespace art |
| 1735 | |
| 1736 | #endif // ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_ |