blob: e2c2e27b850202416ec9f2d537d1fa57c6b94c76 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_
18#define ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Elliott Hughes07ed66b2012-12-12 18:34:25 -080020#include <vector>
21
Vladimir Marko80afd022015-05-19 18:08:00 +010022#include "base/bit_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080023#include "base/logging.h"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070024#include "base/value_object.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070025#include "constants_arm.h"
Ian Rogers166db042013-07-26 12:05:57 -070026#include "utils/arm/managed_register_arm.h"
27#include "utils/assembler.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070028#include "offsets.h"
Carl Shapiroa2e18e12011-06-21 18:57:55 -070029
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070030namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070031namespace arm {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070032
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +000033class Arm32Assembler;
34class Thumb2Assembler;
35
Carl Shapiroa2e18e12011-06-21 18:57:55 -070036class ShifterOperand {
37 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -070038 ShifterOperand() : type_(kUnknown), rm_(kNoRegister), rs_(kNoRegister),
39 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070040 }
41
Nicolas Geoffray96f89a22014-07-11 10:57:49 +010042 explicit ShifterOperand(uint32_t immed);
Carl Shapiroa2e18e12011-06-21 18:57:55 -070043
44 // Data-processing operands - Register
Dave Allison65fcc2c2014-04-28 13:45:27 -070045 explicit ShifterOperand(Register rm) : type_(kRegister), rm_(rm), rs_(kNoRegister),
46 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070047 }
48
Dave Allison65fcc2c2014-04-28 13:45:27 -070049 ShifterOperand(uint32_t rotate, uint32_t immed8) : type_(kImmediate), rm_(kNoRegister),
50 rs_(kNoRegister),
51 is_rotate_(true), is_shift_(false), shift_(kNoShift), rotate_(rotate), immed_(immed8) {
52 }
53
54 ShifterOperand(Register rm, Shift shift, uint32_t shift_imm = 0) : type_(kRegister), rm_(rm),
55 rs_(kNoRegister),
56 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(shift_imm) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070057 }
58
59 // Data-processing operands - Logical shift/rotate by register
Dave Allison65fcc2c2014-04-28 13:45:27 -070060 ShifterOperand(Register rm, Shift shift, Register rs) : type_(kRegister), rm_(rm),
61 rs_(rs),
62 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -070063 }
64
Dave Allison65fcc2c2014-04-28 13:45:27 -070065 bool is_valid() const { return (type_ == kImmediate) || (type_ == kRegister); }
Carl Shapiroa2e18e12011-06-21 18:57:55 -070066
67 uint32_t type() const {
68 CHECK(is_valid());
69 return type_;
70 }
71
Dave Allison65fcc2c2014-04-28 13:45:27 -070072 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -070073 uint32_t encodingThumb() const;
Dave Allison65fcc2c2014-04-28 13:45:27 -070074
75 bool IsEmpty() const {
76 return type_ == kUnknown;
Carl Shapiroa2e18e12011-06-21 18:57:55 -070077 }
78
Dave Allison65fcc2c2014-04-28 13:45:27 -070079 bool IsImmediate() const {
80 return type_ == kImmediate;
81 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -070082
Dave Allison65fcc2c2014-04-28 13:45:27 -070083 bool IsRegister() const {
84 return type_ == kRegister;
85 }
86
87 bool IsShift() const {
88 return is_shift_;
89 }
90
91 uint32_t GetImmediate() const {
92 return immed_;
93 }
94
95 Shift GetShift() const {
96 return shift_;
97 }
98
99 Register GetRegister() const {
100 return rm_;
101 }
102
Guillaume "Vermeille" Sanchezab4a2f52015-03-11 14:00:30 +0000103 Register GetSecondRegister() const {
104 return rs_;
105 }
106
Dave Allison65fcc2c2014-04-28 13:45:27 -0700107 enum Type {
108 kUnknown = -1,
109 kRegister,
110 kImmediate
111 };
112
Dave Allison65fcc2c2014-04-28 13:45:27 -0700113 private:
114 Type type_;
115 Register rm_;
116 Register rs_;
117 bool is_rotate_;
118 bool is_shift_;
119 Shift shift_;
120 uint32_t rotate_;
121 uint32_t immed_;
122
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000123 friend class Arm32Assembler;
124 friend class Thumb2Assembler;
125
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700126#ifdef SOURCE_ASSEMBLER_SUPPORT
127 friend class BinaryAssembler;
128#endif
129};
130
131
132enum LoadOperandType {
133 kLoadSignedByte,
134 kLoadUnsignedByte,
135 kLoadSignedHalfword,
136 kLoadUnsignedHalfword,
137 kLoadWord,
138 kLoadWordPair,
139 kLoadSWord,
140 kLoadDWord
141};
142
143
144enum StoreOperandType {
145 kStoreByte,
146 kStoreHalfword,
147 kStoreWord,
148 kStoreWordPair,
149 kStoreSWord,
150 kStoreDWord
151};
152
153
154// Load/store multiple addressing mode.
155enum BlockAddressMode {
156 // bit encoding P U W
157 DA = (0|0|0) << 21, // decrement after
158 IA = (0|4|0) << 21, // increment after
159 DB = (8|0|0) << 21, // decrement before
160 IB = (8|4|0) << 21, // increment before
161 DA_W = (0|0|1) << 21, // decrement after with writeback to base
162 IA_W = (0|4|1) << 21, // increment after with writeback to base
163 DB_W = (8|0|1) << 21, // decrement before with writeback to base
164 IB_W = (8|4|1) << 21 // increment before with writeback to base
165};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700166inline std::ostream& operator<<(std::ostream& os, const BlockAddressMode& rhs) {
167 os << static_cast<int>(rhs);
168 return os;
169}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700170
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700171class Address : public ValueObject {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700172 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -0700173 // Memory operand addressing mode (in ARM encoding form. For others we need
174 // to adjust)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700175 enum Mode {
176 // bit encoding P U W
177 Offset = (8|4|0) << 21, // offset (w/o writeback to base)
178 PreIndex = (8|4|1) << 21, // pre-indexed addressing with writeback
179 PostIndex = (0|4|0) << 21, // post-indexed addressing with writeback
180 NegOffset = (8|0|0) << 21, // negative offset (w/o writeback to base)
181 NegPreIndex = (8|0|1) << 21, // negative pre-indexed with writeback
182 NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
183 };
184
Dave Allison45fdb932014-06-25 12:37:10 -0700185 Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
186 offset_(offset),
187 am_(am), is_immed_offset_(true), shift_(LSL) {
188 }
189
190 Address(Register rn, Register rm, Mode am = Offset) : rn_(rn), rm_(rm), offset_(0),
191 am_(am), is_immed_offset_(false), shift_(LSL) {
192 CHECK_NE(rm, PC);
193 }
194
195 Address(Register rn, Register rm, Shift shift, uint32_t count, Mode am = Offset) :
196 rn_(rn), rm_(rm), offset_(count),
197 am_(am), is_immed_offset_(false), shift_(shift) {
198 CHECK_NE(rm, PC);
199 }
200
201 // LDR(literal) - pc relative load.
202 explicit Address(int32_t offset) :
203 rn_(PC), rm_(R0), offset_(offset),
204 am_(Offset), is_immed_offset_(false), shift_(LSL) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700205 }
206
Dave Allison65fcc2c2014-04-28 13:45:27 -0700207 static bool CanHoldLoadOffsetArm(LoadOperandType type, int offset);
208 static bool CanHoldStoreOffsetArm(StoreOperandType type, int offset);
209
210 static bool CanHoldLoadOffsetThumb(LoadOperandType type, int offset);
211 static bool CanHoldStoreOffsetThumb(StoreOperandType type, int offset);
212
213 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700214 uint32_t encodingThumb(bool is_32bit) const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700215
216 uint32_t encoding3() const;
217 uint32_t vencoding() const;
218
219 uint32_t encodingThumbLdrdStrd() const;
220
221 Register GetRegister() const {
222 return rn_;
223 }
224
Dave Allison45fdb932014-06-25 12:37:10 -0700225 Register GetRegisterOffset() const {
226 return rm_;
227 }
228
Dave Allison65fcc2c2014-04-28 13:45:27 -0700229 int32_t GetOffset() const {
230 return offset_;
231 }
232
233 Mode GetMode() const {
234 return am_;
235 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700236
Dave Allison45fdb932014-06-25 12:37:10 -0700237 bool IsImmediate() const {
238 return is_immed_offset_;
239 }
240
241 Shift GetShift() const {
242 return shift_;
243 }
244
245 int32_t GetShiftCount() const {
246 CHECK(!is_immed_offset_);
247 return offset_;
248 }
249
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700250 private:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700251 const Register rn_;
252 const Register rm_;
253 const int32_t offset_; // Used as shift amount for register offset.
254 const Mode am_;
255 const bool is_immed_offset_;
256 const Shift shift_;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700257};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700258inline std::ostream& operator<<(std::ostream& os, const Address::Mode& rhs) {
259 os << static_cast<int>(rhs);
260 return os;
261}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700262
Dave Allison65fcc2c2014-04-28 13:45:27 -0700263// Instruction encoding bits.
264enum {
265 H = 1 << 5, // halfword (or byte)
266 L = 1 << 20, // load (or store)
267 S = 1 << 20, // set condition code (or leave unchanged)
268 W = 1 << 21, // writeback base register (or leave unchanged)
269 A = 1 << 21, // accumulate in multiply instruction (or not)
270 B = 1 << 22, // unsigned byte (or word)
271 N = 1 << 22, // long (or short)
272 U = 1 << 23, // positive (or negative) offset/index
273 P = 1 << 24, // offset/pre-indexed addressing (or post-indexed addressing)
274 I = 1 << 25, // immediate shifter operand (or not)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700275
Dave Allison65fcc2c2014-04-28 13:45:27 -0700276 B0 = 1,
277 B1 = 1 << 1,
278 B2 = 1 << 2,
279 B3 = 1 << 3,
280 B4 = 1 << 4,
281 B5 = 1 << 5,
282 B6 = 1 << 6,
283 B7 = 1 << 7,
284 B8 = 1 << 8,
285 B9 = 1 << 9,
286 B10 = 1 << 10,
287 B11 = 1 << 11,
288 B12 = 1 << 12,
289 B13 = 1 << 13,
290 B14 = 1 << 14,
291 B15 = 1 << 15,
292 B16 = 1 << 16,
293 B17 = 1 << 17,
294 B18 = 1 << 18,
295 B19 = 1 << 19,
296 B20 = 1 << 20,
297 B21 = 1 << 21,
298 B22 = 1 << 22,
299 B23 = 1 << 23,
300 B24 = 1 << 24,
301 B25 = 1 << 25,
302 B26 = 1 << 26,
303 B27 = 1 << 27,
304 B28 = 1 << 28,
305 B29 = 1 << 29,
306 B30 = 1 << 30,
307 B31 = 1 << 31,
308
309 // Instruction bit masks.
310 RdMask = 15 << 12, // in str instruction
311 CondMask = 15 << 28,
312 CoprocessorMask = 15 << 8,
313 OpCodeMask = 15 << 21, // in data-processing instructions
314 Imm24Mask = (1 << 24) - 1,
315 Off12Mask = (1 << 12) - 1,
316
317 // ldrex/strex register field encodings.
318 kLdExRnShift = 16,
319 kLdExRtShift = 12,
320 kStrExRnShift = 16,
321 kStrExRdShift = 12,
322 kStrExRtShift = 0,
323};
324
325// IfThen state for IT instructions.
326enum ItState {
327 kItOmitted,
328 kItThen,
329 kItT = kItThen,
330 kItElse,
331 kItE = kItElse
332};
333
334constexpr uint32_t kNoItCondition = 3;
335constexpr uint32_t kInvalidModifiedImmediate = -1;
336
337extern const char* kRegisterNames[];
338extern const char* kConditionNames[];
Dave Allison65fcc2c2014-04-28 13:45:27 -0700339
340// This is an abstract ARM assembler. Subclasses provide assemblers for the individual
341// instruction sets (ARM32, Thumb2, etc.)
342//
343class ArmAssembler : public Assembler {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700344 public:
Ian Rogers2c8f6532011-09-02 17:16:34 -0700345 virtual ~ArmAssembler() {}
buzbeec143c552011-08-20 17:38:58 -0700346
Dave Allison65fcc2c2014-04-28 13:45:27 -0700347 // Is this assembler for the thumb instruction set?
348 virtual bool IsThumb() const = 0;
349
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700350 // Data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700351 virtual void and_(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700352
Dave Allison65fcc2c2014-04-28 13:45:27 -0700353 virtual void eor(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700354
Dave Allison65fcc2c2014-04-28 13:45:27 -0700355 virtual void sub(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
356 virtual void subs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700357
Dave Allison65fcc2c2014-04-28 13:45:27 -0700358 virtual void rsb(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
359 virtual void rsbs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700360
Dave Allison65fcc2c2014-04-28 13:45:27 -0700361 virtual void add(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700362
Dave Allison65fcc2c2014-04-28 13:45:27 -0700363 virtual void adds(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700364
Dave Allison65fcc2c2014-04-28 13:45:27 -0700365 virtual void adc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700366
Dave Allison65fcc2c2014-04-28 13:45:27 -0700367 virtual void sbc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700368
Dave Allison65fcc2c2014-04-28 13:45:27 -0700369 virtual void rsc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700370
Dave Allison65fcc2c2014-04-28 13:45:27 -0700371 virtual void tst(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700372
Dave Allison65fcc2c2014-04-28 13:45:27 -0700373 virtual void teq(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700374
Dave Allison65fcc2c2014-04-28 13:45:27 -0700375 virtual void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700376
Dave Allison65fcc2c2014-04-28 13:45:27 -0700377 virtual void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700378
Dave Allison65fcc2c2014-04-28 13:45:27 -0700379 virtual void orr(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
380 virtual void orrs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700381
Dave Allison65fcc2c2014-04-28 13:45:27 -0700382 virtual void mov(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
383 virtual void movs(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700384
Dave Allison65fcc2c2014-04-28 13:45:27 -0700385 virtual void bic(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700386
Dave Allison65fcc2c2014-04-28 13:45:27 -0700387 virtual void mvn(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
388 virtual void mvns(Register rd, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700389
390 // Miscellaneous data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700391 virtual void clz(Register rd, Register rm, Condition cond = AL) = 0;
392 virtual void movw(Register rd, uint16_t imm16, Condition cond = AL) = 0;
393 virtual void movt(Register rd, uint16_t imm16, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700394
395 // Multiply instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700396 virtual void mul(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
397 virtual void mla(Register rd, Register rn, Register rm, Register ra,
398 Condition cond = AL) = 0;
399 virtual void mls(Register rd, Register rn, Register rm, Register ra,
400 Condition cond = AL) = 0;
Zheng Xuc6667102015-05-15 16:08:45 +0800401 virtual void smull(Register rd_lo, Register rd_hi, Register rn, Register rm,
402 Condition cond = AL) = 0;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700403 virtual void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
404 Condition cond = AL) = 0;
405
406 virtual void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
407 virtual void udiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700408
Roland Levillain981e4542014-11-14 11:47:14 +0000409 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000410 virtual void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
411 Condition cond = AL) = 0;
Roland Levillain981e4542014-11-14 11:47:14 +0000412 virtual void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
413 Condition cond = AL) = 0;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000414
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700415 // Load/store instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700416 virtual void ldr(Register rd, const Address& ad, Condition cond = AL) = 0;
417 virtual void str(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700418
Dave Allison65fcc2c2014-04-28 13:45:27 -0700419 virtual void ldrb(Register rd, const Address& ad, Condition cond = AL) = 0;
420 virtual void strb(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700421
Dave Allison65fcc2c2014-04-28 13:45:27 -0700422 virtual void ldrh(Register rd, const Address& ad, Condition cond = AL) = 0;
423 virtual void strh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700424
Dave Allison65fcc2c2014-04-28 13:45:27 -0700425 virtual void ldrsb(Register rd, const Address& ad, Condition cond = AL) = 0;
426 virtual void ldrsh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700427
Dave Allison65fcc2c2014-04-28 13:45:27 -0700428 virtual void ldrd(Register rd, const Address& ad, Condition cond = AL) = 0;
429 virtual void strd(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700430
Dave Allison65fcc2c2014-04-28 13:45:27 -0700431 virtual void ldm(BlockAddressMode am, Register base,
432 RegList regs, Condition cond = AL) = 0;
433 virtual void stm(BlockAddressMode am, Register base,
434 RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700435
Dave Allison65fcc2c2014-04-28 13:45:27 -0700436 virtual void ldrex(Register rd, Register rn, Condition cond = AL) = 0;
437 virtual void strex(Register rd, Register rt, Register rn, Condition cond = AL) = 0;
Calin Juravle52c48962014-12-16 17:02:57 +0000438 virtual void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
439 virtual void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700440
441 // Miscellaneous instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700442 virtual void clrex(Condition cond = AL) = 0;
443 virtual void nop(Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700444
445 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700446 virtual void bkpt(uint16_t imm16) = 0;
447 virtual void svc(uint32_t imm24) = 0;
448
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700449 virtual void it(Condition firstcond ATTRIBUTE_UNUSED,
450 ItState i1 ATTRIBUTE_UNUSED = kItOmitted,
451 ItState i2 ATTRIBUTE_UNUSED = kItOmitted,
452 ItState i3 ATTRIBUTE_UNUSED = kItOmitted) {
Dave Allison65fcc2c2014-04-28 13:45:27 -0700453 // Ignored if not supported.
454 }
455
456 virtual void cbz(Register rn, Label* target) = 0;
457 virtual void cbnz(Register rn, Label* target) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700458
459 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
Dave Allison65fcc2c2014-04-28 13:45:27 -0700460 virtual void vmovsr(SRegister sn, Register rt, Condition cond = AL) = 0;
461 virtual void vmovrs(Register rt, SRegister sn, Condition cond = AL) = 0;
462 virtual void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) = 0;
463 virtual void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) = 0;
464 virtual void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) = 0;
465 virtual void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) = 0;
466 virtual void vmovs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
467 virtual void vmovd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700468
469 // Returns false if the immediate cannot be encoded.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700470 virtual bool vmovs(SRegister sd, float s_imm, Condition cond = AL) = 0;
471 virtual bool vmovd(DRegister dd, double d_imm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700472
Dave Allison65fcc2c2014-04-28 13:45:27 -0700473 virtual void vldrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
474 virtual void vstrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
475 virtual void vldrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
476 virtual void vstrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700477
Dave Allison65fcc2c2014-04-28 13:45:27 -0700478 virtual void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
479 virtual void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
480 virtual void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
481 virtual void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
482 virtual void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
483 virtual void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
484 virtual void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
485 virtual void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
486 virtual void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
487 virtual void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
488 virtual void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
489 virtual void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700490
Dave Allison65fcc2c2014-04-28 13:45:27 -0700491 virtual void vabss(SRegister sd, SRegister sm, Condition cond = AL) = 0;
492 virtual void vabsd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
493 virtual void vnegs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
494 virtual void vnegd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
495 virtual void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) = 0;
496 virtual void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700497
Dave Allison65fcc2c2014-04-28 13:45:27 -0700498 virtual void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) = 0;
499 virtual void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) = 0;
500 virtual void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) = 0;
501 virtual void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) = 0;
502 virtual void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) = 0;
503 virtual void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) = 0;
504 virtual void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) = 0;
505 virtual void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) = 0;
506 virtual void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) = 0;
507 virtual void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700508
Dave Allison65fcc2c2014-04-28 13:45:27 -0700509 virtual void vcmps(SRegister sd, SRegister sm, Condition cond = AL) = 0;
510 virtual void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
511 virtual void vcmpsz(SRegister sd, Condition cond = AL) = 0;
512 virtual void vcmpdz(DRegister dd, Condition cond = AL) = 0;
513 virtual void vmstat(Condition cond = AL) = 0; // VMRS APSR_nzcv, FPSCR
514
515 virtual void vpushs(SRegister reg, int nregs, Condition cond = AL) = 0;
516 virtual void vpushd(DRegister reg, int nregs, Condition cond = AL) = 0;
517 virtual void vpops(SRegister reg, int nregs, Condition cond = AL) = 0;
518 virtual void vpopd(DRegister reg, int nregs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700519
520 // Branch instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700521 virtual void b(Label* label, Condition cond = AL) = 0;
522 virtual void bl(Label* label, Condition cond = AL) = 0;
523 virtual void blx(Register rm, Condition cond = AL) = 0;
524 virtual void bx(Register rm, Condition cond = AL) = 0;
525
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100526 // Memory barriers.
527 virtual void dmb(DmbOptions flavor) = 0;
528
Dave Allison65fcc2c2014-04-28 13:45:27 -0700529 void Pad(uint32_t bytes);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700530
531 // Macros.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700532 // Most of these are pure virtual as they need to be implemented per instruction set.
533
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700534 // Add signed constant value to rd. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700535 virtual void AddConstant(Register rd, int32_t value, Condition cond = AL) = 0;
536 virtual void AddConstant(Register rd, Register rn, int32_t value,
537 Condition cond = AL) = 0;
538 virtual void AddConstantSetFlags(Register rd, Register rn, int32_t value,
539 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700540
541 // Load and Store. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700542 virtual void LoadImmediate(Register rd, int32_t value, Condition cond = AL) = 0;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000543 void LoadSImmediate(SRegister sd, float value, Condition cond = AL) {
544 if (!vmovs(sd, value, cond)) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000545 int32_t int_value = bit_cast<int32_t, float>(value);
546 if (int_value == bit_cast<int32_t, float>(0.0f)) {
547 // 0.0 is quite common, so we special case it by loading
548 // 2.0 in `sd` and then substracting it.
549 bool success = vmovs(sd, 2.0, cond);
550 CHECK(success);
551 vsubs(sd, sd, sd, cond);
552 } else {
553 LoadImmediate(IP, int_value, cond);
554 vmovsr(sd, IP, cond);
555 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000556 }
557 }
558
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000559 void LoadDImmediate(DRegister sd, double value, Condition cond = AL) {
560 if (!vmovd(sd, value, cond)) {
561 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000562 if (int_value == bit_cast<uint64_t, double>(0.0)) {
563 // 0.0 is quite common, so we special case it by loading
564 // 2.0 in `sd` and then substracting it.
565 bool success = vmovd(sd, 2.0, cond);
566 CHECK(success);
567 vsubd(sd, sd, sd, cond);
568 } else {
569 if (sd < 16) {
570 SRegister low = static_cast<SRegister>(sd << 1);
571 SRegister high = static_cast<SRegister>(low + 1);
572 LoadSImmediate(low, bit_cast<float, uint32_t>(Low32Bits(int_value)), cond);
573 if (High32Bits(int_value) == Low32Bits(int_value)) {
574 vmovs(high, low);
575 } else {
576 LoadSImmediate(high, bit_cast<float, uint32_t>(High32Bits(int_value)), cond);
577 }
578 } else {
579 LOG(FATAL) << "Unimplemented loading of double into a D register "
580 << "that cannot be split into two S registers";
581 }
582 }
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000583 }
584 }
585
Dave Allison65fcc2c2014-04-28 13:45:27 -0700586 virtual void MarkExceptionHandler(Label* label) = 0;
587 virtual void LoadFromOffset(LoadOperandType type,
588 Register reg,
589 Register base,
590 int32_t offset,
591 Condition cond = AL) = 0;
592 virtual void StoreToOffset(StoreOperandType type,
593 Register reg,
594 Register base,
595 int32_t offset,
596 Condition cond = AL) = 0;
597 virtual void LoadSFromOffset(SRegister reg,
598 Register base,
599 int32_t offset,
600 Condition cond = AL) = 0;
601 virtual void StoreSToOffset(SRegister reg,
602 Register base,
603 int32_t offset,
604 Condition cond = AL) = 0;
605 virtual void LoadDFromOffset(DRegister reg,
606 Register base,
607 int32_t offset,
608 Condition cond = AL) = 0;
609 virtual void StoreDToOffset(DRegister reg,
610 Register base,
611 int32_t offset,
612 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700613
Dave Allison65fcc2c2014-04-28 13:45:27 -0700614 virtual void Push(Register rd, Condition cond = AL) = 0;
615 virtual void Pop(Register rd, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700616
Dave Allison65fcc2c2014-04-28 13:45:27 -0700617 virtual void PushList(RegList regs, Condition cond = AL) = 0;
618 virtual void PopList(RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700619
Dave Allison65fcc2c2014-04-28 13:45:27 -0700620 virtual void Mov(Register rd, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700621
622 // Convenience shift instructions. Use mov instruction with shifter operand
623 // for variants setting the status flags or using a register shift count.
Dave Allison45fdb932014-06-25 12:37:10 -0700624 virtual void Lsl(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
625 Condition cond = AL) = 0;
626 virtual void Lsr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
627 Condition cond = AL) = 0;
628 virtual void Asr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
629 Condition cond = AL) = 0;
630 virtual void Ror(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
631 Condition cond = AL) = 0;
632 virtual void Rrx(Register rd, Register rm, bool setcc = false,
633 Condition cond = AL) = 0;
634
635 virtual void Lsl(Register rd, Register rm, Register rn, bool setcc = false,
636 Condition cond = AL) = 0;
637 virtual void Lsr(Register rd, Register rm, Register rn, bool setcc = false,
638 Condition cond = AL) = 0;
639 virtual void Asr(Register rd, Register rm, Register rn, bool setcc = false,
640 Condition cond = AL) = 0;
641 virtual void Ror(Register rd, Register rm, Register rn, bool setcc = false,
642 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700643
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000644 // Returns whether the `immediate` can fit in a `ShifterOperand`. If yes,
645 // `shifter_op` contains the operand.
646 virtual bool ShifterOperandCanHold(Register rd,
647 Register rn,
648 Opcode opcode,
649 uint32_t immediate,
650 ShifterOperand* shifter_op) = 0;
651
Ian Rogers13735952014-10-08 12:43:28 -0700652 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700653
Dave Allison65fcc2c2014-04-28 13:45:27 -0700654 virtual void Bind(Label* label) = 0;
655
656 virtual void CompareAndBranchIfZero(Register r, Label* label) = 0;
657 virtual void CompareAndBranchIfNonZero(Register r, Label* label) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700658
Ian Rogers2c8f6532011-09-02 17:16:34 -0700659 //
660 // Overridden common assembler high-level functionality
661 //
Ian Rogers45a76cb2011-07-21 22:00:15 -0700662
Ian Rogers2c8f6532011-09-02 17:16:34 -0700663 // Emit code that will create an activation on the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700664 void BuildFrame(size_t frame_size, ManagedRegister method_reg,
665 const std::vector<ManagedRegister>& callee_save_regs,
666 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700667
Ian Rogers2c8f6532011-09-02 17:16:34 -0700668 // Emit code that will remove an activation from the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700669 void RemoveFrame(size_t frame_size, const std::vector<ManagedRegister>& callee_save_regs)
Dave Allison65fcc2c2014-04-28 13:45:27 -0700670 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700671
Ian Rogersdd7624d2014-03-14 17:43:00 -0700672 void IncreaseFrameSize(size_t adjust) OVERRIDE;
673 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700674
675 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700676 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
677 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
678 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700679
Ian Rogersdd7624d2014-03-14 17:43:00 -0700680 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700681
Ian Rogersdd7624d2014-03-14 17:43:00 -0700682 void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm, ManagedRegister scratch)
683 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700684
Ian Rogersdd7624d2014-03-14 17:43:00 -0700685 void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
686 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700687
Ian Rogersdd7624d2014-03-14 17:43:00 -0700688 void StoreStackPointerToThread32(ThreadOffset<4> thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700689
Ian Rogersdd7624d2014-03-14 17:43:00 -0700690 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
691 ManagedRegister scratch) OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -0700692
Ian Rogers2c8f6532011-09-02 17:16:34 -0700693 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700694 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700695
Ian Rogersdd7624d2014-03-14 17:43:00 -0700696 void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700697
Ian Rogersdd7624d2014-03-14 17:43:00 -0700698 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700699
Ian Rogersdd7624d2014-03-14 17:43:00 -0700700 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700701
Ian Rogersdd7624d2014-03-14 17:43:00 -0700702 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700703
Ian Rogersdd7624d2014-03-14 17:43:00 -0700704 void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700705
706 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700707 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700708
Ian Rogersdd7624d2014-03-14 17:43:00 -0700709 void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
710 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700711
Ian Rogersdd7624d2014-03-14 17:43:00 -0700712 void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
713 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700714
Ian Rogersdd7624d2014-03-14 17:43:00 -0700715 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700716
Ian Rogersdd7624d2014-03-14 17:43:00 -0700717 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700718
Ian Rogersdd7624d2014-03-14 17:43:00 -0700719 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
720 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700721
Ian Rogersdd7624d2014-03-14 17:43:00 -0700722 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
723 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700724
Ian Rogersdd7624d2014-03-14 17:43:00 -0700725 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
726 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700727
Ian Rogersdd7624d2014-03-14 17:43:00 -0700728 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
729 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700730
Ian Rogersdd7624d2014-03-14 17:43:00 -0700731 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
732 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700733
jeffhao58136ca2012-05-24 13:40:11 -0700734 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700735 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700736
jeffhaocee4d0c2012-06-15 14:42:01 -0700737 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700738 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700739
Ian Rogers2c8f6532011-09-02 17:16:34 -0700740 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700741 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
742 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700743
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700744 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700745 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700746 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700747 // null.
748 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
749 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700750
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700751 // Set up out_off to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700752 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700753 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
754 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700755
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700756 // src holds a handle scope entry (Object**) load this into dst
757 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700758
759 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
760 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700761 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
762 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700763
764 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700765 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
766 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
767 void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700768
Ian Rogers2c8f6532011-09-02 17:16:34 -0700769 // Generate code to check if Thread::Current()->exception_ is non-null
770 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700771 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogersb033c752011-07-20 12:22:35 -0700772
Dave Allison65fcc2c2014-04-28 13:45:27 -0700773 static uint32_t ModifiedImmediate(uint32_t value);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700774
Dave Allison45fdb932014-06-25 12:37:10 -0700775 static bool IsLowRegister(Register r) {
776 return r < R8;
777 }
778
779 static bool IsHighRegister(Register r) {
780 return r >= R8;
781 }
782
Dave Allison65fcc2c2014-04-28 13:45:27 -0700783 protected:
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700784 // Returns whether or not the given register is used for passing parameters.
785 static int RegisterCompare(const Register* reg1, const Register* reg2) {
786 return *reg1 - *reg2;
787 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700788};
789
Ian Rogers2c8f6532011-09-02 17:16:34 -0700790// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700791class ArmExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700792 public:
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700793 explicit ArmExceptionSlowPath(ArmManagedRegister scratch, size_t stack_adjust)
794 : scratch_(scratch), stack_adjust_(stack_adjust) {
795 }
Ian Rogersdd7624d2014-03-14 17:43:00 -0700796 void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers67375ac2011-09-14 00:55:44 -0700797 private:
798 const ArmManagedRegister scratch_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700799 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700800};
801
Ian Rogers2c8f6532011-09-02 17:16:34 -0700802} // namespace arm
Ian Rogersb033c752011-07-20 12:22:35 -0700803} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700804
Ian Rogers166db042013-07-26 12:05:57 -0700805#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_