Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 1 | /* |
| 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_THUMB2_H_ |
| 18 | #define ART_COMPILER_UTILS_ARM_ASSEMBLER_THUMB2_H_ |
| 19 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 20 | #include <deque> |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 21 | #include <utility> |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 24 | #include "base/arena_containers.h" |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 25 | #include "base/logging.h" |
| 26 | #include "constants_arm.h" |
| 27 | #include "utils/arm/managed_register_arm.h" |
| 28 | #include "utils/arm/assembler_arm.h" |
Vladimir Marko | 6b756b5 | 2015-07-14 11:58:38 +0100 | [diff] [blame] | 29 | #include "utils/array_ref.h" |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 30 | #include "offsets.h" |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 31 | |
| 32 | namespace art { |
| 33 | namespace arm { |
| 34 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 35 | class Thumb2Assembler FINAL : public ArmAssembler { |
| 36 | public: |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 37 | explicit Thumb2Assembler(ArenaAllocator* arena, bool can_relocate_branches = true) |
| 38 | : ArmAssembler(arena), |
| 39 | can_relocate_branches_(can_relocate_branches), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 40 | force_32bit_(false), |
| 41 | it_cond_index_(kNoItCondition), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 42 | next_condition_(AL), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 43 | fixups_(arena->Adapter(kArenaAllocAssembler)), |
| 44 | fixup_dependents_(arena->Adapter(kArenaAllocAssembler)), |
| 45 | literals_(arena->Adapter(kArenaAllocAssembler)), |
| 46 | jump_tables_(arena->Adapter(kArenaAllocAssembler)), |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 47 | last_position_adjustment_(0u), |
| 48 | last_old_position_(0u), |
| 49 | last_fixup_id_(0u) { |
Vladimir Marko | 10ef694 | 2015-10-22 15:25:54 +0100 | [diff] [blame] | 50 | cfi().DelayEmittingAdvancePCs(); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | virtual ~Thumb2Assembler() { |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | bool IsThumb() const OVERRIDE { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | bool IsForced32Bit() const { |
| 61 | return force_32bit_; |
| 62 | } |
| 63 | |
Nicolas Geoffray | d126ba1 | 2015-05-20 11:25:27 +0100 | [diff] [blame] | 64 | bool CanRelocateBranches() const { |
| 65 | return can_relocate_branches_; |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 68 | void FinalizeCode() OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 69 | |
| 70 | // Data-processing instructions. |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 71 | virtual void and_(Register rd, Register rn, const ShifterOperand& so, |
| 72 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 73 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 74 | virtual void eor(Register rd, Register rn, const ShifterOperand& so, |
| 75 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 76 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 77 | virtual void sub(Register rd, Register rn, const ShifterOperand& so, |
| 78 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 79 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 80 | virtual void rsb(Register rd, Register rn, const ShifterOperand& so, |
| 81 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 82 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 83 | virtual void add(Register rd, Register rn, const ShifterOperand& so, |
| 84 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 85 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 86 | virtual void adc(Register rd, Register rn, const ShifterOperand& so, |
| 87 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 88 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 89 | virtual void sbc(Register rd, Register rn, const ShifterOperand& so, |
| 90 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 91 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 92 | virtual void rsc(Register rd, Register rn, const ShifterOperand& so, |
| 93 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 94 | |
| 95 | void tst(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE; |
| 96 | |
| 97 | void teq(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE; |
| 98 | |
| 99 | void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE; |
| 100 | |
| 101 | void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE; |
| 102 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 103 | virtual void orr(Register rd, Register rn, const ShifterOperand& so, |
| 104 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 105 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 106 | virtual void orn(Register rd, Register rn, const ShifterOperand& so, |
| 107 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 108 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 109 | virtual void mov(Register rd, const ShifterOperand& so, |
| 110 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 111 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 112 | virtual void bic(Register rd, Register rn, const ShifterOperand& so, |
| 113 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 114 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 115 | virtual void mvn(Register rd, const ShifterOperand& so, |
| 116 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 117 | |
| 118 | // Miscellaneous data-processing instructions. |
| 119 | void clz(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
| 120 | void movw(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE; |
| 121 | void movt(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE; |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 122 | void rbit(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
Artem Serov | c257da7 | 2016-02-02 13:49:43 +0000 | [diff] [blame] | 123 | void rev(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
| 124 | void rev16(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
| 125 | void revsh(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 126 | |
| 127 | // Multiply instructions. |
| 128 | void mul(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE; |
| 129 | void mla(Register rd, Register rn, Register rm, Register ra, |
| 130 | Condition cond = AL) OVERRIDE; |
| 131 | void mls(Register rd, Register rn, Register rm, Register ra, |
| 132 | Condition cond = AL) OVERRIDE; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 133 | void smull(Register rd_lo, Register rd_hi, Register rn, Register rm, |
| 134 | Condition cond = AL) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 135 | void umull(Register rd_lo, Register rd_hi, Register rn, Register rm, |
| 136 | Condition cond = AL) OVERRIDE; |
| 137 | |
| 138 | void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE; |
| 139 | void udiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE; |
| 140 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 141 | // Bit field extract instructions. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 142 | void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE; |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 143 | void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE; |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 144 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 145 | // Load/store instructions. |
| 146 | void ldr(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 147 | void str(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 148 | |
| 149 | void ldrb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 150 | void strb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 151 | |
| 152 | void ldrh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 153 | void strh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 154 | |
| 155 | void ldrsb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 156 | void ldrsh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 157 | |
Roland Levillain | 4af147e | 2015-04-07 13:54:49 +0100 | [diff] [blame] | 158 | // Load/store register dual instructions using registers `rd` and `rd` + 1. |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 159 | void ldrd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 160 | void strd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 161 | |
Roland Levillain | 4af147e | 2015-04-07 13:54:49 +0100 | [diff] [blame] | 162 | // Load/store register dual instructions using registers `rd` and `rd2`. |
| 163 | // Note that contrary to the ARM A1 encoding, the Thumb-2 T1 encoding |
| 164 | // does not require `rd` to be even, nor `rd2' to be equal to `rd` + 1. |
| 165 | void ldrd(Register rd, Register rd2, const Address& ad, Condition cond); |
| 166 | void strd(Register rd, Register rd2, const Address& ad, Condition cond); |
| 167 | |
| 168 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 169 | void ldm(BlockAddressMode am, Register base, |
| 170 | RegList regs, Condition cond = AL) OVERRIDE; |
| 171 | void stm(BlockAddressMode am, Register base, |
| 172 | RegList regs, Condition cond = AL) OVERRIDE; |
| 173 | |
| 174 | void ldrex(Register rd, Register rn, Condition cond = AL) OVERRIDE; |
| 175 | void strex(Register rd, Register rt, Register rn, Condition cond = AL) OVERRIDE; |
| 176 | |
| 177 | void ldrex(Register rd, Register rn, uint16_t imm, Condition cond = AL); |
| 178 | void strex(Register rd, Register rt, Register rn, uint16_t imm, Condition cond = AL); |
| 179 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 180 | void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE; |
| 181 | void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 182 | |
| 183 | // Miscellaneous instructions. |
| 184 | void clrex(Condition cond = AL) OVERRIDE; |
| 185 | void nop(Condition cond = AL) OVERRIDE; |
| 186 | |
| 187 | void bkpt(uint16_t imm16) OVERRIDE; |
| 188 | void svc(uint32_t imm24) OVERRIDE; |
| 189 | |
| 190 | // If-then |
| 191 | void it(Condition firstcond, ItState i1 = kItOmitted, |
| 192 | ItState i2 = kItOmitted, ItState i3 = kItOmitted) OVERRIDE; |
| 193 | |
| 194 | void cbz(Register rn, Label* target) OVERRIDE; |
| 195 | void cbnz(Register rn, Label* target) OVERRIDE; |
| 196 | |
| 197 | // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles). |
| 198 | void vmovsr(SRegister sn, Register rt, Condition cond = AL) OVERRIDE; |
| 199 | void vmovrs(Register rt, SRegister sn, Condition cond = AL) OVERRIDE; |
| 200 | void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) OVERRIDE; |
| 201 | void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) OVERRIDE; |
| 202 | void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) OVERRIDE; |
| 203 | void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) OVERRIDE; |
| 204 | void vmovs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 205 | void vmovd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 206 | |
| 207 | // Returns false if the immediate cannot be encoded. |
| 208 | bool vmovs(SRegister sd, float s_imm, Condition cond = AL) OVERRIDE; |
| 209 | bool vmovd(DRegister dd, double d_imm, Condition cond = AL) OVERRIDE; |
| 210 | |
| 211 | void vldrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 212 | void vstrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 213 | void vldrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 214 | void vstrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE; |
| 215 | |
| 216 | void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 217 | void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 218 | void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 219 | void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 220 | void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 221 | void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 222 | void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 223 | void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 224 | void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 225 | void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 226 | void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE; |
| 227 | void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE; |
| 228 | |
| 229 | void vabss(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 230 | void vabsd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 231 | void vnegs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 232 | void vnegd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 233 | void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 234 | void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 235 | |
| 236 | void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 237 | void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 238 | void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 239 | void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 240 | void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 241 | void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 242 | void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 243 | void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 244 | void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 245 | void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 246 | |
| 247 | void vcmps(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE; |
| 248 | void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE; |
| 249 | void vcmpsz(SRegister sd, Condition cond = AL) OVERRIDE; |
| 250 | void vcmpdz(DRegister dd, Condition cond = AL) OVERRIDE; |
| 251 | void vmstat(Condition cond = AL) OVERRIDE; // VMRS APSR_nzcv, FPSCR |
| 252 | |
| 253 | void vpushs(SRegister reg, int nregs, Condition cond = AL) OVERRIDE; |
| 254 | void vpushd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE; |
| 255 | void vpops(SRegister reg, int nregs, Condition cond = AL) OVERRIDE; |
| 256 | void vpopd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE; |
| 257 | |
| 258 | // Branch instructions. |
| 259 | void b(Label* label, Condition cond = AL); |
| 260 | void bl(Label* label, Condition cond = AL); |
| 261 | void blx(Label* label); |
| 262 | void blx(Register rm, Condition cond = AL) OVERRIDE; |
| 263 | void bx(Register rm, Condition cond = AL) OVERRIDE; |
| 264 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 265 | virtual void Lsl(Register rd, Register rm, uint32_t shift_imm, |
| 266 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 267 | virtual void Lsr(Register rd, Register rm, uint32_t shift_imm, |
| 268 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 269 | virtual void Asr(Register rd, Register rm, uint32_t shift_imm, |
| 270 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 271 | virtual void Ror(Register rd, Register rm, uint32_t shift_imm, |
| 272 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 273 | virtual void Rrx(Register rd, Register rm, |
| 274 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 45fdb93 | 2014-06-25 12:37:10 -0700 | [diff] [blame] | 275 | |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 276 | virtual void Lsl(Register rd, Register rm, Register rn, |
| 277 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 278 | virtual void Lsr(Register rd, Register rm, Register rn, |
| 279 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 280 | virtual void Asr(Register rd, Register rm, Register rn, |
| 281 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
| 282 | virtual void Ror(Register rd, Register rm, Register rn, |
| 283 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 284 | |
| 285 | void Push(Register rd, Condition cond = AL) OVERRIDE; |
| 286 | void Pop(Register rd, Condition cond = AL) OVERRIDE; |
| 287 | |
| 288 | void PushList(RegList regs, Condition cond = AL) OVERRIDE; |
| 289 | void PopList(RegList regs, Condition cond = AL) OVERRIDE; |
| 290 | |
| 291 | void Mov(Register rd, Register rm, Condition cond = AL) OVERRIDE; |
| 292 | |
| 293 | void CompareAndBranchIfZero(Register r, Label* label) OVERRIDE; |
| 294 | void CompareAndBranchIfNonZero(Register r, Label* label) OVERRIDE; |
| 295 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 296 | // Memory barriers. |
| 297 | void dmb(DmbOptions flavor) OVERRIDE; |
| 298 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 299 | // Get the final position of a label after local fixup based on the old position |
| 300 | // recorded before FinalizeCode(). |
| 301 | uint32_t GetAdjustedPosition(uint32_t old_position) OVERRIDE; |
| 302 | |
| 303 | using ArmAssembler::NewLiteral; // Make the helper template visible. |
| 304 | |
| 305 | Literal* NewLiteral(size_t size, const uint8_t* data) OVERRIDE; |
| 306 | void LoadLiteral(Register rt, Literal* literal) OVERRIDE; |
| 307 | void LoadLiteral(Register rt, Register rt2, Literal* literal) OVERRIDE; |
| 308 | void LoadLiteral(SRegister sd, Literal* literal) OVERRIDE; |
| 309 | void LoadLiteral(DRegister dd, Literal* literal) OVERRIDE; |
| 310 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 311 | // Add signed constant value to rd. May clobber IP. |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 312 | void AddConstant(Register rd, Register rn, int32_t value, |
Vladimir Marko | 449b109 | 2015-09-08 12:16:45 +0100 | [diff] [blame] | 313 | Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 314 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 315 | void CmpConstant(Register rn, int32_t value, Condition cond = AL) OVERRIDE; |
| 316 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 317 | // Load and Store. May clobber IP. |
| 318 | void LoadImmediate(Register rd, int32_t value, Condition cond = AL) OVERRIDE; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 319 | void MarkExceptionHandler(Label* label) OVERRIDE; |
| 320 | void LoadFromOffset(LoadOperandType type, |
| 321 | Register reg, |
| 322 | Register base, |
| 323 | int32_t offset, |
| 324 | Condition cond = AL) OVERRIDE; |
| 325 | void StoreToOffset(StoreOperandType type, |
| 326 | Register reg, |
| 327 | Register base, |
| 328 | int32_t offset, |
| 329 | Condition cond = AL) OVERRIDE; |
| 330 | void LoadSFromOffset(SRegister reg, |
| 331 | Register base, |
| 332 | int32_t offset, |
| 333 | Condition cond = AL) OVERRIDE; |
| 334 | void StoreSToOffset(SRegister reg, |
| 335 | Register base, |
| 336 | int32_t offset, |
| 337 | Condition cond = AL) OVERRIDE; |
| 338 | void LoadDFromOffset(DRegister reg, |
| 339 | Register base, |
| 340 | int32_t offset, |
| 341 | Condition cond = AL) OVERRIDE; |
| 342 | void StoreDToOffset(DRegister reg, |
| 343 | Register base, |
| 344 | int32_t offset, |
| 345 | Condition cond = AL) OVERRIDE; |
| 346 | |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 347 | bool ShifterOperandCanHold(Register rd, |
| 348 | Register rn, |
| 349 | Opcode opcode, |
| 350 | uint32_t immediate, |
Vladimir Marko | f5c09c3 | 2015-12-17 12:08:08 +0000 | [diff] [blame] | 351 | SetCc set_cc, |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 352 | ShifterOperand* shifter_op) OVERRIDE; |
Vladimir Marko | f5c09c3 | 2015-12-17 12:08:08 +0000 | [diff] [blame] | 353 | using ArmAssembler::ShifterOperandCanHold; // Don't hide the non-virtual override. |
Nicolas Geoffray | 3bcc8ea | 2014-11-28 15:00:02 +0000 | [diff] [blame] | 354 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 355 | bool ShifterOperandCanAlwaysHold(uint32_t immediate) OVERRIDE; |
| 356 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 357 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 358 | static bool IsInstructionForExceptionHandling(uintptr_t pc); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 359 | |
| 360 | // Emit data (e.g. encoded instruction or immediate) to the. |
| 361 | // instruction stream. |
| 362 | void Emit32(int32_t value); // Emit a 32 bit instruction in thumb format. |
| 363 | void Emit16(int16_t value); // Emit a 16 bit instruction in little endian format. |
| 364 | void Bind(Label* label) OVERRIDE; |
| 365 | |
| 366 | void MemoryBarrier(ManagedRegister scratch) OVERRIDE; |
| 367 | |
| 368 | // Force the assembler to generate 32 bit instructions. |
| 369 | void Force32Bit() { |
| 370 | force_32bit_ = true; |
| 371 | } |
| 372 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 373 | // Emit an ADR (or a sequence of instructions) to load the jump table address into base_reg. This |
| 374 | // will generate a fixup. |
| 375 | JumpTable* CreateJumpTable(std::vector<Label*>&& labels, Register base_reg) OVERRIDE; |
| 376 | // Emit an ADD PC, X to dispatch a jump-table jump. This will generate a fixup. |
| 377 | void EmitJumpTableDispatch(JumpTable* jump_table, Register displacement_reg) OVERRIDE; |
| 378 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 379 | private: |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 380 | typedef uint16_t FixupId; |
| 381 | |
| 382 | // Fixup: branches and literal pool references. |
| 383 | // |
| 384 | // The thumb2 architecture allows branches to be either 16 or 32 bit instructions. This |
| 385 | // depends on both the type of branch and the offset to which it is branching. The 16-bit |
| 386 | // cbz and cbnz instructions may also need to be replaced with a separate 16-bit compare |
| 387 | // instruction and a 16- or 32-bit branch instruction. Load from a literal pool can also be |
| 388 | // 16-bit or 32-bit instruction and, if the method is large, we may need to use a sequence |
| 389 | // of instructions to make up for the limited range of load literal instructions (up to |
| 390 | // 4KiB for the 32-bit variant). When generating code for these insns we don't know the |
| 391 | // size before hand, so we assume it is the smallest available size and determine the final |
| 392 | // code offsets and sizes and emit code in FinalizeCode(). |
| 393 | // |
| 394 | // To handle this, we keep a record of every branch and literal pool load in the program. |
| 395 | // The actual instruction encoding for these is delayed until we know the final size of |
| 396 | // every instruction. When we bind a label to a branch we don't know the final location yet |
| 397 | // as some preceding instructions may need to be expanded, so we record a non-final offset. |
| 398 | // In FinalizeCode(), we expand the sizes of branches and literal loads that are out of |
| 399 | // range. With each expansion, we need to update dependent Fixups, i.e. insntructios with |
| 400 | // target on the other side of the expanded insn, as their offsets change and this may |
| 401 | // trigger further expansion. |
| 402 | // |
| 403 | // All Fixups have a 'fixup id' which is a 16 bit unsigned number used to identify the |
| 404 | // Fixup. For each unresolved label we keep a singly-linked list of all Fixups pointing |
| 405 | // to it, using the fixup ids as links. The first link is stored in the label's position |
| 406 | // (the label is linked but not bound), the following links are stored in the code buffer, |
| 407 | // in the placeholder where we will eventually emit the actual code. |
| 408 | |
| 409 | class Fixup { |
| 410 | public: |
| 411 | // Branch type. |
| 412 | enum Type : uint8_t { |
| 413 | kConditional, // B<cond>. |
| 414 | kUnconditional, // B. |
| 415 | kUnconditionalLink, // BL. |
| 416 | kUnconditionalLinkX, // BLX. |
| 417 | kCompareAndBranchXZero, // cbz/cbnz. |
| 418 | kLoadLiteralNarrow, // Load narrrow integer literal. |
| 419 | kLoadLiteralWide, // Load wide integer literal. |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 420 | kLoadLiteralAddr, // Load address of literal (used for jump table). |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 421 | kLoadFPLiteralSingle, // Load FP literal single. |
| 422 | kLoadFPLiteralDouble, // Load FP literal double. |
| 423 | }; |
| 424 | |
| 425 | // Calculated size of branch instruction based on type and offset. |
| 426 | enum Size : uint8_t { |
| 427 | // Branch variants. |
| 428 | kBranch16Bit, |
| 429 | kBranch32Bit, |
| 430 | // NOTE: We don't support branches which would require multiple instructions, i.e. |
| 431 | // conditinoal branches beyond +-1MiB and unconditional branches beyond +-16MiB. |
| 432 | |
| 433 | // CBZ/CBNZ variants. |
| 434 | kCbxz16Bit, // CBZ/CBNZ rX, label; X < 8; 7-bit positive offset. |
| 435 | kCbxz32Bit, // CMP rX, #0 + Bcc label; X < 8; 16-bit Bcc; +-8-bit offset. |
| 436 | kCbxz48Bit, // CMP rX, #0 + Bcc label; X < 8; 32-bit Bcc; up to +-1MiB offset. |
| 437 | |
| 438 | // Load integer literal variants. |
| 439 | // LDR rX, label; X < 8; 16-bit variant up to 1KiB offset; 2 bytes. |
| 440 | kLiteral1KiB, |
| 441 | // LDR rX, label; 32-bit variant up to 4KiB offset; 4 bytes. |
| 442 | kLiteral4KiB, |
| 443 | // MOV rX, imm16 + ADD rX, pc + LDR rX, [rX]; X < 8; up to 64KiB offset; 8 bytes. |
| 444 | kLiteral64KiB, |
| 445 | // MOV rX, modimm + ADD rX, pc + LDR rX, [rX, #imm12]; up to 1MiB offset; 10 bytes. |
| 446 | kLiteral1MiB, |
| 447 | // NOTE: We don't provide the 12-byte version of kLiteralFar below where the LDR is 16-bit. |
| 448 | // MOV rX, imm16 + MOVT rX, imm16 + ADD rX, pc + LDR rX, [rX]; any offset; 14 bytes. |
| 449 | kLiteralFar, |
| 450 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 451 | // Load literal base addr. |
| 452 | // ADR rX, label; X < 8; 8 bit immediate, shifted to 10 bit. 2 bytes. |
| 453 | kLiteralAddr1KiB, |
| 454 | // ADR rX, label; 4KiB offset. 4 bytes. |
| 455 | kLiteralAddr4KiB, |
| 456 | // MOV rX, imm16 + ADD rX, pc; 64KiB offset. 6 bytes. |
| 457 | kLiteralAddr64KiB, |
| 458 | // MOV rX, imm16 + MOVT rX, imm16 + ADD rX, pc; any offset; 10 bytes. |
| 459 | kLiteralAddrFar, |
| 460 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 461 | // Load long or FP literal variants. |
| 462 | // VLDR s/dX, label; 32-bit insn, up to 1KiB offset; 4 bytes. |
| 463 | kLongOrFPLiteral1KiB, |
| 464 | // MOV ip, modimm + ADD ip, pc + VLDR s/dX, [IP, #imm8*4]; up to 256KiB offset; 10 bytes. |
| 465 | kLongOrFPLiteral256KiB, |
| 466 | // MOV ip, imm16 + MOVT ip, imm16 + ADD ip, pc + VLDR s/dX, [IP]; any offset; 14 bytes. |
| 467 | kLongOrFPLiteralFar, |
| 468 | }; |
| 469 | |
| 470 | // Unresolved branch possibly with a condition. |
| 471 | static Fixup Branch(uint32_t location, Type type, Size size = kBranch16Bit, |
| 472 | Condition cond = AL) { |
| 473 | DCHECK(type == kConditional || type == kUnconditional || |
| 474 | type == kUnconditionalLink || type == kUnconditionalLinkX); |
| 475 | DCHECK(size == kBranch16Bit || size == kBranch32Bit); |
| 476 | DCHECK(size == kBranch32Bit || (type == kConditional || type == kUnconditional)); |
| 477 | return Fixup(kNoRegister, kNoRegister, kNoSRegister, kNoDRegister, |
| 478 | cond, type, size, location); |
| 479 | } |
| 480 | |
| 481 | // Unresolved compare-and-branch instruction with a register and condition (EQ or NE). |
| 482 | static Fixup CompareAndBranch(uint32_t location, Register rn, Condition cond) { |
| 483 | DCHECK(cond == EQ || cond == NE); |
| 484 | return Fixup(rn, kNoRegister, kNoSRegister, kNoDRegister, |
| 485 | cond, kCompareAndBranchXZero, kCbxz16Bit, location); |
| 486 | } |
| 487 | |
| 488 | // Load narrow literal. |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 489 | static Fixup LoadNarrowLiteral(uint32_t location, Register rt, Size size) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 490 | DCHECK(size == kLiteral1KiB || size == kLiteral4KiB || size == kLiteral64KiB || |
| 491 | size == kLiteral1MiB || size == kLiteralFar); |
| 492 | DCHECK(!IsHighRegister(rt) || (size != kLiteral1KiB && size != kLiteral64KiB)); |
| 493 | return Fixup(rt, kNoRegister, kNoSRegister, kNoDRegister, |
| 494 | AL, kLoadLiteralNarrow, size, location); |
| 495 | } |
| 496 | |
| 497 | // Load wide literal. |
| 498 | static Fixup LoadWideLiteral(uint32_t location, Register rt, Register rt2, |
| 499 | Size size = kLongOrFPLiteral1KiB) { |
| 500 | DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB || |
| 501 | size == kLongOrFPLiteralFar); |
| 502 | DCHECK(!IsHighRegister(rt) || (size != kLiteral1KiB && size != kLiteral64KiB)); |
| 503 | return Fixup(rt, rt2, kNoSRegister, kNoDRegister, |
| 504 | AL, kLoadLiteralWide, size, location); |
| 505 | } |
| 506 | |
| 507 | // Load FP single literal. |
| 508 | static Fixup LoadSingleLiteral(uint32_t location, SRegister sd, |
| 509 | Size size = kLongOrFPLiteral1KiB) { |
| 510 | DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB || |
| 511 | size == kLongOrFPLiteralFar); |
| 512 | return Fixup(kNoRegister, kNoRegister, sd, kNoDRegister, |
| 513 | AL, kLoadFPLiteralSingle, size, location); |
| 514 | } |
| 515 | |
| 516 | // Load FP double literal. |
| 517 | static Fixup LoadDoubleLiteral(uint32_t location, DRegister dd, |
| 518 | Size size = kLongOrFPLiteral1KiB) { |
| 519 | DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB || |
| 520 | size == kLongOrFPLiteralFar); |
| 521 | return Fixup(kNoRegister, kNoRegister, kNoSRegister, dd, |
| 522 | AL, kLoadFPLiteralDouble, size, location); |
| 523 | } |
| 524 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 525 | static Fixup LoadLiteralAddress(uint32_t location, Register rt, Size size) { |
| 526 | DCHECK(size == kLiteralAddr1KiB || size == kLiteralAddr4KiB || size == kLiteralAddr64KiB || |
| 527 | size == kLiteralAddrFar); |
| 528 | DCHECK(!IsHighRegister(rt) || size != kLiteralAddr1KiB); |
| 529 | return Fixup(rt, kNoRegister, kNoSRegister, kNoDRegister, |
| 530 | AL, kLoadLiteralAddr, size, location); |
| 531 | } |
| 532 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 533 | Type GetType() const { |
| 534 | return type_; |
| 535 | } |
| 536 | |
Vladimir Marko | 663c934 | 2015-07-22 11:28:14 +0100 | [diff] [blame] | 537 | bool IsLoadLiteral() const { |
| 538 | return GetType() >= kLoadLiteralNarrow; |
| 539 | } |
| 540 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 541 | Size GetOriginalSize() const { |
| 542 | return original_size_; |
| 543 | } |
| 544 | |
| 545 | Size GetSize() const { |
| 546 | return size_; |
| 547 | } |
| 548 | |
| 549 | uint32_t GetOriginalSizeInBytes() const; |
| 550 | |
| 551 | uint32_t GetSizeInBytes() const; |
| 552 | |
| 553 | uint32_t GetLocation() const { |
| 554 | return location_; |
| 555 | } |
| 556 | |
| 557 | uint32_t GetAdjustment() const { |
| 558 | return adjustment_; |
| 559 | } |
| 560 | |
Vladimir Marko | 6b756b5 | 2015-07-14 11:58:38 +0100 | [diff] [blame] | 561 | // Prepare the assembler->fixup_dependents_ and each Fixup's dependents_start_/count_. |
| 562 | static void PrepareDependents(Thumb2Assembler* assembler); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 563 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 564 | ArrayRef<const FixupId> Dependents(const Thumb2Assembler& assembler) const { |
| 565 | return ArrayRef<const FixupId>(assembler.fixup_dependents_).SubArray(dependents_start_, |
| 566 | dependents_count_); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | // Resolve a branch when the target is known. |
| 570 | void Resolve(uint32_t target) { |
| 571 | DCHECK_EQ(target_, kUnresolved); |
| 572 | DCHECK_NE(target, kUnresolved); |
| 573 | target_ = target; |
| 574 | } |
| 575 | |
| 576 | // Check if the current size is OK for current location_, target_ and adjustment_. |
| 577 | // If not, increase the size. Return the size increase, 0 if unchanged. |
| 578 | // If the target if after this Fixup, also add the difference to adjustment_, |
| 579 | // so that we don't need to consider forward Fixups as their own dependencies. |
| 580 | uint32_t AdjustSizeIfNeeded(uint32_t current_code_size); |
| 581 | |
| 582 | // Increase adjustments. This is called for dependents of a Fixup when its size changes. |
| 583 | void IncreaseAdjustment(uint32_t increase) { |
| 584 | adjustment_ += increase; |
| 585 | } |
| 586 | |
| 587 | // Finalize the branch with an adjustment to the location. Both location and target are updated. |
| 588 | void Finalize(uint32_t location_adjustment) { |
| 589 | DCHECK_NE(target_, kUnresolved); |
| 590 | location_ += location_adjustment; |
| 591 | target_ += location_adjustment; |
| 592 | } |
| 593 | |
| 594 | // Emit the branch instruction into the assembler buffer. This does the |
| 595 | // encoding into the thumb instruction. |
| 596 | void Emit(AssemblerBuffer* buffer, uint32_t code_size) const; |
| 597 | |
| 598 | private: |
| 599 | Fixup(Register rn, Register rt2, SRegister sd, DRegister dd, |
| 600 | Condition cond, Type type, Size size, uint32_t location) |
| 601 | : rn_(rn), |
| 602 | rt2_(rt2), |
| 603 | sd_(sd), |
| 604 | dd_(dd), |
| 605 | cond_(cond), |
| 606 | type_(type), |
| 607 | original_size_(size), size_(size), |
| 608 | location_(location), |
| 609 | target_(kUnresolved), |
| 610 | adjustment_(0u), |
Vladimir Marko | 6b756b5 | 2015-07-14 11:58:38 +0100 | [diff] [blame] | 611 | dependents_count_(0u), |
| 612 | dependents_start_(0u) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 613 | } |
| 614 | static size_t SizeInBytes(Size size); |
| 615 | |
| 616 | // The size of padding added before the literal pool. |
| 617 | static size_t LiteralPoolPaddingSize(uint32_t current_code_size); |
| 618 | |
| 619 | // Returns the offset from the PC-using insn to the target. |
| 620 | int32_t GetOffset(uint32_t current_code_size) const; |
| 621 | |
| 622 | size_t IncreaseSize(Size new_size); |
| 623 | |
| 624 | int32_t LoadWideOrFpEncoding(Register rbase, int32_t offset) const; |
| 625 | |
| 626 | static constexpr uint32_t kUnresolved = 0xffffffff; // Value for target_ for unresolved. |
| 627 | |
| 628 | const Register rn_; // Rn for cbnz/cbz, Rt for literal loads. |
| 629 | Register rt2_; // For kLoadLiteralWide. |
| 630 | SRegister sd_; // For kLoadFPLiteralSingle. |
| 631 | DRegister dd_; // For kLoadFPLiteralDouble. |
| 632 | const Condition cond_; |
| 633 | const Type type_; |
| 634 | Size original_size_; |
| 635 | Size size_; |
| 636 | uint32_t location_; // Offset into assembler buffer in bytes. |
| 637 | uint32_t target_; // Offset into assembler buffer in bytes. |
| 638 | uint32_t adjustment_; // The number of extra bytes inserted between location_ and target_. |
Vladimir Marko | 6b756b5 | 2015-07-14 11:58:38 +0100 | [diff] [blame] | 639 | // Fixups that require adjustment when current size changes are stored in a single |
| 640 | // array in the assembler and we store only the start index and count here. |
| 641 | uint32_t dependents_count_; |
| 642 | uint32_t dependents_start_; |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 643 | }; |
| 644 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 645 | // Emit a single 32 or 16 bit data processing instruction. |
| 646 | void EmitDataProcessing(Condition cond, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 647 | Opcode opcode, |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 648 | SetCc set_cc, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 649 | Register rn, |
| 650 | Register rd, |
| 651 | const ShifterOperand& so); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 652 | |
Artem Serov | c257da7 | 2016-02-02 13:49:43 +0000 | [diff] [blame] | 653 | // Emit a single 32 bit miscellaneous instruction. |
| 654 | void Emit32Miscellaneous(uint8_t op1, |
| 655 | uint8_t op2, |
| 656 | uint32_t rest_encoding); |
| 657 | |
| 658 | // Emit reverse byte instructions: rev, rev16, revsh. |
| 659 | void EmitReverseBytes(Register rd, Register rm, uint32_t op); |
| 660 | |
| 661 | // Emit a single 16 bit miscellaneous instruction. |
| 662 | void Emit16Miscellaneous(uint32_t rest_encoding); |
| 663 | |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 664 | // Must the instruction be 32 bits or can it possibly be encoded |
| 665 | // in 16 bits? |
| 666 | bool Is32BitDataProcessing(Condition cond, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 667 | Opcode opcode, |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 668 | SetCc set_cc, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 669 | Register rn, |
| 670 | Register rd, |
| 671 | const ShifterOperand& so); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 672 | |
| 673 | // Emit a 32 bit data processing instruction. |
| 674 | void Emit32BitDataProcessing(Condition cond, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 675 | Opcode opcode, |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 676 | SetCc set_cc, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 677 | Register rn, |
| 678 | Register rd, |
| 679 | const ShifterOperand& so); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 680 | |
| 681 | // Emit a 16 bit data processing instruction. |
| 682 | void Emit16BitDataProcessing(Condition cond, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 683 | Opcode opcode, |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 684 | SetCc set_cc, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 685 | Register rn, |
| 686 | Register rd, |
| 687 | const ShifterOperand& so); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 688 | |
| 689 | void Emit16BitAddSub(Condition cond, |
| 690 | Opcode opcode, |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 691 | SetCc set_cc, |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 692 | Register rn, |
| 693 | Register rd, |
| 694 | const ShifterOperand& so); |
| 695 | |
| 696 | uint16_t EmitCompareAndBranch(Register rn, uint16_t prev, bool n); |
| 697 | |
| 698 | void EmitLoadStore(Condition cond, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 699 | bool load, |
| 700 | bool byte, |
| 701 | bool half, |
| 702 | bool is_signed, |
| 703 | Register rd, |
| 704 | const Address& ad); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 705 | |
| 706 | void EmitMemOpAddressMode3(Condition cond, |
| 707 | int32_t mode, |
| 708 | Register rd, |
| 709 | const Address& ad); |
| 710 | |
| 711 | void EmitMultiMemOp(Condition cond, |
| 712 | BlockAddressMode am, |
| 713 | bool load, |
| 714 | Register base, |
| 715 | RegList regs); |
| 716 | |
| 717 | void EmitMulOp(Condition cond, |
| 718 | int32_t opcode, |
| 719 | Register rd, |
| 720 | Register rn, |
| 721 | Register rm, |
| 722 | Register rs); |
| 723 | |
| 724 | void EmitVFPsss(Condition cond, |
| 725 | int32_t opcode, |
| 726 | SRegister sd, |
| 727 | SRegister sn, |
| 728 | SRegister sm); |
| 729 | |
| 730 | void EmitVFPddd(Condition cond, |
| 731 | int32_t opcode, |
| 732 | DRegister dd, |
| 733 | DRegister dn, |
| 734 | DRegister dm); |
| 735 | |
| 736 | void EmitVFPsd(Condition cond, |
| 737 | int32_t opcode, |
| 738 | SRegister sd, |
| 739 | DRegister dm); |
| 740 | |
| 741 | void EmitVFPds(Condition cond, |
| 742 | int32_t opcode, |
| 743 | DRegister dd, |
| 744 | SRegister sm); |
| 745 | |
| 746 | void EmitVPushPop(uint32_t reg, int nregs, bool push, bool dbl, Condition cond); |
| 747 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 748 | void EmitBranch(Condition cond, Label* label, bool link, bool x); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 749 | static int32_t EncodeBranchOffset(int32_t offset, int32_t inst); |
| 750 | static int DecodeBranchOffset(int32_t inst); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 751 | void EmitShift(Register rd, Register rm, Shift shift, uint8_t amount, |
| 752 | Condition cond = AL, SetCc set_cc = kCcDontCare); |
| 753 | void EmitShift(Register rd, Register rn, Shift shift, Register rm, |
| 754 | Condition cond = AL, SetCc set_cc = kCcDontCare); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 755 | |
Vladimir Marko | 6fd0ffe | 2015-11-19 21:13:52 +0000 | [diff] [blame] | 756 | static int32_t GetAllowedLoadOffsetBits(LoadOperandType type); |
| 757 | static int32_t GetAllowedStoreOffsetBits(StoreOperandType type); |
| 758 | bool CanSplitLoadStoreOffset(int32_t allowed_offset_bits, |
| 759 | int32_t offset, |
| 760 | /*out*/ int32_t* add_to_base, |
| 761 | /*out*/ int32_t* offset_for_load_store); |
| 762 | int32_t AdjustLoadStoreOffset(int32_t allowed_offset_bits, |
| 763 | Register temp, |
| 764 | Register base, |
| 765 | int32_t offset, |
| 766 | Condition cond); |
| 767 | |
Nicolas Geoffray | d126ba1 | 2015-05-20 11:25:27 +0100 | [diff] [blame] | 768 | // Whether the assembler can relocate branches. If false, unresolved branches will be |
| 769 | // emitted on 32bits. |
| 770 | bool can_relocate_branches_; |
| 771 | |
| 772 | // Force the assembler to use 32 bit thumb2 instructions. |
| 773 | bool force_32bit_; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 774 | |
| 775 | // IfThen conditions. Used to check that conditional instructions match the preceding IT. |
| 776 | Condition it_conditions_[4]; |
| 777 | uint8_t it_cond_index_; |
| 778 | Condition next_condition_; |
| 779 | |
| 780 | void SetItCondition(ItState s, Condition cond, uint8_t index); |
| 781 | |
| 782 | void CheckCondition(Condition cond) { |
| 783 | CHECK_EQ(cond, next_condition_); |
| 784 | |
| 785 | // Move to the next condition if there is one. |
| 786 | if (it_cond_index_ < 3) { |
| 787 | ++it_cond_index_; |
| 788 | next_condition_ = it_conditions_[it_cond_index_]; |
| 789 | } else { |
| 790 | next_condition_ = AL; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | void CheckConditionLastIt(Condition cond) { |
| 795 | if (it_cond_index_ < 3) { |
| 796 | // Check that the next condition is AL. This means that the |
| 797 | // current condition is the last in the IT block. |
| 798 | CHECK_EQ(it_conditions_[it_cond_index_ + 1], AL); |
| 799 | } |
| 800 | CheckCondition(cond); |
| 801 | } |
| 802 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 803 | FixupId AddFixup(Fixup fixup) { |
| 804 | FixupId fixup_id = static_cast<FixupId>(fixups_.size()); |
| 805 | fixups_.push_back(fixup); |
| 806 | // For iterating using FixupId, we need the next id to be representable. |
| 807 | DCHECK_EQ(static_cast<size_t>(static_cast<FixupId>(fixups_.size())), fixups_.size()); |
| 808 | return fixup_id; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 811 | Fixup* GetFixup(FixupId fixup_id) { |
| 812 | DCHECK_LT(fixup_id, fixups_.size()); |
| 813 | return &fixups_[fixup_id]; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 816 | void BindLabel(Label* label, uint32_t bound_pc); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 817 | uint32_t BindLiterals(); |
| 818 | void BindJumpTables(uint32_t code_size); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 819 | void AdjustFixupIfNeeded(Fixup* fixup, uint32_t* current_code_size, |
| 820 | std::deque<FixupId>* fixups_to_recalculate); |
| 821 | uint32_t AdjustFixups(); |
| 822 | void EmitFixups(uint32_t adjusted_code_size); |
| 823 | void EmitLiterals(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 824 | void EmitJumpTables(); |
Vladimir Marko | 10ef694 | 2015-10-22 15:25:54 +0100 | [diff] [blame] | 825 | void PatchCFI(); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 826 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 827 | static int16_t BEncoding16(int32_t offset, Condition cond); |
| 828 | static int32_t BEncoding32(int32_t offset, Condition cond); |
| 829 | static int16_t CbxzEncoding16(Register rn, int32_t offset, Condition cond); |
| 830 | static int16_t CmpRnImm8Encoding16(Register rn, int32_t value); |
| 831 | static int16_t AddRdnRmEncoding16(Register rdn, Register rm); |
| 832 | static int32_t MovwEncoding32(Register rd, int32_t value); |
| 833 | static int32_t MovtEncoding32(Register rd, int32_t value); |
| 834 | static int32_t MovModImmEncoding32(Register rd, int32_t value); |
| 835 | static int16_t LdrLitEncoding16(Register rt, int32_t offset); |
| 836 | static int32_t LdrLitEncoding32(Register rt, int32_t offset); |
| 837 | static int32_t LdrdEncoding32(Register rt, Register rt2, Register rn, int32_t offset); |
| 838 | static int32_t VldrsEncoding32(SRegister sd, Register rn, int32_t offset); |
| 839 | static int32_t VldrdEncoding32(DRegister dd, Register rn, int32_t offset); |
| 840 | static int16_t LdrRtRnImm5Encoding16(Register rt, Register rn, int32_t offset); |
| 841 | static int32_t LdrRtRnImm12Encoding(Register rt, Register rn, int32_t offset); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 842 | static int16_t AdrEncoding16(Register rd, int32_t offset); |
| 843 | static int32_t AdrEncoding32(Register rd, int32_t offset); |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 844 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 845 | ArenaVector<Fixup> fixups_; |
| 846 | ArenaVector<FixupId> fixup_dependents_; |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 847 | |
| 848 | // Use std::deque<> for literal labels to allow insertions at the end |
| 849 | // without invalidating pointers and references to existing elements. |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 850 | ArenaDeque<Literal> literals_; |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 851 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 852 | // Jump table list. |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame^] | 853 | ArenaDeque<JumpTable> jump_tables_; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 854 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 855 | // Data for AdjustedPosition(), see the description there. |
| 856 | uint32_t last_position_adjustment_; |
| 857 | uint32_t last_old_position_; |
| 858 | FixupId last_fixup_id_; |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | } // namespace arm |
| 862 | } // namespace art |
| 863 | |
| 864 | #endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_THUMB2_H_ |