blob: b922d66513f9b1ae8c69104c95f2df3565cbe3de [file] [log] [blame]
Dave Allison65fcc2c2014-04-28 13:45:27 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM32_H_
18#define ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM32_H_
19
20#include <vector>
21
22#include "base/logging.h"
23#include "constants_arm.h"
24#include "utils/arm/managed_register_arm.h"
25#include "utils/arm/assembler_arm.h"
26#include "offsets.h"
27#include "utils.h"
28
29namespace art {
30namespace arm {
31
32class Arm32Assembler FINAL : public ArmAssembler {
33 public:
34 Arm32Assembler() {
35 }
36 virtual ~Arm32Assembler() {}
37
38 bool IsThumb() const OVERRIDE {
39 return false;
40 }
41
42 // Data-processing instructions.
43 void and_(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
44
45 void eor(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
46
47 void sub(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
48 void subs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
49
50 void rsb(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
51 void rsbs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
52
53 void add(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
54
55 void adds(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
56
57 void adc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
58
59 void sbc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
60
61 void rsc(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
62
63 void tst(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
64
65 void teq(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
66
67 void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
68
69 void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
70
71 void orr(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
72 void orrs(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
73
74 void mov(Register rd, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
75 void movs(Register rd, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
76
77 void bic(Register rd, Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
78
79 void mvn(Register rd, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
80 void mvns(Register rd, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
81
82 // Miscellaneous data-processing instructions.
83 void clz(Register rd, Register rm, Condition cond = AL) OVERRIDE;
84 void movw(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE;
85 void movt(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE;
86
87 // Multiply instructions.
88 void mul(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
89 void mla(Register rd, Register rn, Register rm, Register ra,
90 Condition cond = AL) OVERRIDE;
91 void mls(Register rd, Register rn, Register rm, Register ra,
92 Condition cond = AL) OVERRIDE;
93 void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
94 Condition cond = AL) OVERRIDE;
95
96 void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
97 void udiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
98
Roland Levillain981e4542014-11-14 11:47:14 +000099 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000100 void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE;
Roland Levillain981e4542014-11-14 11:47:14 +0000101 void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000102
Dave Allison65fcc2c2014-04-28 13:45:27 -0700103 // Load/store instructions.
104 void ldr(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
105 void str(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
106
107 void ldrb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
108 void strb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
109
110 void ldrh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
111 void strh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
112
113 void ldrsb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
114 void ldrsh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
115
116 void ldrd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
117 void strd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
118
119 void ldm(BlockAddressMode am, Register base,
120 RegList regs, Condition cond = AL) OVERRIDE;
121 void stm(BlockAddressMode am, Register base,
122 RegList regs, Condition cond = AL) OVERRIDE;
123
124 void ldrex(Register rd, Register rn, Condition cond = AL) OVERRIDE;
125 void strex(Register rd, Register rt, Register rn, Condition cond = AL) OVERRIDE;
Calin Juravle52c48962014-12-16 17:02:57 +0000126 void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE;
127 void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700128
129 // Miscellaneous instructions.
130 void clrex(Condition cond = AL) OVERRIDE;
131 void nop(Condition cond = AL) OVERRIDE;
132
133 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
134 void bkpt(uint16_t imm16) OVERRIDE;
135 void svc(uint32_t imm24) OVERRIDE;
136
137 void cbz(Register rn, Label* target) OVERRIDE;
138 void cbnz(Register rn, Label* target) OVERRIDE;
139
140 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
141 void vmovsr(SRegister sn, Register rt, Condition cond = AL) OVERRIDE;
142 void vmovrs(Register rt, SRegister sn, Condition cond = AL) OVERRIDE;
143 void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
144 void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) OVERRIDE;
145 void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
146 void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) OVERRIDE;
147 void vmovs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
148 void vmovd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
149
150 // Returns false if the immediate cannot be encoded.
151 bool vmovs(SRegister sd, float s_imm, Condition cond = AL) OVERRIDE;
152 bool vmovd(DRegister dd, double d_imm, Condition cond = AL) OVERRIDE;
153
154 void vldrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
155 void vstrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
156 void vldrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
157 void vstrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
158
159 void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
160 void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
161 void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
162 void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
163 void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
164 void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
165 void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
166 void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
167 void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
168 void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
169 void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
170 void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
171
172 void vabss(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
173 void vabsd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
174 void vnegs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
175 void vnegd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
176 void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
177 void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
178
179 void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
180 void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
181 void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
182 void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
183 void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
184 void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
185 void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
186 void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
187 void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
188 void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
189
190 void vcmps(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
191 void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
192 void vcmpsz(SRegister sd, Condition cond = AL) OVERRIDE;
193 void vcmpdz(DRegister dd, Condition cond = AL) OVERRIDE;
194 void vmstat(Condition cond = AL) OVERRIDE; // VMRS APSR_nzcv, FPSCR
195
196 void vpushs(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
197 void vpushd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
198 void vpops(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
199 void vpopd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
200
201 // Branch instructions.
202 void b(Label* label, Condition cond = AL);
203 void bl(Label* label, Condition cond = AL);
204 void blx(Register rm, Condition cond = AL) OVERRIDE;
205 void bx(Register rm, Condition cond = AL) OVERRIDE;
Dave Allison45fdb932014-06-25 12:37:10 -0700206 void Lsl(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
207 Condition cond = AL) OVERRIDE;
208 void Lsr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
209 Condition cond = AL) OVERRIDE;
210 void Asr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
211 Condition cond = AL) OVERRIDE;
212 void Ror(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
213 Condition cond = AL) OVERRIDE;
214 void Rrx(Register rd, Register rm, bool setcc = false,
215 Condition cond = AL) OVERRIDE;
216
217 void Lsl(Register rd, Register rm, Register rn, bool setcc = false,
218 Condition cond = AL) OVERRIDE;
219 void Lsr(Register rd, Register rm, Register rn, bool setcc = false,
220 Condition cond = AL) OVERRIDE;
221 void Asr(Register rd, Register rm, Register rn, bool setcc = false,
222 Condition cond = AL) OVERRIDE;
223 void Ror(Register rd, Register rm, Register rn, bool setcc = false,
224 Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700225
226 void Push(Register rd, Condition cond = AL) OVERRIDE;
227 void Pop(Register rd, Condition cond = AL) OVERRIDE;
228
229 void PushList(RegList regs, Condition cond = AL) OVERRIDE;
230 void PopList(RegList regs, Condition cond = AL) OVERRIDE;
231
232 void Mov(Register rd, Register rm, Condition cond = AL) OVERRIDE;
233
234 void CompareAndBranchIfZero(Register r, Label* label) OVERRIDE;
235 void CompareAndBranchIfNonZero(Register r, Label* label) OVERRIDE;
236
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100237 // Memory barriers.
238 void dmb(DmbOptions flavor) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700239
240 // Macros.
241 // Add signed constant value to rd. May clobber IP.
242 void AddConstant(Register rd, int32_t value, Condition cond = AL) OVERRIDE;
243 void AddConstant(Register rd, Register rn, int32_t value,
244 Condition cond = AL) OVERRIDE;
245 void AddConstantSetFlags(Register rd, Register rn, int32_t value,
246 Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700247
248 // Load and Store. May clobber IP.
249 void LoadImmediate(Register rd, int32_t value, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700250 void MarkExceptionHandler(Label* label) OVERRIDE;
251 void LoadFromOffset(LoadOperandType type,
252 Register reg,
253 Register base,
254 int32_t offset,
255 Condition cond = AL) OVERRIDE;
256 void StoreToOffset(StoreOperandType type,
257 Register reg,
258 Register base,
259 int32_t offset,
260 Condition cond = AL) OVERRIDE;
261 void LoadSFromOffset(SRegister reg,
262 Register base,
263 int32_t offset,
264 Condition cond = AL) OVERRIDE;
265 void StoreSToOffset(SRegister reg,
266 Register base,
267 int32_t offset,
268 Condition cond = AL) OVERRIDE;
269 void LoadDFromOffset(DRegister reg,
270 Register base,
271 int32_t offset,
272 Condition cond = AL) OVERRIDE;
273 void StoreDToOffset(DRegister reg,
274 Register base,
275 int32_t offset,
276 Condition cond = AL) OVERRIDE;
277
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000278 bool ShifterOperandCanHold(Register rd,
279 Register rn,
280 Opcode opcode,
281 uint32_t immediate,
282 ShifterOperand* shifter_op) OVERRIDE;
283
Dave Allison65fcc2c2014-04-28 13:45:27 -0700284
Ian Rogers13735952014-10-08 12:43:28 -0700285 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700286
287 // Emit data (e.g. encoded instruction or immediate) to the
288 // instruction stream.
289 void Emit(int32_t value);
290 void Bind(Label* label) OVERRIDE;
291
292 void MemoryBarrier(ManagedRegister scratch) OVERRIDE;
293
294 private:
295 void EmitType01(Condition cond,
296 int type,
297 Opcode opcode,
298 int set_cc,
299 Register rn,
300 Register rd,
301 const ShifterOperand& so);
302
303 void EmitType5(Condition cond, int offset, bool link);
304
305 void EmitMemOp(Condition cond,
306 bool load,
307 bool byte,
308 Register rd,
309 const Address& ad);
310
311 void EmitMemOpAddressMode3(Condition cond,
312 int32_t mode,
313 Register rd,
314 const Address& ad);
315
316 void EmitMultiMemOp(Condition cond,
317 BlockAddressMode am,
318 bool load,
319 Register base,
320 RegList regs);
321
322 void EmitShiftImmediate(Condition cond,
323 Shift opcode,
324 Register rd,
325 Register rm,
326 const ShifterOperand& so);
327
328 void EmitShiftRegister(Condition cond,
329 Shift opcode,
330 Register rd,
331 Register rm,
332 const ShifterOperand& so);
333
334 void EmitMulOp(Condition cond,
335 int32_t opcode,
336 Register rd,
337 Register rn,
338 Register rm,
339 Register rs);
340
341 void EmitVFPsss(Condition cond,
342 int32_t opcode,
343 SRegister sd,
344 SRegister sn,
345 SRegister sm);
346
347 void EmitVFPddd(Condition cond,
348 int32_t opcode,
349 DRegister dd,
350 DRegister dn,
351 DRegister dm);
352
353 void EmitVFPsd(Condition cond,
354 int32_t opcode,
355 SRegister sd,
356 DRegister dm);
357
358 void EmitVFPds(Condition cond,
359 int32_t opcode,
360 DRegister dd,
361 SRegister sm);
362
363 void EmitVPushPop(uint32_t reg, int nregs, bool push, bool dbl, Condition cond);
364
365 void EmitBranch(Condition cond, Label* label, bool link);
366 static int32_t EncodeBranchOffset(int offset, int32_t inst);
367 static int DecodeBranchOffset(int32_t inst);
368 int32_t EncodeTstOffset(int offset, int32_t inst);
369 int DecodeTstOffset(int32_t inst);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000370 bool ShifterOperandCanHoldArm32(uint32_t immediate, ShifterOperand* shifter_op);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700371};
372
373} // namespace arm
374} // namespace art
375
376#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM32_H_