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