mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3 | // |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions |
| 6 | // are met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // |
| 16 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 17 | // be used to endorse or promote products derived from this software without |
| 18 | // specific prior written permission. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 33 | // The original source code covered by the above license above has been |
| 34 | // modified significantly by Google Inc. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 35 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | #include "v8.h" |
| 38 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 39 | #if defined(V8_TARGET_ARCH_ARM) |
| 40 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 41 | #include "arm/assembler-arm-inl.h" |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 42 | #include "serialize.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 44 | namespace v8 { |
| 45 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 47 | #ifdef DEBUG |
| 48 | bool CpuFeatures::initialized_ = false; |
| 49 | #endif |
| 50 | unsigned CpuFeatures::supported_ = 0; |
| 51 | unsigned CpuFeatures::found_by_runtime_probing_ = 0; |
| 52 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 53 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 54 | // Get the CPU features enabled by the build. For cross compilation the |
| 55 | // preprocessor symbols CAN_USE_ARMV7_INSTRUCTIONS and CAN_USE_VFP_INSTRUCTIONS |
| 56 | // can be defined to enable ARMv7 and VFPv3 instructions when building the |
| 57 | // snapshot. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 58 | static uint64_t CpuFeaturesImpliedByCompiler() { |
| 59 | uint64_t answer = 0; |
| 60 | #ifdef CAN_USE_ARMV7_INSTRUCTIONS |
| 61 | answer |= 1u << ARMv7; |
| 62 | #endif // def CAN_USE_ARMV7_INSTRUCTIONS |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 63 | #ifdef CAN_USE_VFP_INSTRUCTIONS |
| 64 | answer |= 1u << VFP3 | 1u << ARMv7; |
| 65 | #endif // def CAN_USE_VFP_INSTRUCTIONS |
| 66 | |
| 67 | #ifdef __arm__ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 68 | // If the compiler is allowed to use VFP then we can use VFP too in our code |
| 69 | // generation even when generating snapshots. This won't work for cross |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 70 | // compilation. VFPv3 implies ARMv7, see ARM DDI 0406B, page A1-6. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 71 | #if defined(__VFP_FP__) && !defined(__SOFTFP__) |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 72 | answer |= 1u << VFP3 | 1u << ARMv7; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 73 | #endif // defined(__VFP_FP__) && !defined(__SOFTFP__) |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 74 | #endif // def __arm__ |
| 75 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 76 | return answer; |
| 77 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 78 | |
| 79 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 80 | void CpuFeatures::Probe() { |
| 81 | ASSERT(!initialized_); |
| 82 | #ifdef DEBUG |
| 83 | initialized_ = true; |
| 84 | #endif |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 85 | |
| 86 | // Get the features implied by the OS and the compiler settings. This is the |
| 87 | // minimal set of features which is also alowed for generated code in the |
| 88 | // snapshot. |
| 89 | supported_ |= OS::CpuFeaturesImpliedByPlatform(); |
| 90 | supported_ |= CpuFeaturesImpliedByCompiler(); |
| 91 | |
| 92 | if (Serializer::enabled()) { |
| 93 | // No probing for features if we might serialize (generate snapshot). |
| 94 | return; |
| 95 | } |
| 96 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 97 | #ifndef __arm__ |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 98 | // For the simulator=arm build, use VFP when FLAG_enable_vfp3 is |
| 99 | // enabled. VFPv3 implies ARMv7, see ARM DDI 0406B, page A1-6. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 100 | if (FLAG_enable_vfp3) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 101 | supported_ |= 1u << VFP3 | 1u << ARMv7; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 102 | } |
| 103 | // For the simulator=arm build, use ARMv7 when FLAG_enable_armv7 is enabled |
| 104 | if (FLAG_enable_armv7) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 105 | supported_ |= 1u << ARMv7; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 106 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 107 | #else // def __arm__ |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 108 | // Probe for additional features not already known to be available. |
| 109 | if (!IsSupported(VFP3) && OS::ArmCpuHasFeature(VFP3)) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 110 | // This implementation also sets the VFP flags if runtime |
| 111 | // detection of VFP returns true. VFPv3 implies ARMv7, see ARM DDI |
| 112 | // 0406B, page A1-6. |
| 113 | supported_ |= 1u << VFP3 | 1u << ARMv7; |
| 114 | found_by_runtime_probing_ |= 1u << VFP3 | 1u << ARMv7; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 115 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 116 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame^] | 117 | if (!IsSupported(ARMv7) && OS::ArmCpuHasFeature(ARMv7)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 118 | supported_ |= 1u << ARMv7; |
| 119 | found_by_runtime_probing_ |= 1u << ARMv7; |
| 120 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 121 | #endif |
| 122 | } |
| 123 | |
| 124 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | // Implementation of RelocInfo |
| 127 | |
| 128 | const int RelocInfo::kApplyMask = 0; |
| 129 | |
| 130 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 131 | bool RelocInfo::IsCodedSpecially() { |
| 132 | // The deserializer needs to know whether a pointer is specially coded. Being |
| 133 | // specially coded on ARM means that it is a movw/movt instruction. We don't |
| 134 | // generate those yet. |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 140 | void RelocInfo::PatchCode(byte* instructions, int instruction_count) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | // Patch the code at the current address with the supplied instructions. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 142 | Instr* pc = reinterpret_cast<Instr*>(pc_); |
| 143 | Instr* instr = reinterpret_cast<Instr*>(instructions); |
| 144 | for (int i = 0; i < instruction_count; i++) { |
| 145 | *(pc + i) = *(instr + i); |
| 146 | } |
| 147 | |
| 148 | // Indicate that code has changed. |
| 149 | CPU::FlushICache(pc_, instruction_count * Assembler::kInstrSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
| 153 | // Patch the code at the current PC with a call to the target address. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 154 | // Additional guard instructions can be added if required. |
| 155 | void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | // Patch the code at the current address with a call to the target. |
| 157 | UNIMPLEMENTED(); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | // ----------------------------------------------------------------------------- |
| 162 | // Implementation of Operand and MemOperand |
| 163 | // See assembler-arm-inl.h for inlined constructors |
| 164 | |
| 165 | Operand::Operand(Handle<Object> handle) { |
| 166 | rm_ = no_reg; |
| 167 | // Verify all Objects referred by code are NOT in new space. |
| 168 | Object* obj = *handle; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 169 | ASSERT(!HEAP->InNewSpace(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | if (obj->IsHeapObject()) { |
| 171 | imm32_ = reinterpret_cast<intptr_t>(handle.location()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 172 | rmode_ = RelocInfo::EMBEDDED_OBJECT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | } else { |
| 174 | // no relocation needed |
| 175 | imm32_ = reinterpret_cast<intptr_t>(obj); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 176 | rmode_ = RelocInfo::NONE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | Operand::Operand(Register rm, ShiftOp shift_op, int shift_imm) { |
| 182 | ASSERT(is_uint5(shift_imm)); |
| 183 | ASSERT(shift_op != ROR || shift_imm != 0); // use RRX if you mean it |
| 184 | rm_ = rm; |
| 185 | rs_ = no_reg; |
| 186 | shift_op_ = shift_op; |
| 187 | shift_imm_ = shift_imm & 31; |
| 188 | if (shift_op == RRX) { |
| 189 | // encoded as ROR with shift_imm == 0 |
| 190 | ASSERT(shift_imm == 0); |
| 191 | shift_op_ = ROR; |
| 192 | shift_imm_ = 0; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | Operand::Operand(Register rm, ShiftOp shift_op, Register rs) { |
| 198 | ASSERT(shift_op != RRX); |
| 199 | rm_ = rm; |
| 200 | rs_ = no_reg; |
| 201 | shift_op_ = shift_op; |
| 202 | rs_ = rs; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | MemOperand::MemOperand(Register rn, int32_t offset, AddrMode am) { |
| 207 | rn_ = rn; |
| 208 | rm_ = no_reg; |
| 209 | offset_ = offset; |
| 210 | am_ = am; |
| 211 | } |
| 212 | |
| 213 | MemOperand::MemOperand(Register rn, Register rm, AddrMode am) { |
| 214 | rn_ = rn; |
| 215 | rm_ = rm; |
| 216 | shift_op_ = LSL; |
| 217 | shift_imm_ = 0; |
| 218 | am_ = am; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | MemOperand::MemOperand(Register rn, Register rm, |
| 223 | ShiftOp shift_op, int shift_imm, AddrMode am) { |
| 224 | ASSERT(is_uint5(shift_imm)); |
| 225 | rn_ = rn; |
| 226 | rm_ = rm; |
| 227 | shift_op_ = shift_op; |
| 228 | shift_imm_ = shift_imm & 31; |
| 229 | am_ = am; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | // ----------------------------------------------------------------------------- |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 234 | // Specific instructions, constants, and masks. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 236 | // add(sp, sp, 4) instruction (aka Pop()) |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 237 | const Instr kPopInstruction = |
| 238 | al | PostIndex | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 239 | // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) |
| 240 | // register r is not encoded. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 241 | const Instr kPushRegPattern = |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 242 | al | B26 | 4 | NegPreIndex | sp.code() * B16; |
| 243 | // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) |
| 244 | // register r is not encoded. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 245 | const Instr kPopRegPattern = |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 246 | al | B26 | L | 4 | PostIndex | sp.code() * B16; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 247 | // mov lr, pc |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 248 | const Instr kMovLrPc = al | MOV | pc.code() | lr.code() * B12; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 249 | // ldr rd, [pc, #offset] |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 250 | const Instr kLdrPCMask = kCondMask | 15 * B24 | 7 * B20 | 15 * B16; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 251 | const Instr kLdrPCPattern = al | 5 * B24 | L | pc.code() * B16; |
| 252 | // blxcc rm |
| 253 | const Instr kBlxRegMask = |
| 254 | 15 * B24 | 15 * B20 | 15 * B16 | 15 * B12 | 15 * B8 | 15 * B4; |
| 255 | const Instr kBlxRegPattern = |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 256 | B24 | B21 | 15 * B16 | 15 * B12 | 15 * B8 | BLX; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 257 | const Instr kMovMvnMask = 0x6d * B21 | 0xf * B16; |
| 258 | const Instr kMovMvnPattern = 0xd * B21; |
| 259 | const Instr kMovMvnFlip = B22; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 260 | const Instr kMovLeaveCCMask = 0xdff * B16; |
| 261 | const Instr kMovLeaveCCPattern = 0x1a0 * B16; |
| 262 | const Instr kMovwMask = 0xff * B20; |
| 263 | const Instr kMovwPattern = 0x30 * B20; |
| 264 | const Instr kMovwLeaveCCFlip = 0x5 * B21; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 265 | const Instr kCmpCmnMask = 0xdd * B20 | 0xf * B12; |
| 266 | const Instr kCmpCmnPattern = 0x15 * B20; |
| 267 | const Instr kCmpCmnFlip = B21; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 268 | const Instr kAddSubFlip = 0x6 * B21; |
| 269 | const Instr kAndBicFlip = 0xe * B21; |
| 270 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 271 | // A mask for the Rd register for push, pop, ldr, str instructions. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 272 | const Instr kLdrRegFpOffsetPattern = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 273 | al | B26 | L | Offset | fp.code() * B16; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 274 | const Instr kStrRegFpOffsetPattern = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 275 | al | B26 | Offset | fp.code() * B16; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 276 | const Instr kLdrRegFpNegOffsetPattern = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 277 | al | B26 | L | NegOffset | fp.code() * B16; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 278 | const Instr kStrRegFpNegOffsetPattern = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 279 | al | B26 | NegOffset | fp.code() * B16; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 280 | const Instr kLdrStrInstrTypeMask = 0xffff0000; |
| 281 | const Instr kLdrStrInstrArgumentMask = 0x0000ffff; |
| 282 | const Instr kLdrStrOffsetMask = 0x00000fff; |
| 283 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 284 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 285 | // Spare buffer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | static const int kMinimalBufferSize = 4*KB; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 288 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 289 | Assembler::Assembler(Isolate* arg_isolate, void* buffer, int buffer_size) |
| 290 | : AssemblerBase(arg_isolate), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 291 | positions_recorder_(this), |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 292 | allow_peephole_optimization_(false), |
| 293 | emit_debug_code_(FLAG_debug_code) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 294 | allow_peephole_optimization_ = FLAG_peephole_optimization; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | if (buffer == NULL) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 296 | // Do our own buffer management. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | if (buffer_size <= kMinimalBufferSize) { |
| 298 | buffer_size = kMinimalBufferSize; |
| 299 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 300 | if (isolate()->assembler_spare_buffer() != NULL) { |
| 301 | buffer = isolate()->assembler_spare_buffer(); |
| 302 | isolate()->set_assembler_spare_buffer(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | if (buffer == NULL) { |
| 306 | buffer_ = NewArray<byte>(buffer_size); |
| 307 | } else { |
| 308 | buffer_ = static_cast<byte*>(buffer); |
| 309 | } |
| 310 | buffer_size_ = buffer_size; |
| 311 | own_buffer_ = true; |
| 312 | |
| 313 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 314 | // Use externally provided buffer instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | ASSERT(buffer_size > 0); |
| 316 | buffer_ = static_cast<byte*>(buffer); |
| 317 | buffer_size_ = buffer_size; |
| 318 | own_buffer_ = false; |
| 319 | } |
| 320 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 321 | // Setup buffer pointers. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | ASSERT(buffer_ != NULL); |
| 323 | pc_ = buffer_; |
| 324 | reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); |
| 325 | num_prinfo_ = 0; |
| 326 | next_buffer_check_ = 0; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 327 | const_pool_blocked_nesting_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | no_const_pool_before_ = 0; |
| 329 | last_const_pool_end_ = 0; |
| 330 | last_bound_pos_ = 0; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 331 | ast_id_for_reloc_info_ = kNoASTId; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | |
| 335 | Assembler::~Assembler() { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 336 | ASSERT(const_pool_blocked_nesting_ == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | if (own_buffer_) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 338 | if (isolate()->assembler_spare_buffer() == NULL && |
| 339 | buffer_size_ == kMinimalBufferSize) { |
| 340 | isolate()->set_assembler_spare_buffer(buffer_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 341 | } else { |
| 342 | DeleteArray(buffer_); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | |
| 348 | void Assembler::GetCode(CodeDesc* desc) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 349 | // Emit constant pool if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | CheckConstPool(true, false); |
| 351 | ASSERT(num_prinfo_ == 0); |
| 352 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 353 | // Setup code descriptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | desc->buffer = buffer_; |
| 355 | desc->buffer_size = buffer_size_; |
| 356 | desc->instr_size = pc_offset(); |
| 357 | desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | void Assembler::Align(int m) { |
| 362 | ASSERT(m >= 4 && IsPowerOf2(m)); |
| 363 | while ((pc_offset() & (m - 1)) != 0) { |
| 364 | nop(); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 369 | void Assembler::CodeTargetAlign() { |
| 370 | // Preferred alignment of jump targets on some ARM chips. |
| 371 | Align(8); |
| 372 | } |
| 373 | |
| 374 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 375 | Condition Assembler::GetCondition(Instr instr) { |
| 376 | return Instruction::ConditionField(instr); |
| 377 | } |
| 378 | |
| 379 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 380 | bool Assembler::IsBranch(Instr instr) { |
| 381 | return (instr & (B27 | B25)) == (B27 | B25); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | int Assembler::GetBranchOffset(Instr instr) { |
| 386 | ASSERT(IsBranch(instr)); |
| 387 | // Take the jump offset in the lower 24 bits, sign extend it and multiply it |
| 388 | // with 4 to get the offset in bytes. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 389 | return ((instr & kImm24Mask) << 8) >> 6; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
| 393 | bool Assembler::IsLdrRegisterImmediate(Instr instr) { |
| 394 | return (instr & (B27 | B26 | B25 | B22 | B20)) == (B26 | B20); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | int Assembler::GetLdrRegisterImmediateOffset(Instr instr) { |
| 399 | ASSERT(IsLdrRegisterImmediate(instr)); |
| 400 | bool positive = (instr & B23) == B23; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 401 | int offset = instr & kOff12Mask; // Zero extended offset. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 402 | return positive ? offset : -offset; |
| 403 | } |
| 404 | |
| 405 | |
| 406 | Instr Assembler::SetLdrRegisterImmediateOffset(Instr instr, int offset) { |
| 407 | ASSERT(IsLdrRegisterImmediate(instr)); |
| 408 | bool positive = offset >= 0; |
| 409 | if (!positive) offset = -offset; |
| 410 | ASSERT(is_uint12(offset)); |
| 411 | // Set bit indicating whether the offset should be added. |
| 412 | instr = (instr & ~B23) | (positive ? B23 : 0); |
| 413 | // Set the actual offset. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 414 | return (instr & ~kOff12Mask) | offset; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 418 | bool Assembler::IsStrRegisterImmediate(Instr instr) { |
| 419 | return (instr & (B27 | B26 | B25 | B22 | B20)) == B26; |
| 420 | } |
| 421 | |
| 422 | |
| 423 | Instr Assembler::SetStrRegisterImmediateOffset(Instr instr, int offset) { |
| 424 | ASSERT(IsStrRegisterImmediate(instr)); |
| 425 | bool positive = offset >= 0; |
| 426 | if (!positive) offset = -offset; |
| 427 | ASSERT(is_uint12(offset)); |
| 428 | // Set bit indicating whether the offset should be added. |
| 429 | instr = (instr & ~B23) | (positive ? B23 : 0); |
| 430 | // Set the actual offset. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 431 | return (instr & ~kOff12Mask) | offset; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
| 435 | bool Assembler::IsAddRegisterImmediate(Instr instr) { |
| 436 | return (instr & (B27 | B26 | B25 | B24 | B23 | B22 | B21)) == (B25 | B23); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | Instr Assembler::SetAddRegisterImmediateOffset(Instr instr, int offset) { |
| 441 | ASSERT(IsAddRegisterImmediate(instr)); |
| 442 | ASSERT(offset >= 0); |
| 443 | ASSERT(is_uint12(offset)); |
| 444 | // Set the offset. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 445 | return (instr & ~kOff12Mask) | offset; |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 449 | Register Assembler::GetRd(Instr instr) { |
| 450 | Register reg; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 451 | reg.code_ = Instruction::RdValue(instr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 452 | return reg; |
| 453 | } |
| 454 | |
| 455 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 456 | Register Assembler::GetRn(Instr instr) { |
| 457 | Register reg; |
| 458 | reg.code_ = Instruction::RnValue(instr); |
| 459 | return reg; |
| 460 | } |
| 461 | |
| 462 | |
| 463 | Register Assembler::GetRm(Instr instr) { |
| 464 | Register reg; |
| 465 | reg.code_ = Instruction::RmValue(instr); |
| 466 | return reg; |
| 467 | } |
| 468 | |
| 469 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 470 | bool Assembler::IsPush(Instr instr) { |
| 471 | return ((instr & ~kRdMask) == kPushRegPattern); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | bool Assembler::IsPop(Instr instr) { |
| 476 | return ((instr & ~kRdMask) == kPopRegPattern); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | bool Assembler::IsStrRegFpOffset(Instr instr) { |
| 481 | return ((instr & kLdrStrInstrTypeMask) == kStrRegFpOffsetPattern); |
| 482 | } |
| 483 | |
| 484 | |
| 485 | bool Assembler::IsLdrRegFpOffset(Instr instr) { |
| 486 | return ((instr & kLdrStrInstrTypeMask) == kLdrRegFpOffsetPattern); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | bool Assembler::IsStrRegFpNegOffset(Instr instr) { |
| 491 | return ((instr & kLdrStrInstrTypeMask) == kStrRegFpNegOffsetPattern); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | bool Assembler::IsLdrRegFpNegOffset(Instr instr) { |
| 496 | return ((instr & kLdrStrInstrTypeMask) == kLdrRegFpNegOffsetPattern); |
| 497 | } |
| 498 | |
| 499 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 500 | bool Assembler::IsLdrPcImmediateOffset(Instr instr) { |
| 501 | // Check the instruction is indeed a |
| 502 | // ldr<cond> <Rd>, [pc +/- offset_12]. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 503 | return (instr & (kLdrPCMask & ~kCondMask)) == 0x051f0000; |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 507 | bool Assembler::IsTstImmediate(Instr instr) { |
| 508 | return (instr & (B27 | B26 | I | kOpCodeMask | S | kRdMask)) == |
| 509 | (I | TST | S); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | bool Assembler::IsCmpRegister(Instr instr) { |
| 514 | return (instr & (B27 | B26 | I | kOpCodeMask | S | kRdMask | B4)) == |
| 515 | (CMP | S); |
| 516 | } |
| 517 | |
| 518 | |
| 519 | bool Assembler::IsCmpImmediate(Instr instr) { |
| 520 | return (instr & (B27 | B26 | I | kOpCodeMask | S | kRdMask)) == |
| 521 | (I | CMP | S); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | Register Assembler::GetCmpImmediateRegister(Instr instr) { |
| 526 | ASSERT(IsCmpImmediate(instr)); |
| 527 | return GetRn(instr); |
| 528 | } |
| 529 | |
| 530 | |
| 531 | int Assembler::GetCmpImmediateRawImmediate(Instr instr) { |
| 532 | ASSERT(IsCmpImmediate(instr)); |
| 533 | return instr & kOff12Mask; |
| 534 | } |
| 535 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | // Labels refer to positions in the (to be) generated code. |
| 537 | // There are bound, linked, and unused labels. |
| 538 | // |
| 539 | // Bound labels refer to known positions in the already |
| 540 | // generated code. pos() is the position the label refers to. |
| 541 | // |
| 542 | // Linked labels refer to unknown positions in the code |
| 543 | // to be generated; pos() is the position of the last |
| 544 | // instruction using the label. |
| 545 | |
| 546 | |
| 547 | // The link chain is terminated by a negative code position (must be aligned) |
| 548 | const int kEndOfChain = -4; |
| 549 | |
| 550 | |
| 551 | int Assembler::target_at(int pos) { |
| 552 | Instr instr = instr_at(pos); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 553 | if ((instr & ~kImm24Mask) == 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 554 | // Emitted label constant, not part of a branch. |
| 555 | return instr - (Code::kHeaderSize - kHeapObjectTag); |
| 556 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx imm24 |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 558 | int imm26 = ((instr & kImm24Mask) << 8) >> 6; |
| 559 | if ((Instruction::ConditionField(instr) == kSpecialCondition) && |
| 560 | ((instr & B24) != 0)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 561 | // blx uses bit 24 to encode bit 2 of imm26 |
| 562 | imm26 += 2; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 563 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 564 | return pos + kPcLoadDelta + imm26; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
| 568 | void Assembler::target_at_put(int pos, int target_pos) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 569 | Instr instr = instr_at(pos); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 570 | if ((instr & ~kImm24Mask) == 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 571 | ASSERT(target_pos == kEndOfChain || target_pos >= 0); |
| 572 | // Emitted label constant, not part of a branch. |
| 573 | // Make label relative to Code* of generated Code object. |
| 574 | instr_at_put(pos, target_pos + (Code::kHeaderSize - kHeapObjectTag)); |
| 575 | return; |
| 576 | } |
| 577 | int imm26 = target_pos - (pos + kPcLoadDelta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx imm24 |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 579 | if (Instruction::ConditionField(instr) == kSpecialCondition) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | // blx uses bit 24 to encode bit 2 of imm26 |
| 581 | ASSERT((imm26 & 1) == 0); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 582 | instr = (instr & ~(B24 | kImm24Mask)) | ((imm26 & 2) >> 1)*B24; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | } else { |
| 584 | ASSERT((imm26 & 3) == 0); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 585 | instr &= ~kImm24Mask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | } |
| 587 | int imm24 = imm26 >> 2; |
| 588 | ASSERT(is_int24(imm24)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 589 | instr_at_put(pos, instr | (imm24 & kImm24Mask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | |
| 593 | void Assembler::print(Label* L) { |
| 594 | if (L->is_unused()) { |
| 595 | PrintF("unused label\n"); |
| 596 | } else if (L->is_bound()) { |
| 597 | PrintF("bound label to %d\n", L->pos()); |
| 598 | } else if (L->is_linked()) { |
| 599 | Label l = *L; |
| 600 | PrintF("unbound label"); |
| 601 | while (l.is_linked()) { |
| 602 | PrintF("@ %d ", l.pos()); |
| 603 | Instr instr = instr_at(l.pos()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 604 | if ((instr & ~kImm24Mask) == 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 605 | PrintF("value\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 607 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 608 | Condition cond = Instruction::ConditionField(instr); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 609 | const char* b; |
| 610 | const char* c; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 611 | if (cond == kSpecialCondition) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 612 | b = "blx"; |
| 613 | c = ""; |
| 614 | } else { |
| 615 | if ((instr & B24) != 0) |
| 616 | b = "bl"; |
| 617 | else |
| 618 | b = "b"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 619 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 620 | switch (cond) { |
| 621 | case eq: c = "eq"; break; |
| 622 | case ne: c = "ne"; break; |
| 623 | case hs: c = "hs"; break; |
| 624 | case lo: c = "lo"; break; |
| 625 | case mi: c = "mi"; break; |
| 626 | case pl: c = "pl"; break; |
| 627 | case vs: c = "vs"; break; |
| 628 | case vc: c = "vc"; break; |
| 629 | case hi: c = "hi"; break; |
| 630 | case ls: c = "ls"; break; |
| 631 | case ge: c = "ge"; break; |
| 632 | case lt: c = "lt"; break; |
| 633 | case gt: c = "gt"; break; |
| 634 | case le: c = "le"; break; |
| 635 | case al: c = ""; break; |
| 636 | default: |
| 637 | c = ""; |
| 638 | UNREACHABLE(); |
| 639 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 641 | PrintF("%s%s\n", b, c); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | next(&l); |
| 644 | } |
| 645 | } else { |
| 646 | PrintF("label in inconsistent state (pos = %d)\n", L->pos_); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 651 | void Assembler::bind_to(Label* L, int pos) { |
| 652 | ASSERT(0 <= pos && pos <= pc_offset()); // must have a valid binding position |
| 653 | while (L->is_linked()) { |
| 654 | int fixup_pos = L->pos(); |
| 655 | next(L); // call next before overwriting link with target at fixup_pos |
| 656 | target_at_put(fixup_pos, pos); |
| 657 | } |
| 658 | L->bind_to(pos); |
| 659 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 660 | // Keep track of the last bound label so we don't eliminate any instructions |
| 661 | // before a bound label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | if (pos > last_bound_pos_) |
| 663 | last_bound_pos_ = pos; |
| 664 | } |
| 665 | |
| 666 | |
| 667 | void Assembler::link_to(Label* L, Label* appendix) { |
| 668 | if (appendix->is_linked()) { |
| 669 | if (L->is_linked()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 670 | // Append appendix to L's list. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 671 | int fixup_pos; |
| 672 | int link = L->pos(); |
| 673 | do { |
| 674 | fixup_pos = link; |
| 675 | link = target_at(fixup_pos); |
| 676 | } while (link > 0); |
| 677 | ASSERT(link == kEndOfChain); |
| 678 | target_at_put(fixup_pos, appendix->pos()); |
| 679 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 680 | // L is empty, simply use appendix. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | *L = *appendix; |
| 682 | } |
| 683 | } |
| 684 | appendix->Unuse(); // appendix should not be used anymore |
| 685 | } |
| 686 | |
| 687 | |
| 688 | void Assembler::bind(Label* L) { |
| 689 | ASSERT(!L->is_bound()); // label can only be bound once |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | bind_to(L, pc_offset()); |
| 691 | } |
| 692 | |
| 693 | |
| 694 | void Assembler::next(Label* L) { |
| 695 | ASSERT(L->is_linked()); |
| 696 | int link = target_at(L->pos()); |
| 697 | if (link > 0) { |
| 698 | L->link_to(link); |
| 699 | } else { |
| 700 | ASSERT(link == kEndOfChain); |
| 701 | L->Unuse(); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 706 | static Instr EncodeMovwImmediate(uint32_t immediate) { |
| 707 | ASSERT(immediate < 0x10000); |
| 708 | return ((immediate & 0xf000) << 4) | (immediate & 0xfff); |
| 709 | } |
| 710 | |
| 711 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 712 | // Low-level code emission routines depending on the addressing mode. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 713 | // If this returns true then you have to use the rotate_imm and immed_8 |
| 714 | // that it returns, because it may have already changed the instruction |
| 715 | // to match them! |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | static bool fits_shifter(uint32_t imm32, |
| 717 | uint32_t* rotate_imm, |
| 718 | uint32_t* immed_8, |
| 719 | Instr* instr) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 720 | // imm32 must be unsigned. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | for (int rot = 0; rot < 16; rot++) { |
| 722 | uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot)); |
| 723 | if ((imm8 <= 0xff)) { |
| 724 | *rotate_imm = rot; |
| 725 | *immed_8 = imm8; |
| 726 | return true; |
| 727 | } |
| 728 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 729 | // If the opcode is one with a complementary version and the complementary |
| 730 | // immediate fits, change the opcode. |
| 731 | if (instr != NULL) { |
| 732 | if ((*instr & kMovMvnMask) == kMovMvnPattern) { |
| 733 | if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) { |
| 734 | *instr ^= kMovMvnFlip; |
| 735 | return true; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 736 | } else if ((*instr & kMovLeaveCCMask) == kMovLeaveCCPattern) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 737 | if (CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 738 | if (imm32 < 0x10000) { |
| 739 | *instr ^= kMovwLeaveCCFlip; |
| 740 | *instr |= EncodeMovwImmediate(imm32); |
| 741 | *rotate_imm = *immed_8 = 0; // Not used for movw. |
| 742 | return true; |
| 743 | } |
| 744 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 745 | } |
| 746 | } else if ((*instr & kCmpCmnMask) == kCmpCmnPattern) { |
| 747 | if (fits_shifter(-imm32, rotate_imm, immed_8, NULL)) { |
| 748 | *instr ^= kCmpCmnFlip; |
| 749 | return true; |
| 750 | } |
| 751 | } else { |
| 752 | Instr alu_insn = (*instr & kALUMask); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 753 | if (alu_insn == ADD || |
| 754 | alu_insn == SUB) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 755 | if (fits_shifter(-imm32, rotate_imm, immed_8, NULL)) { |
| 756 | *instr ^= kAddSubFlip; |
| 757 | return true; |
| 758 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 759 | } else if (alu_insn == AND || |
| 760 | alu_insn == BIC) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 761 | if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) { |
| 762 | *instr ^= kAndBicFlip; |
| 763 | return true; |
| 764 | } |
| 765 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 772 | // We have to use the temporary register for things that can be relocated even |
| 773 | // if they can be encoded in the ARM's 12 bits of immediate-offset instruction |
| 774 | // space. There is no guarantee that the relocated location can be similarly |
| 775 | // encoded. |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 776 | bool Operand::must_use_constant_pool() const { |
| 777 | if (rmode_ == RelocInfo::EXTERNAL_REFERENCE) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 778 | #ifdef DEBUG |
| 779 | if (!Serializer::enabled()) { |
| 780 | Serializer::TooLateToEnableNow(); |
| 781 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 782 | #endif // def DEBUG |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 783 | return Serializer::enabled(); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 784 | } else if (rmode_ == RelocInfo::NONE) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | return true; |
| 788 | } |
| 789 | |
| 790 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 791 | bool Operand::is_single_instruction(Instr instr) const { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 792 | if (rm_.is_valid()) return true; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 793 | uint32_t dummy1, dummy2; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 794 | if (must_use_constant_pool() || |
| 795 | !fits_shifter(imm32_, &dummy1, &dummy2, &instr)) { |
| 796 | // The immediate operand cannot be encoded as a shifter operand, or use of |
| 797 | // constant pool is required. For a mov instruction not setting the |
| 798 | // condition code additional instruction conventions can be used. |
| 799 | if ((instr & ~kCondMask) == 13*B21) { // mov, S not set |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 800 | if (must_use_constant_pool() || |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 801 | !CpuFeatures::IsSupported(ARMv7)) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 802 | // mov instruction will be an ldr from constant pool (one instruction). |
| 803 | return true; |
| 804 | } else { |
| 805 | // mov instruction will be a mov or movw followed by movt (two |
| 806 | // instructions). |
| 807 | return false; |
| 808 | } |
| 809 | } else { |
| 810 | // If this is not a mov or mvn instruction there will always an additional |
| 811 | // instructions - either mov or ldr. The mov might actually be two |
| 812 | // instructions mov or movw followed by movt so including the actual |
| 813 | // instruction two or three instructions will be generated. |
| 814 | return false; |
| 815 | } |
| 816 | } else { |
| 817 | // No use of constant pool and the immediate operand can be encoded as a |
| 818 | // shifter operand. |
| 819 | return true; |
| 820 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 824 | void Assembler::addrmod1(Instr instr, |
| 825 | Register rn, |
| 826 | Register rd, |
| 827 | const Operand& x) { |
| 828 | CheckBuffer(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 829 | ASSERT((instr & ~(kCondMask | kOpCodeMask | S)) == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 831 | // Immediate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | uint32_t rotate_imm; |
| 833 | uint32_t immed_8; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 834 | if (x.must_use_constant_pool() || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) { |
| 836 | // The immediate operand cannot be encoded as a shifter operand, so load |
| 837 | // it first to register ip and change the original instruction to use ip. |
| 838 | // However, if the original instruction is a 'mov rd, x' (not setting the |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 839 | // condition code), then replace it with a 'ldr rd, [pc]'. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 840 | CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 841 | Condition cond = Instruction::ConditionField(instr); |
| 842 | if ((instr & ~kCondMask) == 13*B21) { // mov, S not set |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 843 | if (x.must_use_constant_pool() || |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 844 | !CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 845 | RecordRelocInfo(x.rmode_, x.imm32_); |
| 846 | ldr(rd, MemOperand(pc, 0), cond); |
| 847 | } else { |
| 848 | // Will probably use movw, will certainly not use constant pool. |
| 849 | mov(rd, Operand(x.imm32_ & 0xffff), LeaveCC, cond); |
| 850 | movt(rd, static_cast<uint32_t>(x.imm32_) >> 16, cond); |
| 851 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | } else { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 853 | // If this is not a mov or mvn instruction we may still be able to avoid |
| 854 | // a constant pool entry by using mvn or movw. |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 855 | if (!x.must_use_constant_pool() && |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 856 | (instr & kMovMvnMask) != kMovMvnPattern) { |
| 857 | mov(ip, x, LeaveCC, cond); |
| 858 | } else { |
| 859 | RecordRelocInfo(x.rmode_, x.imm32_); |
| 860 | ldr(ip, MemOperand(pc, 0), cond); |
| 861 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 862 | addrmod1(instr, rn, rd, Operand(ip)); |
| 863 | } |
| 864 | return; |
| 865 | } |
| 866 | instr |= I | rotate_imm*B8 | immed_8; |
| 867 | } else if (!x.rs_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 868 | // Immediate shift. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 869 | instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); |
| 870 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 871 | // Register shift. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | ASSERT(!rn.is(pc) && !rd.is(pc) && !x.rm_.is(pc) && !x.rs_.is(pc)); |
| 873 | instr |= x.rs_.code()*B8 | x.shift_op_ | B4 | x.rm_.code(); |
| 874 | } |
| 875 | emit(instr | rn.code()*B16 | rd.code()*B12); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 876 | if (rn.is(pc) || x.rm_.is(pc)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 877 | // Block constant pool emission for one instruction after reading pc. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 879 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
| 883 | void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 884 | ASSERT((instr & ~(kCondMask | B | L)) == B26); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | int am = x.am_; |
| 886 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 887 | // Immediate offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | int offset_12 = x.offset_; |
| 889 | if (offset_12 < 0) { |
| 890 | offset_12 = -offset_12; |
| 891 | am ^= U; |
| 892 | } |
| 893 | if (!is_uint12(offset_12)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 894 | // Immediate offset cannot be encoded, load it first to register ip |
| 895 | // rn (and rd in a load) should never be ip, or will be trashed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 897 | mov(ip, Operand(x.offset_), LeaveCC, Instruction::ConditionField(instr)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 898 | addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 899 | return; |
| 900 | } |
| 901 | ASSERT(offset_12 >= 0); // no masking needed |
| 902 | instr |= offset_12; |
| 903 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 904 | // Register offset (shift_imm_ and shift_op_ are 0) or scaled |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 905 | // register offset the constructors make sure than both shift_imm_ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 906 | // and shift_op_ are initialized. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | ASSERT(!x.rm_.is(pc)); |
| 908 | instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); |
| 909 | } |
| 910 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 911 | emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 916 | ASSERT((instr & ~(kCondMask | L | S6 | H)) == (B4 | B7)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 917 | ASSERT(x.rn_.is_valid()); |
| 918 | int am = x.am_; |
| 919 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 920 | // Immediate offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | int offset_8 = x.offset_; |
| 922 | if (offset_8 < 0) { |
| 923 | offset_8 = -offset_8; |
| 924 | am ^= U; |
| 925 | } |
| 926 | if (!is_uint8(offset_8)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 927 | // Immediate offset cannot be encoded, load it first to register ip |
| 928 | // rn (and rd in a load) should never be ip, or will be trashed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 929 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 930 | mov(ip, Operand(x.offset_), LeaveCC, Instruction::ConditionField(instr)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 932 | return; |
| 933 | } |
| 934 | ASSERT(offset_8 >= 0); // no masking needed |
| 935 | instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf); |
| 936 | } else if (x.shift_imm_ != 0) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 937 | // Scaled register offset not supported, load index first |
| 938 | // rn (and rd in a load) should never be ip, or will be trashed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 939 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
| 940 | mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 941 | Instruction::ConditionField(instr)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 943 | return; |
| 944 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 945 | // Register offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 946 | ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback |
| 947 | instr |= x.rm_.code(); |
| 948 | } |
| 949 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 950 | emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); |
| 951 | } |
| 952 | |
| 953 | |
| 954 | void Assembler::addrmod4(Instr instr, Register rn, RegList rl) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 955 | ASSERT((instr & ~(kCondMask | P | U | W | L)) == B27); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 956 | ASSERT(rl != 0); |
| 957 | ASSERT(!rn.is(pc)); |
| 958 | emit(instr | rn.code()*B16 | rl); |
| 959 | } |
| 960 | |
| 961 | |
| 962 | void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 963 | // Unindexed addressing is not encoded by this function. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 964 | ASSERT_EQ((B27 | B26), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 965 | (instr & ~(kCondMask | kCoprocessorMask | P | U | N | W | L))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 966 | ASSERT(x.rn_.is_valid() && !x.rm_.is_valid()); |
| 967 | int am = x.am_; |
| 968 | int offset_8 = x.offset_; |
| 969 | ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset |
| 970 | offset_8 >>= 2; |
| 971 | if (offset_8 < 0) { |
| 972 | offset_8 = -offset_8; |
| 973 | am ^= U; |
| 974 | } |
| 975 | ASSERT(is_uint8(offset_8)); // unsigned word offset must fit in a byte |
| 976 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 977 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 978 | // Post-indexed addressing requires W == 1; different than in addrmod2/3. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 979 | if ((am & P) == 0) |
| 980 | am |= W; |
| 981 | |
| 982 | ASSERT(offset_8 >= 0); // no masking needed |
| 983 | emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8); |
| 984 | } |
| 985 | |
| 986 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 987 | int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | int target_pos; |
| 989 | if (L->is_bound()) { |
| 990 | target_pos = L->pos(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 991 | } else { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 992 | if (L->is_linked()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | target_pos = L->pos(); // L's link |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 994 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 995 | target_pos = kEndOfChain; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 996 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | L->link_to(pc_offset()); |
| 998 | } |
| 999 | |
| 1000 | // Block the emission of the constant pool, since the branch instruction must |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1001 | // be emitted at the pc offset recorded by the label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1003 | return target_pos - (pc_offset() + kPcLoadDelta); |
| 1004 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1006 | |
| 1007 | void Assembler::label_at_put(Label* L, int at_offset) { |
| 1008 | int target_pos; |
| 1009 | if (L->is_bound()) { |
| 1010 | target_pos = L->pos(); |
| 1011 | } else { |
| 1012 | if (L->is_linked()) { |
| 1013 | target_pos = L->pos(); // L's link |
| 1014 | } else { |
| 1015 | target_pos = kEndOfChain; |
| 1016 | } |
| 1017 | L->link_to(at_offset); |
| 1018 | instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag)); |
| 1019 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1023 | // Branch instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | void Assembler::b(int branch_offset, Condition cond) { |
| 1025 | ASSERT((branch_offset & 3) == 0); |
| 1026 | int imm24 = branch_offset >> 2; |
| 1027 | ASSERT(is_int24(imm24)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1028 | emit(cond | B27 | B25 | (imm24 & kImm24Mask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1029 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1030 | if (cond == al) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1031 | // Dead code is a good location to emit the constant pool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1032 | CheckConstPool(false, false); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1033 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | void Assembler::bl(int branch_offset, Condition cond) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1038 | positions_recorder()->WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | ASSERT((branch_offset & 3) == 0); |
| 1040 | int imm24 = branch_offset >> 2; |
| 1041 | ASSERT(is_int24(imm24)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1042 | emit(cond | B27 | B25 | B24 | (imm24 & kImm24Mask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | void Assembler::blx(int branch_offset) { // v5 and above |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1047 | positions_recorder()->WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1048 | ASSERT((branch_offset & 1) == 0); |
| 1049 | int h = ((branch_offset & 2) >> 1)*B24; |
| 1050 | int imm24 = branch_offset >> 2; |
| 1051 | ASSERT(is_int24(imm24)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1052 | emit(kSpecialCondition | B27 | B25 | h | (imm24 & kImm24Mask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | void Assembler::blx(Register target, Condition cond) { // v5 and above |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1057 | positions_recorder()->WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | ASSERT(!target.is(pc)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1059 | emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | BLX | target.code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1064 | positions_recorder()->WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1065 | ASSERT(!target.is(pc)); // use of pc is actually allowed, but discouraged |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1066 | emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | BX | target.code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1070 | // Data-processing instructions. |
| 1071 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1072 | void Assembler::and_(Register dst, Register src1, const Operand& src2, |
| 1073 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1074 | addrmod1(cond | AND | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | void Assembler::eor(Register dst, Register src1, const Operand& src2, |
| 1079 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1080 | addrmod1(cond | EOR | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | void Assembler::sub(Register dst, Register src1, const Operand& src2, |
| 1085 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1086 | addrmod1(cond | SUB | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | void Assembler::rsb(Register dst, Register src1, const Operand& src2, |
| 1091 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1092 | addrmod1(cond | RSB | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | void Assembler::add(Register dst, Register src1, const Operand& src2, |
| 1097 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1098 | addrmod1(cond | ADD | s, src1, dst, src2); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1099 | |
| 1100 | // Eliminate pattern: push(r), pop() |
| 1101 | // str(src, MemOperand(sp, 4, NegPreIndex), al); |
| 1102 | // add(sp, sp, Operand(kPointerSize)); |
| 1103 | // Both instructions can be eliminated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1104 | if (can_peephole_optimize(2) && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1105 | // Pattern. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1106 | instr_at(pc_ - 1 * kInstrSize) == kPopInstruction && |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1107 | (instr_at(pc_ - 2 * kInstrSize) & ~kRdMask) == kPushRegPattern) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1108 | pc_ -= 2 * kInstrSize; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1109 | if (FLAG_print_peephole_optimization) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1110 | PrintF("%x push(reg)/pop() eliminated\n", pc_offset()); |
| 1111 | } |
| 1112 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | void Assembler::adc(Register dst, Register src1, const Operand& src2, |
| 1117 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1118 | addrmod1(cond | ADC | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | void Assembler::sbc(Register dst, Register src1, const Operand& src2, |
| 1123 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1124 | addrmod1(cond | SBC | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | void Assembler::rsc(Register dst, Register src1, const Operand& src2, |
| 1129 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1130 | addrmod1(cond | RSC | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | |
| 1134 | void Assembler::tst(Register src1, const Operand& src2, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1135 | addrmod1(cond | TST | S, src1, r0, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | void Assembler::teq(Register src1, const Operand& src2, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1140 | addrmod1(cond | TEQ | S, src1, r0, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | void Assembler::cmp(Register src1, const Operand& src2, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1145 | addrmod1(cond | CMP | S, src1, r0, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1149 | void Assembler::cmp_raw_immediate( |
| 1150 | Register src, int raw_immediate, Condition cond) { |
| 1151 | ASSERT(is_uint12(raw_immediate)); |
| 1152 | emit(cond | I | CMP | S | src.code() << 16 | raw_immediate); |
| 1153 | } |
| 1154 | |
| 1155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1156 | void Assembler::cmn(Register src1, const Operand& src2, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1157 | addrmod1(cond | CMN | S, src1, r0, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | void Assembler::orr(Register dst, Register src1, const Operand& src2, |
| 1162 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1163 | addrmod1(cond | ORR | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void Assembler::mov(Register dst, const Operand& src, SBit s, Condition cond) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1168 | if (dst.is(pc)) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1169 | positions_recorder()->WriteRecordedPositions(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1170 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1171 | // Don't allow nop instructions in the form mov rn, rn to be generated using |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 1172 | // the mov instruction. They must be generated using nop(int/NopMarkerTypes) |
| 1173 | // or MarkCode(int/NopMarkerTypes) pseudo instructions. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1174 | ASSERT(!(src.is_reg() && src.rm().is(dst) && s == LeaveCC && cond == al)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1175 | addrmod1(cond | MOV | s, r0, dst, src); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1179 | void Assembler::movw(Register reg, uint32_t immediate, Condition cond) { |
| 1180 | ASSERT(immediate < 0x10000); |
| 1181 | mov(reg, Operand(immediate), LeaveCC, cond); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | void Assembler::movt(Register reg, uint32_t immediate, Condition cond) { |
| 1186 | emit(cond | 0x34*B20 | reg.code()*B12 | EncodeMovwImmediate(immediate)); |
| 1187 | } |
| 1188 | |
| 1189 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1190 | void Assembler::bic(Register dst, Register src1, const Operand& src2, |
| 1191 | SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1192 | addrmod1(cond | BIC | s, src1, dst, src2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1197 | addrmod1(cond | MVN | s, r0, dst, src); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1201 | // Multiply instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1202 | void Assembler::mla(Register dst, Register src1, Register src2, Register srcA, |
| 1203 | SBit s, Condition cond) { |
| 1204 | ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc) && !srcA.is(pc)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1205 | emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 | |
| 1206 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | void Assembler::mul(Register dst, Register src1, Register src2, |
| 1211 | SBit s, Condition cond) { |
| 1212 | ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1213 | // dst goes in bits 16-19 for this instruction! |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1214 | emit(cond | s | dst.code()*B16 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | void Assembler::smlal(Register dstL, |
| 1219 | Register dstH, |
| 1220 | Register src1, |
| 1221 | Register src2, |
| 1222 | SBit s, |
| 1223 | Condition cond) { |
| 1224 | ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1225 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1226 | emit(cond | B23 | B22 | A | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1227 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | void Assembler::smull(Register dstL, |
| 1232 | Register dstH, |
| 1233 | Register src1, |
| 1234 | Register src2, |
| 1235 | SBit s, |
| 1236 | Condition cond) { |
| 1237 | ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1238 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | emit(cond | B23 | B22 | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1240 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | void Assembler::umlal(Register dstL, |
| 1245 | Register dstH, |
| 1246 | Register src1, |
| 1247 | Register src2, |
| 1248 | SBit s, |
| 1249 | Condition cond) { |
| 1250 | ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1251 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1252 | emit(cond | B23 | A | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1253 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | void Assembler::umull(Register dstL, |
| 1258 | Register dstH, |
| 1259 | Register src1, |
| 1260 | Register src2, |
| 1261 | SBit s, |
| 1262 | Condition cond) { |
| 1263 | ASSERT(!dstL.is(pc) && !dstH.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1264 | ASSERT(!dstL.is(dstH)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1265 | emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1267 | } |
| 1268 | |
| 1269 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1270 | // Miscellaneous arithmetic instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | void Assembler::clz(Register dst, Register src, Condition cond) { |
| 1272 | // v5 and above. |
| 1273 | ASSERT(!dst.is(pc) && !src.is(pc)); |
| 1274 | emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1275 | 15*B8 | CLZ | src.code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 1279 | // Saturating instructions. |
| 1280 | |
| 1281 | // Unsigned saturate. |
| 1282 | void Assembler::usat(Register dst, |
| 1283 | int satpos, |
| 1284 | const Operand& src, |
| 1285 | Condition cond) { |
| 1286 | // v6 and above. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1287 | ASSERT(CpuFeatures::IsSupported(ARMv7)); |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 1288 | ASSERT(!dst.is(pc) && !src.rm_.is(pc)); |
| 1289 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 1290 | ASSERT((src.shift_op_ == ASR) || (src.shift_op_ == LSL)); |
| 1291 | ASSERT(src.rs_.is(no_reg)); |
| 1292 | |
| 1293 | int sh = 0; |
| 1294 | if (src.shift_op_ == ASR) { |
| 1295 | sh = 1; |
| 1296 | } |
| 1297 | |
| 1298 | emit(cond | 0x6*B24 | 0xe*B20 | satpos*B16 | dst.code()*B12 | |
| 1299 | src.shift_imm_*B7 | sh*B6 | 0x1*B4 | src.rm_.code()); |
| 1300 | } |
| 1301 | |
| 1302 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1303 | // Bitfield manipulation instructions. |
| 1304 | |
| 1305 | // Unsigned bit field extract. |
| 1306 | // Extracts #width adjacent bits from position #lsb in a register, and |
| 1307 | // writes them to the low bits of a destination register. |
| 1308 | // ubfx dst, src, #lsb, #width |
| 1309 | void Assembler::ubfx(Register dst, |
| 1310 | Register src, |
| 1311 | int lsb, |
| 1312 | int width, |
| 1313 | Condition cond) { |
| 1314 | // v7 and above. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1315 | ASSERT(CpuFeatures::IsSupported(ARMv7)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1316 | ASSERT(!dst.is(pc) && !src.is(pc)); |
| 1317 | ASSERT((lsb >= 0) && (lsb <= 31)); |
| 1318 | ASSERT((width >= 1) && (width <= (32 - lsb))); |
| 1319 | emit(cond | 0xf*B23 | B22 | B21 | (width - 1)*B16 | dst.code()*B12 | |
| 1320 | lsb*B7 | B6 | B4 | src.code()); |
| 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | // Signed bit field extract. |
| 1325 | // Extracts #width adjacent bits from position #lsb in a register, and |
| 1326 | // writes them to the low bits of a destination register. The extracted |
| 1327 | // value is sign extended to fill the destination register. |
| 1328 | // sbfx dst, src, #lsb, #width |
| 1329 | void Assembler::sbfx(Register dst, |
| 1330 | Register src, |
| 1331 | int lsb, |
| 1332 | int width, |
| 1333 | Condition cond) { |
| 1334 | // v7 and above. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1335 | ASSERT(CpuFeatures::IsSupported(ARMv7)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1336 | ASSERT(!dst.is(pc) && !src.is(pc)); |
| 1337 | ASSERT((lsb >= 0) && (lsb <= 31)); |
| 1338 | ASSERT((width >= 1) && (width <= (32 - lsb))); |
| 1339 | emit(cond | 0xf*B23 | B21 | (width - 1)*B16 | dst.code()*B12 | |
| 1340 | lsb*B7 | B6 | B4 | src.code()); |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | // Bit field clear. |
| 1345 | // Sets #width adjacent bits at position #lsb in the destination register |
| 1346 | // to zero, preserving the value of the other bits. |
| 1347 | // bfc dst, #lsb, #width |
| 1348 | void Assembler::bfc(Register dst, int lsb, int width, Condition cond) { |
| 1349 | // v7 and above. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1350 | ASSERT(CpuFeatures::IsSupported(ARMv7)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1351 | ASSERT(!dst.is(pc)); |
| 1352 | ASSERT((lsb >= 0) && (lsb <= 31)); |
| 1353 | ASSERT((width >= 1) && (width <= (32 - lsb))); |
| 1354 | int msb = lsb + width - 1; |
| 1355 | emit(cond | 0x1f*B22 | msb*B16 | dst.code()*B12 | lsb*B7 | B4 | 0xf); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | // Bit field insert. |
| 1360 | // Inserts #width adjacent bits from the low bits of the source register |
| 1361 | // into position #lsb of the destination register. |
| 1362 | // bfi dst, src, #lsb, #width |
| 1363 | void Assembler::bfi(Register dst, |
| 1364 | Register src, |
| 1365 | int lsb, |
| 1366 | int width, |
| 1367 | Condition cond) { |
| 1368 | // v7 and above. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1369 | ASSERT(CpuFeatures::IsSupported(ARMv7)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1370 | ASSERT(!dst.is(pc) && !src.is(pc)); |
| 1371 | ASSERT((lsb >= 0) && (lsb <= 31)); |
| 1372 | ASSERT((width >= 1) && (width <= (32 - lsb))); |
| 1373 | int msb = lsb + width - 1; |
| 1374 | emit(cond | 0x1f*B22 | msb*B16 | dst.code()*B12 | lsb*B7 | B4 | |
| 1375 | src.code()); |
| 1376 | } |
| 1377 | |
| 1378 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1379 | // Status register access instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1380 | void Assembler::mrs(Register dst, SRegister s, Condition cond) { |
| 1381 | ASSERT(!dst.is(pc)); |
| 1382 | emit(cond | B24 | s | 15*B16 | dst.code()*B12); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | void Assembler::msr(SRegisterFieldMask fields, const Operand& src, |
| 1387 | Condition cond) { |
| 1388 | ASSERT(fields >= B16 && fields < B20); // at least one field set |
| 1389 | Instr instr; |
| 1390 | if (!src.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1391 | // Immediate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1392 | uint32_t rotate_imm; |
| 1393 | uint32_t immed_8; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1394 | if (src.must_use_constant_pool() || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1395 | !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1396 | // Immediate operand cannot be encoded, load it first to register ip. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | RecordRelocInfo(src.rmode_, src.imm32_); |
| 1398 | ldr(ip, MemOperand(pc, 0), cond); |
| 1399 | msr(fields, Operand(ip), cond); |
| 1400 | return; |
| 1401 | } |
| 1402 | instr = I | rotate_imm*B8 | immed_8; |
| 1403 | } else { |
| 1404 | ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed |
| 1405 | instr = src.rm_.code(); |
| 1406 | } |
| 1407 | emit(cond | instr | B24 | B21 | fields | 15*B12); |
| 1408 | } |
| 1409 | |
| 1410 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1411 | // Load/Store instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1412 | void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1413 | if (dst.is(pc)) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1414 | positions_recorder()->WriteRecordedPositions(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1415 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1416 | addrmod2(cond | B26 | L, dst, src); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1417 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1418 | // Eliminate pattern: push(ry), pop(rx) |
| 1419 | // str(ry, MemOperand(sp, 4, NegPreIndex), al) |
| 1420 | // ldr(rx, MemOperand(sp, 4, PostIndex), al) |
| 1421 | // Both instructions can be eliminated if ry = rx. |
| 1422 | // If ry != rx, a register copy from ry to rx is inserted |
| 1423 | // after eliminating the push and the pop instructions. |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 1424 | if (can_peephole_optimize(2)) { |
| 1425 | Instr push_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1426 | Instr pop_instr = instr_at(pc_ - 1 * kInstrSize); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1427 | |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 1428 | if (IsPush(push_instr) && IsPop(pop_instr)) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1429 | if (Instruction::RdValue(pop_instr) != Instruction::RdValue(push_instr)) { |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 1430 | // For consecutive push and pop on different registers, |
| 1431 | // we delete both the push & pop and insert a register move. |
| 1432 | // push ry, pop rx --> mov rx, ry |
| 1433 | Register reg_pushed, reg_popped; |
| 1434 | reg_pushed = GetRd(push_instr); |
| 1435 | reg_popped = GetRd(pop_instr); |
| 1436 | pc_ -= 2 * kInstrSize; |
| 1437 | // Insert a mov instruction, which is better than a pair of push & pop |
| 1438 | mov(reg_popped, reg_pushed); |
| 1439 | if (FLAG_print_peephole_optimization) { |
| 1440 | PrintF("%x push/pop (diff reg) replaced by a reg move\n", |
| 1441 | pc_offset()); |
| 1442 | } |
| 1443 | } else { |
| 1444 | // For consecutive push and pop on the same register, |
| 1445 | // both the push and the pop can be deleted. |
| 1446 | pc_ -= 2 * kInstrSize; |
| 1447 | if (FLAG_print_peephole_optimization) { |
| 1448 | PrintF("%x push/pop (same reg) eliminated\n", pc_offset()); |
| 1449 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | if (can_peephole_optimize(2)) { |
| 1455 | Instr str_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1456 | Instr ldr_instr = instr_at(pc_ - 1 * kInstrSize); |
| 1457 | |
| 1458 | if ((IsStrRegFpOffset(str_instr) && |
| 1459 | IsLdrRegFpOffset(ldr_instr)) || |
| 1460 | (IsStrRegFpNegOffset(str_instr) && |
| 1461 | IsLdrRegFpNegOffset(ldr_instr))) { |
| 1462 | if ((ldr_instr & kLdrStrInstrArgumentMask) == |
| 1463 | (str_instr & kLdrStrInstrArgumentMask)) { |
| 1464 | // Pattern: Ldr/str same fp+offset, same register. |
| 1465 | // |
| 1466 | // The following: |
| 1467 | // str rx, [fp, #-12] |
| 1468 | // ldr rx, [fp, #-12] |
| 1469 | // |
| 1470 | // Becomes: |
| 1471 | // str rx, [fp, #-12] |
| 1472 | |
| 1473 | pc_ -= 1 * kInstrSize; |
| 1474 | if (FLAG_print_peephole_optimization) { |
| 1475 | PrintF("%x str/ldr (fp + same offset), same reg\n", pc_offset()); |
| 1476 | } |
| 1477 | } else if ((ldr_instr & kLdrStrOffsetMask) == |
| 1478 | (str_instr & kLdrStrOffsetMask)) { |
| 1479 | // Pattern: Ldr/str same fp+offset, different register. |
| 1480 | // |
| 1481 | // The following: |
| 1482 | // str rx, [fp, #-12] |
| 1483 | // ldr ry, [fp, #-12] |
| 1484 | // |
| 1485 | // Becomes: |
| 1486 | // str rx, [fp, #-12] |
| 1487 | // mov ry, rx |
| 1488 | |
| 1489 | Register reg_stored, reg_loaded; |
| 1490 | reg_stored = GetRd(str_instr); |
| 1491 | reg_loaded = GetRd(ldr_instr); |
| 1492 | pc_ -= 1 * kInstrSize; |
| 1493 | // Insert a mov instruction, which is better than ldr. |
| 1494 | mov(reg_loaded, reg_stored); |
| 1495 | if (FLAG_print_peephole_optimization) { |
| 1496 | PrintF("%x str/ldr (fp + same offset), diff reg \n", pc_offset()); |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | if (can_peephole_optimize(3)) { |
| 1503 | Instr mem_write_instr = instr_at(pc_ - 3 * kInstrSize); |
| 1504 | Instr ldr_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1505 | Instr mem_read_instr = instr_at(pc_ - 1 * kInstrSize); |
| 1506 | if (IsPush(mem_write_instr) && |
| 1507 | IsPop(mem_read_instr)) { |
| 1508 | if ((IsLdrRegFpOffset(ldr_instr) || |
| 1509 | IsLdrRegFpNegOffset(ldr_instr))) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1510 | if (Instruction::RdValue(mem_write_instr) == |
| 1511 | Instruction::RdValue(mem_read_instr)) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1512 | // Pattern: push & pop from/to same register, |
| 1513 | // with a fp+offset ldr in between |
| 1514 | // |
| 1515 | // The following: |
| 1516 | // str rx, [sp, #-4]! |
| 1517 | // ldr rz, [fp, #-24] |
| 1518 | // ldr rx, [sp], #+4 |
| 1519 | // |
| 1520 | // Becomes: |
| 1521 | // if(rx == rz) |
| 1522 | // delete all |
| 1523 | // else |
| 1524 | // ldr rz, [fp, #-24] |
| 1525 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1526 | if (Instruction::RdValue(mem_write_instr) == |
| 1527 | Instruction::RdValue(ldr_instr)) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1528 | pc_ -= 3 * kInstrSize; |
| 1529 | } else { |
| 1530 | pc_ -= 3 * kInstrSize; |
| 1531 | // Reinsert back the ldr rz. |
| 1532 | emit(ldr_instr); |
| 1533 | } |
| 1534 | if (FLAG_print_peephole_optimization) { |
| 1535 | PrintF("%x push/pop -dead ldr fp+offset in middle\n", pc_offset()); |
| 1536 | } |
| 1537 | } else { |
| 1538 | // Pattern: push & pop from/to different registers |
| 1539 | // with a fp+offset ldr in between |
| 1540 | // |
| 1541 | // The following: |
| 1542 | // str rx, [sp, #-4]! |
| 1543 | // ldr rz, [fp, #-24] |
| 1544 | // ldr ry, [sp], #+4 |
| 1545 | // |
| 1546 | // Becomes: |
| 1547 | // if(ry == rz) |
| 1548 | // mov ry, rx; |
| 1549 | // else if(rx != rz) |
| 1550 | // ldr rz, [fp, #-24] |
| 1551 | // mov ry, rx |
| 1552 | // else if((ry != rz) || (rx == rz)) becomes: |
| 1553 | // mov ry, rx |
| 1554 | // ldr rz, [fp, #-24] |
| 1555 | |
| 1556 | Register reg_pushed, reg_popped; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1557 | if (Instruction::RdValue(mem_read_instr) == |
| 1558 | Instruction::RdValue(ldr_instr)) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1559 | reg_pushed = GetRd(mem_write_instr); |
| 1560 | reg_popped = GetRd(mem_read_instr); |
| 1561 | pc_ -= 3 * kInstrSize; |
| 1562 | mov(reg_popped, reg_pushed); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1563 | } else if (Instruction::RdValue(mem_write_instr) != |
| 1564 | Instruction::RdValue(ldr_instr)) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1565 | reg_pushed = GetRd(mem_write_instr); |
| 1566 | reg_popped = GetRd(mem_read_instr); |
| 1567 | pc_ -= 3 * kInstrSize; |
| 1568 | emit(ldr_instr); |
| 1569 | mov(reg_popped, reg_pushed); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1570 | } else if ((Instruction::RdValue(mem_read_instr) != |
| 1571 | Instruction::RdValue(ldr_instr)) || |
| 1572 | (Instruction::RdValue(mem_write_instr) == |
| 1573 | Instruction::RdValue(ldr_instr))) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1574 | reg_pushed = GetRd(mem_write_instr); |
| 1575 | reg_popped = GetRd(mem_read_instr); |
| 1576 | pc_ -= 3 * kInstrSize; |
| 1577 | mov(reg_popped, reg_pushed); |
| 1578 | emit(ldr_instr); |
| 1579 | } |
| 1580 | if (FLAG_print_peephole_optimization) { |
| 1581 | PrintF("%x push/pop (ldr fp+off in middle)\n", pc_offset()); |
| 1582 | } |
| 1583 | } |
| 1584 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1585 | } |
| 1586 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | void Assembler::str(Register src, const MemOperand& dst, Condition cond) { |
| 1591 | addrmod2(cond | B26, src, dst); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1592 | |
| 1593 | // Eliminate pattern: pop(), push(r) |
| 1594 | // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al |
| 1595 | // -> str r, [sp, 0], al |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1596 | if (can_peephole_optimize(2) && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1597 | // Pattern. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1598 | instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) && |
| 1599 | instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) { |
| 1600 | pc_ -= 2 * kInstrSize; |
| 1601 | emit(al | B26 | 0 | Offset | sp.code() * B16 | src.code() * B12); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1602 | if (FLAG_print_peephole_optimization) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1603 | PrintF("%x pop()/push(reg) eliminated\n", pc_offset()); |
| 1604 | } |
| 1605 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | void Assembler::ldrb(Register dst, const MemOperand& src, Condition cond) { |
| 1610 | addrmod2(cond | B26 | B | L, dst, src); |
| 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | void Assembler::strb(Register src, const MemOperand& dst, Condition cond) { |
| 1615 | addrmod2(cond | B26 | B, src, dst); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | void Assembler::ldrh(Register dst, const MemOperand& src, Condition cond) { |
| 1620 | addrmod3(cond | L | B7 | H | B4, dst, src); |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void Assembler::strh(Register src, const MemOperand& dst, Condition cond) { |
| 1625 | addrmod3(cond | B7 | H | B4, src, dst); |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) { |
| 1630 | addrmod3(cond | L | B7 | S6 | B4, dst, src); |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) { |
| 1635 | addrmod3(cond | L | B7 | S6 | H | B4, dst, src); |
| 1636 | } |
| 1637 | |
| 1638 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1639 | void Assembler::ldrd(Register dst1, Register dst2, |
| 1640 | const MemOperand& src, Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1641 | ASSERT(CpuFeatures::IsEnabled(ARMv7)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1642 | ASSERT(src.rm().is(no_reg)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1643 | ASSERT(!dst1.is(lr)); // r14. |
| 1644 | ASSERT_EQ(0, dst1.code() % 2); |
| 1645 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 1646 | addrmod3(cond | B7 | B6 | B4, dst1, src); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1650 | void Assembler::strd(Register src1, Register src2, |
| 1651 | const MemOperand& dst, Condition cond) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1652 | ASSERT(dst.rm().is(no_reg)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1653 | ASSERT(!src1.is(lr)); // r14. |
| 1654 | ASSERT_EQ(0, src1.code() % 2); |
| 1655 | ASSERT_EQ(src1.code() + 1, src2.code()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1656 | ASSERT(CpuFeatures::IsEnabled(ARMv7)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1657 | addrmod3(cond | B7 | B6 | B5 | B4, src1, dst); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1660 | // Load/Store multiple instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | void Assembler::ldm(BlockAddrMode am, |
| 1662 | Register base, |
| 1663 | RegList dst, |
| 1664 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1665 | // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1666 | ASSERT(base.is(sp) || (dst & sp.bit()) == 0); |
| 1667 | |
| 1668 | addrmod4(cond | B27 | am | L, base, dst); |
| 1669 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1670 | // Emit the constant pool after a function return implemented by ldm ..{..pc}. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1671 | if (cond == al && (dst & pc.bit()) != 0) { |
| 1672 | // There is a slight chance that the ldm instruction was actually a call, |
| 1673 | // in which case it would be wrong to return into the constant pool; we |
| 1674 | // recognize this case by checking if the emission of the pool was blocked |
| 1675 | // at the pc of the ldm instruction by a mov lr, pc instruction; if this is |
| 1676 | // the case, we emit a jump over the pool. |
| 1677 | CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize); |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | void Assembler::stm(BlockAddrMode am, |
| 1683 | Register base, |
| 1684 | RegList src, |
| 1685 | Condition cond) { |
| 1686 | addrmod4(cond | B27 | am, base, src); |
| 1687 | } |
| 1688 | |
| 1689 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1690 | // Exception-generating instructions and debugging support. |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1691 | // Stops with a non-negative code less than kNumOfWatchedStops support |
| 1692 | // enabling/disabling and a counter feature. See simulator-arm.h . |
| 1693 | void Assembler::stop(const char* msg, Condition cond, int32_t code) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1694 | #ifndef __arm__ |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1695 | ASSERT(code >= kDefaultStopCode); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1696 | // The Simulator will handle the stop instruction and get the message address. |
| 1697 | // It expects to find the address just after the svc instruction. |
| 1698 | BlockConstPoolFor(2); |
| 1699 | if (code >= 0) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1700 | svc(kStopCode + code, cond); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1701 | } else { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1702 | svc(kStopCode + kMaxStopCode, cond); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1703 | } |
| 1704 | emit(reinterpret_cast<Instr>(msg)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1705 | #else // def __arm__ |
| 1706 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1707 | if (cond != al) { |
| 1708 | Label skip; |
| 1709 | b(&skip, NegateCondition(cond)); |
| 1710 | bkpt(0); |
| 1711 | bind(&skip); |
| 1712 | } else { |
| 1713 | bkpt(0); |
| 1714 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1715 | #else // ndef CAN_USE_ARMV5_INSTRUCTIONS |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1716 | svc(0x9f0001, cond); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1717 | #endif // ndef CAN_USE_ARMV5_INSTRUCTIONS |
| 1718 | #endif // def __arm__ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | void Assembler::bkpt(uint32_t imm16) { // v5 and above |
| 1723 | ASSERT(is_uint16(imm16)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1724 | emit(al | B24 | B21 | (imm16 >> 4)*B8 | BKPT | (imm16 & 0xf)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1728 | void Assembler::svc(uint32_t imm24, Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1729 | ASSERT(is_uint24(imm24)); |
| 1730 | emit(cond | 15*B24 | imm24); |
| 1731 | } |
| 1732 | |
| 1733 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1734 | // Coprocessor instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1735 | void Assembler::cdp(Coprocessor coproc, |
| 1736 | int opcode_1, |
| 1737 | CRegister crd, |
| 1738 | CRegister crn, |
| 1739 | CRegister crm, |
| 1740 | int opcode_2, |
| 1741 | Condition cond) { |
| 1742 | ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2)); |
| 1743 | emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 | |
| 1744 | crd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | crm.code()); |
| 1745 | } |
| 1746 | |
| 1747 | |
| 1748 | void Assembler::cdp2(Coprocessor coproc, |
| 1749 | int opcode_1, |
| 1750 | CRegister crd, |
| 1751 | CRegister crn, |
| 1752 | CRegister crm, |
| 1753 | int opcode_2) { // v5 and above |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1754 | cdp(coproc, opcode_1, crd, crn, crm, opcode_2, kSpecialCondition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | |
| 1758 | void Assembler::mcr(Coprocessor coproc, |
| 1759 | int opcode_1, |
| 1760 | Register rd, |
| 1761 | CRegister crn, |
| 1762 | CRegister crm, |
| 1763 | int opcode_2, |
| 1764 | Condition cond) { |
| 1765 | ASSERT(is_uint3(opcode_1) && is_uint3(opcode_2)); |
| 1766 | emit(cond | B27 | B26 | B25 | (opcode_1 & 7)*B21 | crn.code()*B16 | |
| 1767 | rd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | B4 | crm.code()); |
| 1768 | } |
| 1769 | |
| 1770 | |
| 1771 | void Assembler::mcr2(Coprocessor coproc, |
| 1772 | int opcode_1, |
| 1773 | Register rd, |
| 1774 | CRegister crn, |
| 1775 | CRegister crm, |
| 1776 | int opcode_2) { // v5 and above |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1777 | mcr(coproc, opcode_1, rd, crn, crm, opcode_2, kSpecialCondition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | void Assembler::mrc(Coprocessor coproc, |
| 1782 | int opcode_1, |
| 1783 | Register rd, |
| 1784 | CRegister crn, |
| 1785 | CRegister crm, |
| 1786 | int opcode_2, |
| 1787 | Condition cond) { |
| 1788 | ASSERT(is_uint3(opcode_1) && is_uint3(opcode_2)); |
| 1789 | emit(cond | B27 | B26 | B25 | (opcode_1 & 7)*B21 | L | crn.code()*B16 | |
| 1790 | rd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | B4 | crm.code()); |
| 1791 | } |
| 1792 | |
| 1793 | |
| 1794 | void Assembler::mrc2(Coprocessor coproc, |
| 1795 | int opcode_1, |
| 1796 | Register rd, |
| 1797 | CRegister crn, |
| 1798 | CRegister crm, |
| 1799 | int opcode_2) { // v5 and above |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1800 | mrc(coproc, opcode_1, rd, crn, crm, opcode_2, kSpecialCondition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | void Assembler::ldc(Coprocessor coproc, |
| 1805 | CRegister crd, |
| 1806 | const MemOperand& src, |
| 1807 | LFlag l, |
| 1808 | Condition cond) { |
| 1809 | addrmod5(cond | B27 | B26 | l | L | coproc*B8, crd, src); |
| 1810 | } |
| 1811 | |
| 1812 | |
| 1813 | void Assembler::ldc(Coprocessor coproc, |
| 1814 | CRegister crd, |
| 1815 | Register rn, |
| 1816 | int option, |
| 1817 | LFlag l, |
| 1818 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1819 | // Unindexed addressing. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | ASSERT(is_uint8(option)); |
| 1821 | emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 | |
| 1822 | coproc*B8 | (option & 255)); |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | void Assembler::ldc2(Coprocessor coproc, |
| 1827 | CRegister crd, |
| 1828 | const MemOperand& src, |
| 1829 | LFlag l) { // v5 and above |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1830 | ldc(coproc, crd, src, l, kSpecialCondition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | void Assembler::ldc2(Coprocessor coproc, |
| 1835 | CRegister crd, |
| 1836 | Register rn, |
| 1837 | int option, |
| 1838 | LFlag l) { // v5 and above |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1839 | ldc(coproc, crd, rn, option, l, kSpecialCondition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1843 | // Support for VFP. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1844 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1845 | void Assembler::vldr(const DwVfpRegister dst, |
| 1846 | const Register base, |
| 1847 | int offset, |
| 1848 | const Condition cond) { |
| 1849 | // Ddst = MEM(Rbase + offset). |
| 1850 | // Instruction details available in ARM DDI 0406A, A8-628. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1851 | // cond(31-28) | 1101(27-24)| U001(23-20) | Rbase(19-16) | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1852 | // Vdst(15-12) | 1011(11-8) | offset |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1853 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1854 | int u = 1; |
| 1855 | if (offset < 0) { |
| 1856 | offset = -offset; |
| 1857 | u = 0; |
| 1858 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1859 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1860 | ASSERT(offset >= 0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1861 | if ((offset % 4) == 0 && (offset / 4) < 256) { |
| 1862 | emit(cond | u*B23 | 0xD1*B20 | base.code()*B16 | dst.code()*B12 | |
| 1863 | 0xB*B8 | ((offset / 4) & 255)); |
| 1864 | } else { |
| 1865 | // Larger offsets must be handled by computing the correct address |
| 1866 | // in the ip register. |
| 1867 | ASSERT(!base.is(ip)); |
| 1868 | if (u == 1) { |
| 1869 | add(ip, base, Operand(offset)); |
| 1870 | } else { |
| 1871 | sub(ip, base, Operand(offset)); |
| 1872 | } |
| 1873 | emit(cond | 0xD1*B20 | ip.code()*B16 | dst.code()*B12 | 0xB*B8); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | void Assembler::vldr(const DwVfpRegister dst, |
| 1879 | const MemOperand& operand, |
| 1880 | const Condition cond) { |
| 1881 | ASSERT(!operand.rm().is_valid()); |
| 1882 | ASSERT(operand.am_ == Offset); |
| 1883 | vldr(dst, operand.rn(), operand.offset(), cond); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1887 | void Assembler::vldr(const SwVfpRegister dst, |
| 1888 | const Register base, |
| 1889 | int offset, |
| 1890 | const Condition cond) { |
| 1891 | // Sdst = MEM(Rbase + offset). |
| 1892 | // Instruction details available in ARM DDI 0406A, A8-628. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1893 | // cond(31-28) | 1101(27-24)| U001(23-20) | Rbase(19-16) | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1894 | // Vdst(15-12) | 1010(11-8) | offset |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1895 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1896 | int u = 1; |
| 1897 | if (offset < 0) { |
| 1898 | offset = -offset; |
| 1899 | u = 0; |
| 1900 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1901 | int sd, d; |
| 1902 | dst.split_code(&sd, &d); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1903 | ASSERT(offset >= 0); |
| 1904 | |
| 1905 | if ((offset % 4) == 0 && (offset / 4) < 256) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | emit(cond | u*B23 | d*B22 | 0xD1*B20 | base.code()*B16 | sd*B12 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1907 | 0xA*B8 | ((offset / 4) & 255)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1908 | } else { |
| 1909 | // Larger offsets must be handled by computing the correct address |
| 1910 | // in the ip register. |
| 1911 | ASSERT(!base.is(ip)); |
| 1912 | if (u == 1) { |
| 1913 | add(ip, base, Operand(offset)); |
| 1914 | } else { |
| 1915 | sub(ip, base, Operand(offset)); |
| 1916 | } |
| 1917 | emit(cond | d*B22 | 0xD1*B20 | ip.code()*B16 | sd*B12 | 0xA*B8); |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | void Assembler::vldr(const SwVfpRegister dst, |
| 1923 | const MemOperand& operand, |
| 1924 | const Condition cond) { |
| 1925 | ASSERT(!operand.rm().is_valid()); |
| 1926 | ASSERT(operand.am_ == Offset); |
| 1927 | vldr(dst, operand.rn(), operand.offset(), cond); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1931 | void Assembler::vstr(const DwVfpRegister src, |
| 1932 | const Register base, |
| 1933 | int offset, |
| 1934 | const Condition cond) { |
| 1935 | // MEM(Rbase + offset) = Dsrc. |
| 1936 | // Instruction details available in ARM DDI 0406A, A8-786. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1937 | // cond(31-28) | 1101(27-24)| U000(23-20) | | Rbase(19-16) | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1938 | // Vsrc(15-12) | 1011(11-8) | (offset/4) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1939 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | int u = 1; |
| 1941 | if (offset < 0) { |
| 1942 | offset = -offset; |
| 1943 | u = 0; |
| 1944 | } |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1945 | ASSERT(offset >= 0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1946 | if ((offset % 4) == 0 && (offset / 4) < 256) { |
| 1947 | emit(cond | u*B23 | 0xD0*B20 | base.code()*B16 | src.code()*B12 | |
| 1948 | 0xB*B8 | ((offset / 4) & 255)); |
| 1949 | } else { |
| 1950 | // Larger offsets must be handled by computing the correct address |
| 1951 | // in the ip register. |
| 1952 | ASSERT(!base.is(ip)); |
| 1953 | if (u == 1) { |
| 1954 | add(ip, base, Operand(offset)); |
| 1955 | } else { |
| 1956 | sub(ip, base, Operand(offset)); |
| 1957 | } |
| 1958 | emit(cond | 0xD0*B20 | ip.code()*B16 | src.code()*B12 | 0xB*B8); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | void Assembler::vstr(const DwVfpRegister src, |
| 1964 | const MemOperand& operand, |
| 1965 | const Condition cond) { |
| 1966 | ASSERT(!operand.rm().is_valid()); |
| 1967 | ASSERT(operand.am_ == Offset); |
| 1968 | vstr(src, operand.rn(), operand.offset(), cond); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1972 | void Assembler::vstr(const SwVfpRegister src, |
| 1973 | const Register base, |
| 1974 | int offset, |
| 1975 | const Condition cond) { |
| 1976 | // MEM(Rbase + offset) = SSrc. |
| 1977 | // Instruction details available in ARM DDI 0406A, A8-786. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1978 | // cond(31-28) | 1101(27-24)| U000(23-20) | Rbase(19-16) | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1979 | // Vdst(15-12) | 1010(11-8) | (offset/4) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1980 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1981 | int u = 1; |
| 1982 | if (offset < 0) { |
| 1983 | offset = -offset; |
| 1984 | u = 0; |
| 1985 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1986 | int sd, d; |
| 1987 | src.split_code(&sd, &d); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1988 | ASSERT(offset >= 0); |
| 1989 | if ((offset % 4) == 0 && (offset / 4) < 256) { |
| 1990 | emit(cond | u*B23 | d*B22 | 0xD0*B20 | base.code()*B16 | sd*B12 | |
| 1991 | 0xA*B8 | ((offset / 4) & 255)); |
| 1992 | } else { |
| 1993 | // Larger offsets must be handled by computing the correct address |
| 1994 | // in the ip register. |
| 1995 | ASSERT(!base.is(ip)); |
| 1996 | if (u == 1) { |
| 1997 | add(ip, base, Operand(offset)); |
| 1998 | } else { |
| 1999 | sub(ip, base, Operand(offset)); |
| 2000 | } |
| 2001 | emit(cond | d*B22 | 0xD0*B20 | ip.code()*B16 | sd*B12 | 0xA*B8); |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | void Assembler::vstr(const SwVfpRegister src, |
| 2007 | const MemOperand& operand, |
| 2008 | const Condition cond) { |
| 2009 | ASSERT(!operand.rm().is_valid()); |
| 2010 | ASSERT(operand.am_ == Offset); |
| 2011 | vldr(src, operand.rn(), operand.offset(), cond); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2015 | void Assembler::vldm(BlockAddrMode am, |
| 2016 | Register base, |
| 2017 | DwVfpRegister first, |
| 2018 | DwVfpRegister last, |
| 2019 | Condition cond) { |
| 2020 | // Instruction details available in ARM DDI 0406A, A8-626. |
| 2021 | // cond(31-28) | 110(27-25)| PUDW1(24-20) | Rbase(19-16) | |
| 2022 | // first(15-12) | 1010(11-8) | (count * 2) |
| 2023 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 2024 | ASSERT_LE(first.code(), last.code()); |
| 2025 | ASSERT(am == ia || am == ia_w || am == db_w); |
| 2026 | ASSERT(!base.is(pc)); |
| 2027 | |
| 2028 | int sd, d; |
| 2029 | first.split_code(&sd, &d); |
| 2030 | int count = last.code() - first.code() + 1; |
| 2031 | emit(cond | B27 | B26 | am | d*B22 | B20 | base.code()*B16 | sd*B12 | |
| 2032 | 0xB*B8 | count*2); |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | void Assembler::vstm(BlockAddrMode am, |
| 2037 | Register base, |
| 2038 | DwVfpRegister first, |
| 2039 | DwVfpRegister last, |
| 2040 | Condition cond) { |
| 2041 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 2042 | // cond(31-28) | 110(27-25)| PUDW0(24-20) | Rbase(19-16) | |
| 2043 | // first(15-12) | 1011(11-8) | (count * 2) |
| 2044 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 2045 | ASSERT_LE(first.code(), last.code()); |
| 2046 | ASSERT(am == ia || am == ia_w || am == db_w); |
| 2047 | ASSERT(!base.is(pc)); |
| 2048 | |
| 2049 | int sd, d; |
| 2050 | first.split_code(&sd, &d); |
| 2051 | int count = last.code() - first.code() + 1; |
| 2052 | emit(cond | B27 | B26 | am | d*B22 | base.code()*B16 | sd*B12 | |
| 2053 | 0xB*B8 | count*2); |
| 2054 | } |
| 2055 | |
| 2056 | void Assembler::vldm(BlockAddrMode am, |
| 2057 | Register base, |
| 2058 | SwVfpRegister first, |
| 2059 | SwVfpRegister last, |
| 2060 | Condition cond) { |
| 2061 | // Instruction details available in ARM DDI 0406A, A8-626. |
| 2062 | // cond(31-28) | 110(27-25)| PUDW1(24-20) | Rbase(19-16) | |
| 2063 | // first(15-12) | 1010(11-8) | (count/2) |
| 2064 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 2065 | ASSERT_LE(first.code(), last.code()); |
| 2066 | ASSERT(am == ia || am == ia_w || am == db_w); |
| 2067 | ASSERT(!base.is(pc)); |
| 2068 | |
| 2069 | int sd, d; |
| 2070 | first.split_code(&sd, &d); |
| 2071 | int count = last.code() - first.code() + 1; |
| 2072 | emit(cond | B27 | B26 | am | d*B22 | B20 | base.code()*B16 | sd*B12 | |
| 2073 | 0xA*B8 | count); |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | void Assembler::vstm(BlockAddrMode am, |
| 2078 | Register base, |
| 2079 | SwVfpRegister first, |
| 2080 | SwVfpRegister last, |
| 2081 | Condition cond) { |
| 2082 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 2083 | // cond(31-28) | 110(27-25)| PUDW0(24-20) | Rbase(19-16) | |
| 2084 | // first(15-12) | 1011(11-8) | (count/2) |
| 2085 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 2086 | ASSERT_LE(first.code(), last.code()); |
| 2087 | ASSERT(am == ia || am == ia_w || am == db_w); |
| 2088 | ASSERT(!base.is(pc)); |
| 2089 | |
| 2090 | int sd, d; |
| 2091 | first.split_code(&sd, &d); |
| 2092 | int count = last.code() - first.code() + 1; |
| 2093 | emit(cond | B27 | B26 | am | d*B22 | base.code()*B16 | sd*B12 | |
| 2094 | 0xA*B8 | count); |
| 2095 | } |
| 2096 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2097 | static void DoubleAsTwoUInt32(double d, uint32_t* lo, uint32_t* hi) { |
| 2098 | uint64_t i; |
| 2099 | memcpy(&i, &d, 8); |
| 2100 | |
| 2101 | *lo = i & 0xffffffff; |
| 2102 | *hi = i >> 32; |
| 2103 | } |
| 2104 | |
| 2105 | // Only works for little endian floating point formats. |
| 2106 | // We don't support VFP on the mixed endian floating point platform. |
| 2107 | static bool FitsVMOVDoubleImmediate(double d, uint32_t *encoding) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2108 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2109 | |
| 2110 | // VMOV can accept an immediate of the form: |
| 2111 | // |
| 2112 | // +/- m * 2^(-n) where 16 <= m <= 31 and 0 <= n <= 7 |
| 2113 | // |
| 2114 | // The immediate is encoded using an 8-bit quantity, comprised of two |
| 2115 | // 4-bit fields. For an 8-bit immediate of the form: |
| 2116 | // |
| 2117 | // [abcdefgh] |
| 2118 | // |
| 2119 | // where a is the MSB and h is the LSB, an immediate 64-bit double can be |
| 2120 | // created of the form: |
| 2121 | // |
| 2122 | // [aBbbbbbb,bbcdefgh,00000000,00000000, |
| 2123 | // 00000000,00000000,00000000,00000000] |
| 2124 | // |
| 2125 | // where B = ~b. |
| 2126 | // |
| 2127 | |
| 2128 | uint32_t lo, hi; |
| 2129 | DoubleAsTwoUInt32(d, &lo, &hi); |
| 2130 | |
| 2131 | // The most obvious constraint is the long block of zeroes. |
| 2132 | if ((lo != 0) || ((hi & 0xffff) != 0)) { |
| 2133 | return false; |
| 2134 | } |
| 2135 | |
| 2136 | // Bits 62:55 must be all clear or all set. |
| 2137 | if (((hi & 0x3fc00000) != 0) && ((hi & 0x3fc00000) != 0x3fc00000)) { |
| 2138 | return false; |
| 2139 | } |
| 2140 | |
| 2141 | // Bit 63 must be NOT bit 62. |
| 2142 | if (((hi ^ (hi << 1)) & (0x40000000)) == 0) { |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
| 2146 | // Create the encoded immediate in the form: |
| 2147 | // [00000000,0000abcd,00000000,0000efgh] |
| 2148 | *encoding = (hi >> 16) & 0xf; // Low nybble. |
| 2149 | *encoding |= (hi >> 4) & 0x70000; // Low three bits of the high nybble. |
| 2150 | *encoding |= (hi >> 12) & 0x80000; // Top bit of the high nybble. |
| 2151 | |
| 2152 | return true; |
| 2153 | } |
| 2154 | |
| 2155 | |
| 2156 | void Assembler::vmov(const DwVfpRegister dst, |
| 2157 | double imm, |
| 2158 | const Condition cond) { |
| 2159 | // Dd = immediate |
| 2160 | // Instruction details available in ARM DDI 0406B, A8-640. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2161 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2162 | |
| 2163 | uint32_t enc; |
| 2164 | if (FitsVMOVDoubleImmediate(imm, &enc)) { |
| 2165 | // The double can be encoded in the instruction. |
| 2166 | emit(cond | 0xE*B24 | 0xB*B20 | dst.code()*B12 | 0xB*B8 | enc); |
| 2167 | } else { |
| 2168 | // Synthesise the double from ARM immediates. This could be implemented |
| 2169 | // using vldr from a constant pool. |
| 2170 | uint32_t lo, hi; |
| 2171 | DoubleAsTwoUInt32(imm, &lo, &hi); |
| 2172 | |
| 2173 | if (lo == hi) { |
| 2174 | // If the lo and hi parts of the double are equal, the literal is easier |
| 2175 | // to create. This is the case with 0.0. |
| 2176 | mov(ip, Operand(lo)); |
| 2177 | vmov(dst, ip, ip); |
| 2178 | } else { |
| 2179 | // Move the low part of the double into the lower of the corresponsing S |
| 2180 | // registers of D register dst. |
| 2181 | mov(ip, Operand(lo)); |
| 2182 | vmov(dst.low(), ip, cond); |
| 2183 | |
| 2184 | // Move the high part of the double into the higher of the corresponsing S |
| 2185 | // registers of D register dst. |
| 2186 | mov(ip, Operand(hi)); |
| 2187 | vmov(dst.high(), ip, cond); |
| 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | |
| 2193 | void Assembler::vmov(const SwVfpRegister dst, |
| 2194 | const SwVfpRegister src, |
| 2195 | const Condition cond) { |
| 2196 | // Sd = Sm |
| 2197 | // Instruction details available in ARM DDI 0406B, A8-642. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2198 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2199 | int sd, d, sm, m; |
| 2200 | dst.split_code(&sd, &d); |
| 2201 | src.split_code(&sm, &m); |
| 2202 | emit(cond | 0xE*B24 | d*B22 | 0xB*B20 | sd*B12 | 0xA*B8 | B6 | m*B5 | sm); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2206 | void Assembler::vmov(const DwVfpRegister dst, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2207 | const DwVfpRegister src, |
| 2208 | const Condition cond) { |
| 2209 | // Dd = Dm |
| 2210 | // Instruction details available in ARM DDI 0406B, A8-642. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2211 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2212 | emit(cond | 0xE*B24 | 0xB*B20 | |
| 2213 | dst.code()*B12 | 0x5*B9 | B8 | B6 | src.code()); |
| 2214 | } |
| 2215 | |
| 2216 | |
| 2217 | void Assembler::vmov(const DwVfpRegister dst, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2218 | const Register src1, |
| 2219 | const Register src2, |
| 2220 | const Condition cond) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2221 | // Dm = <Rt,Rt2>. |
| 2222 | // Instruction details available in ARM DDI 0406A, A8-646. |
| 2223 | // cond(31-28) | 1100(27-24)| 010(23-21) | op=0(20) | Rt2(19-16) | |
| 2224 | // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2225 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2226 | ASSERT(!src1.is(pc) && !src2.is(pc)); |
| 2227 | emit(cond | 0xC*B24 | B22 | src2.code()*B16 | |
| 2228 | src1.code()*B12 | 0xB*B8 | B4 | dst.code()); |
| 2229 | } |
| 2230 | |
| 2231 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2232 | void Assembler::vmov(const Register dst1, |
| 2233 | const Register dst2, |
| 2234 | const DwVfpRegister src, |
| 2235 | const Condition cond) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2236 | // <Rt,Rt2> = Dm. |
| 2237 | // Instruction details available in ARM DDI 0406A, A8-646. |
| 2238 | // cond(31-28) | 1100(27-24)| 010(23-21) | op=1(20) | Rt2(19-16) | |
| 2239 | // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2240 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2241 | ASSERT(!dst1.is(pc) && !dst2.is(pc)); |
| 2242 | emit(cond | 0xC*B24 | B22 | B20 | dst2.code()*B16 | |
| 2243 | dst1.code()*B12 | 0xB*B8 | B4 | src.code()); |
| 2244 | } |
| 2245 | |
| 2246 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2247 | void Assembler::vmov(const SwVfpRegister dst, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2248 | const Register src, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2249 | const Condition cond) { |
| 2250 | // Sn = Rt. |
| 2251 | // Instruction details available in ARM DDI 0406A, A8-642. |
| 2252 | // cond(31-28) | 1110(27-24)| 000(23-21) | op=0(20) | Vn(19-16) | |
| 2253 | // Rt(15-12) | 1010(11-8) | N(7)=0 | 00(6-5) | 1(4) | 0000(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2254 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2255 | ASSERT(!src.is(pc)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2256 | int sn, n; |
| 2257 | dst.split_code(&sn, &n); |
| 2258 | emit(cond | 0xE*B24 | sn*B16 | src.code()*B12 | 0xA*B8 | n*B7 | B4); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2262 | void Assembler::vmov(const Register dst, |
| 2263 | const SwVfpRegister src, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2264 | const Condition cond) { |
| 2265 | // Rt = Sn. |
| 2266 | // Instruction details available in ARM DDI 0406A, A8-642. |
| 2267 | // cond(31-28) | 1110(27-24)| 000(23-21) | op=1(20) | Vn(19-16) | |
| 2268 | // Rt(15-12) | 1010(11-8) | N(7)=0 | 00(6-5) | 1(4) | 0000(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2269 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2270 | ASSERT(!dst.is(pc)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2271 | int sn, n; |
| 2272 | src.split_code(&sn, &n); |
| 2273 | emit(cond | 0xE*B24 | B20 | sn*B16 | dst.code()*B12 | 0xA*B8 | n*B7 | B4); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2277 | // Type of data to read from or write to VFP register. |
| 2278 | // Used as specifier in generic vcvt instruction. |
| 2279 | enum VFPType { S32, U32, F32, F64 }; |
| 2280 | |
| 2281 | |
| 2282 | static bool IsSignedVFPType(VFPType type) { |
| 2283 | switch (type) { |
| 2284 | case S32: |
| 2285 | return true; |
| 2286 | case U32: |
| 2287 | return false; |
| 2288 | default: |
| 2289 | UNREACHABLE(); |
| 2290 | return false; |
| 2291 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2295 | static bool IsIntegerVFPType(VFPType type) { |
| 2296 | switch (type) { |
| 2297 | case S32: |
| 2298 | case U32: |
| 2299 | return true; |
| 2300 | case F32: |
| 2301 | case F64: |
| 2302 | return false; |
| 2303 | default: |
| 2304 | UNREACHABLE(); |
| 2305 | return false; |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | |
| 2310 | static bool IsDoubleVFPType(VFPType type) { |
| 2311 | switch (type) { |
| 2312 | case F32: |
| 2313 | return false; |
| 2314 | case F64: |
| 2315 | return true; |
| 2316 | default: |
| 2317 | UNREACHABLE(); |
| 2318 | return false; |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2323 | // Split five bit reg_code based on size of reg_type. |
| 2324 | // 32-bit register codes are Vm:M |
| 2325 | // 64-bit register codes are M:Vm |
| 2326 | // where Vm is four bits, and M is a single bit. |
| 2327 | static void SplitRegCode(VFPType reg_type, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2328 | int reg_code, |
| 2329 | int* vm, |
| 2330 | int* m) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2331 | ASSERT((reg_code >= 0) && (reg_code <= 31)); |
| 2332 | if (IsIntegerVFPType(reg_type) || !IsDoubleVFPType(reg_type)) { |
| 2333 | // 32 bit type. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2334 | *m = reg_code & 0x1; |
| 2335 | *vm = reg_code >> 1; |
| 2336 | } else { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2337 | // 64 bit type. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2338 | *m = (reg_code & 0x10) >> 4; |
| 2339 | *vm = reg_code & 0x0F; |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | |
| 2344 | // Encode vcvt.src_type.dst_type instruction. |
| 2345 | static Instr EncodeVCVT(const VFPType dst_type, |
| 2346 | const int dst_code, |
| 2347 | const VFPType src_type, |
| 2348 | const int src_code, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2349 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2350 | const Condition cond) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2351 | ASSERT(src_type != dst_type); |
| 2352 | int D, Vd, M, Vm; |
| 2353 | SplitRegCode(src_type, src_code, &Vm, &M); |
| 2354 | SplitRegCode(dst_type, dst_code, &Vd, &D); |
| 2355 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2356 | if (IsIntegerVFPType(dst_type) || IsIntegerVFPType(src_type)) { |
| 2357 | // Conversion between IEEE floating point and 32-bit integer. |
| 2358 | // Instruction details available in ARM DDI 0406B, A8.6.295. |
| 2359 | // cond(31-28) | 11101(27-23)| D(22) | 11(21-20) | 1(19) | opc2(18-16) | |
| 2360 | // Vd(15-12) | 101(11-9) | sz(8) | op(7) | 1(6) | M(5) | 0(4) | Vm(3-0) |
| 2361 | ASSERT(!IsIntegerVFPType(dst_type) || !IsIntegerVFPType(src_type)); |
| 2362 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2363 | int sz, opc2, op; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2364 | |
| 2365 | if (IsIntegerVFPType(dst_type)) { |
| 2366 | opc2 = IsSignedVFPType(dst_type) ? 0x5 : 0x4; |
| 2367 | sz = IsDoubleVFPType(src_type) ? 0x1 : 0x0; |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2368 | op = mode; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2369 | } else { |
| 2370 | ASSERT(IsIntegerVFPType(src_type)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2371 | opc2 = 0x0; |
| 2372 | sz = IsDoubleVFPType(dst_type) ? 0x1 : 0x0; |
| 2373 | op = IsSignedVFPType(src_type) ? 0x1 : 0x0; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | return (cond | 0xE*B24 | B23 | D*B22 | 0x3*B20 | B19 | opc2*B16 | |
| 2377 | Vd*B12 | 0x5*B9 | sz*B8 | op*B7 | B6 | M*B5 | Vm); |
| 2378 | } else { |
| 2379 | // Conversion between IEEE double and single precision. |
| 2380 | // Instruction details available in ARM DDI 0406B, A8.6.298. |
| 2381 | // cond(31-28) | 11101(27-23)| D(22) | 11(21-20) | 0111(19-16) | |
| 2382 | // Vd(15-12) | 101(11-9) | sz(8) | 1(7) | 1(6) | M(5) | 0(4) | Vm(3-0) |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2383 | int sz = IsDoubleVFPType(src_type) ? 0x1 : 0x0; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2384 | return (cond | 0xE*B24 | B23 | D*B22 | 0x3*B20 | 0x7*B16 | |
| 2385 | Vd*B12 | 0x5*B9 | sz*B8 | B7 | B6 | M*B5 | Vm); |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | |
| 2390 | void Assembler::vcvt_f64_s32(const DwVfpRegister dst, |
| 2391 | const SwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2392 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2393 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2394 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2395 | emit(EncodeVCVT(F64, dst.code(), S32, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | |
| 2399 | void Assembler::vcvt_f32_s32(const SwVfpRegister dst, |
| 2400 | const SwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2401 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2402 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2403 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2404 | emit(EncodeVCVT(F32, dst.code(), S32, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | |
| 2408 | void Assembler::vcvt_f64_u32(const DwVfpRegister dst, |
| 2409 | const SwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2410 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2411 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2412 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2413 | emit(EncodeVCVT(F64, dst.code(), U32, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | void Assembler::vcvt_s32_f64(const SwVfpRegister dst, |
| 2418 | const DwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2419 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2420 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2421 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2422 | emit(EncodeVCVT(S32, dst.code(), F64, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | void Assembler::vcvt_u32_f64(const SwVfpRegister dst, |
| 2427 | const DwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2428 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2429 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2430 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2431 | emit(EncodeVCVT(U32, dst.code(), F64, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | void Assembler::vcvt_f64_f32(const DwVfpRegister dst, |
| 2436 | const SwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2437 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2438 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2439 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2440 | emit(EncodeVCVT(F64, dst.code(), F32, src.code(), mode, cond)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | |
| 2444 | void Assembler::vcvt_f32_f64(const SwVfpRegister dst, |
| 2445 | const DwVfpRegister src, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2446 | VFPConversionMode mode, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2447 | const Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2448 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2449 | emit(EncodeVCVT(F32, dst.code(), F64, src.code(), mode, cond)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2453 | void Assembler::vneg(const DwVfpRegister dst, |
| 2454 | const DwVfpRegister src, |
| 2455 | const Condition cond) { |
| 2456 | emit(cond | 0xE*B24 | 0xB*B20 | B16 | dst.code()*B12 | |
| 2457 | 0x5*B9 | B8 | B6 | src.code()); |
| 2458 | } |
| 2459 | |
| 2460 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 2461 | void Assembler::vabs(const DwVfpRegister dst, |
| 2462 | const DwVfpRegister src, |
| 2463 | const Condition cond) { |
| 2464 | emit(cond | 0xE*B24 | 0xB*B20 | dst.code()*B12 | |
| 2465 | 0x5*B9 | B8 | 0x3*B6 | src.code()); |
| 2466 | } |
| 2467 | |
| 2468 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2469 | void Assembler::vadd(const DwVfpRegister dst, |
| 2470 | const DwVfpRegister src1, |
| 2471 | const DwVfpRegister src2, |
| 2472 | const Condition cond) { |
| 2473 | // Dd = vadd(Dn, Dm) double precision floating point addition. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2474 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 2475 | // Instruction details available in ARM DDI 0406A, A8-536. |
| 2476 | // cond(31-28) | 11100(27-23)| D=?(22) | 11(21-20) | Vn(19-16) | |
| 2477 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2478 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2479 | emit(cond | 0xE*B24 | 0x3*B20 | src1.code()*B16 | |
| 2480 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 2481 | } |
| 2482 | |
| 2483 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2484 | void Assembler::vsub(const DwVfpRegister dst, |
| 2485 | const DwVfpRegister src1, |
| 2486 | const DwVfpRegister src2, |
| 2487 | const Condition cond) { |
| 2488 | // Dd = vsub(Dn, Dm) double precision floating point subtraction. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2489 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 2490 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 2491 | // cond(31-28) | 11100(27-23)| D=?(22) | 11(21-20) | Vn(19-16) | |
| 2492 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 1(6) | M=?(5) | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2493 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2494 | emit(cond | 0xE*B24 | 0x3*B20 | src1.code()*B16 | |
| 2495 | dst.code()*B12 | 0x5*B9 | B8 | B6 | src2.code()); |
| 2496 | } |
| 2497 | |
| 2498 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2499 | void Assembler::vmul(const DwVfpRegister dst, |
| 2500 | const DwVfpRegister src1, |
| 2501 | const DwVfpRegister src2, |
| 2502 | const Condition cond) { |
| 2503 | // Dd = vmul(Dn, Dm) double precision floating point multiplication. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2504 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 2505 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 2506 | // cond(31-28) | 11100(27-23)| D=?(22) | 10(21-20) | Vn(19-16) | |
| 2507 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2508 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2509 | emit(cond | 0xE*B24 | 0x2*B20 | src1.code()*B16 | |
| 2510 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 2511 | } |
| 2512 | |
| 2513 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2514 | void Assembler::vdiv(const DwVfpRegister dst, |
| 2515 | const DwVfpRegister src1, |
| 2516 | const DwVfpRegister src2, |
| 2517 | const Condition cond) { |
| 2518 | // Dd = vdiv(Dn, Dm) double precision floating point division. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2519 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 2520 | // Instruction details available in ARM DDI 0406A, A8-584. |
| 2521 | // cond(31-28) | 11101(27-23)| D=?(22) | 00(21-20) | Vn(19-16) | |
| 2522 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=? | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2523 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2524 | emit(cond | 0xE*B24 | B23 | src1.code()*B16 | |
| 2525 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 2526 | } |
| 2527 | |
| 2528 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2529 | void Assembler::vcmp(const DwVfpRegister src1, |
| 2530 | const DwVfpRegister src2, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2531 | const Condition cond) { |
| 2532 | // vcmp(Dd, Dm) double precision floating point comparison. |
| 2533 | // Instruction details available in ARM DDI 0406A, A8-570. |
| 2534 | // cond(31-28) | 11101 (27-23)| D=?(22) | 11 (21-20) | 0100 (19-16) | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2535 | // Vd(15-12) | 101(11-9) | sz(8)=1 | E(7)=0 | 1(6) | M(5)=? | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2536 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2537 | emit(cond | 0xE*B24 |B23 | 0x3*B20 | B18 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2538 | src1.code()*B12 | 0x5*B9 | B8 | B6 | src2.code()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2542 | void Assembler::vcmp(const DwVfpRegister src1, |
| 2543 | const double src2, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2544 | const Condition cond) { |
| 2545 | // vcmp(Dd, Dm) double precision floating point comparison. |
| 2546 | // Instruction details available in ARM DDI 0406A, A8-570. |
| 2547 | // cond(31-28) | 11101 (27-23)| D=?(22) | 11 (21-20) | 0101 (19-16) | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2548 | // Vd(15-12) | 101(11-9) | sz(8)=1 | E(7)=0 | 1(6) | M(5)=? | 0(4) | 0000(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2549 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2550 | ASSERT(src2 == 0.0); |
| 2551 | emit(cond | 0xE*B24 |B23 | 0x3*B20 | B18 | B16 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2552 | src1.code()*B12 | 0x5*B9 | B8 | B6); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2556 | void Assembler::vmsr(Register dst, Condition cond) { |
| 2557 | // Instruction details available in ARM DDI 0406A, A8-652. |
| 2558 | // cond(31-28) | 1110 (27-24) | 1110(23-20)| 0001 (19-16) | |
| 2559 | // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2560 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 2561 | emit(cond | 0xE*B24 | 0xE*B20 | B16 | |
| 2562 | dst.code()*B12 | 0xA*B8 | B4); |
| 2563 | } |
| 2564 | |
| 2565 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2566 | void Assembler::vmrs(Register dst, Condition cond) { |
| 2567 | // Instruction details available in ARM DDI 0406A, A8-652. |
| 2568 | // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) | |
| 2569 | // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2570 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2571 | emit(cond | 0xE*B24 | 0xF*B20 | B16 | |
| 2572 | dst.code()*B12 | 0xA*B8 | B4); |
| 2573 | } |
| 2574 | |
| 2575 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2576 | void Assembler::vsqrt(const DwVfpRegister dst, |
| 2577 | const DwVfpRegister src, |
| 2578 | const Condition cond) { |
| 2579 | // cond(31-28) | 11101 (27-23)| D=?(22) | 11 (21-20) | 0001 (19-16) | |
| 2580 | // Vd(15-12) | 101(11-9) | sz(8)=1 | 11 (7-6) | M(5)=? | 0(4) | Vm(3-0) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2581 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2582 | emit(cond | 0xE*B24 | B23 | 0x3*B20 | B16 | |
| 2583 | dst.code()*B12 | 0x5*B9 | B8 | 3*B6 | src.code()); |
| 2584 | } |
| 2585 | |
| 2586 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2587 | // Pseudo instructions. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2588 | void Assembler::nop(int type) { |
| 2589 | // This is mov rx, rx. |
| 2590 | ASSERT(0 <= type && type <= 14); // mov pc, pc is not a nop. |
| 2591 | emit(al | 13*B21 | type*B12 | type); |
| 2592 | } |
| 2593 | |
| 2594 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2595 | bool Assembler::IsNop(Instr instr, int type) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2596 | // Check for mov rx, rx where x = type. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2597 | ASSERT(0 <= type && type <= 14); // mov pc, pc is not a nop. |
| 2598 | return instr == (al | 13*B21 | type*B12 | type); |
| 2599 | } |
| 2600 | |
| 2601 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2602 | bool Assembler::ImmediateFitsAddrMode1Instruction(int32_t imm32) { |
| 2603 | uint32_t dummy1; |
| 2604 | uint32_t dummy2; |
| 2605 | return fits_shifter(imm32, &dummy1, &dummy2, NULL); |
| 2606 | } |
| 2607 | |
| 2608 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2609 | void Assembler::BlockConstPoolFor(int instructions) { |
| 2610 | BlockConstPoolBefore(pc_offset() + instructions * kInstrSize); |
| 2611 | } |
| 2612 | |
| 2613 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2614 | // Debugging. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2615 | void Assembler::RecordJSReturn() { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2616 | positions_recorder()->WriteRecordedPositions(); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2617 | CheckBuffer(); |
| 2618 | RecordRelocInfo(RelocInfo::JS_RETURN); |
| 2619 | } |
| 2620 | |
| 2621 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2622 | void Assembler::RecordDebugBreakSlot() { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2623 | positions_recorder()->WriteRecordedPositions(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2624 | CheckBuffer(); |
| 2625 | RecordRelocInfo(RelocInfo::DEBUG_BREAK_SLOT); |
| 2626 | } |
| 2627 | |
| 2628 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | void Assembler::RecordComment(const char* msg) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2630 | if (FLAG_code_comments) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2631 | CheckBuffer(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2632 | RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2637 | void Assembler::GrowBuffer() { |
| 2638 | if (!own_buffer_) FATAL("external code buffer is too small"); |
| 2639 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2640 | // Compute new buffer size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2641 | CodeDesc desc; // the new buffer |
| 2642 | if (buffer_size_ < 4*KB) { |
| 2643 | desc.buffer_size = 4*KB; |
| 2644 | } else if (buffer_size_ < 1*MB) { |
| 2645 | desc.buffer_size = 2*buffer_size_; |
| 2646 | } else { |
| 2647 | desc.buffer_size = buffer_size_ + 1*MB; |
| 2648 | } |
| 2649 | CHECK_GT(desc.buffer_size, 0); // no overflow |
| 2650 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2651 | // Setup new buffer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | desc.buffer = NewArray<byte>(desc.buffer_size); |
| 2653 | |
| 2654 | desc.instr_size = pc_offset(); |
| 2655 | desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| 2656 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2657 | // Copy the data. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2658 | int pc_delta = desc.buffer - buffer_; |
| 2659 | int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_); |
| 2660 | memmove(desc.buffer, buffer_, desc.instr_size); |
| 2661 | memmove(reloc_info_writer.pos() + rc_delta, |
| 2662 | reloc_info_writer.pos(), desc.reloc_size); |
| 2663 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2664 | // Switch buffers. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2665 | DeleteArray(buffer_); |
| 2666 | buffer_ = desc.buffer; |
| 2667 | buffer_size_ = desc.buffer_size; |
| 2668 | pc_ += pc_delta; |
| 2669 | reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
| 2670 | reloc_info_writer.last_pc() + pc_delta); |
| 2671 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2672 | // None of our relocation types are pc relative pointing outside the code |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2673 | // buffer nor pc absolute pointing inside the code buffer, so there is no need |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2674 | // to relocate any emitted relocation entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2675 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2676 | // Relocate pending relocation entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2677 | for (int i = 0; i < num_prinfo_; i++) { |
| 2678 | RelocInfo& rinfo = prinfo_[i]; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2679 | ASSERT(rinfo.rmode() != RelocInfo::COMMENT && |
| 2680 | rinfo.rmode() != RelocInfo::POSITION); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2681 | if (rinfo.rmode() != RelocInfo::JS_RETURN) { |
| 2682 | rinfo.set_pc(rinfo.pc() + pc_delta); |
| 2683 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2688 | void Assembler::db(uint8_t data) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2689 | // No relocation info should be pending while using db. db is used |
| 2690 | // to write pure data with no pointers and the constant pool should |
| 2691 | // be emitted before using db. |
| 2692 | ASSERT(num_prinfo_ == 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2693 | CheckBuffer(); |
| 2694 | *reinterpret_cast<uint8_t*>(pc_) = data; |
| 2695 | pc_ += sizeof(uint8_t); |
| 2696 | } |
| 2697 | |
| 2698 | |
| 2699 | void Assembler::dd(uint32_t data) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2700 | // No relocation info should be pending while using dd. dd is used |
| 2701 | // to write pure data with no pointers and the constant pool should |
| 2702 | // be emitted before using dd. |
| 2703 | ASSERT(num_prinfo_ == 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2704 | CheckBuffer(); |
| 2705 | *reinterpret_cast<uint32_t*>(pc_) = data; |
| 2706 | pc_ += sizeof(uint32_t); |
| 2707 | } |
| 2708 | |
| 2709 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2710 | void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2711 | RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2712 | if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::DEBUG_BREAK_SLOT) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2713 | // Adjust code for new modes. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 2714 | ASSERT(RelocInfo::IsDebugBreakSlot(rmode) |
| 2715 | || RelocInfo::IsJSReturn(rmode) |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2716 | || RelocInfo::IsComment(rmode) |
| 2717 | || RelocInfo::IsPosition(rmode)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2718 | // These modes do not need an entry in the constant pool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2719 | } else { |
| 2720 | ASSERT(num_prinfo_ < kMaxNumPRInfo); |
| 2721 | prinfo_[num_prinfo_++] = rinfo; |
| 2722 | // Make sure the constant pool is not emitted in place of the next |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2723 | // instruction for which we just recorded relocation info. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
| 2725 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2726 | if (rinfo.rmode() != RelocInfo::NONE) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2727 | // Don't record external references unless the heap will be serialized. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2728 | if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
| 2729 | #ifdef DEBUG |
| 2730 | if (!Serializer::enabled()) { |
| 2731 | Serializer::TooLateToEnableNow(); |
| 2732 | } |
| 2733 | #endif |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2734 | if (!Serializer::enabled() && !emit_debug_code()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2735 | return; |
| 2736 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2737 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2738 | ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2739 | if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 2740 | ASSERT(ast_id_for_reloc_info_ != kNoASTId); |
| 2741 | RelocInfo reloc_info_with_ast_id(pc_, rmode, ast_id_for_reloc_info_); |
| 2742 | ast_id_for_reloc_info_ = kNoASTId; |
| 2743 | reloc_info_writer.Write(&reloc_info_with_ast_id); |
| 2744 | } else { |
| 2745 | reloc_info_writer.Write(&rinfo); |
| 2746 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | |
| 2751 | void Assembler::CheckConstPool(bool force_emit, bool require_jump) { |
| 2752 | // Calculate the offset of the next check. It will be overwritten |
| 2753 | // when a const pool is generated or when const pools are being |
| 2754 | // blocked for a specific range. |
| 2755 | next_buffer_check_ = pc_offset() + kCheckConstInterval; |
| 2756 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2757 | // There is nothing to do if there are no pending relocation info entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2758 | if (num_prinfo_ == 0) return; |
| 2759 | |
| 2760 | // We emit a constant pool at regular intervals of about kDistBetweenPools |
| 2761 | // or when requested by parameter force_emit (e.g. after each function). |
| 2762 | // We prefer not to emit a jump unless the max distance is reached or if we |
| 2763 | // are running low on slots, which can happen if a lot of constants are being |
| 2764 | // emitted (e.g. --debug-code and many static references). |
| 2765 | int dist = pc_offset() - last_const_pool_end_; |
| 2766 | if (!force_emit && dist < kMaxDistBetweenPools && |
| 2767 | (require_jump || dist < kDistBetweenPools) && |
| 2768 | // TODO(1236125): Cleanup the "magic" number below. We know that |
| 2769 | // the code generation will test every kCheckConstIntervalInst. |
| 2770 | // Thus we are safe as long as we generate less than 7 constant |
| 2771 | // entries per instruction. |
| 2772 | (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) { |
| 2773 | return; |
| 2774 | } |
| 2775 | |
| 2776 | // If we did not return by now, we need to emit the constant pool soon. |
| 2777 | |
| 2778 | // However, some small sequences of instructions must not be broken up by the |
| 2779 | // insertion of a constant pool; such sequences are protected by setting |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2780 | // either const_pool_blocked_nesting_ or no_const_pool_before_, which are |
| 2781 | // both checked here. Also, recursive calls to CheckConstPool are blocked by |
| 2782 | // no_const_pool_before_. |
| 2783 | if (const_pool_blocked_nesting_ > 0 || pc_offset() < no_const_pool_before_) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2784 | // Emission is currently blocked; make sure we try again as soon as |
| 2785 | // possible. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2786 | if (const_pool_blocked_nesting_ > 0) { |
| 2787 | next_buffer_check_ = pc_offset() + kInstrSize; |
| 2788 | } else { |
| 2789 | next_buffer_check_ = no_const_pool_before_; |
| 2790 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2791 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2792 | // Something is wrong if emission is forced and blocked at the same time. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2793 | ASSERT(!force_emit); |
| 2794 | return; |
| 2795 | } |
| 2796 | |
| 2797 | int jump_instr = require_jump ? kInstrSize : 0; |
| 2798 | |
| 2799 | // Check that the code buffer is large enough before emitting the constant |
| 2800 | // pool and relocation information (include the jump over the pool and the |
| 2801 | // constant pool marker). |
| 2802 | int max_needed_space = |
| 2803 | jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize); |
| 2804 | while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer(); |
| 2805 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2806 | // Block recursive calls to CheckConstPool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2807 | BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize + |
| 2808 | num_prinfo_*kInstrSize); |
| 2809 | // Don't bother to check for the emit calls below. |
| 2810 | next_buffer_check_ = no_const_pool_before_; |
| 2811 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2812 | // Emit jump over constant pool if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2813 | Label after_pool; |
| 2814 | if (require_jump) b(&after_pool); |
| 2815 | |
| 2816 | RecordComment("[ Constant Pool"); |
| 2817 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2818 | // Put down constant pool marker "Undefined instruction" as specified by |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2819 | // A5.6 (ARMv7) Instruction set encoding. |
| 2820 | emit(kConstantPoolMarker | num_prinfo_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2821 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2822 | // Emit constant pool entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2823 | for (int i = 0; i < num_prinfo_; i++) { |
| 2824 | RelocInfo& rinfo = prinfo_[i]; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2825 | ASSERT(rinfo.rmode() != RelocInfo::COMMENT && |
| 2826 | rinfo.rmode() != RelocInfo::POSITION && |
| 2827 | rinfo.rmode() != RelocInfo::STATEMENT_POSITION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2828 | Instr instr = instr_at(rinfo.pc()); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2829 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2830 | // Instruction to patch must be a ldr/str [pc, #offset]. |
| 2831 | // P and U set, B and W clear, Rn == pc, offset12 still 0. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2832 | ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | kOff12Mask)) == |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | (2*B25 | P | U | pc.code()*B16)); |
| 2834 | int delta = pc_ - rinfo.pc() - 8; |
| 2835 | ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32 |
| 2836 | if (delta < 0) { |
| 2837 | instr &= ~U; |
| 2838 | delta = -delta; |
| 2839 | } |
| 2840 | ASSERT(is_uint12(delta)); |
| 2841 | instr_at_put(rinfo.pc(), instr + delta); |
| 2842 | emit(rinfo.data()); |
| 2843 | } |
| 2844 | num_prinfo_ = 0; |
| 2845 | last_const_pool_end_ = pc_offset(); |
| 2846 | |
| 2847 | RecordComment("]"); |
| 2848 | |
| 2849 | if (after_pool.is_linked()) { |
| 2850 | bind(&after_pool); |
| 2851 | } |
| 2852 | |
| 2853 | // Since a constant pool was just emitted, move the check offset forward by |
| 2854 | // the standard interval. |
| 2855 | next_buffer_check_ = pc_offset() + kCheckConstInterval; |
| 2856 | } |
| 2857 | |
| 2858 | |
| 2859 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2860 | |
| 2861 | #endif // V8_TARGET_ARCH_ARM |