blob: 8ba6fb4f91d5cd621b15707a220f75bdf950280f [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
Vladimir Markocf93a5c2015-06-16 11:33:24 +000020#include <type_traits>
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include <vector>
22
Vladimir Marko93205e32016-04-13 11:59:46 +010023#include "base/arena_allocator.h"
24#include "base/arena_containers.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010025#include "base/bit_utils.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070026#include "base/enums.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080027#include "base/logging.h"
Vladimir Marko88b2b802015-12-04 14:19:04 +000028#include "base/stl_util.h"
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070029#include "base/value_object.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070030#include "constants_arm.h"
Ian Rogers166db042013-07-26 12:05:57 -070031#include "utils/arm/managed_register_arm.h"
32#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070033#include "utils/jni_macro_assembler.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070034#include "offsets.h"
Carl Shapiroa2e18e12011-06-21 18:57:55 -070035
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070036namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070037namespace arm {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070038
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +000039class Thumb2Assembler;
40
Vladimir Markocf93a5c2015-06-16 11:33:24 +000041// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
42class Literal {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000043 public:
Vladimir Markocf93a5c2015-06-16 11:33:24 +000044 static constexpr size_t kMaxSize = 8;
45
46 Literal(uint32_t size, const uint8_t* data)
47 : label_(), size_(size) {
48 DCHECK_LE(size, Literal::kMaxSize);
49 memcpy(data_, data, size);
50 }
51
52 template <typename T>
53 T GetValue() const {
54 DCHECK_EQ(size_, sizeof(T));
55 T value;
56 memcpy(&value, data_, sizeof(T));
57 return value;
58 }
59
60 uint32_t GetSize() const {
61 return size_;
62 }
63
64 const uint8_t* GetData() const {
65 return data_;
66 }
67
68 Label* GetLabel() {
69 return &label_;
70 }
71
72 const Label* GetLabel() const {
73 return &label_;
74 }
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000075
76 private:
Vladimir Markocf93a5c2015-06-16 11:33:24 +000077 Label label_;
78 const uint32_t size_;
79 uint8_t data_[kMaxSize];
80
81 DISALLOW_COPY_AND_ASSIGN(Literal);
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +000082};
83
Andreas Gampe7cffc3b2015-10-19 21:31:53 -070084// Jump table: table of labels emitted after the literals. Similar to literals.
85class JumpTable {
86 public:
87 explicit JumpTable(std::vector<Label*>&& labels)
88 : label_(), anchor_label_(), labels_(std::move(labels)) {
89 }
90
91 uint32_t GetSize() const {
92 return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
93 }
94
95 const std::vector<Label*>& GetData() const {
96 return labels_;
97 }
98
99 Label* GetLabel() {
100 return &label_;
101 }
102
103 const Label* GetLabel() const {
104 return &label_;
105 }
106
107 Label* GetAnchorLabel() {
108 return &anchor_label_;
109 }
110
111 const Label* GetAnchorLabel() const {
112 return &anchor_label_;
113 }
114
115 private:
116 Label label_;
117 Label anchor_label_;
118 std::vector<Label*> labels_;
119
120 DISALLOW_COPY_AND_ASSIGN(JumpTable);
121};
122
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700123class ShifterOperand {
124 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -0700125 ShifterOperand() : type_(kUnknown), rm_(kNoRegister), rs_(kNoRegister),
126 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700127 }
128
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100129 explicit ShifterOperand(uint32_t immed);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700130
131 // Data-processing operands - Register
Dave Allison65fcc2c2014-04-28 13:45:27 -0700132 explicit ShifterOperand(Register rm) : type_(kRegister), rm_(rm), rs_(kNoRegister),
133 is_rotate_(false), is_shift_(false), shift_(kNoShift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700134 }
135
Dave Allison65fcc2c2014-04-28 13:45:27 -0700136 ShifterOperand(uint32_t rotate, uint32_t immed8) : type_(kImmediate), rm_(kNoRegister),
137 rs_(kNoRegister),
138 is_rotate_(true), is_shift_(false), shift_(kNoShift), rotate_(rotate), immed_(immed8) {
139 }
140
141 ShifterOperand(Register rm, Shift shift, uint32_t shift_imm = 0) : type_(kRegister), rm_(rm),
142 rs_(kNoRegister),
143 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(shift_imm) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700144 }
145
146 // Data-processing operands - Logical shift/rotate by register
Dave Allison65fcc2c2014-04-28 13:45:27 -0700147 ShifterOperand(Register rm, Shift shift, Register rs) : type_(kRegister), rm_(rm),
148 rs_(rs),
149 is_rotate_(false), is_shift_(true), shift_(shift), rotate_(0), immed_(0) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700150 }
151
Dave Allison65fcc2c2014-04-28 13:45:27 -0700152 bool is_valid() const { return (type_ == kImmediate) || (type_ == kRegister); }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700153
154 uint32_t type() const {
155 CHECK(is_valid());
156 return type_;
157 }
158
Dave Allison65fcc2c2014-04-28 13:45:27 -0700159 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700160 uint32_t encodingThumb() const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700161
162 bool IsEmpty() const {
163 return type_ == kUnknown;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700164 }
165
Dave Allison65fcc2c2014-04-28 13:45:27 -0700166 bool IsImmediate() const {
167 return type_ == kImmediate;
168 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700169
Dave Allison65fcc2c2014-04-28 13:45:27 -0700170 bool IsRegister() const {
171 return type_ == kRegister;
172 }
173
174 bool IsShift() const {
175 return is_shift_;
176 }
177
178 uint32_t GetImmediate() const {
179 return immed_;
180 }
181
182 Shift GetShift() const {
183 return shift_;
184 }
185
186 Register GetRegister() const {
187 return rm_;
188 }
189
Guillaume "Vermeille" Sanchezab4a2f52015-03-11 14:00:30 +0000190 Register GetSecondRegister() const {
191 return rs_;
192 }
193
Dave Allison65fcc2c2014-04-28 13:45:27 -0700194 enum Type {
195 kUnknown = -1,
196 kRegister,
197 kImmediate
198 };
199
Dave Allison65fcc2c2014-04-28 13:45:27 -0700200 private:
201 Type type_;
202 Register rm_;
203 Register rs_;
204 bool is_rotate_;
205 bool is_shift_;
206 Shift shift_;
207 uint32_t rotate_;
208 uint32_t immed_;
209
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000210 friend class Thumb2Assembler;
211
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700212#ifdef SOURCE_ASSEMBLER_SUPPORT
213 friend class BinaryAssembler;
214#endif
215};
216
217
218enum LoadOperandType {
219 kLoadSignedByte,
220 kLoadUnsignedByte,
221 kLoadSignedHalfword,
222 kLoadUnsignedHalfword,
223 kLoadWord,
224 kLoadWordPair,
225 kLoadSWord,
226 kLoadDWord
227};
228
229
230enum StoreOperandType {
231 kStoreByte,
232 kStoreHalfword,
233 kStoreWord,
234 kStoreWordPair,
235 kStoreSWord,
236 kStoreDWord
237};
238
239
240// Load/store multiple addressing mode.
241enum BlockAddressMode {
242 // bit encoding P U W
243 DA = (0|0|0) << 21, // decrement after
244 IA = (0|4|0) << 21, // increment after
245 DB = (8|0|0) << 21, // decrement before
246 IB = (8|4|0) << 21, // increment before
247 DA_W = (0|0|1) << 21, // decrement after with writeback to base
248 IA_W = (0|4|1) << 21, // increment after with writeback to base
249 DB_W = (8|0|1) << 21, // decrement before with writeback to base
250 IB_W = (8|4|1) << 21 // increment before with writeback to base
251};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700252inline std::ostream& operator<<(std::ostream& os, const BlockAddressMode& rhs) {
253 os << static_cast<int>(rhs);
254 return os;
255}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700256
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700257class Address : public ValueObject {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700258 public:
Dave Allison65fcc2c2014-04-28 13:45:27 -0700259 // Memory operand addressing mode (in ARM encoding form. For others we need
260 // to adjust)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700261 enum Mode {
262 // bit encoding P U W
263 Offset = (8|4|0) << 21, // offset (w/o writeback to base)
264 PreIndex = (8|4|1) << 21, // pre-indexed addressing with writeback
265 PostIndex = (0|4|0) << 21, // post-indexed addressing with writeback
266 NegOffset = (8|0|0) << 21, // negative offset (w/o writeback to base)
267 NegPreIndex = (8|0|1) << 21, // negative pre-indexed with writeback
268 NegPostIndex = (0|0|0) << 21 // negative post-indexed with writeback
269 };
270
Dave Allison45fdb932014-06-25 12:37:10 -0700271 Address(Register rn, int32_t offset = 0, Mode am = Offset) : rn_(rn), rm_(R0),
272 offset_(offset),
273 am_(am), is_immed_offset_(true), shift_(LSL) {
274 }
275
276 Address(Register rn, Register rm, Mode am = Offset) : rn_(rn), rm_(rm), offset_(0),
277 am_(am), is_immed_offset_(false), shift_(LSL) {
278 CHECK_NE(rm, PC);
279 }
280
281 Address(Register rn, Register rm, Shift shift, uint32_t count, Mode am = Offset) :
282 rn_(rn), rm_(rm), offset_(count),
283 am_(am), is_immed_offset_(false), shift_(shift) {
284 CHECK_NE(rm, PC);
285 }
286
287 // LDR(literal) - pc relative load.
288 explicit Address(int32_t offset) :
289 rn_(PC), rm_(R0), offset_(offset),
290 am_(Offset), is_immed_offset_(false), shift_(LSL) {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700291 }
292
Dave Allison65fcc2c2014-04-28 13:45:27 -0700293 static bool CanHoldLoadOffsetArm(LoadOperandType type, int offset);
294 static bool CanHoldStoreOffsetArm(StoreOperandType type, int offset);
295
296 static bool CanHoldLoadOffsetThumb(LoadOperandType type, int offset);
297 static bool CanHoldStoreOffsetThumb(StoreOperandType type, int offset);
298
299 uint32_t encodingArm() const;
Dave Allison45fdb932014-06-25 12:37:10 -0700300 uint32_t encodingThumb(bool is_32bit) const;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700301
302 uint32_t encoding3() const;
303 uint32_t vencoding() const;
304
305 uint32_t encodingThumbLdrdStrd() const;
306
307 Register GetRegister() const {
308 return rn_;
309 }
310
Dave Allison45fdb932014-06-25 12:37:10 -0700311 Register GetRegisterOffset() const {
312 return rm_;
313 }
314
Dave Allison65fcc2c2014-04-28 13:45:27 -0700315 int32_t GetOffset() const {
316 return offset_;
317 }
318
319 Mode GetMode() const {
320 return am_;
321 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700322
Dave Allison45fdb932014-06-25 12:37:10 -0700323 bool IsImmediate() const {
324 return is_immed_offset_;
325 }
326
327 Shift GetShift() const {
328 return shift_;
329 }
330
331 int32_t GetShiftCount() const {
332 CHECK(!is_immed_offset_);
333 return offset_;
334 }
335
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700336 private:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700337 const Register rn_;
338 const Register rm_;
339 const int32_t offset_; // Used as shift amount for register offset.
340 const Mode am_;
341 const bool is_immed_offset_;
342 const Shift shift_;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700343};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700344inline std::ostream& operator<<(std::ostream& os, const Address::Mode& rhs) {
345 os << static_cast<int>(rhs);
346 return os;
347}
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700348
Dave Allison65fcc2c2014-04-28 13:45:27 -0700349// Instruction encoding bits.
350enum {
351 H = 1 << 5, // halfword (or byte)
352 L = 1 << 20, // load (or store)
353 S = 1 << 20, // set condition code (or leave unchanged)
354 W = 1 << 21, // writeback base register (or leave unchanged)
355 A = 1 << 21, // accumulate in multiply instruction (or not)
356 B = 1 << 22, // unsigned byte (or word)
357 N = 1 << 22, // long (or short)
358 U = 1 << 23, // positive (or negative) offset/index
359 P = 1 << 24, // offset/pre-indexed addressing (or post-indexed addressing)
360 I = 1 << 25, // immediate shifter operand (or not)
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700361
Dave Allison65fcc2c2014-04-28 13:45:27 -0700362 B0 = 1,
363 B1 = 1 << 1,
364 B2 = 1 << 2,
365 B3 = 1 << 3,
366 B4 = 1 << 4,
367 B5 = 1 << 5,
368 B6 = 1 << 6,
369 B7 = 1 << 7,
370 B8 = 1 << 8,
371 B9 = 1 << 9,
372 B10 = 1 << 10,
373 B11 = 1 << 11,
374 B12 = 1 << 12,
375 B13 = 1 << 13,
376 B14 = 1 << 14,
377 B15 = 1 << 15,
378 B16 = 1 << 16,
379 B17 = 1 << 17,
380 B18 = 1 << 18,
381 B19 = 1 << 19,
382 B20 = 1 << 20,
383 B21 = 1 << 21,
384 B22 = 1 << 22,
385 B23 = 1 << 23,
386 B24 = 1 << 24,
387 B25 = 1 << 25,
388 B26 = 1 << 26,
389 B27 = 1 << 27,
390 B28 = 1 << 28,
391 B29 = 1 << 29,
392 B30 = 1 << 30,
393 B31 = 1 << 31,
394
395 // Instruction bit masks.
396 RdMask = 15 << 12, // in str instruction
397 CondMask = 15 << 28,
398 CoprocessorMask = 15 << 8,
399 OpCodeMask = 15 << 21, // in data-processing instructions
400 Imm24Mask = (1 << 24) - 1,
401 Off12Mask = (1 << 12) - 1,
402
403 // ldrex/strex register field encodings.
404 kLdExRnShift = 16,
405 kLdExRtShift = 12,
406 kStrExRnShift = 16,
407 kStrExRdShift = 12,
408 kStrExRtShift = 0,
409};
410
411// IfThen state for IT instructions.
412enum ItState {
413 kItOmitted,
414 kItThen,
415 kItT = kItThen,
416 kItElse,
417 kItE = kItElse
418};
419
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100420// Set condition codes request.
421enum SetCc {
422 kCcDontCare, // Allows prioritizing 16-bit instructions on Thumb2 whether they set CCs or not.
423 kCcSet,
424 kCcKeep,
425};
426
Dave Allison65fcc2c2014-04-28 13:45:27 -0700427constexpr uint32_t kNoItCondition = 3;
428constexpr uint32_t kInvalidModifiedImmediate = -1;
429
430extern const char* kRegisterNames[];
431extern const char* kConditionNames[];
Dave Allison65fcc2c2014-04-28 13:45:27 -0700432
433// This is an abstract ARM assembler. Subclasses provide assemblers for the individual
434// instruction sets (ARM32, Thumb2, etc.)
435//
Andreas Gampe60b1e1d2016-08-08 17:32:34 -0700436class ArmAssembler : public Assembler {
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700437 public:
Ian Rogers2c8f6532011-09-02 17:16:34 -0700438 virtual ~ArmAssembler() {}
buzbeec143c552011-08-20 17:38:58 -0700439
Dave Allison65fcc2c2014-04-28 13:45:27 -0700440 // Is this assembler for the thumb instruction set?
441 virtual bool IsThumb() const = 0;
442
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700443 // Data-processing instructions.
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100444 virtual void and_(Register rd, Register rn, const ShifterOperand& so,
445 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700446
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100447 virtual void ands(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
448 and_(rd, rn, so, cond, kCcSet);
449 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700450
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100451 virtual void eor(Register rd, Register rn, const ShifterOperand& so,
452 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700453
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100454 virtual void eors(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
455 eor(rd, rn, so, cond, kCcSet);
456 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700457
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100458 virtual void sub(Register rd, Register rn, const ShifterOperand& so,
459 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700460
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100461 virtual void subs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
462 sub(rd, rn, so, cond, kCcSet);
463 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700464
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100465 virtual void rsb(Register rd, Register rn, const ShifterOperand& so,
466 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700467
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100468 virtual void rsbs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
469 rsb(rd, rn, so, cond, kCcSet);
470 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700471
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100472 virtual void add(Register rd, Register rn, const ShifterOperand& so,
473 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
474
475 virtual void adds(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
476 add(rd, rn, so, cond, kCcSet);
477 }
478
479 virtual void adc(Register rd, Register rn, const ShifterOperand& so,
480 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
481
482 virtual void adcs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
483 adc(rd, rn, so, cond, kCcSet);
484 }
485
486 virtual void sbc(Register rd, Register rn, const ShifterOperand& so,
487 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
488
489 virtual void sbcs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
490 sbc(rd, rn, so, cond, kCcSet);
491 }
492
493 virtual void rsc(Register rd, Register rn, const ShifterOperand& so,
494 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
495
496 virtual void rscs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
497 rsc(rd, rn, so, cond, kCcSet);
498 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700499
Dave Allison65fcc2c2014-04-28 13:45:27 -0700500 virtual void tst(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700501
Dave Allison65fcc2c2014-04-28 13:45:27 -0700502 virtual void teq(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700503
Dave Allison65fcc2c2014-04-28 13:45:27 -0700504 virtual void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700505
Vladimir Markoac6ac102015-12-17 12:14:00 +0000506 // Note: CMN updates flags based on addition of its operands. Do not confuse
507 // the "N" suffix with bitwise inversion performed by MVN.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700508 virtual void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700509
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100510 virtual void orr(Register rd, Register rn, const ShifterOperand& so,
511 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700512
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100513 virtual void orrs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
514 orr(rd, rn, so, cond, kCcSet);
515 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700516
Vladimir Markod2b4ca22015-09-14 15:13:26 +0100517 virtual void orn(Register rd, Register rn, const ShifterOperand& so,
518 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
519
520 virtual void orns(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
521 orn(rd, rn, so, cond, kCcSet);
522 }
523
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100524 virtual void mov(Register rd, const ShifterOperand& so,
525 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700526
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100527 virtual void movs(Register rd, const ShifterOperand& so, Condition cond = AL) {
528 mov(rd, so, cond, kCcSet);
529 }
530
531 virtual void bic(Register rd, Register rn, const ShifterOperand& so,
532 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
533
534 virtual void bics(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) {
535 bic(rd, rn, so, cond, kCcSet);
536 }
537
538 virtual void mvn(Register rd, const ShifterOperand& so,
539 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
540
541 virtual void mvns(Register rd, const ShifterOperand& so, Condition cond = AL) {
542 mvn(rd, so, cond, kCcSet);
543 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700544
545 // Miscellaneous data-processing instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700546 virtual void clz(Register rd, Register rm, Condition cond = AL) = 0;
547 virtual void movw(Register rd, uint16_t imm16, Condition cond = AL) = 0;
548 virtual void movt(Register rd, uint16_t imm16, Condition cond = AL) = 0;
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100549 virtual void rbit(Register rd, Register rm, Condition cond = AL) = 0;
Artem Serovc257da72016-02-02 13:49:43 +0000550 virtual void rev(Register rd, Register rm, Condition cond = AL) = 0;
551 virtual void rev16(Register rd, Register rm, Condition cond = AL) = 0;
552 virtual void revsh(Register rd, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700553
554 // Multiply instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700555 virtual void mul(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
556 virtual void mla(Register rd, Register rn, Register rm, Register ra,
557 Condition cond = AL) = 0;
558 virtual void mls(Register rd, Register rn, Register rm, Register ra,
559 Condition cond = AL) = 0;
Zheng Xuc6667102015-05-15 16:08:45 +0800560 virtual void smull(Register rd_lo, Register rd_hi, Register rn, Register rm,
561 Condition cond = AL) = 0;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700562 virtual void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
563 Condition cond = AL) = 0;
564
565 virtual void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
566 virtual void udiv(Register rd, Register rn, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700567
Roland Levillain981e4542014-11-14 11:47:14 +0000568 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000569 virtual void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
570 Condition cond = AL) = 0;
Roland Levillain981e4542014-11-14 11:47:14 +0000571 virtual void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width,
572 Condition cond = AL) = 0;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000573
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700574 // Load/store instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700575 virtual void ldr(Register rd, const Address& ad, Condition cond = AL) = 0;
576 virtual void str(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700577
Dave Allison65fcc2c2014-04-28 13:45:27 -0700578 virtual void ldrb(Register rd, const Address& ad, Condition cond = AL) = 0;
579 virtual void strb(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700580
Dave Allison65fcc2c2014-04-28 13:45:27 -0700581 virtual void ldrh(Register rd, const Address& ad, Condition cond = AL) = 0;
582 virtual void strh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700583
Dave Allison65fcc2c2014-04-28 13:45:27 -0700584 virtual void ldrsb(Register rd, const Address& ad, Condition cond = AL) = 0;
585 virtual void ldrsh(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700586
Dave Allison65fcc2c2014-04-28 13:45:27 -0700587 virtual void ldrd(Register rd, const Address& ad, Condition cond = AL) = 0;
588 virtual void strd(Register rd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700589
Dave Allison65fcc2c2014-04-28 13:45:27 -0700590 virtual void ldm(BlockAddressMode am, Register base,
591 RegList regs, Condition cond = AL) = 0;
592 virtual void stm(BlockAddressMode am, Register base,
593 RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700594
Dave Allison65fcc2c2014-04-28 13:45:27 -0700595 virtual void ldrex(Register rd, Register rn, Condition cond = AL) = 0;
596 virtual void strex(Register rd, Register rt, Register rn, Condition cond = AL) = 0;
Calin Juravle52c48962014-12-16 17:02:57 +0000597 virtual void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
598 virtual void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700599
600 // Miscellaneous instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700601 virtual void clrex(Condition cond = AL) = 0;
602 virtual void nop(Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700603
604 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700605 virtual void bkpt(uint16_t imm16) = 0;
606 virtual void svc(uint32_t imm24) = 0;
607
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700608 virtual void it(Condition firstcond ATTRIBUTE_UNUSED,
609 ItState i1 ATTRIBUTE_UNUSED = kItOmitted,
610 ItState i2 ATTRIBUTE_UNUSED = kItOmitted,
611 ItState i3 ATTRIBUTE_UNUSED = kItOmitted) {
Dave Allison65fcc2c2014-04-28 13:45:27 -0700612 // Ignored if not supported.
613 }
614
615 virtual void cbz(Register rn, Label* target) = 0;
616 virtual void cbnz(Register rn, Label* target) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700617
618 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
Dave Allison65fcc2c2014-04-28 13:45:27 -0700619 virtual void vmovsr(SRegister sn, Register rt, Condition cond = AL) = 0;
620 virtual void vmovrs(Register rt, SRegister sn, Condition cond = AL) = 0;
621 virtual void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) = 0;
622 virtual void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) = 0;
623 virtual void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) = 0;
624 virtual void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) = 0;
625 virtual void vmovs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
626 virtual void vmovd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700627
628 // Returns false if the immediate cannot be encoded.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700629 virtual bool vmovs(SRegister sd, float s_imm, Condition cond = AL) = 0;
630 virtual bool vmovd(DRegister dd, double d_imm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700631
Dave Allison65fcc2c2014-04-28 13:45:27 -0700632 virtual void vldrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
633 virtual void vstrs(SRegister sd, const Address& ad, Condition cond = AL) = 0;
634 virtual void vldrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
635 virtual void vstrd(DRegister dd, const Address& ad, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700636
Dave Allison65fcc2c2014-04-28 13:45:27 -0700637 virtual void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
638 virtual void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
639 virtual void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
640 virtual void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
641 virtual void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
642 virtual void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
643 virtual void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
644 virtual void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
645 virtual void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
646 virtual void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
647 virtual void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) = 0;
648 virtual void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700649
Dave Allison65fcc2c2014-04-28 13:45:27 -0700650 virtual void vabss(SRegister sd, SRegister sm, Condition cond = AL) = 0;
651 virtual void vabsd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
652 virtual void vnegs(SRegister sd, SRegister sm, Condition cond = AL) = 0;
653 virtual void vnegd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
654 virtual void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) = 0;
655 virtual void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700656
Dave Allison65fcc2c2014-04-28 13:45:27 -0700657 virtual void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) = 0;
658 virtual void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) = 0;
659 virtual void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) = 0;
660 virtual void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) = 0;
661 virtual void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) = 0;
662 virtual void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) = 0;
663 virtual void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) = 0;
664 virtual void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) = 0;
665 virtual void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) = 0;
666 virtual void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700667
Dave Allison65fcc2c2014-04-28 13:45:27 -0700668 virtual void vcmps(SRegister sd, SRegister sm, Condition cond = AL) = 0;
669 virtual void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) = 0;
670 virtual void vcmpsz(SRegister sd, Condition cond = AL) = 0;
671 virtual void vcmpdz(DRegister dd, Condition cond = AL) = 0;
672 virtual void vmstat(Condition cond = AL) = 0; // VMRS APSR_nzcv, FPSCR
673
xueliang.zhonge652c122016-06-13 14:42:27 +0100674 virtual void vcntd(DRegister dd, DRegister dm) = 0;
675 virtual void vpaddld(DRegister dd, DRegister dm, int32_t size, bool is_unsigned) = 0;
676
Dave Allison65fcc2c2014-04-28 13:45:27 -0700677 virtual void vpushs(SRegister reg, int nregs, Condition cond = AL) = 0;
678 virtual void vpushd(DRegister reg, int nregs, Condition cond = AL) = 0;
679 virtual void vpops(SRegister reg, int nregs, Condition cond = AL) = 0;
680 virtual void vpopd(DRegister reg, int nregs, Condition cond = AL) = 0;
Artem Serovcb3cf4a2016-07-15 15:01:13 +0100681 virtual void vldmiad(Register base_reg, DRegister reg, int nregs, Condition cond = AL) = 0;
682 virtual void vstmiad(Register base_reg, DRegister reg, int nregs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700683
684 // Branch instructions.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700685 virtual void b(Label* label, Condition cond = AL) = 0;
686 virtual void bl(Label* label, Condition cond = AL) = 0;
687 virtual void blx(Register rm, Condition cond = AL) = 0;
688 virtual void bx(Register rm, Condition cond = AL) = 0;
689
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100690 // Memory barriers.
691 virtual void dmb(DmbOptions flavor) = 0;
692
Dave Allison65fcc2c2014-04-28 13:45:27 -0700693 void Pad(uint32_t bytes);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700694
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000695 // Adjust label position.
696 void AdjustLabelPosition(Label* label) {
697 DCHECK(label->IsBound());
698 uint32_t old_position = static_cast<uint32_t>(label->Position());
699 uint32_t new_position = GetAdjustedPosition(old_position);
700 label->Reinitialize();
701 DCHECK_GE(static_cast<int>(new_position), 0);
702 label->BindTo(static_cast<int>(new_position));
703 }
704
705 // Get the final position of a label after local fixup based on the old position
706 // recorded before FinalizeCode().
707 virtual uint32_t GetAdjustedPosition(uint32_t old_position) = 0;
708
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700709 // Macros.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700710 // Most of these are pure virtual as they need to be implemented per instruction set.
711
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000712 // Create a new literal with a given value.
Vladimir Marko88b2b802015-12-04 14:19:04 +0000713 // NOTE: Force the template parameter to be explicitly specified.
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000714 template <typename T>
Vladimir Marko88b2b802015-12-04 14:19:04 +0000715 Literal* NewLiteral(typename Identity<T>::type value) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000716 static_assert(std::is_integral<T>::value, "T must be an integral type.");
717 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
718 }
719
720 // Create a new literal with the given data.
721 virtual Literal* NewLiteral(size_t size, const uint8_t* data) = 0;
722
723 // Load literal.
724 virtual void LoadLiteral(Register rt, Literal* literal) = 0;
725 virtual void LoadLiteral(Register rt, Register rt2, Literal* literal) = 0;
726 virtual void LoadLiteral(SRegister sd, Literal* literal) = 0;
727 virtual void LoadLiteral(DRegister dd, Literal* literal) = 0;
728
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700729 // Add signed constant value to rd. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700730 virtual void AddConstant(Register rd, Register rn, int32_t value,
Vladimir Marko449b1092015-09-08 12:16:45 +0100731 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
732 void AddConstantSetFlags(Register rd, Register rn, int32_t value, Condition cond = AL) {
733 AddConstant(rd, rn, value, cond, kCcSet);
734 }
735 void AddConstant(Register rd, int32_t value, Condition cond = AL, SetCc set_cc = kCcDontCare) {
736 AddConstant(rd, rd, value, cond, set_cc);
737 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700738
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700739 virtual void CmpConstant(Register rn, int32_t value, Condition cond = AL) = 0;
740
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700741 // Load and Store. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700742 virtual void LoadImmediate(Register rd, int32_t value, Condition cond = AL) = 0;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000743 void LoadSImmediate(SRegister sd, float value, Condition cond = AL) {
744 if (!vmovs(sd, value, cond)) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +0000745 int32_t int_value = bit_cast<int32_t, float>(value);
746 if (int_value == bit_cast<int32_t, float>(0.0f)) {
747 // 0.0 is quite common, so we special case it by loading
748 // 2.0 in `sd` and then substracting it.
749 bool success = vmovs(sd, 2.0, cond);
750 CHECK(success);
751 vsubs(sd, sd, sd, cond);
752 } else {
753 LoadImmediate(IP, int_value, cond);
754 vmovsr(sd, IP, cond);
755 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000756 }
757 }
758
Vladimir Markoebdbf4b2016-07-07 15:37:02 +0100759 virtual void LoadDImmediate(DRegister dd, double value, Condition cond = AL) = 0;
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +0000760
Dave Allison65fcc2c2014-04-28 13:45:27 -0700761 virtual void MarkExceptionHandler(Label* label) = 0;
762 virtual void LoadFromOffset(LoadOperandType type,
763 Register reg,
764 Register base,
765 int32_t offset,
766 Condition cond = AL) = 0;
767 virtual void StoreToOffset(StoreOperandType type,
768 Register reg,
769 Register base,
770 int32_t offset,
771 Condition cond = AL) = 0;
772 virtual void LoadSFromOffset(SRegister reg,
773 Register base,
774 int32_t offset,
775 Condition cond = AL) = 0;
776 virtual void StoreSToOffset(SRegister reg,
777 Register base,
778 int32_t offset,
779 Condition cond = AL) = 0;
780 virtual void LoadDFromOffset(DRegister reg,
781 Register base,
782 int32_t offset,
783 Condition cond = AL) = 0;
784 virtual void StoreDToOffset(DRegister reg,
785 Register base,
786 int32_t offset,
787 Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700788
Dave Allison65fcc2c2014-04-28 13:45:27 -0700789 virtual void Push(Register rd, Condition cond = AL) = 0;
790 virtual void Pop(Register rd, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700791
Dave Allison65fcc2c2014-04-28 13:45:27 -0700792 virtual void PushList(RegList regs, Condition cond = AL) = 0;
793 virtual void PopList(RegList regs, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700794
Dave Allison65fcc2c2014-04-28 13:45:27 -0700795 virtual void Mov(Register rd, Register rm, Condition cond = AL) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700796
797 // Convenience shift instructions. Use mov instruction with shifter operand
798 // for variants setting the status flags or using a register shift count.
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100799 virtual void Lsl(Register rd, Register rm, uint32_t shift_imm,
800 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
Dave Allison45fdb932014-06-25 12:37:10 -0700801
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100802 void Lsls(Register rd, Register rm, uint32_t shift_imm, Condition cond = AL) {
803 Lsl(rd, rm, shift_imm, cond, kCcSet);
804 }
805
806 virtual void Lsr(Register rd, Register rm, uint32_t shift_imm,
807 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
808
809 void Lsrs(Register rd, Register rm, uint32_t shift_imm, Condition cond = AL) {
810 Lsr(rd, rm, shift_imm, cond, kCcSet);
811 }
812
813 virtual void Asr(Register rd, Register rm, uint32_t shift_imm,
814 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
815
816 void Asrs(Register rd, Register rm, uint32_t shift_imm, Condition cond = AL) {
817 Asr(rd, rm, shift_imm, cond, kCcSet);
818 }
819
820 virtual void Ror(Register rd, Register rm, uint32_t shift_imm,
821 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
822
823 void Rors(Register rd, Register rm, uint32_t shift_imm, Condition cond = AL) {
824 Ror(rd, rm, shift_imm, cond, kCcSet);
825 }
826
827 virtual void Rrx(Register rd, Register rm,
828 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
829
830 void Rrxs(Register rd, Register rm, Condition cond = AL) {
831 Rrx(rd, rm, cond, kCcSet);
832 }
833
834 virtual void Lsl(Register rd, Register rm, Register rn,
835 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
836
837 void Lsls(Register rd, Register rm, Register rn, Condition cond = AL) {
838 Lsl(rd, rm, rn, cond, kCcSet);
839 }
840
841 virtual void Lsr(Register rd, Register rm, Register rn,
842 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
843
844 void Lsrs(Register rd, Register rm, Register rn, Condition cond = AL) {
845 Lsr(rd, rm, rn, cond, kCcSet);
846 }
847
848 virtual void Asr(Register rd, Register rm, Register rn,
849 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
850
851 void Asrs(Register rd, Register rm, Register rn, Condition cond = AL) {
852 Asr(rd, rm, rn, cond, kCcSet);
853 }
854
855 virtual void Ror(Register rd, Register rm, Register rn,
856 Condition cond = AL, SetCc set_cc = kCcDontCare) = 0;
857
858 void Rors(Register rd, Register rm, Register rn, Condition cond = AL) {
859 Ror(rd, rm, rn, cond, kCcSet);
860 }
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700861
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000862 // Returns whether the `immediate` can fit in a `ShifterOperand`. If yes,
863 // `shifter_op` contains the operand.
864 virtual bool ShifterOperandCanHold(Register rd,
865 Register rn,
866 Opcode opcode,
867 uint32_t immediate,
Vladimir Markof5c09c32015-12-17 12:08:08 +0000868 SetCc set_cc,
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000869 ShifterOperand* shifter_op) = 0;
Vladimir Markof5c09c32015-12-17 12:08:08 +0000870 bool ShifterOperandCanHold(Register rd,
871 Register rn,
872 Opcode opcode,
873 uint32_t immediate,
874 ShifterOperand* shifter_op) {
875 return ShifterOperandCanHold(rd, rn, opcode, immediate, kCcDontCare, shifter_op);
876 }
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000877
Nicolas Geoffray0ccb3832015-10-14 11:44:23 +0100878 virtual bool ShifterOperandCanAlwaysHold(uint32_t immediate) = 0;
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +0100879
Ian Rogers13735952014-10-08 12:43:28 -0700880 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700881
Dave Allison65fcc2c2014-04-28 13:45:27 -0700882 virtual void CompareAndBranchIfZero(Register r, Label* label) = 0;
883 virtual void CompareAndBranchIfNonZero(Register r, Label* label) = 0;
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700884
Dave Allison65fcc2c2014-04-28 13:45:27 -0700885 static uint32_t ModifiedImmediate(uint32_t value);
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700886
Dave Allison45fdb932014-06-25 12:37:10 -0700887 static bool IsLowRegister(Register r) {
888 return r < R8;
889 }
890
891 static bool IsHighRegister(Register r) {
892 return r >= R8;
893 }
894
Roland Levillain4d027112015-07-01 15:41:14 +0100895 //
896 // Heap poisoning.
897 //
898
899 // Poison a heap reference contained in `reg`.
900 void PoisonHeapReference(Register reg) {
901 // reg = -reg.
902 rsb(reg, reg, ShifterOperand(0));
903 }
904 // Unpoison a heap reference contained in `reg`.
905 void UnpoisonHeapReference(Register reg) {
906 // reg = -reg.
907 rsb(reg, reg, ShifterOperand(0));
908 }
909 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
910 void MaybeUnpoisonHeapReference(Register reg) {
911 if (kPoisonHeapReferences) {
912 UnpoisonHeapReference(reg);
913 }
914 }
915
Andreas Gampe85b62f22015-09-09 13:15:38 -0700916 void Jump(Label* label) OVERRIDE {
917 b(label);
918 }
919
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700920 // Jump table support. This is split into three functions:
921 //
922 // * CreateJumpTable creates the internal metadata to track the jump targets, and emits code to
923 // load the base address of the jump table.
924 //
925 // * EmitJumpTableDispatch emits the code to actually jump, assuming that the right table value
926 // has been loaded into a register already.
927 //
928 // * FinalizeTables emits the jump table into the literal pool. This can only be called after the
929 // labels for the jump targets have been finalized.
930
931 // Create a jump table for the given labels that will be emitted when finalizing. Create a load
932 // sequence (or placeholder) that stores the base address into the given register. When the table
933 // is emitted, offsets will be relative to the location EmitJumpTableDispatch was called on (the
934 // anchor).
935 virtual JumpTable* CreateJumpTable(std::vector<Label*>&& labels, Register base_reg) = 0;
936
937 // Emit the jump-table jump, assuming that the right value was loaded into displacement_reg.
938 virtual void EmitJumpTableDispatch(JumpTable* jump_table, Register displacement_reg) = 0;
939
940 // Bind a Label that needs to be updated by the assembler in FinalizeCode() if its position
941 // changes due to branch/literal fixup.
942 void BindTrackedLabel(Label* label) {
943 Bind(label);
944 tracked_labels_.push_back(label);
945 }
946
Dave Allison65fcc2c2014-04-28 13:45:27 -0700947 protected:
Vladimir Marko93205e32016-04-13 11:59:46 +0100948 explicit ArmAssembler(ArenaAllocator* arena)
949 : Assembler(arena), tracked_labels_(arena->Adapter(kArenaAllocAssembler)) {}
950
Carl Shapiroa2e18e12011-06-21 18:57:55 -0700951 // Returns whether or not the given register is used for passing parameters.
952 static int RegisterCompare(const Register* reg1, const Register* reg2) {
953 return *reg1 - *reg2;
954 }
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700955
956 void FinalizeTrackedLabels();
957
958 // Tracked labels. Use a vector, as we need to sort before adjusting.
Vladimir Marko93205e32016-04-13 11:59:46 +0100959 ArenaVector<Label*> tracked_labels_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700960};
961
Ian Rogers2c8f6532011-09-02 17:16:34 -0700962} // namespace arm
Ian Rogersb033c752011-07-20 12:22:35 -0700963} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700964
Ian Rogers166db042013-07-26 12:05:57 -0700965#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_H_