blob: b582e9e5abd60b17781a35f3214fbb1135f5c3b4 [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 Levillain51d3fc42014-11-13 14:11:42 +000099 void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE;
100
Dave Allison65fcc2c2014-04-28 13:45:27 -0700101 // Load/store instructions.
102 void ldr(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
103 void str(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
104
105 void ldrb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
106 void strb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
107
108 void ldrh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
109 void strh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
110
111 void ldrsb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
112 void ldrsh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
113
114 void ldrd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
115 void strd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
116
117 void ldm(BlockAddressMode am, Register base,
118 RegList regs, Condition cond = AL) OVERRIDE;
119 void stm(BlockAddressMode am, Register base,
120 RegList regs, Condition cond = AL) OVERRIDE;
121
122 void ldrex(Register rd, Register rn, Condition cond = AL) OVERRIDE;
123 void strex(Register rd, Register rt, Register rn, Condition cond = AL) OVERRIDE;
124
125 // Miscellaneous instructions.
126 void clrex(Condition cond = AL) OVERRIDE;
127 void nop(Condition cond = AL) OVERRIDE;
128
129 // Note that gdb sets breakpoints using the undefined instruction 0xe7f001f0.
130 void bkpt(uint16_t imm16) OVERRIDE;
131 void svc(uint32_t imm24) OVERRIDE;
132
133 void cbz(Register rn, Label* target) OVERRIDE;
134 void cbnz(Register rn, Label* target) OVERRIDE;
135
136 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
137 void vmovsr(SRegister sn, Register rt, Condition cond = AL) OVERRIDE;
138 void vmovrs(Register rt, SRegister sn, Condition cond = AL) OVERRIDE;
139 void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
140 void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) OVERRIDE;
141 void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
142 void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) OVERRIDE;
143 void vmovs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
144 void vmovd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
145
146 // Returns false if the immediate cannot be encoded.
147 bool vmovs(SRegister sd, float s_imm, Condition cond = AL) OVERRIDE;
148 bool vmovd(DRegister dd, double d_imm, Condition cond = AL) OVERRIDE;
149
150 void vldrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
151 void vstrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
152 void vldrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
153 void vstrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
154
155 void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
156 void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
157 void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
158 void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
159 void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
160 void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
161 void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
162 void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
163 void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
164 void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
165 void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
166 void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
167
168 void vabss(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
169 void vabsd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
170 void vnegs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
171 void vnegd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
172 void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
173 void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
174
175 void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
176 void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
177 void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
178 void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
179 void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
180 void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
181 void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
182 void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
183 void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
184 void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
185
186 void vcmps(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
187 void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
188 void vcmpsz(SRegister sd, Condition cond = AL) OVERRIDE;
189 void vcmpdz(DRegister dd, Condition cond = AL) OVERRIDE;
190 void vmstat(Condition cond = AL) OVERRIDE; // VMRS APSR_nzcv, FPSCR
191
192 void vpushs(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
193 void vpushd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
194 void vpops(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
195 void vpopd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
196
197 // Branch instructions.
198 void b(Label* label, Condition cond = AL);
199 void bl(Label* label, Condition cond = AL);
200 void blx(Register rm, Condition cond = AL) OVERRIDE;
201 void bx(Register rm, Condition cond = AL) OVERRIDE;
Dave Allison45fdb932014-06-25 12:37:10 -0700202 void Lsl(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
203 Condition cond = AL) OVERRIDE;
204 void Lsr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
205 Condition cond = AL) OVERRIDE;
206 void Asr(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
207 Condition cond = AL) OVERRIDE;
208 void Ror(Register rd, Register rm, uint32_t shift_imm, bool setcc = false,
209 Condition cond = AL) OVERRIDE;
210 void Rrx(Register rd, Register rm, bool setcc = false,
211 Condition cond = AL) OVERRIDE;
212
213 void Lsl(Register rd, Register rm, Register rn, bool setcc = false,
214 Condition cond = AL) OVERRIDE;
215 void Lsr(Register rd, Register rm, Register rn, bool setcc = false,
216 Condition cond = AL) OVERRIDE;
217 void Asr(Register rd, Register rm, Register rn, bool setcc = false,
218 Condition cond = AL) OVERRIDE;
219 void Ror(Register rd, Register rm, Register rn, bool setcc = false,
220 Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700221
222 void Push(Register rd, Condition cond = AL) OVERRIDE;
223 void Pop(Register rd, Condition cond = AL) OVERRIDE;
224
225 void PushList(RegList regs, Condition cond = AL) OVERRIDE;
226 void PopList(RegList regs, Condition cond = AL) OVERRIDE;
227
228 void Mov(Register rd, Register rm, Condition cond = AL) OVERRIDE;
229
230 void CompareAndBranchIfZero(Register r, Label* label) OVERRIDE;
231 void CompareAndBranchIfNonZero(Register r, Label* label) OVERRIDE;
232
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100233 // Memory barriers.
234 void dmb(DmbOptions flavor) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700235
236 // Macros.
237 // Add signed constant value to rd. May clobber IP.
238 void AddConstant(Register rd, int32_t value, Condition cond = AL) OVERRIDE;
239 void AddConstant(Register rd, Register rn, int32_t value,
240 Condition cond = AL) OVERRIDE;
241 void AddConstantSetFlags(Register rd, Register rn, int32_t value,
242 Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700243
244 // Load and Store. May clobber IP.
245 void LoadImmediate(Register rd, int32_t value, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700246 void MarkExceptionHandler(Label* label) OVERRIDE;
247 void LoadFromOffset(LoadOperandType type,
248 Register reg,
249 Register base,
250 int32_t offset,
251 Condition cond = AL) OVERRIDE;
252 void StoreToOffset(StoreOperandType type,
253 Register reg,
254 Register base,
255 int32_t offset,
256 Condition cond = AL) OVERRIDE;
257 void LoadSFromOffset(SRegister reg,
258 Register base,
259 int32_t offset,
260 Condition cond = AL) OVERRIDE;
261 void StoreSToOffset(SRegister reg,
262 Register base,
263 int32_t offset,
264 Condition cond = AL) OVERRIDE;
265 void LoadDFromOffset(DRegister reg,
266 Register base,
267 int32_t offset,
268 Condition cond = AL) OVERRIDE;
269 void StoreDToOffset(DRegister reg,
270 Register base,
271 int32_t offset,
272 Condition cond = AL) OVERRIDE;
273
274
Ian Rogers13735952014-10-08 12:43:28 -0700275 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700276
277 // Emit data (e.g. encoded instruction or immediate) to the
278 // instruction stream.
279 void Emit(int32_t value);
280 void Bind(Label* label) OVERRIDE;
281
282 void MemoryBarrier(ManagedRegister scratch) OVERRIDE;
283
284 private:
285 void EmitType01(Condition cond,
286 int type,
287 Opcode opcode,
288 int set_cc,
289 Register rn,
290 Register rd,
291 const ShifterOperand& so);
292
293 void EmitType5(Condition cond, int offset, bool link);
294
295 void EmitMemOp(Condition cond,
296 bool load,
297 bool byte,
298 Register rd,
299 const Address& ad);
300
301 void EmitMemOpAddressMode3(Condition cond,
302 int32_t mode,
303 Register rd,
304 const Address& ad);
305
306 void EmitMultiMemOp(Condition cond,
307 BlockAddressMode am,
308 bool load,
309 Register base,
310 RegList regs);
311
312 void EmitShiftImmediate(Condition cond,
313 Shift opcode,
314 Register rd,
315 Register rm,
316 const ShifterOperand& so);
317
318 void EmitShiftRegister(Condition cond,
319 Shift opcode,
320 Register rd,
321 Register rm,
322 const ShifterOperand& so);
323
324 void EmitMulOp(Condition cond,
325 int32_t opcode,
326 Register rd,
327 Register rn,
328 Register rm,
329 Register rs);
330
331 void EmitVFPsss(Condition cond,
332 int32_t opcode,
333 SRegister sd,
334 SRegister sn,
335 SRegister sm);
336
337 void EmitVFPddd(Condition cond,
338 int32_t opcode,
339 DRegister dd,
340 DRegister dn,
341 DRegister dm);
342
343 void EmitVFPsd(Condition cond,
344 int32_t opcode,
345 SRegister sd,
346 DRegister dm);
347
348 void EmitVFPds(Condition cond,
349 int32_t opcode,
350 DRegister dd,
351 SRegister sm);
352
353 void EmitVPushPop(uint32_t reg, int nregs, bool push, bool dbl, Condition cond);
354
355 void EmitBranch(Condition cond, Label* label, bool link);
356 static int32_t EncodeBranchOffset(int offset, int32_t inst);
357 static int DecodeBranchOffset(int32_t inst);
358 int32_t EncodeTstOffset(int offset, int32_t inst);
359 int DecodeTstOffset(int32_t inst);
360};
361
362} // namespace arm
363} // namespace art
364
365#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM32_H_