jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_ |
| 18 | #define ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_ |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 19 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 20 | #include <deque> |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 21 | #include <utility> |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 22 | #include <vector> |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 23 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 24 | #include "arch/mips/instruction_set_features_mips.h" |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [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" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 27 | #include "base/macros.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 28 | #include "base/stl_util_identity.h" |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 29 | #include "constants_mips.h" |
| 30 | #include "globals.h" |
| 31 | #include "managed_register_mips.h" |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 32 | #include "offsets.h" |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 33 | #include "utils/assembler.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 34 | #include "utils/jni_macro_assembler.h" |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 35 | #include "utils/label.h" |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 36 | |
| 37 | namespace art { |
| 38 | namespace mips { |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 39 | |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 40 | static constexpr size_t kMipsHalfwordSize = 2; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 41 | static constexpr size_t kMipsWordSize = 4; |
| 42 | static constexpr size_t kMipsDoublewordSize = 8; |
| 43 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 44 | enum LoadOperandType { |
| 45 | kLoadSignedByte, |
| 46 | kLoadUnsignedByte, |
| 47 | kLoadSignedHalfword, |
| 48 | kLoadUnsignedHalfword, |
| 49 | kLoadWord, |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 50 | kLoadDoubleword, |
| 51 | kLoadQuadword |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | enum StoreOperandType { |
| 55 | kStoreByte, |
| 56 | kStoreHalfword, |
| 57 | kStoreWord, |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 58 | kStoreDoubleword, |
| 59 | kStoreQuadword |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 62 | // Used to test the values returned by ClassS/ClassD. |
| 63 | enum FPClassMaskType { |
| 64 | kSignalingNaN = 0x001, |
| 65 | kQuietNaN = 0x002, |
| 66 | kNegativeInfinity = 0x004, |
| 67 | kNegativeNormal = 0x008, |
| 68 | kNegativeSubnormal = 0x010, |
| 69 | kNegativeZero = 0x020, |
| 70 | kPositiveInfinity = 0x040, |
| 71 | kPositiveNormal = 0x080, |
| 72 | kPositiveSubnormal = 0x100, |
| 73 | kPositiveZero = 0x200, |
| 74 | }; |
| 75 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 76 | class MipsLabel : public Label { |
| 77 | public: |
| 78 | MipsLabel() : prev_branch_id_plus_one_(0) {} |
| 79 | |
| 80 | MipsLabel(MipsLabel&& src) |
| 81 | : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {} |
| 82 | |
| 83 | private: |
| 84 | uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any. |
| 85 | |
| 86 | friend class MipsAssembler; |
| 87 | DISALLOW_COPY_AND_ASSIGN(MipsLabel); |
| 88 | }; |
| 89 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 90 | // Assembler literal is a value embedded in code, retrieved using a PC-relative load. |
| 91 | class Literal { |
| 92 | public: |
| 93 | static constexpr size_t kMaxSize = 8; |
| 94 | |
| 95 | Literal(uint32_t size, const uint8_t* data) |
| 96 | : label_(), size_(size) { |
| 97 | DCHECK_LE(size, Literal::kMaxSize); |
| 98 | memcpy(data_, data, size); |
| 99 | } |
| 100 | |
| 101 | template <typename T> |
| 102 | T GetValue() const { |
| 103 | DCHECK_EQ(size_, sizeof(T)); |
| 104 | T value; |
| 105 | memcpy(&value, data_, sizeof(T)); |
| 106 | return value; |
| 107 | } |
| 108 | |
| 109 | uint32_t GetSize() const { |
| 110 | return size_; |
| 111 | } |
| 112 | |
| 113 | const uint8_t* GetData() const { |
| 114 | return data_; |
| 115 | } |
| 116 | |
| 117 | MipsLabel* GetLabel() { |
| 118 | return &label_; |
| 119 | } |
| 120 | |
| 121 | const MipsLabel* GetLabel() const { |
| 122 | return &label_; |
| 123 | } |
| 124 | |
| 125 | private: |
| 126 | MipsLabel label_; |
| 127 | const uint32_t size_; |
| 128 | uint8_t data_[kMaxSize]; |
| 129 | |
| 130 | DISALLOW_COPY_AND_ASSIGN(Literal); |
| 131 | }; |
| 132 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 133 | // Jump table: table of labels emitted after the literals. Similar to literals. |
| 134 | class JumpTable { |
| 135 | public: |
| 136 | explicit JumpTable(std::vector<MipsLabel*>&& labels) |
| 137 | : label_(), labels_(std::move(labels)) { |
| 138 | } |
| 139 | |
| 140 | uint32_t GetSize() const { |
| 141 | return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t); |
| 142 | } |
| 143 | |
| 144 | const std::vector<MipsLabel*>& GetData() const { |
| 145 | return labels_; |
| 146 | } |
| 147 | |
| 148 | MipsLabel* GetLabel() { |
| 149 | return &label_; |
| 150 | } |
| 151 | |
| 152 | const MipsLabel* GetLabel() const { |
| 153 | return &label_; |
| 154 | } |
| 155 | |
| 156 | private: |
| 157 | MipsLabel label_; |
| 158 | std::vector<MipsLabel*> labels_; |
| 159 | |
| 160 | DISALLOW_COPY_AND_ASSIGN(JumpTable); |
| 161 | }; |
| 162 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 163 | // Slowpath entered when Thread::Current()->_exception is non-null. |
| 164 | class MipsExceptionSlowPath { |
| 165 | public: |
| 166 | explicit MipsExceptionSlowPath(MipsManagedRegister scratch, size_t stack_adjust) |
| 167 | : scratch_(scratch), stack_adjust_(stack_adjust) {} |
| 168 | |
| 169 | MipsExceptionSlowPath(MipsExceptionSlowPath&& src) |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 170 | : scratch_(src.scratch_), |
| 171 | stack_adjust_(src.stack_adjust_), |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 172 | exception_entry_(std::move(src.exception_entry_)) {} |
| 173 | |
| 174 | private: |
| 175 | MipsLabel* Entry() { return &exception_entry_; } |
| 176 | const MipsManagedRegister scratch_; |
| 177 | const size_t stack_adjust_; |
| 178 | MipsLabel exception_entry_; |
| 179 | |
| 180 | friend class MipsAssembler; |
| 181 | DISALLOW_COPY_AND_ASSIGN(MipsExceptionSlowPath); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 184 | class MipsAssembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> { |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 185 | public: |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 186 | using JNIBase = JNIMacroAssembler<PointerSize::k32>; |
| 187 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 188 | explicit MipsAssembler(ArenaAllocator* arena, |
| 189 | const MipsInstructionSetFeatures* instruction_set_features = nullptr) |
| 190 | : Assembler(arena), |
| 191 | overwriting_(false), |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 192 | overwrite_location_(0), |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 193 | reordering_(true), |
| 194 | ds_fsm_state_(kExpectingLabel), |
| 195 | ds_fsm_target_pc_(0), |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 196 | literals_(arena->Adapter(kArenaAllocAssembler)), |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 197 | jump_tables_(arena->Adapter(kArenaAllocAssembler)), |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 198 | last_position_adjustment_(0), |
| 199 | last_old_position_(0), |
| 200 | last_branch_id_(0), |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 201 | has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false), |
Vladimir Marko | 10ef694 | 2015-10-22 15:25:54 +0100 | [diff] [blame] | 202 | isa_features_(instruction_set_features) { |
| 203 | cfi().DelayEmittingAdvancePCs(); |
| 204 | } |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 205 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 206 | size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); } |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 207 | size_t CodePosition() OVERRIDE; |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 208 | DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); } |
| 209 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 210 | virtual ~MipsAssembler() { |
| 211 | for (auto& branch : branches_) { |
| 212 | CHECK(branch.IsResolved()); |
| 213 | } |
| 214 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 215 | |
| 216 | // Emit Machine Instructions. |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 217 | void Addu(Register rd, Register rs, Register rt); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 218 | void Addiu(Register rt, Register rs, uint16_t imm16); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 219 | void Subu(Register rd, Register rs, Register rt); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 220 | |
| 221 | void MultR2(Register rs, Register rt); // R2 |
| 222 | void MultuR2(Register rs, Register rt); // R2 |
| 223 | void DivR2(Register rs, Register rt); // R2 |
| 224 | void DivuR2(Register rs, Register rt); // R2 |
| 225 | void MulR2(Register rd, Register rs, Register rt); // R2 |
| 226 | void DivR2(Register rd, Register rs, Register rt); // R2 |
| 227 | void ModR2(Register rd, Register rs, Register rt); // R2 |
| 228 | void DivuR2(Register rd, Register rs, Register rt); // R2 |
| 229 | void ModuR2(Register rd, Register rs, Register rt); // R2 |
| 230 | void MulR6(Register rd, Register rs, Register rt); // R6 |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 231 | void MuhR6(Register rd, Register rs, Register rt); // R6 |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 232 | void MuhuR6(Register rd, Register rs, Register rt); // R6 |
| 233 | void DivR6(Register rd, Register rs, Register rt); // R6 |
| 234 | void ModR6(Register rd, Register rs, Register rt); // R6 |
| 235 | void DivuR6(Register rd, Register rs, Register rt); // R6 |
| 236 | void ModuR6(Register rd, Register rs, Register rt); // R6 |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 237 | |
| 238 | void And(Register rd, Register rs, Register rt); |
| 239 | void Andi(Register rt, Register rs, uint16_t imm16); |
| 240 | void Or(Register rd, Register rs, Register rt); |
| 241 | void Ori(Register rt, Register rs, uint16_t imm16); |
| 242 | void Xor(Register rd, Register rs, Register rt); |
| 243 | void Xori(Register rt, Register rs, uint16_t imm16); |
| 244 | void Nor(Register rd, Register rs, Register rt); |
| 245 | |
Chris Larsen | e384547 | 2015-11-18 12:27:15 -0800 | [diff] [blame] | 246 | void Movz(Register rd, Register rs, Register rt); // R2 |
| 247 | void Movn(Register rd, Register rs, Register rt); // R2 |
| 248 | void Seleqz(Register rd, Register rs, Register rt); // R6 |
| 249 | void Selnez(Register rd, Register rs, Register rt); // R6 |
| 250 | void ClzR6(Register rd, Register rs); |
| 251 | void ClzR2(Register rd, Register rs); |
| 252 | void CloR6(Register rd, Register rs); |
| 253 | void CloR2(Register rd, Register rs); |
| 254 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 255 | void Seb(Register rd, Register rt); // R2+ |
| 256 | void Seh(Register rd, Register rt); // R2+ |
Chris Larsen | 3f8bf65 | 2015-10-28 10:08:56 -0700 | [diff] [blame] | 257 | void Wsbh(Register rd, Register rt); // R2+ |
Chris Larsen | 70014c8 | 2015-11-18 12:26:08 -0800 | [diff] [blame] | 258 | void Bitswap(Register rd, Register rt); // R6 |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 259 | |
| 260 | void Sll(Register rd, Register rt, int shamt); |
| 261 | void Srl(Register rd, Register rt, int shamt); |
Chris Larsen | 3f8bf65 | 2015-10-28 10:08:56 -0700 | [diff] [blame] | 262 | void Rotr(Register rd, Register rt, int shamt); // R2+ |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 263 | void Sra(Register rd, Register rt, int shamt); |
| 264 | void Sllv(Register rd, Register rt, Register rs); |
| 265 | void Srlv(Register rd, Register rt, Register rs); |
Chris Larsen | e16ce5a | 2015-11-18 12:30:20 -0800 | [diff] [blame] | 266 | void Rotrv(Register rd, Register rt, Register rs); // R2+ |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 267 | void Srav(Register rd, Register rt, Register rs); |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 268 | void Ext(Register rd, Register rt, int pos, int size); // R2+ |
| 269 | void Ins(Register rd, Register rt, int pos, int size); // R2+ |
Chris Larsen | 692235e | 2016-11-21 16:04:53 -0800 | [diff] [blame] | 270 | void Lsa(Register rd, Register rs, Register rt, int saPlusOne); // R6 |
Chris Larsen | cd0295d | 2017-03-31 15:26:54 -0700 | [diff] [blame] | 271 | void ShiftAndAdd(Register dst, Register src_idx, Register src_base, int shamt, Register tmp = AT); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 272 | |
| 273 | void Lb(Register rt, Register rs, uint16_t imm16); |
| 274 | void Lh(Register rt, Register rs, uint16_t imm16); |
| 275 | void Lw(Register rt, Register rs, uint16_t imm16); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 276 | void Lwl(Register rt, Register rs, uint16_t imm16); |
| 277 | void Lwr(Register rt, Register rs, uint16_t imm16); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 278 | void Lbu(Register rt, Register rs, uint16_t imm16); |
| 279 | void Lhu(Register rt, Register rs, uint16_t imm16); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 280 | void Lwpc(Register rs, uint32_t imm19); // R6 |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 281 | void Lui(Register rt, uint16_t imm16); |
Alexey Frunze | cad3a4c | 2016-06-07 23:40:37 -0700 | [diff] [blame] | 282 | void Aui(Register rt, Register rs, uint16_t imm16); // R6 |
Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 283 | void AddUpper(Register rt, Register rs, uint16_t imm16, Register tmp = AT); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 284 | void Sync(uint32_t stype); |
| 285 | void Mfhi(Register rd); // R2 |
| 286 | void Mflo(Register rd); // R2 |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 287 | |
| 288 | void Sb(Register rt, Register rs, uint16_t imm16); |
| 289 | void Sh(Register rt, Register rs, uint16_t imm16); |
| 290 | void Sw(Register rt, Register rs, uint16_t imm16); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 291 | void Swl(Register rt, Register rs, uint16_t imm16); |
| 292 | void Swr(Register rt, Register rs, uint16_t imm16); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 293 | |
Alexey Frunze | 51aff3a | 2016-03-17 17:21:45 -0700 | [diff] [blame] | 294 | void LlR2(Register rt, Register base, int16_t imm16 = 0); |
| 295 | void ScR2(Register rt, Register base, int16_t imm16 = 0); |
| 296 | void LlR6(Register rt, Register base, int16_t imm9 = 0); |
| 297 | void ScR6(Register rt, Register base, int16_t imm9 = 0); |
| 298 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 299 | void Slt(Register rd, Register rs, Register rt); |
| 300 | void Sltu(Register rd, Register rs, Register rt); |
| 301 | void Slti(Register rt, Register rs, uint16_t imm16); |
| 302 | void Sltiu(Register rt, Register rs, uint16_t imm16); |
| 303 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 304 | // Branches and jumps to immediate offsets/addresses do not take care of their |
| 305 | // delay/forbidden slots and generally should not be used directly. This applies |
| 306 | // to the following R2 and R6 branch/jump instructions with imm16, imm21, addr26 |
| 307 | // offsets/addresses. |
| 308 | // Use branches/jumps to labels instead. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 309 | void B(uint16_t imm16); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 310 | void Bal(uint16_t imm16); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 311 | void Beq(Register rs, Register rt, uint16_t imm16); |
| 312 | void Bne(Register rs, Register rt, uint16_t imm16); |
| 313 | void Beqz(Register rt, uint16_t imm16); |
| 314 | void Bnez(Register rt, uint16_t imm16); |
| 315 | void Bltz(Register rt, uint16_t imm16); |
| 316 | void Bgez(Register rt, uint16_t imm16); |
| 317 | void Blez(Register rt, uint16_t imm16); |
| 318 | void Bgtz(Register rt, uint16_t imm16); |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 319 | void Bc1f(uint16_t imm16); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 320 | void Bc1f(int cc, uint16_t imm16); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 321 | void Bc1t(uint16_t imm16); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 322 | void Bc1t(int cc, uint16_t imm16); // R2 |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 323 | void J(uint32_t addr26); |
| 324 | void Jal(uint32_t addr26); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 325 | // Jalr() and Jr() fill their delay slots when reordering is enabled. |
| 326 | // When reordering is disabled, the delay slots must be filled manually. |
| 327 | // You may use NopIfNoReordering() to fill them when reordering is disabled. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 328 | void Jalr(Register rd, Register rs); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 329 | void Jalr(Register rs); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 330 | void Jr(Register rs); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 331 | // Nal() does not fill its delay slot. It must be filled manually. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 332 | void Nal(); |
| 333 | void Auipc(Register rs, uint16_t imm16); // R6 |
| 334 | void Addiupc(Register rs, uint32_t imm19); // R6 |
| 335 | void Bc(uint32_t imm26); // R6 |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 336 | void Balc(uint32_t imm26); // R6 |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 337 | void Jic(Register rt, uint16_t imm16); // R6 |
| 338 | void Jialc(Register rt, uint16_t imm16); // R6 |
| 339 | void Bltc(Register rs, Register rt, uint16_t imm16); // R6 |
| 340 | void Bltzc(Register rt, uint16_t imm16); // R6 |
| 341 | void Bgtzc(Register rt, uint16_t imm16); // R6 |
| 342 | void Bgec(Register rs, Register rt, uint16_t imm16); // R6 |
| 343 | void Bgezc(Register rt, uint16_t imm16); // R6 |
| 344 | void Blezc(Register rt, uint16_t imm16); // R6 |
| 345 | void Bltuc(Register rs, Register rt, uint16_t imm16); // R6 |
| 346 | void Bgeuc(Register rs, Register rt, uint16_t imm16); // R6 |
| 347 | void Beqc(Register rs, Register rt, uint16_t imm16); // R6 |
| 348 | void Bnec(Register rs, Register rt, uint16_t imm16); // R6 |
| 349 | void Beqzc(Register rs, uint32_t imm21); // R6 |
| 350 | void Bnezc(Register rs, uint32_t imm21); // R6 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 351 | void Bc1eqz(FRegister ft, uint16_t imm16); // R6 |
| 352 | void Bc1nez(FRegister ft, uint16_t imm16); // R6 |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 353 | |
| 354 | void AddS(FRegister fd, FRegister fs, FRegister ft); |
| 355 | void SubS(FRegister fd, FRegister fs, FRegister ft); |
| 356 | void MulS(FRegister fd, FRegister fs, FRegister ft); |
| 357 | void DivS(FRegister fd, FRegister fs, FRegister ft); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 358 | void AddD(FRegister fd, FRegister fs, FRegister ft); |
| 359 | void SubD(FRegister fd, FRegister fs, FRegister ft); |
| 360 | void MulD(FRegister fd, FRegister fs, FRegister ft); |
| 361 | void DivD(FRegister fd, FRegister fs, FRegister ft); |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 362 | void SqrtS(FRegister fd, FRegister fs); |
| 363 | void SqrtD(FRegister fd, FRegister fs); |
| 364 | void AbsS(FRegister fd, FRegister fs); |
| 365 | void AbsD(FRegister fd, FRegister fs); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 366 | void MovS(FRegister fd, FRegister fs); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 367 | void MovD(FRegister fd, FRegister fs); |
| 368 | void NegS(FRegister fd, FRegister fs); |
| 369 | void NegD(FRegister fd, FRegister fs); |
| 370 | |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 371 | void CunS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 372 | void CunS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 373 | void CeqS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 374 | void CeqS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 375 | void CueqS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 376 | void CueqS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 377 | void ColtS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 378 | void ColtS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 379 | void CultS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 380 | void CultS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 381 | void ColeS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 382 | void ColeS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 383 | void CuleS(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 384 | void CuleS(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 385 | void CunD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 386 | void CunD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 387 | void CeqD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 388 | void CeqD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 389 | void CueqD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 390 | void CueqD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 391 | void ColtD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 392 | void ColtD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 393 | void CultD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 394 | void CultD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 395 | void ColeD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 396 | void ColeD(int cc, FRegister fs, FRegister ft); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 397 | void CuleD(FRegister fs, FRegister ft); // R2 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 398 | void CuleD(int cc, FRegister fs, FRegister ft); // R2 |
| 399 | void CmpUnS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 400 | void CmpEqS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 401 | void CmpUeqS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 402 | void CmpLtS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 403 | void CmpUltS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 404 | void CmpLeS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 405 | void CmpUleS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 406 | void CmpOrS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 407 | void CmpUneS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 408 | void CmpNeS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 409 | void CmpUnD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 410 | void CmpEqD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 411 | void CmpUeqD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 412 | void CmpLtD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 413 | void CmpUltD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 414 | void CmpLeD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 415 | void CmpUleD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 416 | void CmpOrD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 417 | void CmpUneD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 418 | void CmpNeD(FRegister fd, FRegister fs, FRegister ft); // R6 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 419 | void Movf(Register rd, Register rs, int cc = 0); // R2 |
| 420 | void Movt(Register rd, Register rs, int cc = 0); // R2 |
| 421 | void MovfS(FRegister fd, FRegister fs, int cc = 0); // R2 |
| 422 | void MovfD(FRegister fd, FRegister fs, int cc = 0); // R2 |
| 423 | void MovtS(FRegister fd, FRegister fs, int cc = 0); // R2 |
| 424 | void MovtD(FRegister fd, FRegister fs, int cc = 0); // R2 |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 425 | void MovzS(FRegister fd, FRegister fs, Register rt); // R2 |
| 426 | void MovzD(FRegister fd, FRegister fs, Register rt); // R2 |
| 427 | void MovnS(FRegister fd, FRegister fs, Register rt); // R2 |
| 428 | void MovnD(FRegister fd, FRegister fs, Register rt); // R2 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 429 | void SelS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 430 | void SelD(FRegister fd, FRegister fs, FRegister ft); // R6 |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 431 | void SeleqzS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 432 | void SeleqzD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 433 | void SelnezS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 434 | void SelnezD(FRegister fd, FRegister fs, FRegister ft); // R6 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 435 | void ClassS(FRegister fd, FRegister fs); // R6 |
| 436 | void ClassD(FRegister fd, FRegister fs); // R6 |
| 437 | void MinS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 438 | void MinD(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 439 | void MaxS(FRegister fd, FRegister fs, FRegister ft); // R6 |
| 440 | void MaxD(FRegister fd, FRegister fs, FRegister ft); // R6 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 441 | |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 442 | void TruncLS(FRegister fd, FRegister fs); // R2+, FR=1 |
| 443 | void TruncLD(FRegister fd, FRegister fs); // R2+, FR=1 |
| 444 | void TruncWS(FRegister fd, FRegister fs); |
| 445 | void TruncWD(FRegister fd, FRegister fs); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 446 | void Cvtsw(FRegister fd, FRegister fs); |
| 447 | void Cvtdw(FRegister fd, FRegister fs); |
| 448 | void Cvtsd(FRegister fd, FRegister fs); |
| 449 | void Cvtds(FRegister fd, FRegister fs); |
Alexey Frunze | baf60b7 | 2015-12-22 15:15:03 -0800 | [diff] [blame] | 450 | void Cvtsl(FRegister fd, FRegister fs); // R2+, FR=1 |
| 451 | void Cvtdl(FRegister fd, FRegister fs); // R2+, FR=1 |
Chris Larsen | b74353a | 2015-11-20 09:07:09 -0800 | [diff] [blame] | 452 | void FloorWS(FRegister fd, FRegister fs); |
| 453 | void FloorWD(FRegister fd, FRegister fs); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 454 | |
| 455 | void Mfc1(Register rt, FRegister fs); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 456 | void Mtc1(Register rt, FRegister fs); |
| 457 | void Mfhc1(Register rt, FRegister fs); |
| 458 | void Mthc1(Register rt, FRegister fs); |
Alexey Frunze | bb9863a | 2016-01-11 15:51:16 -0800 | [diff] [blame] | 459 | void MoveFromFpuHigh(Register rt, FRegister fs); |
| 460 | void MoveToFpuHigh(Register rt, FRegister fs); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 461 | void Lwc1(FRegister ft, Register rs, uint16_t imm16); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 462 | void Ldc1(FRegister ft, Register rs, uint16_t imm16); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 463 | void Swc1(FRegister ft, Register rs, uint16_t imm16); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 464 | void Sdc1(FRegister ft, Register rs, uint16_t imm16); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 465 | |
| 466 | void Break(); |
jeffhao | 0703060 | 2012-09-26 14:33:14 -0700 | [diff] [blame] | 467 | void Nop(); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 468 | void NopIfNoReordering(); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 469 | void Move(Register rd, Register rs); |
| 470 | void Clear(Register rd); |
| 471 | void Not(Register rd, Register rs); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 472 | |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 473 | // MSA instructions. |
| 474 | void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 475 | void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 476 | void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 477 | void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 478 | |
| 479 | void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 480 | void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 481 | void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 482 | void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 483 | void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 484 | void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 485 | void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 486 | void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 487 | void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 488 | void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 489 | void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 490 | void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 491 | void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 492 | void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 493 | void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 494 | void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 495 | void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 496 | void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 497 | void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 498 | void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 499 | void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 500 | void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 501 | void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 502 | void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 503 | void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 504 | void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 505 | void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 506 | void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 507 | void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 508 | void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 509 | void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 510 | void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 511 | void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 512 | void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 513 | void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 514 | void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 515 | void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 516 | void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 517 | void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 518 | void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 519 | void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 520 | void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 521 | void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 522 | void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 523 | void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 524 | void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 525 | void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 526 | void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 527 | void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 528 | void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 529 | void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 530 | void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 531 | void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 532 | void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 533 | void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 534 | void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 535 | void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 536 | void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 537 | void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 538 | void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 539 | void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 540 | void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 541 | void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 542 | void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 543 | |
| 544 | void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 545 | void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 546 | void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 547 | void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 548 | void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 549 | void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 550 | void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 551 | void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 552 | void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 553 | void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 554 | void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 555 | void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 556 | |
| 557 | void Ffint_sW(VectorRegister wd, VectorRegister ws); |
| 558 | void Ffint_sD(VectorRegister wd, VectorRegister ws); |
| 559 | void Ftint_sW(VectorRegister wd, VectorRegister ws); |
| 560 | void Ftint_sD(VectorRegister wd, VectorRegister ws); |
| 561 | |
| 562 | void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 563 | void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 564 | void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 565 | void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 566 | void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 567 | void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 568 | void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 569 | void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 570 | void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 571 | void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 572 | void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 573 | void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 574 | |
| 575 | // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1). |
| 576 | void SlliB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 577 | void SlliH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 578 | void SlliW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 579 | void SlliD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 580 | void SraiB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 581 | void SraiH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 582 | void SraiW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 583 | void SraiD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 584 | void SrliB(VectorRegister wd, VectorRegister ws, int shamt3); |
| 585 | void SrliH(VectorRegister wd, VectorRegister ws, int shamt4); |
| 586 | void SrliW(VectorRegister wd, VectorRegister ws, int shamt5); |
| 587 | void SrliD(VectorRegister wd, VectorRegister ws, int shamt6); |
| 588 | |
| 589 | void MoveV(VectorRegister wd, VectorRegister ws); |
| 590 | void SplatiB(VectorRegister wd, VectorRegister ws, int n4); |
| 591 | void SplatiH(VectorRegister wd, VectorRegister ws, int n3); |
| 592 | void SplatiW(VectorRegister wd, VectorRegister ws, int n2); |
| 593 | void SplatiD(VectorRegister wd, VectorRegister ws, int n1); |
| 594 | void FillB(VectorRegister wd, Register rs); |
| 595 | void FillH(VectorRegister wd, Register rs); |
| 596 | void FillW(VectorRegister wd, Register rs); |
| 597 | |
| 598 | void LdiB(VectorRegister wd, int imm8); |
| 599 | void LdiH(VectorRegister wd, int imm10); |
| 600 | void LdiW(VectorRegister wd, int imm10); |
| 601 | void LdiD(VectorRegister wd, int imm10); |
| 602 | void LdB(VectorRegister wd, Register rs, int offset); |
| 603 | void LdH(VectorRegister wd, Register rs, int offset); |
| 604 | void LdW(VectorRegister wd, Register rs, int offset); |
| 605 | void LdD(VectorRegister wd, Register rs, int offset); |
| 606 | void StB(VectorRegister wd, Register rs, int offset); |
| 607 | void StH(VectorRegister wd, Register rs, int offset); |
| 608 | void StW(VectorRegister wd, Register rs, int offset); |
| 609 | void StD(VectorRegister wd, Register rs, int offset); |
| 610 | |
| 611 | void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 612 | void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 613 | void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 614 | void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 615 | |
Lena Djokic | b3d79e4 | 2017-07-25 11:20:52 +0200 | [diff] [blame] | 616 | void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 617 | void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 618 | void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 619 | void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 620 | void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 621 | void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 622 | void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 623 | void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 624 | void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 625 | void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 626 | void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 627 | void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt); |
| 628 | |
Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 629 | // Helper for replicating floating point value in all destination elements. |
| 630 | void ReplicateFPToVectorRegister(VectorRegister dst, FRegister src, bool is_double); |
| 631 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 632 | // Higher level composite instructions. |
| 633 | void LoadConst32(Register rd, int32_t value); |
| 634 | void LoadConst64(Register reg_hi, Register reg_lo, int64_t value); |
| 635 | void LoadDConst64(FRegister rd, int64_t value, Register temp); |
| 636 | void LoadSConst32(FRegister r, int32_t value, Register temp); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 637 | void Addiu32(Register rt, Register rs, int32_t value, Register rtmp = AT); |
| 638 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 639 | void Bind(MipsLabel* label); |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 640 | // When `is_bare` is false, the branches will promote to long (if the range |
| 641 | // of the individual branch instruction is insufficient) and the delay/ |
| 642 | // forbidden slots will be taken care of. |
| 643 | // Use `is_bare = false` when the branch target may be out of reach of the |
| 644 | // individual branch instruction. IOW, this is for general purpose use. |
| 645 | // |
| 646 | // When `is_bare` is true, just the branch instructions will be generated |
| 647 | // leaving delay/forbidden slot filling up to the caller and the branches |
| 648 | // won't promote to long if the range is insufficient (you'll get a |
| 649 | // compilation error when the range is exceeded). |
| 650 | // Use `is_bare = true` when the branch target is known to be within reach |
| 651 | // of the individual branch instruction. This is intended for small local |
| 652 | // optimizations around delay/forbidden slots. |
| 653 | // Also prefer using `is_bare = true` if the code near the branch is to be |
| 654 | // patched or analyzed at run time (e.g. introspection) to |
| 655 | // - show the intent and |
| 656 | // - fail during compilation rather than during patching/execution if the |
| 657 | // bare branch range is insufficent but the code size and layout are |
| 658 | // expected to remain unchanged |
| 659 | // |
| 660 | // R2 branches with delay slots that are also available on R6. |
| 661 | // On R6 when `is_bare` is false these convert to equivalent R6 compact |
| 662 | // branches (to reduce code size). On R2 or when `is_bare` is true they |
| 663 | // remain R2 branches with delay slots. |
| 664 | void B(MipsLabel* label, bool is_bare = false); |
| 665 | void Bal(MipsLabel* label, bool is_bare = false); |
| 666 | void Beq(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 667 | void Bne(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 668 | void Beqz(Register rt, MipsLabel* label, bool is_bare = false); |
| 669 | void Bnez(Register rt, MipsLabel* label, bool is_bare = false); |
| 670 | void Bltz(Register rt, MipsLabel* label, bool is_bare = false); |
| 671 | void Bgez(Register rt, MipsLabel* label, bool is_bare = false); |
| 672 | void Blez(Register rt, MipsLabel* label, bool is_bare = false); |
| 673 | void Bgtz(Register rt, MipsLabel* label, bool is_bare = false); |
| 674 | void Blt(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 675 | void Bge(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 676 | void Bltu(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 677 | void Bgeu(Register rs, Register rt, MipsLabel* label, bool is_bare = false); |
| 678 | // R2-only branches with delay slots. |
| 679 | void Bc1f(MipsLabel* label, bool is_bare = false); // R2 |
| 680 | void Bc1f(int cc, MipsLabel* label, bool is_bare = false); // R2 |
| 681 | void Bc1t(MipsLabel* label, bool is_bare = false); // R2 |
| 682 | void Bc1t(int cc, MipsLabel* label, bool is_bare = false); // R2 |
| 683 | // R6-only compact branches without delay/forbidden slots. |
| 684 | void Bc(MipsLabel* label, bool is_bare = false); // R6 |
| 685 | void Balc(MipsLabel* label, bool is_bare = false); // R6 |
| 686 | // R6-only compact branches with forbidden slots. |
| 687 | void Beqc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 688 | void Bnec(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 689 | void Beqzc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 690 | void Bnezc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 691 | void Bltzc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 692 | void Bgezc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 693 | void Blezc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 694 | void Bgtzc(Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 695 | void Bltc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 696 | void Bgec(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 697 | void Bltuc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 698 | void Bgeuc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6 |
| 699 | // R6-only branches with delay slots. |
| 700 | void Bc1eqz(FRegister ft, MipsLabel* label, bool is_bare = false); // R6 |
| 701 | void Bc1nez(FRegister ft, MipsLabel* label, bool is_bare = false); // R6 |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 702 | |
| 703 | void EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset, size_t size); |
Alexey Frunze | cad3a4c | 2016-06-07 23:40:37 -0700 | [diff] [blame] | 704 | void AdjustBaseAndOffset(Register& base, |
| 705 | int32_t& offset, |
| 706 | bool is_doubleword, |
| 707 | bool is_float = false); |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 708 | void AdjustBaseOffsetAndElementSizeShift(Register& base, |
| 709 | int32_t& offset, |
| 710 | int& element_size_shift); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 711 | |
| 712 | private: |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 713 | // This will be used as an argument for loads/stores |
| 714 | // when there is no need for implicit null checks. |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 715 | struct NoImplicitNullChecker { |
Tijana Jakovljevic | 5743386 | 2017-01-17 16:59:03 +0100 | [diff] [blame] | 716 | void operator()() const {} |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | public: |
| 720 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 721 | void StoreConstToOffset(StoreOperandType type, |
| 722 | int64_t value, |
| 723 | Register base, |
| 724 | int32_t offset, |
| 725 | Register temp, |
| 726 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 727 | // We permit `base` and `temp` to coincide (however, we check that neither is AT), |
| 728 | // in which case the `base` register may be overwritten in the process. |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 729 | CHECK_NE(temp, AT); // Must not use AT as temp, so as not to overwrite the adjusted base. |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 730 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword)); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 731 | uint32_t low = Low32Bits(value); |
| 732 | uint32_t high = High32Bits(value); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 733 | Register reg; |
| 734 | // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp` |
| 735 | // to load and hold the value but we can use AT instead as AT hasn't been used yet. |
| 736 | // Otherwise, `temp` can be used for the value. And if `temp` is the same as the |
| 737 | // original `base` (that is, `base` prior to the adjustment), the original `base` |
| 738 | // register will be overwritten. |
| 739 | if (base == temp) { |
| 740 | temp = AT; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 741 | } |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 742 | if (low == 0) { |
| 743 | reg = ZERO; |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 744 | } else { |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 745 | reg = temp; |
| 746 | LoadConst32(reg, low); |
| 747 | } |
| 748 | switch (type) { |
| 749 | case kStoreByte: |
| 750 | Sb(reg, base, offset); |
| 751 | break; |
| 752 | case kStoreHalfword: |
| 753 | Sh(reg, base, offset); |
| 754 | break; |
| 755 | case kStoreWord: |
| 756 | Sw(reg, base, offset); |
| 757 | break; |
| 758 | case kStoreDoubleword: |
| 759 | Sw(reg, base, offset); |
| 760 | null_checker(); |
| 761 | if (high == 0) { |
| 762 | reg = ZERO; |
| 763 | } else { |
| 764 | reg = temp; |
| 765 | if (high != low) { |
| 766 | LoadConst32(reg, high); |
| 767 | } |
| 768 | } |
| 769 | Sw(reg, base, offset + kMipsWordSize); |
| 770 | break; |
| 771 | default: |
| 772 | LOG(FATAL) << "UNREACHABLE"; |
| 773 | } |
| 774 | if (type != kStoreDoubleword) { |
| 775 | null_checker(); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 780 | void LoadFromOffset(LoadOperandType type, |
| 781 | Register reg, |
| 782 | Register base, |
| 783 | int32_t offset, |
| 784 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 785 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword)); |
| 786 | switch (type) { |
| 787 | case kLoadSignedByte: |
| 788 | Lb(reg, base, offset); |
| 789 | break; |
| 790 | case kLoadUnsignedByte: |
| 791 | Lbu(reg, base, offset); |
| 792 | break; |
| 793 | case kLoadSignedHalfword: |
| 794 | Lh(reg, base, offset); |
| 795 | break; |
| 796 | case kLoadUnsignedHalfword: |
| 797 | Lhu(reg, base, offset); |
| 798 | break; |
| 799 | case kLoadWord: |
| 800 | Lw(reg, base, offset); |
| 801 | break; |
| 802 | case kLoadDoubleword: |
| 803 | if (reg == base) { |
| 804 | // This will clobber the base when loading the lower register. Since we have to load the |
| 805 | // higher register as well, this will fail. Solution: reverse the order. |
| 806 | Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize); |
| 807 | null_checker(); |
| 808 | Lw(reg, base, offset); |
| 809 | } else { |
| 810 | Lw(reg, base, offset); |
| 811 | null_checker(); |
| 812 | Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize); |
| 813 | } |
| 814 | break; |
| 815 | default: |
| 816 | LOG(FATAL) << "UNREACHABLE"; |
| 817 | } |
| 818 | if (type != kLoadDoubleword) { |
| 819 | null_checker(); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 824 | void LoadSFromOffset(FRegister reg, |
| 825 | Register base, |
| 826 | int32_t offset, |
| 827 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 828 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true); |
| 829 | Lwc1(reg, base, offset); |
| 830 | null_checker(); |
| 831 | } |
| 832 | |
| 833 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 834 | void LoadDFromOffset(FRegister reg, |
| 835 | Register base, |
| 836 | int32_t offset, |
| 837 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 838 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true); |
| 839 | if (IsAligned<kMipsDoublewordSize>(offset)) { |
| 840 | Ldc1(reg, base, offset); |
| 841 | null_checker(); |
| 842 | } else { |
| 843 | if (Is32BitFPU()) { |
| 844 | Lwc1(reg, base, offset); |
| 845 | null_checker(); |
| 846 | Lwc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize); |
| 847 | } else { |
| 848 | // 64-bit FPU. |
| 849 | Lwc1(reg, base, offset); |
| 850 | null_checker(); |
| 851 | Lw(T8, base, offset + kMipsWordSize); |
| 852 | Mthc1(T8, reg); |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 858 | void LoadQFromOffset(FRegister reg, |
| 859 | Register base, |
| 860 | int32_t offset, |
| 861 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 862 | int element_size_shift = -1; |
| 863 | AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift); |
| 864 | switch (element_size_shift) { |
| 865 | case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break; |
| 866 | case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break; |
| 867 | case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break; |
| 868 | case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break; |
| 869 | default: |
| 870 | LOG(FATAL) << "UNREACHABLE"; |
| 871 | } |
| 872 | null_checker(); |
| 873 | } |
| 874 | |
| 875 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 876 | void StoreToOffset(StoreOperandType type, |
| 877 | Register reg, |
| 878 | Register base, |
| 879 | int32_t offset, |
| 880 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 881 | // Must not use AT as `reg`, so as not to overwrite the value being stored |
| 882 | // with the adjusted `base`. |
| 883 | CHECK_NE(reg, AT); |
| 884 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword)); |
| 885 | switch (type) { |
| 886 | case kStoreByte: |
| 887 | Sb(reg, base, offset); |
| 888 | break; |
| 889 | case kStoreHalfword: |
| 890 | Sh(reg, base, offset); |
| 891 | break; |
| 892 | case kStoreWord: |
| 893 | Sw(reg, base, offset); |
| 894 | break; |
| 895 | case kStoreDoubleword: |
| 896 | CHECK_NE(reg, base); |
| 897 | CHECK_NE(static_cast<Register>(reg + 1), base); |
| 898 | Sw(reg, base, offset); |
| 899 | null_checker(); |
| 900 | Sw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize); |
| 901 | break; |
| 902 | default: |
| 903 | LOG(FATAL) << "UNREACHABLE"; |
| 904 | } |
| 905 | if (type != kStoreDoubleword) { |
| 906 | null_checker(); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 911 | void StoreSToOffset(FRegister reg, |
| 912 | Register base, |
| 913 | int32_t offset, |
| 914 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 915 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true); |
| 916 | Swc1(reg, base, offset); |
| 917 | null_checker(); |
| 918 | } |
| 919 | |
| 920 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 921 | void StoreDToOffset(FRegister reg, |
| 922 | Register base, |
| 923 | int32_t offset, |
| 924 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 925 | AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true); |
| 926 | if (IsAligned<kMipsDoublewordSize>(offset)) { |
| 927 | Sdc1(reg, base, offset); |
| 928 | null_checker(); |
| 929 | } else { |
| 930 | if (Is32BitFPU()) { |
| 931 | Swc1(reg, base, offset); |
| 932 | null_checker(); |
| 933 | Swc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize); |
| 934 | } else { |
| 935 | // 64-bit FPU. |
| 936 | Mfhc1(T8, reg); |
| 937 | Swc1(reg, base, offset); |
| 938 | null_checker(); |
| 939 | Sw(T8, base, offset + kMipsWordSize); |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 944 | template <typename ImplicitNullChecker = NoImplicitNullChecker> |
| 945 | void StoreQToOffset(FRegister reg, |
| 946 | Register base, |
| 947 | int32_t offset, |
| 948 | ImplicitNullChecker null_checker = NoImplicitNullChecker()) { |
| 949 | int element_size_shift = -1; |
| 950 | AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift); |
| 951 | switch (element_size_shift) { |
| 952 | case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break; |
| 953 | case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break; |
| 954 | case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break; |
| 955 | case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break; |
| 956 | default: |
| 957 | LOG(FATAL) << "UNREACHABLE"; |
| 958 | } |
| 959 | null_checker(); |
| 960 | } |
| 961 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 962 | void LoadFromOffset(LoadOperandType type, Register reg, Register base, int32_t offset); |
| 963 | void LoadSFromOffset(FRegister reg, Register base, int32_t offset); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 964 | void LoadDFromOffset(FRegister reg, Register base, int32_t offset); |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 965 | void LoadQFromOffset(FRegister reg, Register base, int32_t offset); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 966 | void StoreToOffset(StoreOperandType type, Register reg, Register base, int32_t offset); |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 967 | void StoreSToOffset(FRegister reg, Register base, int32_t offset); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 968 | void StoreDToOffset(FRegister reg, Register base, int32_t offset); |
Lena Djokic | 2e0a7e5 | 2017-07-06 11:55:24 +0200 | [diff] [blame] | 969 | void StoreQToOffset(FRegister reg, Register base, int32_t offset); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 970 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 971 | // Emit data (e.g. encoded instruction or immediate) to the instruction stream. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 972 | void Emit(uint32_t value); |
| 973 | |
| 974 | // Push/pop composite routines. |
| 975 | void Push(Register rs); |
| 976 | void Pop(Register rd); |
| 977 | void PopAndReturn(Register rd, Register rt); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 978 | |
Alexey Frunze | c061de1 | 2017-02-14 13:27:23 -0800 | [diff] [blame] | 979 | // |
| 980 | // Heap poisoning. |
| 981 | // |
| 982 | |
| 983 | // Poison a heap reference contained in `src` and store it in `dst`. |
| 984 | void PoisonHeapReference(Register dst, Register src) { |
| 985 | // dst = -src. |
| 986 | Subu(dst, ZERO, src); |
| 987 | } |
| 988 | // Poison a heap reference contained in `reg`. |
| 989 | void PoisonHeapReference(Register reg) { |
| 990 | // reg = -reg. |
| 991 | PoisonHeapReference(reg, reg); |
| 992 | } |
| 993 | // Unpoison a heap reference contained in `reg`. |
| 994 | void UnpoisonHeapReference(Register reg) { |
| 995 | // reg = -reg. |
| 996 | Subu(reg, ZERO, reg); |
| 997 | } |
| 998 | // Poison a heap reference contained in `reg` if heap poisoning is enabled. |
| 999 | void MaybePoisonHeapReference(Register reg) { |
| 1000 | if (kPoisonHeapReferences) { |
| 1001 | PoisonHeapReference(reg); |
| 1002 | } |
| 1003 | } |
| 1004 | // Unpoison a heap reference contained in `reg` if heap poisoning is enabled. |
| 1005 | void MaybeUnpoisonHeapReference(Register reg) { |
| 1006 | if (kPoisonHeapReferences) { |
| 1007 | UnpoisonHeapReference(reg); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1011 | void Bind(Label* label) OVERRIDE { |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1012 | Bind(down_cast<MipsLabel*>(label)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1013 | } |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1014 | void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE { |
| 1015 | UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS"; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Igor Murashkin | ae7ff92 | 2016-10-06 14:59:19 -0700 | [diff] [blame] | 1018 | // Don't warn about a different virtual Bind/Jump in the base class. |
| 1019 | using JNIBase::Bind; |
| 1020 | using JNIBase::Jump; |
| 1021 | |
| 1022 | // Create a new label that can be used with Jump/Bind calls. |
| 1023 | std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE { |
| 1024 | LOG(FATAL) << "Not implemented on MIPS32"; |
| 1025 | UNREACHABLE(); |
| 1026 | } |
| 1027 | // Emit an unconditional jump to the label. |
| 1028 | void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE { |
| 1029 | LOG(FATAL) << "Not implemented on MIPS32"; |
| 1030 | UNREACHABLE(); |
| 1031 | } |
| 1032 | // Emit a conditional jump to the label by applying a unary condition test to the register. |
| 1033 | void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED, |
| 1034 | JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED, |
| 1035 | ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE { |
| 1036 | LOG(FATAL) << "Not implemented on MIPS32"; |
| 1037 | UNREACHABLE(); |
| 1038 | } |
| 1039 | |
| 1040 | // Code at this offset will serve as the target for the Jump call. |
| 1041 | void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE { |
| 1042 | LOG(FATAL) << "Not implemented on MIPS32"; |
| 1043 | UNREACHABLE(); |
| 1044 | } |
| 1045 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1046 | // Create a new literal with a given value. |
| 1047 | // NOTE: Force the template parameter to be explicitly specified. |
| 1048 | template <typename T> |
| 1049 | Literal* NewLiteral(typename Identity<T>::type value) { |
| 1050 | static_assert(std::is_integral<T>::value, "T must be an integral type."); |
| 1051 | return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value)); |
| 1052 | } |
| 1053 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1054 | // Load label address using the base register (for R2 only) or using PC-relative loads |
| 1055 | // (for R6 only; base_reg must be ZERO). To be used with data labels in the literal / |
| 1056 | // jump table area only and not with regular code labels. |
| 1057 | void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label); |
| 1058 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1059 | // Create a new literal with the given data. |
| 1060 | Literal* NewLiteral(size_t size, const uint8_t* data); |
| 1061 | |
| 1062 | // Load literal using the base register (for R2 only) or using PC-relative loads |
| 1063 | // (for R6 only; base_reg must be ZERO). |
| 1064 | void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal); |
| 1065 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1066 | // Create a jump table for the given labels that will be emitted when finalizing. |
| 1067 | // When the table is emitted, offsets will be relative to the location of the table. |
| 1068 | // The table location is determined by the location of its label (the label precedes |
| 1069 | // the table data) and should be loaded using LoadLabelAddress(). |
| 1070 | JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels); |
| 1071 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1072 | // |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1073 | // Overridden common assembler high-level functionality. |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1074 | // |
| 1075 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1076 | // Emit code that will create an activation on the stack. |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1077 | void BuildFrame(size_t frame_size, |
| 1078 | ManagedRegister method_reg, |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 1079 | ArrayRef<const ManagedRegister> callee_save_regs, |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1080 | const ManagedRegisterEntrySpills& entry_spills) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1081 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1082 | // Emit code that will remove an activation from the stack. |
Vladimir Marko | 3224838 | 2016-05-19 10:37:24 +0100 | [diff] [blame] | 1083 | void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs) |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1084 | OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1085 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1086 | void IncreaseFrameSize(size_t adjust) OVERRIDE; |
| 1087 | void DecreaseFrameSize(size_t adjust) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1088 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1089 | // Store routines. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1090 | void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE; |
| 1091 | void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE; |
| 1092 | void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1093 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1094 | void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1095 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1096 | void StoreStackOffsetToThread(ThreadOffset32 thr_offs, |
| 1097 | FrameOffset fr_offs, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1098 | ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1099 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1100 | void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1101 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1102 | void StoreSpanning(FrameOffset dest, |
| 1103 | ManagedRegister msrc, |
| 1104 | FrameOffset in_off, |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1105 | ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1106 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1107 | // Load routines. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1108 | void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1109 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1110 | void LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1111 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1112 | void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1113 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1114 | void LoadRef(ManagedRegister mdest, |
| 1115 | ManagedRegister base, |
| 1116 | MemberOffset offs, |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1117 | bool unpoison_reference) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1118 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1119 | void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1120 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1121 | void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1122 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1123 | // Copying routines. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1124 | void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1125 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1126 | void CopyRawPtrFromThread(FrameOffset fr_offs, |
| 1127 | ThreadOffset32 thr_offs, |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1128 | ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1129 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1130 | void CopyRawPtrToThread(ThreadOffset32 thr_offs, |
| 1131 | FrameOffset fr_offs, |
| 1132 | ManagedRegister mscratch) OVERRIDE; |
| 1133 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1134 | void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1135 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1136 | void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1137 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1138 | void Copy(FrameOffset dest, |
| 1139 | ManagedRegister src_base, |
| 1140 | Offset src_offset, |
| 1141 | ManagedRegister mscratch, |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1142 | size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1143 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1144 | void Copy(ManagedRegister dest_base, |
| 1145 | Offset dest_offset, |
| 1146 | FrameOffset src, |
| 1147 | ManagedRegister mscratch, |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1148 | size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1149 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1150 | void Copy(FrameOffset dest, |
| 1151 | FrameOffset src_base, |
| 1152 | Offset src_offset, |
| 1153 | ManagedRegister mscratch, |
| 1154 | size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1155 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1156 | void Copy(ManagedRegister dest, |
| 1157 | Offset dest_offset, |
| 1158 | ManagedRegister src, |
| 1159 | Offset src_offset, |
| 1160 | ManagedRegister mscratch, |
| 1161 | size_t size) OVERRIDE; |
| 1162 | |
| 1163 | void Copy(FrameOffset dest, |
| 1164 | Offset dest_offset, |
| 1165 | FrameOffset src, |
| 1166 | Offset src_offset, |
| 1167 | ManagedRegister mscratch, |
| 1168 | size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1169 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1170 | void MemoryBarrier(ManagedRegister) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1171 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1172 | // Sign extension. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1173 | void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1174 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1175 | // Zero extension. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1176 | void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1177 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1178 | // Exploit fast access in managed code to Thread::Current(). |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1179 | void GetCurrentThread(ManagedRegister tr) OVERRIDE; |
| 1180 | void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1181 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1182 | // Set up out_reg to hold a Object** into the handle scope, or to be null if the |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1183 | // value is null and null_allowed. in_reg holds a possibly stale reference |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1184 | // 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] | 1185 | // null. |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1186 | void CreateHandleScopeEntry(ManagedRegister out_reg, |
| 1187 | FrameOffset handlescope_offset, |
| 1188 | ManagedRegister in_reg, |
| 1189 | bool null_allowed) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1190 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1191 | // Set up out_off to hold a Object** into the handle scope, or to be null if the |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1192 | // value is null and null_allowed. |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1193 | void CreateHandleScopeEntry(FrameOffset out_off, |
| 1194 | FrameOffset handlescope_offset, |
| 1195 | ManagedRegister mscratch, |
| 1196 | bool null_allowed) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1197 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1198 | // src holds a handle scope entry (Object**) load this into dst. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1199 | void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1200 | |
| 1201 | // Heap::VerifyObject on src. In some cases (such as a reference to this) we |
| 1202 | // know that src may not be null. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1203 | void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE; |
| 1204 | void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1205 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1206 | // Call to address held at [base+offset]. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1207 | void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE; |
| 1208 | void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE; |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 1209 | void CallFromThread(ThreadOffset32 offset, ManagedRegister mscratch) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1210 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1211 | // Generate code to check if Thread::Current()->exception_ is non-null |
| 1212 | // and branch to a ExceptionSlowPath if it is. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1213 | void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1214 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1215 | // Emit slow paths queued during assembly and promote short branches to long if needed. |
| 1216 | void FinalizeCode() OVERRIDE; |
| 1217 | |
| 1218 | // Emit branches and finalize all instructions. |
| 1219 | void FinalizeInstructions(const MemoryRegion& region); |
| 1220 | |
| 1221 | // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS, |
| 1222 | // must be used instead of MipsLabel::GetPosition()). |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1223 | uint32_t GetLabelLocation(const MipsLabel* label) const; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1224 | |
| 1225 | // Get the final position of a label after local fixup based on the old position |
| 1226 | // recorded before FinalizeCode(). |
| 1227 | uint32_t GetAdjustedPosition(uint32_t old_position); |
| 1228 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1229 | // R2 doesn't have PC-relative addressing, which we need to access literals. We simulate it by |
| 1230 | // reading the PC value into a general-purpose register with the NAL instruction and then loading |
| 1231 | // literals through this base register. The code generator calls this method (at most once per |
| 1232 | // method being compiled) to bind a label to the location for which the PC value is acquired. |
| 1233 | // The assembler then computes literal offsets relative to this label. |
| 1234 | void BindPcRelBaseLabel(); |
| 1235 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 1236 | // Returns the location of the label bound with BindPcRelBaseLabel(). |
| 1237 | uint32_t GetPcRelBaseLabelLocation() const; |
| 1238 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1239 | // Note that PC-relative literal loads are handled as pseudo branches because they need very |
| 1240 | // similar relocation and may similarly expand in size to accomodate for larger offsets relative |
| 1241 | // to PC. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1242 | enum BranchCondition { |
| 1243 | kCondLT, |
| 1244 | kCondGE, |
| 1245 | kCondLE, |
| 1246 | kCondGT, |
| 1247 | kCondLTZ, |
| 1248 | kCondGEZ, |
| 1249 | kCondLEZ, |
| 1250 | kCondGTZ, |
| 1251 | kCondEQ, |
| 1252 | kCondNE, |
| 1253 | kCondEQZ, |
| 1254 | kCondNEZ, |
| 1255 | kCondLTU, |
| 1256 | kCondGEU, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1257 | kCondF, // Floating-point predicate false. |
| 1258 | kCondT, // Floating-point predicate true. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1259 | kUncond, |
| 1260 | }; |
| 1261 | friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs); |
| 1262 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1263 | // Enables or disables instruction reordering (IOW, automatic filling of delay slots) |
| 1264 | // similarly to ".set reorder" / ".set noreorder" in traditional MIPS assembly. |
| 1265 | // Returns the last state, which may be useful for temporary enabling/disabling of |
| 1266 | // reordering. |
| 1267 | bool SetReorder(bool enable); |
| 1268 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1269 | private: |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1270 | // Description of the last instruction in terms of input and output registers. |
| 1271 | // Used to make the decision of moving the instruction into a delay slot. |
| 1272 | struct DelaySlot { |
| 1273 | DelaySlot(); |
| 1274 | // Encoded instruction that may be used to fill the delay slot or 0 |
| 1275 | // (0 conveniently represents NOP). |
| 1276 | uint32_t instruction_; |
| 1277 | // Mask of output GPRs for the instruction. |
| 1278 | uint32_t gpr_outs_mask_; |
| 1279 | // Mask of input GPRs for the instruction. |
| 1280 | uint32_t gpr_ins_mask_; |
| 1281 | // Mask of output FPRs for the instruction. |
| 1282 | uint32_t fpr_outs_mask_; |
| 1283 | // Mask of input FPRs for the instruction. |
| 1284 | uint32_t fpr_ins_mask_; |
| 1285 | // Mask of output FPU condition code flags for the instruction. |
| 1286 | uint32_t cc_outs_mask_; |
| 1287 | // Mask of input FPU condition code flags for the instruction. |
| 1288 | uint32_t cc_ins_mask_; |
| 1289 | // Branches never operate on the LO and HI registers, hence there's |
| 1290 | // no mask for LO and HI. |
| 1291 | }; |
| 1292 | |
| 1293 | // Delay slot finite state machine's (DS FSM's) state. The FSM state is updated |
| 1294 | // upon every new instruction and label generated. The FSM detects instructions |
| 1295 | // suitable for delay slots and immediately preceded with labels. These are target |
| 1296 | // instructions for branches. If an unconditional R2 branch does not get its delay |
| 1297 | // slot filled with the immediately preceding instruction, it may instead get the |
| 1298 | // slot filled with the target instruction (the branch will need its offset |
| 1299 | // incremented past the target instruction). We call this "absorption". The FSM |
| 1300 | // records PCs of the target instructions suitable for this optimization. |
| 1301 | enum DsFsmState { |
| 1302 | kExpectingLabel, |
| 1303 | kExpectingInstruction, |
| 1304 | kExpectingCommit |
| 1305 | }; |
| 1306 | friend std::ostream& operator<<(std::ostream& os, const DsFsmState& rhs); |
| 1307 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1308 | class Branch { |
| 1309 | public: |
| 1310 | enum Type { |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1311 | // R2 short branches (can be promoted to long). |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1312 | kUncondBranch, |
| 1313 | kCondBranch, |
| 1314 | kCall, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1315 | // R2 short branches (can't be promoted to long), delay slots filled manually. |
| 1316 | kBareUncondBranch, |
| 1317 | kBareCondBranch, |
| 1318 | kBareCall, |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1319 | // R2 near label. |
| 1320 | kLabel, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1321 | // R2 near literal. |
| 1322 | kLiteral, |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1323 | // R2 long branches. |
| 1324 | kLongUncondBranch, |
| 1325 | kLongCondBranch, |
| 1326 | kLongCall, |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1327 | // R2 far label. |
| 1328 | kFarLabel, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1329 | // R2 far literal. |
| 1330 | kFarLiteral, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1331 | // R6 short branches (can be promoted to long). |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1332 | kR6UncondBranch, |
| 1333 | kR6CondBranch, |
| 1334 | kR6Call, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1335 | // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually. |
| 1336 | kR6BareUncondBranch, |
| 1337 | kR6BareCondBranch, |
| 1338 | kR6BareCall, |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1339 | // R6 near label. |
| 1340 | kR6Label, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1341 | // R6 near literal. |
| 1342 | kR6Literal, |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1343 | // R6 long branches. |
| 1344 | kR6LongUncondBranch, |
| 1345 | kR6LongCondBranch, |
| 1346 | kR6LongCall, |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1347 | // R6 far label. |
| 1348 | kR6FarLabel, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1349 | // R6 far literal. |
| 1350 | kR6FarLiteral, |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1351 | }; |
| 1352 | // Bit sizes of offsets defined as enums to minimize chance of typos. |
| 1353 | enum OffsetBits { |
| 1354 | kOffset16 = 16, |
| 1355 | kOffset18 = 18, |
| 1356 | kOffset21 = 21, |
| 1357 | kOffset23 = 23, |
| 1358 | kOffset28 = 28, |
| 1359 | kOffset32 = 32, |
| 1360 | }; |
| 1361 | |
| 1362 | static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_ |
| 1363 | static constexpr int32_t kMaxBranchLength = 32; |
| 1364 | static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1365 | // The following two instruction encodings can never legally occur in branch delay |
| 1366 | // slots and are used as markers. |
| 1367 | // |
| 1368 | // kUnfilledDelaySlot means that the branch may use either the preceding or the target |
| 1369 | // instruction to fill its delay slot (the latter is only possible with unconditional |
| 1370 | // R2 branches and is termed here as "absorption"). |
| 1371 | static constexpr uint32_t kUnfilledDelaySlot = 0x10000000; // beq zero, zero, 0. |
| 1372 | // kUnfillableDelaySlot means that the branch cannot use an instruction (other than NOP) |
| 1373 | // to fill its delay slot. This is only used for unconditional R2 branches to prevent |
| 1374 | // absorption of the target instruction when reordering is disabled. |
| 1375 | static constexpr uint32_t kUnfillableDelaySlot = 0x13FF0000; // beq ra, ra, 0. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1376 | |
| 1377 | struct BranchInfo { |
| 1378 | // Branch length as a number of 4-byte-long instructions. |
| 1379 | uint32_t length; |
| 1380 | // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's |
| 1381 | // PC-relative offset (or its most significant 16-bit half, which goes first). |
| 1382 | uint32_t instr_offset; |
| 1383 | // Different MIPS instructions with PC-relative offsets apply said offsets to slightly |
| 1384 | // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte |
| 1385 | // instructions) from the instruction containing the offset. |
| 1386 | uint32_t pc_org; |
| 1387 | // How large (in bits) a PC-relative offset can be for a given type of branch (kR6CondBranch |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1388 | // and kR6BareCondBranch are an exception: use kOffset23 for beqzc/bnezc). |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1389 | OffsetBits offset_size; |
| 1390 | // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift |
| 1391 | // count. |
| 1392 | int offset_shift; |
| 1393 | }; |
| 1394 | static const BranchInfo branch_info_[/* Type */]; |
| 1395 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1396 | // Unconditional branch or call. |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1397 | Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call, bool is_bare); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1398 | // Conditional branch. |
| 1399 | Branch(bool is_r6, |
| 1400 | uint32_t location, |
| 1401 | uint32_t target, |
| 1402 | BranchCondition condition, |
| 1403 | Register lhs_reg, |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1404 | Register rhs_reg, |
| 1405 | bool is_bare); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1406 | // Label address (in literal area) or literal. |
| 1407 | Branch(bool is_r6, |
| 1408 | uint32_t location, |
| 1409 | Register dest_reg, |
| 1410 | Register base_reg, |
| 1411 | Type label_or_literal_type); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1412 | |
| 1413 | // Some conditional branches with lhs = rhs are effectively NOPs, while some |
| 1414 | // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs. |
| 1415 | // So, we need a way to identify such branches in order to emit no instructions for them |
| 1416 | // or change them to unconditional. |
| 1417 | static bool IsNop(BranchCondition condition, Register lhs, Register rhs); |
| 1418 | static bool IsUncond(BranchCondition condition, Register lhs, Register rhs); |
| 1419 | |
| 1420 | static BranchCondition OppositeCondition(BranchCondition cond); |
| 1421 | |
| 1422 | Type GetType() const; |
| 1423 | BranchCondition GetCondition() const; |
| 1424 | Register GetLeftRegister() const; |
| 1425 | Register GetRightRegister() const; |
| 1426 | uint32_t GetTarget() const; |
| 1427 | uint32_t GetLocation() const; |
| 1428 | uint32_t GetOldLocation() const; |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1429 | uint32_t GetPrecedingInstructionLength(Type type) const; |
| 1430 | uint32_t GetPrecedingInstructionSize(Type type) const; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1431 | uint32_t GetLength() const; |
| 1432 | uint32_t GetOldLength() const; |
| 1433 | uint32_t GetSize() const; |
| 1434 | uint32_t GetOldSize() const; |
| 1435 | uint32_t GetEndLocation() const; |
| 1436 | uint32_t GetOldEndLocation() const; |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1437 | bool IsBare() const; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1438 | bool IsLong() const; |
| 1439 | bool IsResolved() const; |
| 1440 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1441 | // Various helpers for branch delay slot management. |
| 1442 | bool CanHaveDelayedInstruction(const DelaySlot& delay_slot) const; |
| 1443 | void SetDelayedInstruction(uint32_t instruction); |
| 1444 | uint32_t GetDelayedInstruction() const; |
| 1445 | void DecrementLocations(); |
| 1446 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1447 | // Returns the bit size of the signed offset that the branch instruction can handle. |
| 1448 | OffsetBits GetOffsetSize() const; |
| 1449 | |
| 1450 | // Calculates the distance between two byte locations in the assembler buffer and |
| 1451 | // returns the number of bits needed to represent the distance as a signed integer. |
| 1452 | // |
| 1453 | // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc), |
| 1454 | // and 26 (bc) bits, which are additionally shifted left 2 positions at run time. |
| 1455 | // |
| 1456 | // Composite branches (made of several instructions) with longer reach have 32-bit |
| 1457 | // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first). |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1458 | // The composite branches cover the range of PC + +/-2GB on MIPS32 CPUs. However, |
| 1459 | // the range is not end-to-end on MIPS64 (unless addresses are forced to zero- or |
| 1460 | // sign-extend from 32 to 64 bits by the appropriate CPU configuration). |
| 1461 | // Consider the following implementation of a long unconditional branch, for |
| 1462 | // example: |
| 1463 | // |
| 1464 | // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16 |
| 1465 | // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0) |
| 1466 | // |
| 1467 | // Both of the above instructions take 16-bit signed offsets as immediate operands. |
| 1468 | // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000 |
| 1469 | // due to sign extension. This must be compensated for by incrementing offset_31_16 |
| 1470 | // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is |
| 1471 | // 0x7FFF, adding 1 will overflow the positive offset into the negative range. |
| 1472 | // Therefore, the long branch range is something like from PC - 0x80000000 to |
| 1473 | // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1474 | // |
| 1475 | // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special |
| 1476 | // case with the addiu instruction and a 16 bit offset. |
| 1477 | static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target); |
| 1478 | |
| 1479 | // Resolve a branch when the target is known. |
| 1480 | void Resolve(uint32_t target); |
| 1481 | |
| 1482 | // Relocate a branch by a given delta if needed due to expansion of this or another |
| 1483 | // branch at a given location by this delta (just changes location_ and target_). |
| 1484 | void Relocate(uint32_t expand_location, uint32_t delta); |
| 1485 | |
| 1486 | // If the branch is short, changes its type to long. |
| 1487 | void PromoteToLong(); |
| 1488 | |
| 1489 | // If necessary, updates the type by promoting a short branch to a long branch |
| 1490 | // based on the branch location and target. Returns the amount (in bytes) by |
| 1491 | // which the branch size has increased. |
| 1492 | // max_short_distance caps the maximum distance between location_ and target_ |
| 1493 | // that is allowed for short branches. This is for debugging/testing purposes. |
| 1494 | // max_short_distance = 0 forces all short branches to become long. |
| 1495 | // Use the implicit default argument when not debugging/testing. |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1496 | uint32_t PromoteIfNeeded(uint32_t location, |
| 1497 | uint32_t max_short_distance = std::numeric_limits<uint32_t>::max()); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1498 | |
| 1499 | // Returns the location of the instruction(s) containing the offset. |
| 1500 | uint32_t GetOffsetLocation() const; |
| 1501 | |
| 1502 | // Calculates and returns the offset ready for encoding in the branch instruction(s). |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1503 | uint32_t GetOffset(uint32_t location) const; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1504 | |
| 1505 | private: |
| 1506 | // Completes branch construction by determining and recording its type. |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1507 | void InitializeType(Type initial_type, bool is_r6); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1508 | // Helper for the above. |
| 1509 | void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type); |
| 1510 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1511 | uint32_t old_location_; // Offset into assembler buffer in bytes. |
| 1512 | uint32_t location_; // Offset into assembler buffer in bytes. |
| 1513 | uint32_t target_; // Offset into assembler buffer in bytes. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1514 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1515 | uint32_t lhs_reg_; // Left-hand side register in conditional branches or |
| 1516 | // FPU condition code. Destination register in literals. |
| 1517 | uint32_t rhs_reg_; // Right-hand side register in conditional branches. |
| 1518 | // Base register in literals (ZERO on R6). |
| 1519 | BranchCondition condition_; // Condition for conditional branches. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1520 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1521 | Type type_; // Current type of the branch. |
| 1522 | Type old_type_; // Initial type of the branch. |
| 1523 | |
| 1524 | uint32_t delayed_instruction_; // Encoded instruction for the delay slot or |
| 1525 | // kUnfilledDelaySlot if none but fillable or |
| 1526 | // kUnfillableDelaySlot if none and unfillable |
| 1527 | // (the latter is only used for unconditional R2 |
| 1528 | // branches). |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1529 | }; |
| 1530 | friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs); |
| 1531 | friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs); |
| 1532 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1533 | uint32_t EmitR(int opcode, Register rs, Register rt, Register rd, int shamt, int funct); |
| 1534 | uint32_t EmitI(int opcode, Register rs, Register rt, uint16_t imm); |
| 1535 | uint32_t EmitI21(int opcode, Register rs, uint32_t imm21); |
| 1536 | uint32_t EmitI26(int opcode, uint32_t imm26); |
| 1537 | uint32_t EmitFR(int opcode, int fmt, FRegister ft, FRegister fs, FRegister fd, int funct); |
| 1538 | uint32_t EmitFI(int opcode, int fmt, FRegister rt, uint16_t imm); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 1539 | void EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16); |
| 1540 | void EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21); |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 1541 | uint32_t EmitMsa3R(int operation, |
| 1542 | int df, |
| 1543 | VectorRegister wt, |
| 1544 | VectorRegister ws, |
| 1545 | VectorRegister wd, |
| 1546 | int minor_opcode); |
| 1547 | uint32_t EmitMsaBIT(int operation, |
| 1548 | int df_m, |
| 1549 | VectorRegister ws, |
| 1550 | VectorRegister wd, |
| 1551 | int minor_opcode); |
| 1552 | uint32_t EmitMsaELM(int operation, |
| 1553 | int df_n, |
| 1554 | VectorRegister ws, |
| 1555 | VectorRegister wd, |
| 1556 | int minor_opcode); |
| 1557 | uint32_t EmitMsaMI10(int s10, Register rs, VectorRegister wd, int minor_opcode, int df); |
| 1558 | uint32_t EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode); |
| 1559 | uint32_t EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode); |
| 1560 | uint32_t EmitMsa2RF(int operation, |
| 1561 | int df, |
| 1562 | VectorRegister ws, |
| 1563 | VectorRegister wd, |
| 1564 | int minor_opcode); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1565 | |
Alexey Frunze | 0cab656 | 2017-07-25 15:19:36 -0700 | [diff] [blame] | 1566 | void Buncond(MipsLabel* label, bool is_r6, bool is_bare); |
| 1567 | void Bcond(MipsLabel* label, |
| 1568 | bool is_r6, |
| 1569 | bool is_bare, |
| 1570 | BranchCondition condition, |
| 1571 | Register lhs, |
| 1572 | Register rhs = ZERO); |
| 1573 | void Call(MipsLabel* label, bool is_r6, bool is_bare); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1574 | void FinalizeLabeledBranch(MipsLabel* label); |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1575 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1576 | // Various helpers for branch delay slot management. |
| 1577 | void DsFsmInstr(uint32_t instruction, |
| 1578 | uint32_t gpr_outs_mask, |
| 1579 | uint32_t gpr_ins_mask, |
| 1580 | uint32_t fpr_outs_mask, |
| 1581 | uint32_t fpr_ins_mask, |
| 1582 | uint32_t cc_outs_mask, |
| 1583 | uint32_t cc_ins_mask); |
| 1584 | void DsFsmInstrNop(uint32_t instruction); |
| 1585 | void DsFsmInstrRrr(uint32_t instruction, Register out, Register in1, Register in2); |
| 1586 | void DsFsmInstrRrrr(uint32_t instruction, Register in1_out, Register in2, Register in3); |
| 1587 | void DsFsmInstrFff(uint32_t instruction, FRegister out, FRegister in1, FRegister in2); |
| 1588 | void DsFsmInstrFfff(uint32_t instruction, FRegister in1_out, FRegister in2, FRegister in3); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 1589 | void DsFsmInstrFffr(uint32_t instruction, FRegister in1_out, FRegister in2, Register in3); |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1590 | void DsFsmInstrRf(uint32_t instruction, Register out, FRegister in); |
| 1591 | void DsFsmInstrFr(uint32_t instruction, FRegister out, Register in); |
| 1592 | void DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2); |
| 1593 | void DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2); |
| 1594 | void DsFsmInstrRrrc(uint32_t instruction, Register in1_out, Register in2, int cc_in); |
| 1595 | void DsFsmInstrFffc(uint32_t instruction, FRegister in1_out, FRegister in2, int cc_in); |
| 1596 | void DsFsmLabel(); |
| 1597 | void DsFsmCommitLabel(); |
| 1598 | void DsFsmDropLabel(); |
| 1599 | void MoveInstructionToDelaySlot(Branch& branch); |
| 1600 | bool CanExchangeWithSlt(Register rs, Register rt) const; |
| 1601 | void ExchangeWithSlt(const DelaySlot& forwarded_slot); |
| 1602 | void GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt); |
| 1603 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1604 | Branch* GetBranch(uint32_t branch_id); |
| 1605 | const Branch* GetBranch(uint32_t branch_id) const; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1606 | uint32_t GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const; |
| 1607 | uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1608 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1609 | void EmitLiterals(); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1610 | void ReserveJumpTableSpace(); |
| 1611 | void EmitJumpTables(); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1612 | void PromoteBranches(); |
| 1613 | void EmitBranch(Branch* branch); |
| 1614 | void EmitBranches(); |
Vladimir Marko | 10ef694 | 2015-10-22 15:25:54 +0100 | [diff] [blame] | 1615 | void PatchCFI(size_t number_of_delayed_adjust_pcs); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1616 | |
| 1617 | // Emits exception block. |
| 1618 | void EmitExceptionPoll(MipsExceptionSlowPath* exception); |
| 1619 | |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 1620 | bool HasMsa() const { |
| 1621 | return has_msa_; |
| 1622 | } |
| 1623 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1624 | bool IsR6() const { |
| 1625 | if (isa_features_ != nullptr) { |
| 1626 | return isa_features_->IsR6(); |
| 1627 | } else { |
| 1628 | return false; |
| 1629 | } |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 1630 | } |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1631 | |
| 1632 | bool Is32BitFPU() const { |
| 1633 | if (isa_features_ != nullptr) { |
| 1634 | return isa_features_->Is32BitFloatingPoint(); |
| 1635 | } else { |
| 1636 | return true; |
| 1637 | } |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 1638 | } |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1639 | |
| 1640 | // List of exception blocks to generate at the end of the code cache. |
| 1641 | std::vector<MipsExceptionSlowPath> exception_blocks_; |
| 1642 | |
| 1643 | std::vector<Branch> branches_; |
| 1644 | |
| 1645 | // Whether appending instructions at the end of the buffer or overwriting the existing ones. |
| 1646 | bool overwriting_; |
| 1647 | // The current overwrite location. |
| 1648 | uint32_t overwrite_location_; |
| 1649 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1650 | // Whether instruction reordering (IOW, automatic filling of delay slots) is enabled. |
| 1651 | bool reordering_; |
| 1652 | // Information about the last instruction that may be used to fill a branch delay slot. |
| 1653 | DelaySlot delay_slot_; |
| 1654 | // Delay slot FSM state. |
| 1655 | DsFsmState ds_fsm_state_; |
| 1656 | // PC of the current labeled target instruction. |
| 1657 | uint32_t ds_fsm_target_pc_; |
| 1658 | // PCs of labeled target instructions. |
| 1659 | std::vector<uint32_t> ds_fsm_target_pcs_; |
| 1660 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1661 | // Use std::deque<> for literal labels to allow insertions at the end |
| 1662 | // without invalidating pointers and references to existing elements. |
| 1663 | ArenaDeque<Literal> literals_; |
| 1664 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 1665 | // Jump table list. |
| 1666 | ArenaDeque<JumpTable> jump_tables_; |
| 1667 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1668 | // There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC |
| 1669 | // we get PC using the NAL instruction. This label marks the position within the assembler buffer |
| 1670 | // that PC (from NAL) points to. |
| 1671 | MipsLabel pc_rel_base_label_; |
| 1672 | |
Alexey Frunze | 57eb0f5 | 2016-07-29 22:04:46 -0700 | [diff] [blame] | 1673 | // Data for GetAdjustedPosition(), see the description there. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1674 | uint32_t last_position_adjustment_; |
| 1675 | uint32_t last_old_position_; |
| 1676 | uint32_t last_branch_id_; |
| 1677 | |
Lena Djokic | 0758ae7 | 2017-05-23 11:06:23 +0200 | [diff] [blame] | 1678 | const bool has_msa_; |
| 1679 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 1680 | const MipsInstructionSetFeatures* isa_features_; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 1681 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1682 | DISALLOW_COPY_AND_ASSIGN(MipsAssembler); |
| 1683 | }; |
| 1684 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 1685 | } // namespace mips |
| 1686 | } // namespace art |
| 1687 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 1688 | #endif // ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_ |