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