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. |
| 35 | // Copyright 2010 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 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 47 | // Safe default is no features. |
| 48 | unsigned CpuFeatures::supported_ = 0; |
| 49 | unsigned CpuFeatures::enabled_ = 0; |
| 50 | unsigned CpuFeatures::found_by_runtime_probing_ = 0; |
| 51 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 52 | |
| 53 | #ifdef __arm__ |
| 54 | static uint64_t CpuFeaturesImpliedByCompiler() { |
| 55 | uint64_t answer = 0; |
| 56 | #ifdef CAN_USE_ARMV7_INSTRUCTIONS |
| 57 | answer |= 1u << ARMv7; |
| 58 | #endif // def CAN_USE_ARMV7_INSTRUCTIONS |
| 59 | // If the compiler is allowed to use VFP then we can use VFP too in our code |
| 60 | // generation even when generating snapshots. This won't work for cross |
| 61 | // compilation. |
| 62 | #if defined(__VFP_FP__) && !defined(__SOFTFP__) |
| 63 | answer |= 1u << VFP3; |
| 64 | #endif // defined(__VFP_FP__) && !defined(__SOFTFP__) |
| 65 | #ifdef CAN_USE_VFP_INSTRUCTIONS |
| 66 | answer |= 1u << VFP3; |
| 67 | #endif // def CAN_USE_VFP_INSTRUCTIONS |
| 68 | return answer; |
| 69 | } |
| 70 | #endif // def __arm__ |
| 71 | |
| 72 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 73 | void CpuFeatures::Probe() { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 74 | #ifndef __arm__ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 75 | // For the simulator=arm build, use VFP when FLAG_enable_vfp3 is enabled. |
| 76 | if (FLAG_enable_vfp3) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 77 | supported_ |= 1u << VFP3; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 78 | } |
| 79 | // For the simulator=arm build, use ARMv7 when FLAG_enable_armv7 is enabled |
| 80 | if (FLAG_enable_armv7) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 81 | supported_ |= 1u << ARMv7; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 82 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 83 | #else // def __arm__ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 84 | if (Serializer::enabled()) { |
| 85 | supported_ |= OS::CpuFeaturesImpliedByPlatform(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 86 | supported_ |= CpuFeaturesImpliedByCompiler(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 87 | return; // No features if we might serialize. |
| 88 | } |
| 89 | |
| 90 | if (OS::ArmCpuHasFeature(VFP3)) { |
| 91 | // This implementation also sets the VFP flags if |
| 92 | // runtime detection of VFP returns true. |
| 93 | supported_ |= 1u << VFP3; |
| 94 | found_by_runtime_probing_ |= 1u << VFP3; |
| 95 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 96 | |
| 97 | if (OS::ArmCpuHasFeature(ARMv7)) { |
| 98 | supported_ |= 1u << ARMv7; |
| 99 | found_by_runtime_probing_ |= 1u << ARMv7; |
| 100 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 101 | #endif |
| 102 | } |
| 103 | |
| 104 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | // Implementation of RelocInfo |
| 107 | |
| 108 | const int RelocInfo::kApplyMask = 0; |
| 109 | |
| 110 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 111 | bool RelocInfo::IsCodedSpecially() { |
| 112 | // The deserializer needs to know whether a pointer is specially coded. Being |
| 113 | // specially coded on ARM means that it is a movw/movt instruction. We don't |
| 114 | // generate those yet. |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 120 | void RelocInfo::PatchCode(byte* instructions, int instruction_count) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | // Patch the code at the current address with the supplied instructions. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 122 | Instr* pc = reinterpret_cast<Instr*>(pc_); |
| 123 | Instr* instr = reinterpret_cast<Instr*>(instructions); |
| 124 | for (int i = 0; i < instruction_count; i++) { |
| 125 | *(pc + i) = *(instr + i); |
| 126 | } |
| 127 | |
| 128 | // Indicate that code has changed. |
| 129 | CPU::FlushICache(pc_, instruction_count * Assembler::kInstrSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | // 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] | 134 | // Additional guard instructions can be added if required. |
| 135 | void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | // Patch the code at the current address with a call to the target. |
| 137 | UNIMPLEMENTED(); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | // ----------------------------------------------------------------------------- |
| 142 | // Implementation of Operand and MemOperand |
| 143 | // See assembler-arm-inl.h for inlined constructors |
| 144 | |
| 145 | Operand::Operand(Handle<Object> handle) { |
| 146 | rm_ = no_reg; |
| 147 | // Verify all Objects referred by code are NOT in new space. |
| 148 | Object* obj = *handle; |
| 149 | ASSERT(!Heap::InNewSpace(obj)); |
| 150 | if (obj->IsHeapObject()) { |
| 151 | imm32_ = reinterpret_cast<intptr_t>(handle.location()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 152 | rmode_ = RelocInfo::EMBEDDED_OBJECT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | } else { |
| 154 | // no relocation needed |
| 155 | imm32_ = reinterpret_cast<intptr_t>(obj); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 156 | rmode_ = RelocInfo::NONE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 | Operand::Operand(Register rm, ShiftOp shift_op, int shift_imm) { |
| 162 | ASSERT(is_uint5(shift_imm)); |
| 163 | ASSERT(shift_op != ROR || shift_imm != 0); // use RRX if you mean it |
| 164 | rm_ = rm; |
| 165 | rs_ = no_reg; |
| 166 | shift_op_ = shift_op; |
| 167 | shift_imm_ = shift_imm & 31; |
| 168 | if (shift_op == RRX) { |
| 169 | // encoded as ROR with shift_imm == 0 |
| 170 | ASSERT(shift_imm == 0); |
| 171 | shift_op_ = ROR; |
| 172 | shift_imm_ = 0; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | Operand::Operand(Register rm, ShiftOp shift_op, Register rs) { |
| 178 | ASSERT(shift_op != RRX); |
| 179 | rm_ = rm; |
| 180 | rs_ = no_reg; |
| 181 | shift_op_ = shift_op; |
| 182 | rs_ = rs; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | MemOperand::MemOperand(Register rn, int32_t offset, AddrMode am) { |
| 187 | rn_ = rn; |
| 188 | rm_ = no_reg; |
| 189 | offset_ = offset; |
| 190 | am_ = am; |
| 191 | } |
| 192 | |
| 193 | MemOperand::MemOperand(Register rn, Register rm, AddrMode am) { |
| 194 | rn_ = rn; |
| 195 | rm_ = rm; |
| 196 | shift_op_ = LSL; |
| 197 | shift_imm_ = 0; |
| 198 | am_ = am; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | MemOperand::MemOperand(Register rn, Register rm, |
| 203 | ShiftOp shift_op, int shift_imm, AddrMode am) { |
| 204 | ASSERT(is_uint5(shift_imm)); |
| 205 | rn_ = rn; |
| 206 | rm_ = rm; |
| 207 | shift_op_ = shift_op; |
| 208 | shift_imm_ = shift_imm & 31; |
| 209 | am_ = am; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | // ----------------------------------------------------------------------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 214 | // Implementation of Assembler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 216 | // Instruction encoding bits. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | enum { |
| 218 | H = 1 << 5, // halfword (or byte) |
| 219 | S6 = 1 << 6, // signed (or unsigned) |
| 220 | L = 1 << 20, // load (or store) |
| 221 | S = 1 << 20, // set condition code (or leave unchanged) |
| 222 | W = 1 << 21, // writeback base register (or leave unchanged) |
| 223 | A = 1 << 21, // accumulate in multiply instruction (or not) |
| 224 | B = 1 << 22, // unsigned byte (or word) |
| 225 | N = 1 << 22, // long (or short) |
| 226 | U = 1 << 23, // positive (or negative) offset/index |
| 227 | P = 1 << 24, // offset/pre-indexed addressing (or post-indexed addressing) |
| 228 | I = 1 << 25, // immediate shifter operand (or not) |
| 229 | |
| 230 | B4 = 1 << 4, |
| 231 | B5 = 1 << 5, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 232 | B6 = 1 << 6, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | B7 = 1 << 7, |
| 234 | B8 = 1 << 8, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 235 | B9 = 1 << 9, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | B12 = 1 << 12, |
| 237 | B16 = 1 << 16, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 238 | B18 = 1 << 18, |
| 239 | B19 = 1 << 19, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | B20 = 1 << 20, |
| 241 | B21 = 1 << 21, |
| 242 | B22 = 1 << 22, |
| 243 | B23 = 1 << 23, |
| 244 | B24 = 1 << 24, |
| 245 | B25 = 1 << 25, |
| 246 | B26 = 1 << 26, |
| 247 | B27 = 1 << 27, |
| 248 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 249 | // Instruction bit masks. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 250 | RdMask = 15 << 12, // in str instruction |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | CondMask = 15 << 28, |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 252 | CoprocessorMask = 15 << 8, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | OpCodeMask = 15 << 21, // in data-processing instructions |
| 254 | Imm24Mask = (1 << 24) - 1, |
| 255 | Off12Mask = (1 << 12) - 1, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 256 | // Reserved condition. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | nv = 15 << 28 |
| 258 | }; |
| 259 | |
| 260 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 261 | // add(sp, sp, 4) instruction (aka Pop()) |
| 262 | static const Instr kPopInstruction = |
| 263 | al | 4 * B21 | 4 | LeaveCC | I | sp.code() * B16 | sp.code() * B12; |
| 264 | // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) |
| 265 | // register r is not encoded. |
| 266 | static const Instr kPushRegPattern = |
| 267 | al | B26 | 4 | NegPreIndex | sp.code() * B16; |
| 268 | // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) |
| 269 | // register r is not encoded. |
| 270 | static const Instr kPopRegPattern = |
| 271 | al | B26 | L | 4 | PostIndex | sp.code() * B16; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 272 | // mov lr, pc |
| 273 | const Instr kMovLrPc = al | 13*B21 | pc.code() | lr.code() * B12; |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 274 | // ldr rd, [pc, #offset] |
| 275 | const Instr kLdrPCMask = CondMask | 15 * B24 | 7 * B20 | 15 * B16; |
| 276 | const Instr kLdrPCPattern = al | 5 * B24 | L | pc.code() * B16; |
| 277 | // blxcc rm |
| 278 | const Instr kBlxRegMask = |
| 279 | 15 * B24 | 15 * B20 | 15 * B16 | 15 * B12 | 15 * B8 | 15 * B4; |
| 280 | const Instr kBlxRegPattern = |
| 281 | B24 | B21 | 15 * B16 | 15 * B12 | 15 * B8 | 3 * B4; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 282 | // A mask for the Rd register for push, pop, ldr, str instructions. |
| 283 | const Instr kRdMask = 0x0000f000; |
| 284 | static const int kRdShift = 12; |
| 285 | static const Instr kLdrRegFpOffsetPattern = |
| 286 | al | B26 | L | Offset | fp.code() * B16; |
| 287 | static const Instr kStrRegFpOffsetPattern = |
| 288 | al | B26 | Offset | fp.code() * B16; |
| 289 | static const Instr kLdrRegFpNegOffsetPattern = |
| 290 | al | B26 | L | NegOffset | fp.code() * B16; |
| 291 | static const Instr kStrRegFpNegOffsetPattern = |
| 292 | al | B26 | NegOffset | fp.code() * B16; |
| 293 | static const Instr kLdrStrInstrTypeMask = 0xffff0000; |
| 294 | static const Instr kLdrStrInstrArgumentMask = 0x0000ffff; |
| 295 | static const Instr kLdrStrOffsetMask = 0x00000fff; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 296 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 297 | // Spare buffer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 298 | static const int kMinimalBufferSize = 4*KB; |
| 299 | static byte* spare_buffer_ = NULL; |
| 300 | |
| 301 | Assembler::Assembler(void* buffer, int buffer_size) { |
| 302 | if (buffer == NULL) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 303 | // Do our own buffer management. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | if (buffer_size <= kMinimalBufferSize) { |
| 305 | buffer_size = kMinimalBufferSize; |
| 306 | |
| 307 | if (spare_buffer_ != NULL) { |
| 308 | buffer = spare_buffer_; |
| 309 | spare_buffer_ = NULL; |
| 310 | } |
| 311 | } |
| 312 | if (buffer == NULL) { |
| 313 | buffer_ = NewArray<byte>(buffer_size); |
| 314 | } else { |
| 315 | buffer_ = static_cast<byte*>(buffer); |
| 316 | } |
| 317 | buffer_size_ = buffer_size; |
| 318 | own_buffer_ = true; |
| 319 | |
| 320 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 321 | // Use externally provided buffer instead. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | ASSERT(buffer_size > 0); |
| 323 | buffer_ = static_cast<byte*>(buffer); |
| 324 | buffer_size_ = buffer_size; |
| 325 | own_buffer_ = false; |
| 326 | } |
| 327 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 328 | // Setup buffer pointers. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 329 | ASSERT(buffer_ != NULL); |
| 330 | pc_ = buffer_; |
| 331 | reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); |
| 332 | num_prinfo_ = 0; |
| 333 | next_buffer_check_ = 0; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 334 | const_pool_blocked_nesting_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 335 | no_const_pool_before_ = 0; |
| 336 | last_const_pool_end_ = 0; |
| 337 | last_bound_pos_ = 0; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 338 | current_statement_position_ = RelocInfo::kNoPosition; |
| 339 | current_position_ = RelocInfo::kNoPosition; |
| 340 | written_statement_position_ = current_statement_position_; |
| 341 | written_position_ = current_position_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
| 345 | Assembler::~Assembler() { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 346 | ASSERT(const_pool_blocked_nesting_ == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | if (own_buffer_) { |
| 348 | if (spare_buffer_ == NULL && buffer_size_ == kMinimalBufferSize) { |
| 349 | spare_buffer_ = buffer_; |
| 350 | } else { |
| 351 | DeleteArray(buffer_); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | void Assembler::GetCode(CodeDesc* desc) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 358 | // Emit constant pool if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | CheckConstPool(true, false); |
| 360 | ASSERT(num_prinfo_ == 0); |
| 361 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 362 | // Setup code descriptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 363 | desc->buffer = buffer_; |
| 364 | desc->buffer_size = buffer_size_; |
| 365 | desc->instr_size = pc_offset(); |
| 366 | desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | void Assembler::Align(int m) { |
| 371 | ASSERT(m >= 4 && IsPowerOf2(m)); |
| 372 | while ((pc_offset() & (m - 1)) != 0) { |
| 373 | nop(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 378 | bool Assembler::IsNop(Instr instr, int type) { |
| 379 | // Check for mov rx, rx. |
| 380 | ASSERT(0 <= type && type <= 14); // mov pc, pc is not a nop. |
| 381 | return instr == (al | 13*B21 | type*B12 | type); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | bool Assembler::IsBranch(Instr instr) { |
| 386 | return (instr & (B27 | B25)) == (B27 | B25); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | int Assembler::GetBranchOffset(Instr instr) { |
| 391 | ASSERT(IsBranch(instr)); |
| 392 | // Take the jump offset in the lower 24 bits, sign extend it and multiply it |
| 393 | // with 4 to get the offset in bytes. |
| 394 | return ((instr & Imm24Mask) << 8) >> 6; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | bool Assembler::IsLdrRegisterImmediate(Instr instr) { |
| 399 | return (instr & (B27 | B26 | B25 | B22 | B20)) == (B26 | B20); |
| 400 | } |
| 401 | |
| 402 | |
| 403 | int Assembler::GetLdrRegisterImmediateOffset(Instr instr) { |
| 404 | ASSERT(IsLdrRegisterImmediate(instr)); |
| 405 | bool positive = (instr & B23) == B23; |
| 406 | int offset = instr & Off12Mask; // Zero extended offset. |
| 407 | return positive ? offset : -offset; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | Instr Assembler::SetLdrRegisterImmediateOffset(Instr instr, int offset) { |
| 412 | ASSERT(IsLdrRegisterImmediate(instr)); |
| 413 | bool positive = offset >= 0; |
| 414 | if (!positive) offset = -offset; |
| 415 | ASSERT(is_uint12(offset)); |
| 416 | // Set bit indicating whether the offset should be added. |
| 417 | instr = (instr & ~B23) | (positive ? B23 : 0); |
| 418 | // Set the actual offset. |
| 419 | return (instr & ~Off12Mask) | offset; |
| 420 | } |
| 421 | |
| 422 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 423 | Register Assembler::GetRd(Instr instr) { |
| 424 | Register reg; |
| 425 | reg.code_ = ((instr & kRdMask) >> kRdShift); |
| 426 | return reg; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | bool Assembler::IsPush(Instr instr) { |
| 431 | return ((instr & ~kRdMask) == kPushRegPattern); |
| 432 | } |
| 433 | |
| 434 | |
| 435 | bool Assembler::IsPop(Instr instr) { |
| 436 | return ((instr & ~kRdMask) == kPopRegPattern); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | bool Assembler::IsStrRegFpOffset(Instr instr) { |
| 441 | return ((instr & kLdrStrInstrTypeMask) == kStrRegFpOffsetPattern); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | bool Assembler::IsLdrRegFpOffset(Instr instr) { |
| 446 | return ((instr & kLdrStrInstrTypeMask) == kLdrRegFpOffsetPattern); |
| 447 | } |
| 448 | |
| 449 | |
| 450 | bool Assembler::IsStrRegFpNegOffset(Instr instr) { |
| 451 | return ((instr & kLdrStrInstrTypeMask) == kStrRegFpNegOffsetPattern); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | bool Assembler::IsLdrRegFpNegOffset(Instr instr) { |
| 456 | return ((instr & kLdrStrInstrTypeMask) == kLdrRegFpNegOffsetPattern); |
| 457 | } |
| 458 | |
| 459 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | // Labels refer to positions in the (to be) generated code. |
| 461 | // There are bound, linked, and unused labels. |
| 462 | // |
| 463 | // Bound labels refer to known positions in the already |
| 464 | // generated code. pos() is the position the label refers to. |
| 465 | // |
| 466 | // Linked labels refer to unknown positions in the code |
| 467 | // to be generated; pos() is the position of the last |
| 468 | // instruction using the label. |
| 469 | |
| 470 | |
| 471 | // The link chain is terminated by a negative code position (must be aligned) |
| 472 | const int kEndOfChain = -4; |
| 473 | |
| 474 | |
| 475 | int Assembler::target_at(int pos) { |
| 476 | Instr instr = instr_at(pos); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 477 | if ((instr & ~Imm24Mask) == 0) { |
| 478 | // Emitted label constant, not part of a branch. |
| 479 | return instr - (Code::kHeaderSize - kHeapObjectTag); |
| 480 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx imm24 |
| 482 | int imm26 = ((instr & Imm24Mask) << 8) >> 6; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 483 | if ((instr & CondMask) == nv && (instr & B24) != 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | // blx uses bit 24 to encode bit 2 of imm26 |
| 485 | imm26 += 2; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 486 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 487 | return pos + kPcLoadDelta + imm26; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
| 491 | void Assembler::target_at_put(int pos, int target_pos) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 492 | Instr instr = instr_at(pos); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 493 | if ((instr & ~Imm24Mask) == 0) { |
| 494 | ASSERT(target_pos == kEndOfChain || target_pos >= 0); |
| 495 | // Emitted label constant, not part of a branch. |
| 496 | // Make label relative to Code* of generated Code object. |
| 497 | instr_at_put(pos, target_pos + (Code::kHeaderSize - kHeapObjectTag)); |
| 498 | return; |
| 499 | } |
| 500 | int imm26 = target_pos - (pos + kPcLoadDelta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx imm24 |
| 502 | if ((instr & CondMask) == nv) { |
| 503 | // blx uses bit 24 to encode bit 2 of imm26 |
| 504 | ASSERT((imm26 & 1) == 0); |
| 505 | instr = (instr & ~(B24 | Imm24Mask)) | ((imm26 & 2) >> 1)*B24; |
| 506 | } else { |
| 507 | ASSERT((imm26 & 3) == 0); |
| 508 | instr &= ~Imm24Mask; |
| 509 | } |
| 510 | int imm24 = imm26 >> 2; |
| 511 | ASSERT(is_int24(imm24)); |
| 512 | instr_at_put(pos, instr | (imm24 & Imm24Mask)); |
| 513 | } |
| 514 | |
| 515 | |
| 516 | void Assembler::print(Label* L) { |
| 517 | if (L->is_unused()) { |
| 518 | PrintF("unused label\n"); |
| 519 | } else if (L->is_bound()) { |
| 520 | PrintF("bound label to %d\n", L->pos()); |
| 521 | } else if (L->is_linked()) { |
| 522 | Label l = *L; |
| 523 | PrintF("unbound label"); |
| 524 | while (l.is_linked()) { |
| 525 | PrintF("@ %d ", l.pos()); |
| 526 | Instr instr = instr_at(l.pos()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 527 | if ((instr & ~Imm24Mask) == 0) { |
| 528 | PrintF("value\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 530 | ASSERT((instr & 7*B25) == 5*B25); // b, bl, or blx |
| 531 | int cond = instr & CondMask; |
| 532 | const char* b; |
| 533 | const char* c; |
| 534 | if (cond == nv) { |
| 535 | b = "blx"; |
| 536 | c = ""; |
| 537 | } else { |
| 538 | if ((instr & B24) != 0) |
| 539 | b = "bl"; |
| 540 | else |
| 541 | b = "b"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 542 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 543 | switch (cond) { |
| 544 | case eq: c = "eq"; break; |
| 545 | case ne: c = "ne"; break; |
| 546 | case hs: c = "hs"; break; |
| 547 | case lo: c = "lo"; break; |
| 548 | case mi: c = "mi"; break; |
| 549 | case pl: c = "pl"; break; |
| 550 | case vs: c = "vs"; break; |
| 551 | case vc: c = "vc"; break; |
| 552 | case hi: c = "hi"; break; |
| 553 | case ls: c = "ls"; break; |
| 554 | case ge: c = "ge"; break; |
| 555 | case lt: c = "lt"; break; |
| 556 | case gt: c = "gt"; break; |
| 557 | case le: c = "le"; break; |
| 558 | case al: c = ""; break; |
| 559 | default: |
| 560 | c = ""; |
| 561 | UNREACHABLE(); |
| 562 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 564 | PrintF("%s%s\n", b, c); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | next(&l); |
| 567 | } |
| 568 | } else { |
| 569 | PrintF("label in inconsistent state (pos = %d)\n", L->pos_); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | void Assembler::bind_to(Label* L, int pos) { |
| 575 | ASSERT(0 <= pos && pos <= pc_offset()); // must have a valid binding position |
| 576 | while (L->is_linked()) { |
| 577 | int fixup_pos = L->pos(); |
| 578 | next(L); // call next before overwriting link with target at fixup_pos |
| 579 | target_at_put(fixup_pos, pos); |
| 580 | } |
| 581 | L->bind_to(pos); |
| 582 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 583 | // Keep track of the last bound label so we don't eliminate any instructions |
| 584 | // before a bound label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 585 | if (pos > last_bound_pos_) |
| 586 | last_bound_pos_ = pos; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | void Assembler::link_to(Label* L, Label* appendix) { |
| 591 | if (appendix->is_linked()) { |
| 592 | if (L->is_linked()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 593 | // Append appendix to L's list. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 594 | int fixup_pos; |
| 595 | int link = L->pos(); |
| 596 | do { |
| 597 | fixup_pos = link; |
| 598 | link = target_at(fixup_pos); |
| 599 | } while (link > 0); |
| 600 | ASSERT(link == kEndOfChain); |
| 601 | target_at_put(fixup_pos, appendix->pos()); |
| 602 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 603 | // L is empty, simply use appendix. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | *L = *appendix; |
| 605 | } |
| 606 | } |
| 607 | appendix->Unuse(); // appendix should not be used anymore |
| 608 | } |
| 609 | |
| 610 | |
| 611 | void Assembler::bind(Label* L) { |
| 612 | ASSERT(!L->is_bound()); // label can only be bound once |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | bind_to(L, pc_offset()); |
| 614 | } |
| 615 | |
| 616 | |
| 617 | void Assembler::next(Label* L) { |
| 618 | ASSERT(L->is_linked()); |
| 619 | int link = target_at(L->pos()); |
| 620 | if (link > 0) { |
| 621 | L->link_to(link); |
| 622 | } else { |
| 623 | ASSERT(link == kEndOfChain); |
| 624 | L->Unuse(); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 629 | // Low-level code emission routines depending on the addressing mode. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | static bool fits_shifter(uint32_t imm32, |
| 631 | uint32_t* rotate_imm, |
| 632 | uint32_t* immed_8, |
| 633 | Instr* instr) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 634 | // imm32 must be unsigned. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | for (int rot = 0; rot < 16; rot++) { |
| 636 | uint32_t imm8 = (imm32 << 2*rot) | (imm32 >> (32 - 2*rot)); |
| 637 | if ((imm8 <= 0xff)) { |
| 638 | *rotate_imm = rot; |
| 639 | *immed_8 = imm8; |
| 640 | return true; |
| 641 | } |
| 642 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 643 | // If the opcode is mov or mvn and if ~imm32 fits, change the opcode. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | if (instr != NULL && (*instr & 0xd*B21) == 0xd*B21) { |
| 645 | if (fits_shifter(~imm32, rotate_imm, immed_8, NULL)) { |
| 646 | *instr ^= 0x2*B21; |
| 647 | return true; |
| 648 | } |
| 649 | } |
| 650 | return false; |
| 651 | } |
| 652 | |
| 653 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 654 | // We have to use the temporary register for things that can be relocated even |
| 655 | // if they can be encoded in the ARM's 12 bits of immediate-offset instruction |
| 656 | // space. There is no guarantee that the relocated location can be similarly |
| 657 | // encoded. |
| 658 | static bool MustUseIp(RelocInfo::Mode rmode) { |
| 659 | if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 660 | #ifdef DEBUG |
| 661 | if (!Serializer::enabled()) { |
| 662 | Serializer::TooLateToEnableNow(); |
| 663 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 664 | #endif // def DEBUG |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 665 | return Serializer::enabled(); |
| 666 | } else if (rmode == RelocInfo::NONE) { |
| 667 | return false; |
| 668 | } |
| 669 | return true; |
| 670 | } |
| 671 | |
| 672 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 673 | void Assembler::addrmod1(Instr instr, |
| 674 | Register rn, |
| 675 | Register rd, |
| 676 | const Operand& x) { |
| 677 | CheckBuffer(); |
| 678 | ASSERT((instr & ~(CondMask | OpCodeMask | S)) == 0); |
| 679 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 680 | // Immediate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | uint32_t rotate_imm; |
| 682 | uint32_t immed_8; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 683 | if (MustUseIp(x.rmode_) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | !fits_shifter(x.imm32_, &rotate_imm, &immed_8, &instr)) { |
| 685 | // The immediate operand cannot be encoded as a shifter operand, so load |
| 686 | // it first to register ip and change the original instruction to use ip. |
| 687 | // 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] | 688 | // condition code), then replace it with a 'ldr rd, [pc]'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | RecordRelocInfo(x.rmode_, x.imm32_); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 690 | CHECK(!rn.is(ip)); // rn should never be ip, or will be trashed |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 691 | Condition cond = static_cast<Condition>(instr & CondMask); |
| 692 | if ((instr & ~CondMask) == 13*B21) { // mov, S not set |
| 693 | ldr(rd, MemOperand(pc, 0), cond); |
| 694 | } else { |
| 695 | ldr(ip, MemOperand(pc, 0), cond); |
| 696 | addrmod1(instr, rn, rd, Operand(ip)); |
| 697 | } |
| 698 | return; |
| 699 | } |
| 700 | instr |= I | rotate_imm*B8 | immed_8; |
| 701 | } else if (!x.rs_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 702 | // Immediate shift. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | instr |= x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); |
| 704 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 705 | // Register shift. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | ASSERT(!rn.is(pc) && !rd.is(pc) && !x.rm_.is(pc) && !x.rs_.is(pc)); |
| 707 | instr |= x.rs_.code()*B8 | x.shift_op_ | B4 | x.rm_.code(); |
| 708 | } |
| 709 | emit(instr | rn.code()*B16 | rd.code()*B12); |
| 710 | if (rn.is(pc) || x.rm_.is(pc)) |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 711 | // Block constant pool emission for one instruction after reading pc. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 712 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | void Assembler::addrmod2(Instr instr, Register rd, const MemOperand& x) { |
| 717 | ASSERT((instr & ~(CondMask | B | L)) == B26); |
| 718 | int am = x.am_; |
| 719 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 720 | // Immediate offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | int offset_12 = x.offset_; |
| 722 | if (offset_12 < 0) { |
| 723 | offset_12 = -offset_12; |
| 724 | am ^= U; |
| 725 | } |
| 726 | if (!is_uint12(offset_12)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 727 | // Immediate offset cannot be encoded, load it first to register ip |
| 728 | // 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] | 729 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
| 730 | mov(ip, Operand(x.offset_), LeaveCC, |
| 731 | static_cast<Condition>(instr & CondMask)); |
| 732 | addrmod2(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 733 | return; |
| 734 | } |
| 735 | ASSERT(offset_12 >= 0); // no masking needed |
| 736 | instr |= offset_12; |
| 737 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 738 | // Register offset (shift_imm_ and shift_op_ are 0) or scaled |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | // register offset the constructors make sure than both shift_imm_ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 740 | // and shift_op_ are initialized. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 741 | ASSERT(!x.rm_.is(pc)); |
| 742 | instr |= B25 | x.shift_imm_*B7 | x.shift_op_ | x.rm_.code(); |
| 743 | } |
| 744 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 745 | emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | void Assembler::addrmod3(Instr instr, Register rd, const MemOperand& x) { |
| 750 | ASSERT((instr & ~(CondMask | L | S6 | H)) == (B4 | B7)); |
| 751 | ASSERT(x.rn_.is_valid()); |
| 752 | int am = x.am_; |
| 753 | if (!x.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 754 | // Immediate offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | int offset_8 = x.offset_; |
| 756 | if (offset_8 < 0) { |
| 757 | offset_8 = -offset_8; |
| 758 | am ^= U; |
| 759 | } |
| 760 | if (!is_uint8(offset_8)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 761 | // Immediate offset cannot be encoded, load it first to register ip |
| 762 | // 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] | 763 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
| 764 | mov(ip, Operand(x.offset_), LeaveCC, |
| 765 | static_cast<Condition>(instr & CondMask)); |
| 766 | addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 767 | return; |
| 768 | } |
| 769 | ASSERT(offset_8 >= 0); // no masking needed |
| 770 | instr |= B | (offset_8 >> 4)*B8 | (offset_8 & 0xf); |
| 771 | } else if (x.shift_imm_ != 0) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 772 | // Scaled register offset not supported, load index first |
| 773 | // 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] | 774 | ASSERT(!x.rn_.is(ip) && ((instr & L) == L || !rd.is(ip))); |
| 775 | mov(ip, Operand(x.rm_, x.shift_op_, x.shift_imm_), LeaveCC, |
| 776 | static_cast<Condition>(instr & CondMask)); |
| 777 | addrmod3(instr, rd, MemOperand(x.rn_, ip, x.am_)); |
| 778 | return; |
| 779 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 780 | // Register offset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | ASSERT((am & (P|W)) == P || !x.rm_.is(pc)); // no pc index with writeback |
| 782 | instr |= x.rm_.code(); |
| 783 | } |
| 784 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 785 | emit(instr | am | x.rn_.code()*B16 | rd.code()*B12); |
| 786 | } |
| 787 | |
| 788 | |
| 789 | void Assembler::addrmod4(Instr instr, Register rn, RegList rl) { |
| 790 | ASSERT((instr & ~(CondMask | P | U | W | L)) == B27); |
| 791 | ASSERT(rl != 0); |
| 792 | ASSERT(!rn.is(pc)); |
| 793 | emit(instr | rn.code()*B16 | rl); |
| 794 | } |
| 795 | |
| 796 | |
| 797 | void Assembler::addrmod5(Instr instr, CRegister crd, const MemOperand& x) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 798 | // Unindexed addressing is not encoded by this function. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 799 | ASSERT_EQ((B27 | B26), |
| 800 | (instr & ~(CondMask | CoprocessorMask | P | U | N | W | L))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 801 | ASSERT(x.rn_.is_valid() && !x.rm_.is_valid()); |
| 802 | int am = x.am_; |
| 803 | int offset_8 = x.offset_; |
| 804 | ASSERT((offset_8 & 3) == 0); // offset must be an aligned word offset |
| 805 | offset_8 >>= 2; |
| 806 | if (offset_8 < 0) { |
| 807 | offset_8 = -offset_8; |
| 808 | am ^= U; |
| 809 | } |
| 810 | ASSERT(is_uint8(offset_8)); // unsigned word offset must fit in a byte |
| 811 | ASSERT((am & (P|W)) == P || !x.rn_.is(pc)); // no pc base with writeback |
| 812 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 813 | // Post-indexed addressing requires W == 1; different than in addrmod2/3. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | if ((am & P) == 0) |
| 815 | am |= W; |
| 816 | |
| 817 | ASSERT(offset_8 >= 0); // no masking needed |
| 818 | emit(instr | am | x.rn_.code()*B16 | crd.code()*B12 | offset_8); |
| 819 | } |
| 820 | |
| 821 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 822 | int Assembler::branch_offset(Label* L, bool jump_elimination_allowed) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 823 | int target_pos; |
| 824 | if (L->is_bound()) { |
| 825 | target_pos = L->pos(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | } else { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 827 | if (L->is_linked()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 828 | target_pos = L->pos(); // L's link |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 829 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | target_pos = kEndOfChain; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 831 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | L->link_to(pc_offset()); |
| 833 | } |
| 834 | |
| 835 | // 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] | 836 | // be emitted at the pc offset recorded by the label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 838 | return target_pos - (pc_offset() + kPcLoadDelta); |
| 839 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 840 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 841 | |
| 842 | void Assembler::label_at_put(Label* L, int at_offset) { |
| 843 | int target_pos; |
| 844 | if (L->is_bound()) { |
| 845 | target_pos = L->pos(); |
| 846 | } else { |
| 847 | if (L->is_linked()) { |
| 848 | target_pos = L->pos(); // L's link |
| 849 | } else { |
| 850 | target_pos = kEndOfChain; |
| 851 | } |
| 852 | L->link_to(at_offset); |
| 853 | instr_at_put(at_offset, target_pos + (Code::kHeaderSize - kHeapObjectTag)); |
| 854 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 858 | // Branch instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 859 | void Assembler::b(int branch_offset, Condition cond) { |
| 860 | ASSERT((branch_offset & 3) == 0); |
| 861 | int imm24 = branch_offset >> 2; |
| 862 | ASSERT(is_int24(imm24)); |
| 863 | emit(cond | B27 | B25 | (imm24 & Imm24Mask)); |
| 864 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 865 | if (cond == al) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 866 | // Dead code is a good location to emit the constant pool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | CheckConstPool(false, false); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 868 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | void Assembler::bl(int branch_offset, Condition cond) { |
| 873 | ASSERT((branch_offset & 3) == 0); |
| 874 | int imm24 = branch_offset >> 2; |
| 875 | ASSERT(is_int24(imm24)); |
| 876 | emit(cond | B27 | B25 | B24 | (imm24 & Imm24Mask)); |
| 877 | } |
| 878 | |
| 879 | |
| 880 | void Assembler::blx(int branch_offset) { // v5 and above |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 881 | WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 882 | ASSERT((branch_offset & 1) == 0); |
| 883 | int h = ((branch_offset & 2) >> 1)*B24; |
| 884 | int imm24 = branch_offset >> 2; |
| 885 | ASSERT(is_int24(imm24)); |
| 886 | emit(15 << 28 | B27 | B25 | h | (imm24 & Imm24Mask)); |
| 887 | } |
| 888 | |
| 889 | |
| 890 | void Assembler::blx(Register target, Condition cond) { // v5 and above |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 891 | WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 892 | ASSERT(!target.is(pc)); |
| 893 | emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | 3*B4 | target.code()); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | void Assembler::bx(Register target, Condition cond) { // v5 and above, plus v4t |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 898 | WriteRecordedPositions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | ASSERT(!target.is(pc)); // use of pc is actually allowed, but discouraged |
| 900 | emit(cond | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | B4 | target.code()); |
| 901 | } |
| 902 | |
| 903 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 904 | // Data-processing instructions. |
| 905 | |
| 906 | // UBFX <Rd>,<Rn>,#<lsb>,#<width - 1> |
| 907 | // Instruction details available in ARM DDI 0406A, A8-464. |
| 908 | // cond(31-28) | 01111(27-23)| 1(22) | 1(21) | widthm1(20-16) | |
| 909 | // Rd(15-12) | lsb(11-7) | 101(6-4) | Rn(3-0) |
| 910 | void Assembler::ubfx(Register dst, Register src1, const Operand& src2, |
| 911 | const Operand& src3, Condition cond) { |
| 912 | ASSERT(!src2.rm_.is_valid() && !src3.rm_.is_valid()); |
| 913 | ASSERT(static_cast<uint32_t>(src2.imm32_) <= 0x1f); |
| 914 | ASSERT(static_cast<uint32_t>(src3.imm32_) <= 0x1f); |
| 915 | emit(cond | 0x3F*B21 | src3.imm32_*B16 | |
| 916 | dst.code()*B12 | src2.imm32_*B7 | 0x5*B4 | src1.code()); |
| 917 | } |
| 918 | |
| 919 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | void Assembler::and_(Register dst, Register src1, const Operand& src2, |
| 921 | SBit s, Condition cond) { |
| 922 | addrmod1(cond | 0*B21 | s, src1, dst, src2); |
| 923 | } |
| 924 | |
| 925 | |
| 926 | void Assembler::eor(Register dst, Register src1, const Operand& src2, |
| 927 | SBit s, Condition cond) { |
| 928 | addrmod1(cond | 1*B21 | s, src1, dst, src2); |
| 929 | } |
| 930 | |
| 931 | |
| 932 | void Assembler::sub(Register dst, Register src1, const Operand& src2, |
| 933 | SBit s, Condition cond) { |
| 934 | addrmod1(cond | 2*B21 | s, src1, dst, src2); |
| 935 | } |
| 936 | |
| 937 | |
| 938 | void Assembler::rsb(Register dst, Register src1, const Operand& src2, |
| 939 | SBit s, Condition cond) { |
| 940 | addrmod1(cond | 3*B21 | s, src1, dst, src2); |
| 941 | } |
| 942 | |
| 943 | |
| 944 | void Assembler::add(Register dst, Register src1, const Operand& src2, |
| 945 | SBit s, Condition cond) { |
| 946 | addrmod1(cond | 4*B21 | s, src1, dst, src2); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 947 | |
| 948 | // Eliminate pattern: push(r), pop() |
| 949 | // str(src, MemOperand(sp, 4, NegPreIndex), al); |
| 950 | // add(sp, sp, Operand(kPointerSize)); |
| 951 | // Both instructions can be eliminated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 952 | if (can_peephole_optimize(2) && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 953 | // Pattern. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 954 | instr_at(pc_ - 1 * kInstrSize) == kPopInstruction && |
| 955 | (instr_at(pc_ - 2 * kInstrSize) & ~RdMask) == kPushRegPattern) { |
| 956 | pc_ -= 2 * kInstrSize; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 957 | if (FLAG_print_peephole_optimization) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 958 | PrintF("%x push(reg)/pop() eliminated\n", pc_offset()); |
| 959 | } |
| 960 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | |
| 964 | void Assembler::adc(Register dst, Register src1, const Operand& src2, |
| 965 | SBit s, Condition cond) { |
| 966 | addrmod1(cond | 5*B21 | s, src1, dst, src2); |
| 967 | } |
| 968 | |
| 969 | |
| 970 | void Assembler::sbc(Register dst, Register src1, const Operand& src2, |
| 971 | SBit s, Condition cond) { |
| 972 | addrmod1(cond | 6*B21 | s, src1, dst, src2); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | void Assembler::rsc(Register dst, Register src1, const Operand& src2, |
| 977 | SBit s, Condition cond) { |
| 978 | addrmod1(cond | 7*B21 | s, src1, dst, src2); |
| 979 | } |
| 980 | |
| 981 | |
| 982 | void Assembler::tst(Register src1, const Operand& src2, Condition cond) { |
| 983 | addrmod1(cond | 8*B21 | S, src1, r0, src2); |
| 984 | } |
| 985 | |
| 986 | |
| 987 | void Assembler::teq(Register src1, const Operand& src2, Condition cond) { |
| 988 | addrmod1(cond | 9*B21 | S, src1, r0, src2); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | void Assembler::cmp(Register src1, const Operand& src2, Condition cond) { |
| 993 | addrmod1(cond | 10*B21 | S, src1, r0, src2); |
| 994 | } |
| 995 | |
| 996 | |
| 997 | void Assembler::cmn(Register src1, const Operand& src2, Condition cond) { |
| 998 | addrmod1(cond | 11*B21 | S, src1, r0, src2); |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | void Assembler::orr(Register dst, Register src1, const Operand& src2, |
| 1003 | SBit s, Condition cond) { |
| 1004 | addrmod1(cond | 12*B21 | s, src1, dst, src2); |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | 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] | 1009 | if (dst.is(pc)) { |
| 1010 | WriteRecordedPositions(); |
| 1011 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1012 | // Don't allow nop instructions in the form mov rn, rn to be generated using |
| 1013 | // the mov instruction. They must be generated using nop(int) |
| 1014 | // pseudo instructions. |
| 1015 | ASSERT(!(src.is_reg() && src.rm().is(dst) && s == LeaveCC && cond == al)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | addrmod1(cond | 13*B21 | s, r0, dst, src); |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | void Assembler::bic(Register dst, Register src1, const Operand& src2, |
| 1021 | SBit s, Condition cond) { |
| 1022 | addrmod1(cond | 14*B21 | s, src1, dst, src2); |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | void Assembler::mvn(Register dst, const Operand& src, SBit s, Condition cond) { |
| 1027 | addrmod1(cond | 15*B21 | s, r0, dst, src); |
| 1028 | } |
| 1029 | |
| 1030 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1031 | // Multiply instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1032 | void Assembler::mla(Register dst, Register src1, Register src2, Register srcA, |
| 1033 | SBit s, Condition cond) { |
| 1034 | 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] | 1035 | emit(cond | A | s | dst.code()*B16 | srcA.code()*B12 | |
| 1036 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | void Assembler::mul(Register dst, Register src1, Register src2, |
| 1041 | SBit s, Condition cond) { |
| 1042 | ASSERT(!dst.is(pc) && !src1.is(pc) && !src2.is(pc)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1043 | // dst goes in bits 16-19 for this instruction! |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1044 | emit(cond | s | dst.code()*B16 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | void Assembler::smlal(Register dstL, |
| 1049 | Register dstH, |
| 1050 | Register src1, |
| 1051 | Register src2, |
| 1052 | SBit s, |
| 1053 | Condition cond) { |
| 1054 | 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] | 1055 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | emit(cond | B23 | B22 | A | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1057 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | void Assembler::smull(Register dstL, |
| 1062 | Register dstH, |
| 1063 | Register src1, |
| 1064 | Register src2, |
| 1065 | SBit s, |
| 1066 | Condition cond) { |
| 1067 | 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] | 1068 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1069 | emit(cond | B23 | B22 | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1070 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | void Assembler::umlal(Register dstL, |
| 1075 | Register dstH, |
| 1076 | Register src1, |
| 1077 | Register src2, |
| 1078 | SBit s, |
| 1079 | Condition cond) { |
| 1080 | 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] | 1081 | ASSERT(!dstL.is(dstH)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1082 | emit(cond | B23 | A | s | dstH.code()*B16 | dstL.code()*B12 | |
| 1083 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | void Assembler::umull(Register dstL, |
| 1088 | Register dstH, |
| 1089 | Register src1, |
| 1090 | Register src2, |
| 1091 | SBit s, |
| 1092 | Condition cond) { |
| 1093 | 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] | 1094 | ASSERT(!dstL.is(dstH)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1095 | emit(cond | B23 | s | dstH.code()*B16 | dstL.code()*B12 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | src2.code()*B8 | B7 | B4 | src1.code()); |
| 1097 | } |
| 1098 | |
| 1099 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1100 | // Miscellaneous arithmetic instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1101 | void Assembler::clz(Register dst, Register src, Condition cond) { |
| 1102 | // v5 and above. |
| 1103 | ASSERT(!dst.is(pc) && !src.is(pc)); |
| 1104 | emit(cond | B24 | B22 | B21 | 15*B16 | dst.code()*B12 | |
| 1105 | 15*B8 | B4 | src.code()); |
| 1106 | } |
| 1107 | |
| 1108 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1109 | // Status register access instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1110 | void Assembler::mrs(Register dst, SRegister s, Condition cond) { |
| 1111 | ASSERT(!dst.is(pc)); |
| 1112 | emit(cond | B24 | s | 15*B16 | dst.code()*B12); |
| 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | void Assembler::msr(SRegisterFieldMask fields, const Operand& src, |
| 1117 | Condition cond) { |
| 1118 | ASSERT(fields >= B16 && fields < B20); // at least one field set |
| 1119 | Instr instr; |
| 1120 | if (!src.rm_.is_valid()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1121 | // Immediate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1122 | uint32_t rotate_imm; |
| 1123 | uint32_t immed_8; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1124 | if (MustUseIp(src.rmode_) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | !fits_shifter(src.imm32_, &rotate_imm, &immed_8, NULL)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1126 | // Immediate operand cannot be encoded, load it first to register ip. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1127 | RecordRelocInfo(src.rmode_, src.imm32_); |
| 1128 | ldr(ip, MemOperand(pc, 0), cond); |
| 1129 | msr(fields, Operand(ip), cond); |
| 1130 | return; |
| 1131 | } |
| 1132 | instr = I | rotate_imm*B8 | immed_8; |
| 1133 | } else { |
| 1134 | ASSERT(!src.rs_.is_valid() && src.shift_imm_ == 0); // only rm allowed |
| 1135 | instr = src.rm_.code(); |
| 1136 | } |
| 1137 | emit(cond | instr | B24 | B21 | fields | 15*B12); |
| 1138 | } |
| 1139 | |
| 1140 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1141 | // Load/Store instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | void Assembler::ldr(Register dst, const MemOperand& src, Condition cond) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1143 | if (dst.is(pc)) { |
| 1144 | WriteRecordedPositions(); |
| 1145 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1146 | addrmod2(cond | B26 | L, dst, src); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1147 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1148 | // Eliminate pattern: push(ry), pop(rx) |
| 1149 | // str(ry, MemOperand(sp, 4, NegPreIndex), al) |
| 1150 | // ldr(rx, MemOperand(sp, 4, PostIndex), al) |
| 1151 | // Both instructions can be eliminated if ry = rx. |
| 1152 | // If ry != rx, a register copy from ry to rx is inserted |
| 1153 | // after eliminating the push and the pop instructions. |
| 1154 | Instr push_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1155 | Instr pop_instr = instr_at(pc_ - 1 * kInstrSize); |
| 1156 | |
| 1157 | if (can_peephole_optimize(2) && |
| 1158 | IsPush(push_instr) && |
| 1159 | IsPop(pop_instr)) { |
| 1160 | if ((pop_instr & kRdMask) != (push_instr & kRdMask)) { |
| 1161 | // For consecutive push and pop on different registers, |
| 1162 | // we delete both the push & pop and insert a register move. |
| 1163 | // push ry, pop rx --> mov rx, ry |
| 1164 | Register reg_pushed, reg_popped; |
| 1165 | reg_pushed = GetRd(push_instr); |
| 1166 | reg_popped = GetRd(pop_instr); |
| 1167 | pc_ -= 2 * kInstrSize; |
| 1168 | // Insert a mov instruction, which is better than a pair of push & pop |
| 1169 | mov(reg_popped, reg_pushed); |
| 1170 | if (FLAG_print_peephole_optimization) { |
| 1171 | PrintF("%x push/pop (diff reg) replaced by a reg move\n", pc_offset()); |
| 1172 | } |
| 1173 | } else { |
| 1174 | // For consecutive push and pop on the same register, |
| 1175 | // both the push and the pop can be deleted. |
| 1176 | pc_ -= 2 * kInstrSize; |
| 1177 | if (FLAG_print_peephole_optimization) { |
| 1178 | PrintF("%x push/pop (same reg) eliminated\n", pc_offset()); |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (can_peephole_optimize(2)) { |
| 1184 | Instr str_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1185 | Instr ldr_instr = instr_at(pc_ - 1 * kInstrSize); |
| 1186 | |
| 1187 | if ((IsStrRegFpOffset(str_instr) && |
| 1188 | IsLdrRegFpOffset(ldr_instr)) || |
| 1189 | (IsStrRegFpNegOffset(str_instr) && |
| 1190 | IsLdrRegFpNegOffset(ldr_instr))) { |
| 1191 | if ((ldr_instr & kLdrStrInstrArgumentMask) == |
| 1192 | (str_instr & kLdrStrInstrArgumentMask)) { |
| 1193 | // Pattern: Ldr/str same fp+offset, same register. |
| 1194 | // |
| 1195 | // The following: |
| 1196 | // str rx, [fp, #-12] |
| 1197 | // ldr rx, [fp, #-12] |
| 1198 | // |
| 1199 | // Becomes: |
| 1200 | // str rx, [fp, #-12] |
| 1201 | |
| 1202 | pc_ -= 1 * kInstrSize; |
| 1203 | if (FLAG_print_peephole_optimization) { |
| 1204 | PrintF("%x str/ldr (fp + same offset), same reg\n", pc_offset()); |
| 1205 | } |
| 1206 | } else if ((ldr_instr & kLdrStrOffsetMask) == |
| 1207 | (str_instr & kLdrStrOffsetMask)) { |
| 1208 | // Pattern: Ldr/str same fp+offset, different register. |
| 1209 | // |
| 1210 | // The following: |
| 1211 | // str rx, [fp, #-12] |
| 1212 | // ldr ry, [fp, #-12] |
| 1213 | // |
| 1214 | // Becomes: |
| 1215 | // str rx, [fp, #-12] |
| 1216 | // mov ry, rx |
| 1217 | |
| 1218 | Register reg_stored, reg_loaded; |
| 1219 | reg_stored = GetRd(str_instr); |
| 1220 | reg_loaded = GetRd(ldr_instr); |
| 1221 | pc_ -= 1 * kInstrSize; |
| 1222 | // Insert a mov instruction, which is better than ldr. |
| 1223 | mov(reg_loaded, reg_stored); |
| 1224 | if (FLAG_print_peephole_optimization) { |
| 1225 | PrintF("%x str/ldr (fp + same offset), diff reg \n", pc_offset()); |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | if (can_peephole_optimize(3)) { |
| 1232 | Instr mem_write_instr = instr_at(pc_ - 3 * kInstrSize); |
| 1233 | Instr ldr_instr = instr_at(pc_ - 2 * kInstrSize); |
| 1234 | Instr mem_read_instr = instr_at(pc_ - 1 * kInstrSize); |
| 1235 | if (IsPush(mem_write_instr) && |
| 1236 | IsPop(mem_read_instr)) { |
| 1237 | if ((IsLdrRegFpOffset(ldr_instr) || |
| 1238 | IsLdrRegFpNegOffset(ldr_instr))) { |
| 1239 | if ((mem_write_instr & kRdMask) == |
| 1240 | (mem_read_instr & kRdMask)) { |
| 1241 | // Pattern: push & pop from/to same register, |
| 1242 | // with a fp+offset ldr in between |
| 1243 | // |
| 1244 | // The following: |
| 1245 | // str rx, [sp, #-4]! |
| 1246 | // ldr rz, [fp, #-24] |
| 1247 | // ldr rx, [sp], #+4 |
| 1248 | // |
| 1249 | // Becomes: |
| 1250 | // if(rx == rz) |
| 1251 | // delete all |
| 1252 | // else |
| 1253 | // ldr rz, [fp, #-24] |
| 1254 | |
| 1255 | if ((mem_write_instr & kRdMask) == (ldr_instr & kRdMask)) { |
| 1256 | pc_ -= 3 * kInstrSize; |
| 1257 | } else { |
| 1258 | pc_ -= 3 * kInstrSize; |
| 1259 | // Reinsert back the ldr rz. |
| 1260 | emit(ldr_instr); |
| 1261 | } |
| 1262 | if (FLAG_print_peephole_optimization) { |
| 1263 | PrintF("%x push/pop -dead ldr fp+offset in middle\n", pc_offset()); |
| 1264 | } |
| 1265 | } else { |
| 1266 | // Pattern: push & pop from/to different registers |
| 1267 | // with a fp+offset ldr in between |
| 1268 | // |
| 1269 | // The following: |
| 1270 | // str rx, [sp, #-4]! |
| 1271 | // ldr rz, [fp, #-24] |
| 1272 | // ldr ry, [sp], #+4 |
| 1273 | // |
| 1274 | // Becomes: |
| 1275 | // if(ry == rz) |
| 1276 | // mov ry, rx; |
| 1277 | // else if(rx != rz) |
| 1278 | // ldr rz, [fp, #-24] |
| 1279 | // mov ry, rx |
| 1280 | // else if((ry != rz) || (rx == rz)) becomes: |
| 1281 | // mov ry, rx |
| 1282 | // ldr rz, [fp, #-24] |
| 1283 | |
| 1284 | Register reg_pushed, reg_popped; |
| 1285 | if ((mem_read_instr & kRdMask) == (ldr_instr & kRdMask)) { |
| 1286 | reg_pushed = GetRd(mem_write_instr); |
| 1287 | reg_popped = GetRd(mem_read_instr); |
| 1288 | pc_ -= 3 * kInstrSize; |
| 1289 | mov(reg_popped, reg_pushed); |
| 1290 | } else if ((mem_write_instr & kRdMask) |
| 1291 | != (ldr_instr & kRdMask)) { |
| 1292 | reg_pushed = GetRd(mem_write_instr); |
| 1293 | reg_popped = GetRd(mem_read_instr); |
| 1294 | pc_ -= 3 * kInstrSize; |
| 1295 | emit(ldr_instr); |
| 1296 | mov(reg_popped, reg_pushed); |
| 1297 | } else if (((mem_read_instr & kRdMask) |
| 1298 | != (ldr_instr & kRdMask)) || |
| 1299 | ((mem_write_instr & kRdMask) |
| 1300 | == (ldr_instr & kRdMask)) ) { |
| 1301 | reg_pushed = GetRd(mem_write_instr); |
| 1302 | reg_popped = GetRd(mem_read_instr); |
| 1303 | pc_ -= 3 * kInstrSize; |
| 1304 | mov(reg_popped, reg_pushed); |
| 1305 | emit(ldr_instr); |
| 1306 | } |
| 1307 | if (FLAG_print_peephole_optimization) { |
| 1308 | PrintF("%x push/pop (ldr fp+off in middle)\n", pc_offset()); |
| 1309 | } |
| 1310 | } |
| 1311 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1312 | } |
| 1313 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | void Assembler::str(Register src, const MemOperand& dst, Condition cond) { |
| 1318 | addrmod2(cond | B26, src, dst); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Eliminate pattern: pop(), push(r) |
| 1321 | // add sp, sp, #4 LeaveCC, al; str r, [sp, #-4], al |
| 1322 | // -> str r, [sp, 0], al |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1323 | if (can_peephole_optimize(2) && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1324 | // Pattern. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1325 | instr_at(pc_ - 1 * kInstrSize) == (kPushRegPattern | src.code() * B12) && |
| 1326 | instr_at(pc_ - 2 * kInstrSize) == kPopInstruction) { |
| 1327 | pc_ -= 2 * kInstrSize; |
| 1328 | 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^] | 1329 | if (FLAG_print_peephole_optimization) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1330 | PrintF("%x pop()/push(reg) eliminated\n", pc_offset()); |
| 1331 | } |
| 1332 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | void Assembler::ldrb(Register dst, const MemOperand& src, Condition cond) { |
| 1337 | addrmod2(cond | B26 | B | L, dst, src); |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | void Assembler::strb(Register src, const MemOperand& dst, Condition cond) { |
| 1342 | addrmod2(cond | B26 | B, src, dst); |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | void Assembler::ldrh(Register dst, const MemOperand& src, Condition cond) { |
| 1347 | addrmod3(cond | L | B7 | H | B4, dst, src); |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | void Assembler::strh(Register src, const MemOperand& dst, Condition cond) { |
| 1352 | addrmod3(cond | B7 | H | B4, src, dst); |
| 1353 | } |
| 1354 | |
| 1355 | |
| 1356 | void Assembler::ldrsb(Register dst, const MemOperand& src, Condition cond) { |
| 1357 | addrmod3(cond | L | B7 | S6 | B4, dst, src); |
| 1358 | } |
| 1359 | |
| 1360 | |
| 1361 | void Assembler::ldrsh(Register dst, const MemOperand& src, Condition cond) { |
| 1362 | addrmod3(cond | L | B7 | S6 | H | B4, dst, src); |
| 1363 | } |
| 1364 | |
| 1365 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1366 | void Assembler::ldrd(Register dst, const MemOperand& src, Condition cond) { |
| 1367 | ASSERT(src.rm().is(no_reg)); |
| 1368 | #ifdef CAN_USE_ARMV7_INSTRUCTIONS |
| 1369 | addrmod3(cond | B7 | B6 | B4, dst, src); |
| 1370 | #else |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1371 | // Generate two ldr instructions if ldrd is not available. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1372 | MemOperand src1(src); |
| 1373 | src1.set_offset(src1.offset() + 4); |
| 1374 | Register dst1(dst); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1375 | dst1.set_code(dst1.code() + 1); |
| 1376 | if (dst.is(src.rn())) { |
| 1377 | ldr(dst1, src1, cond); |
| 1378 | ldr(dst, src, cond); |
| 1379 | } else { |
| 1380 | ldr(dst, src, cond); |
| 1381 | ldr(dst1, src1, cond); |
| 1382 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1383 | #endif |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | void Assembler::strd(Register src, const MemOperand& dst, Condition cond) { |
| 1388 | ASSERT(dst.rm().is(no_reg)); |
| 1389 | #ifdef CAN_USE_ARMV7_INSTRUCTIONS |
| 1390 | addrmod3(cond | B7 | B6 | B5 | B4, src, dst); |
| 1391 | #else |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1392 | // Generate two str instructions if strd is not available. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1393 | MemOperand dst1(dst); |
| 1394 | dst1.set_offset(dst1.offset() + 4); |
| 1395 | Register src1(src); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 1396 | src1.set_code(src1.code() + 1); |
| 1397 | str(src, dst, cond); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1398 | str(src1, dst1, cond); |
| 1399 | #endif |
| 1400 | } |
| 1401 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1402 | // Load/Store multiple instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1403 | void Assembler::ldm(BlockAddrMode am, |
| 1404 | Register base, |
| 1405 | RegList dst, |
| 1406 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1407 | // ABI stack constraint: ldmxx base, {..sp..} base != sp is not restartable. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1408 | ASSERT(base.is(sp) || (dst & sp.bit()) == 0); |
| 1409 | |
| 1410 | addrmod4(cond | B27 | am | L, base, dst); |
| 1411 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1412 | // 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] | 1413 | if (cond == al && (dst & pc.bit()) != 0) { |
| 1414 | // There is a slight chance that the ldm instruction was actually a call, |
| 1415 | // in which case it would be wrong to return into the constant pool; we |
| 1416 | // recognize this case by checking if the emission of the pool was blocked |
| 1417 | // at the pc of the ldm instruction by a mov lr, pc instruction; if this is |
| 1418 | // the case, we emit a jump over the pool. |
| 1419 | CheckConstPool(true, no_const_pool_before_ == pc_offset() - kInstrSize); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | void Assembler::stm(BlockAddrMode am, |
| 1425 | Register base, |
| 1426 | RegList src, |
| 1427 | Condition cond) { |
| 1428 | addrmod4(cond | B27 | am, base, src); |
| 1429 | } |
| 1430 | |
| 1431 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1432 | // Exception-generating instructions and debugging support. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1433 | void Assembler::stop(const char* msg) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1434 | #ifndef __arm__ |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1435 | // The simulator handles these special instructions and stops execution. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | emit(15 << 28 | ((intptr_t) msg)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1437 | #else // def __arm__ |
| 1438 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1439 | bkpt(0); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1440 | #else // ndef CAN_USE_ARMV5_INSTRUCTIONS |
| 1441 | swi(0x9f0001); |
| 1442 | #endif // ndef CAN_USE_ARMV5_INSTRUCTIONS |
| 1443 | #endif // def __arm__ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | void Assembler::bkpt(uint32_t imm16) { // v5 and above |
| 1448 | ASSERT(is_uint16(imm16)); |
| 1449 | emit(al | B24 | B21 | (imm16 >> 4)*B8 | 7*B4 | (imm16 & 0xf)); |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | void Assembler::swi(uint32_t imm24, Condition cond) { |
| 1454 | ASSERT(is_uint24(imm24)); |
| 1455 | emit(cond | 15*B24 | imm24); |
| 1456 | } |
| 1457 | |
| 1458 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1459 | // Coprocessor instructions. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1460 | void Assembler::cdp(Coprocessor coproc, |
| 1461 | int opcode_1, |
| 1462 | CRegister crd, |
| 1463 | CRegister crn, |
| 1464 | CRegister crm, |
| 1465 | int opcode_2, |
| 1466 | Condition cond) { |
| 1467 | ASSERT(is_uint4(opcode_1) && is_uint3(opcode_2)); |
| 1468 | emit(cond | B27 | B26 | B25 | (opcode_1 & 15)*B20 | crn.code()*B16 | |
| 1469 | crd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | crm.code()); |
| 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | void Assembler::cdp2(Coprocessor coproc, |
| 1474 | int opcode_1, |
| 1475 | CRegister crd, |
| 1476 | CRegister crn, |
| 1477 | CRegister crm, |
| 1478 | int opcode_2) { // v5 and above |
| 1479 | cdp(coproc, opcode_1, crd, crn, crm, opcode_2, static_cast<Condition>(nv)); |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | void Assembler::mcr(Coprocessor coproc, |
| 1484 | int opcode_1, |
| 1485 | Register rd, |
| 1486 | CRegister crn, |
| 1487 | CRegister crm, |
| 1488 | int opcode_2, |
| 1489 | Condition cond) { |
| 1490 | ASSERT(is_uint3(opcode_1) && is_uint3(opcode_2)); |
| 1491 | emit(cond | B27 | B26 | B25 | (opcode_1 & 7)*B21 | crn.code()*B16 | |
| 1492 | rd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | B4 | crm.code()); |
| 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | void Assembler::mcr2(Coprocessor coproc, |
| 1497 | int opcode_1, |
| 1498 | Register rd, |
| 1499 | CRegister crn, |
| 1500 | CRegister crm, |
| 1501 | int opcode_2) { // v5 and above |
| 1502 | mcr(coproc, opcode_1, rd, crn, crm, opcode_2, static_cast<Condition>(nv)); |
| 1503 | } |
| 1504 | |
| 1505 | |
| 1506 | void Assembler::mrc(Coprocessor coproc, |
| 1507 | int opcode_1, |
| 1508 | Register rd, |
| 1509 | CRegister crn, |
| 1510 | CRegister crm, |
| 1511 | int opcode_2, |
| 1512 | Condition cond) { |
| 1513 | ASSERT(is_uint3(opcode_1) && is_uint3(opcode_2)); |
| 1514 | emit(cond | B27 | B26 | B25 | (opcode_1 & 7)*B21 | L | crn.code()*B16 | |
| 1515 | rd.code()*B12 | coproc*B8 | (opcode_2 & 7)*B5 | B4 | crm.code()); |
| 1516 | } |
| 1517 | |
| 1518 | |
| 1519 | void Assembler::mrc2(Coprocessor coproc, |
| 1520 | int opcode_1, |
| 1521 | Register rd, |
| 1522 | CRegister crn, |
| 1523 | CRegister crm, |
| 1524 | int opcode_2) { // v5 and above |
| 1525 | mrc(coproc, opcode_1, rd, crn, crm, opcode_2, static_cast<Condition>(nv)); |
| 1526 | } |
| 1527 | |
| 1528 | |
| 1529 | void Assembler::ldc(Coprocessor coproc, |
| 1530 | CRegister crd, |
| 1531 | const MemOperand& src, |
| 1532 | LFlag l, |
| 1533 | Condition cond) { |
| 1534 | addrmod5(cond | B27 | B26 | l | L | coproc*B8, crd, src); |
| 1535 | } |
| 1536 | |
| 1537 | |
| 1538 | void Assembler::ldc(Coprocessor coproc, |
| 1539 | CRegister crd, |
| 1540 | Register rn, |
| 1541 | int option, |
| 1542 | LFlag l, |
| 1543 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1544 | // Unindexed addressing. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1545 | ASSERT(is_uint8(option)); |
| 1546 | emit(cond | B27 | B26 | U | l | L | rn.code()*B16 | crd.code()*B12 | |
| 1547 | coproc*B8 | (option & 255)); |
| 1548 | } |
| 1549 | |
| 1550 | |
| 1551 | void Assembler::ldc2(Coprocessor coproc, |
| 1552 | CRegister crd, |
| 1553 | const MemOperand& src, |
| 1554 | LFlag l) { // v5 and above |
| 1555 | ldc(coproc, crd, src, l, static_cast<Condition>(nv)); |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | void Assembler::ldc2(Coprocessor coproc, |
| 1560 | CRegister crd, |
| 1561 | Register rn, |
| 1562 | int option, |
| 1563 | LFlag l) { // v5 and above |
| 1564 | ldc(coproc, crd, rn, option, l, static_cast<Condition>(nv)); |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | void Assembler::stc(Coprocessor coproc, |
| 1569 | CRegister crd, |
| 1570 | const MemOperand& dst, |
| 1571 | LFlag l, |
| 1572 | Condition cond) { |
| 1573 | addrmod5(cond | B27 | B26 | l | coproc*B8, crd, dst); |
| 1574 | } |
| 1575 | |
| 1576 | |
| 1577 | void Assembler::stc(Coprocessor coproc, |
| 1578 | CRegister crd, |
| 1579 | Register rn, |
| 1580 | int option, |
| 1581 | LFlag l, |
| 1582 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1583 | // Unindexed addressing. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1584 | ASSERT(is_uint8(option)); |
| 1585 | emit(cond | B27 | B26 | U | l | rn.code()*B16 | crd.code()*B12 | |
| 1586 | coproc*B8 | (option & 255)); |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | void Assembler::stc2(Coprocessor |
| 1591 | coproc, CRegister crd, |
| 1592 | const MemOperand& dst, |
| 1593 | LFlag l) { // v5 and above |
| 1594 | stc(coproc, crd, dst, l, static_cast<Condition>(nv)); |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | void Assembler::stc2(Coprocessor coproc, |
| 1599 | CRegister crd, |
| 1600 | Register rn, |
| 1601 | int option, |
| 1602 | LFlag l) { // v5 and above |
| 1603 | stc(coproc, crd, rn, option, l, static_cast<Condition>(nv)); |
| 1604 | } |
| 1605 | |
| 1606 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1607 | // Support for VFP. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1608 | void Assembler::vldr(const DwVfpRegister dst, |
| 1609 | const Register base, |
| 1610 | int offset, |
| 1611 | const Condition cond) { |
| 1612 | // Ddst = MEM(Rbase + offset). |
| 1613 | // Instruction details available in ARM DDI 0406A, A8-628. |
| 1614 | // cond(31-28) | 1101(27-24)| 1001(23-20) | Rbase(19-16) | |
| 1615 | // Vdst(15-12) | 1011(11-8) | offset |
| 1616 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1617 | ASSERT(offset % 4 == 0); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1618 | ASSERT((offset / 4) < 256); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1619 | emit(cond | 0xD9*B20 | base.code()*B16 | dst.code()*B12 | |
| 1620 | 0xB*B8 | ((offset / 4) & 255)); |
| 1621 | } |
| 1622 | |
| 1623 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1624 | void Assembler::vldr(const SwVfpRegister dst, |
| 1625 | const Register base, |
| 1626 | int offset, |
| 1627 | const Condition cond) { |
| 1628 | // Sdst = MEM(Rbase + offset). |
| 1629 | // Instruction details available in ARM DDI 0406A, A8-628. |
| 1630 | // cond(31-28) | 1101(27-24)| 1001(23-20) | Rbase(19-16) | |
| 1631 | // Vdst(15-12) | 1010(11-8) | offset |
| 1632 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1633 | ASSERT(offset % 4 == 0); |
| 1634 | ASSERT((offset / 4) < 256); |
| 1635 | emit(cond | 0xD9*B20 | base.code()*B16 | dst.code()*B12 | |
| 1636 | 0xA*B8 | ((offset / 4) & 255)); |
| 1637 | } |
| 1638 | |
| 1639 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1640 | void Assembler::vstr(const DwVfpRegister src, |
| 1641 | const Register base, |
| 1642 | int offset, |
| 1643 | const Condition cond) { |
| 1644 | // MEM(Rbase + offset) = Dsrc. |
| 1645 | // Instruction details available in ARM DDI 0406A, A8-786. |
| 1646 | // cond(31-28) | 1101(27-24)| 1000(23-20) | | Rbase(19-16) | |
| 1647 | // Vsrc(15-12) | 1011(11-8) | (offset/4) |
| 1648 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1649 | ASSERT(offset % 4 == 0); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1650 | ASSERT((offset / 4) < 256); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1651 | emit(cond | 0xD8*B20 | base.code()*B16 | src.code()*B12 | |
| 1652 | 0xB*B8 | ((offset / 4) & 255)); |
| 1653 | } |
| 1654 | |
| 1655 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1656 | void Assembler::vmov(const DwVfpRegister dst, |
| 1657 | const Register src1, |
| 1658 | const Register src2, |
| 1659 | const Condition cond) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1660 | // Dm = <Rt,Rt2>. |
| 1661 | // Instruction details available in ARM DDI 0406A, A8-646. |
| 1662 | // cond(31-28) | 1100(27-24)| 010(23-21) | op=0(20) | Rt2(19-16) | |
| 1663 | // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm |
| 1664 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1665 | ASSERT(!src1.is(pc) && !src2.is(pc)); |
| 1666 | emit(cond | 0xC*B24 | B22 | src2.code()*B16 | |
| 1667 | src1.code()*B12 | 0xB*B8 | B4 | dst.code()); |
| 1668 | } |
| 1669 | |
| 1670 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1671 | void Assembler::vmov(const Register dst1, |
| 1672 | const Register dst2, |
| 1673 | const DwVfpRegister src, |
| 1674 | const Condition cond) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1675 | // <Rt,Rt2> = Dm. |
| 1676 | // Instruction details available in ARM DDI 0406A, A8-646. |
| 1677 | // cond(31-28) | 1100(27-24)| 010(23-21) | op=1(20) | Rt2(19-16) | |
| 1678 | // Rt(15-12) | 1011(11-8) | 00(7-6) | M(5) | 1(4) | Vm |
| 1679 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1680 | ASSERT(!dst1.is(pc) && !dst2.is(pc)); |
| 1681 | emit(cond | 0xC*B24 | B22 | B20 | dst2.code()*B16 | |
| 1682 | dst1.code()*B12 | 0xB*B8 | B4 | src.code()); |
| 1683 | } |
| 1684 | |
| 1685 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1686 | void Assembler::vmov(const SwVfpRegister dst, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1687 | const Register src, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1688 | const Condition cond) { |
| 1689 | // Sn = Rt. |
| 1690 | // Instruction details available in ARM DDI 0406A, A8-642. |
| 1691 | // cond(31-28) | 1110(27-24)| 000(23-21) | op=0(20) | Vn(19-16) | |
| 1692 | // Rt(15-12) | 1010(11-8) | N(7)=0 | 00(6-5) | 1(4) | 0000(3-0) |
| 1693 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1694 | ASSERT(!src.is(pc)); |
| 1695 | emit(cond | 0xE*B24 | (dst.code() >> 1)*B16 | |
| 1696 | src.code()*B12 | 0xA*B8 | (0x1 & dst.code())*B7 | B4); |
| 1697 | } |
| 1698 | |
| 1699 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1700 | void Assembler::vmov(const Register dst, |
| 1701 | const SwVfpRegister src, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1702 | const Condition cond) { |
| 1703 | // Rt = Sn. |
| 1704 | // Instruction details available in ARM DDI 0406A, A8-642. |
| 1705 | // cond(31-28) | 1110(27-24)| 000(23-21) | op=1(20) | Vn(19-16) | |
| 1706 | // Rt(15-12) | 1010(11-8) | N(7)=0 | 00(6-5) | 1(4) | 0000(3-0) |
| 1707 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1708 | ASSERT(!dst.is(pc)); |
| 1709 | emit(cond | 0xE*B24 | B20 | (src.code() >> 1)*B16 | |
| 1710 | dst.code()*B12 | 0xA*B8 | (0x1 & src.code())*B7 | B4); |
| 1711 | } |
| 1712 | |
| 1713 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1714 | // Type of data to read from or write to VFP register. |
| 1715 | // Used as specifier in generic vcvt instruction. |
| 1716 | enum VFPType { S32, U32, F32, F64 }; |
| 1717 | |
| 1718 | |
| 1719 | static bool IsSignedVFPType(VFPType type) { |
| 1720 | switch (type) { |
| 1721 | case S32: |
| 1722 | return true; |
| 1723 | case U32: |
| 1724 | return false; |
| 1725 | default: |
| 1726 | UNREACHABLE(); |
| 1727 | return false; |
| 1728 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1732 | static bool IsIntegerVFPType(VFPType type) { |
| 1733 | switch (type) { |
| 1734 | case S32: |
| 1735 | case U32: |
| 1736 | return true; |
| 1737 | case F32: |
| 1738 | case F64: |
| 1739 | return false; |
| 1740 | default: |
| 1741 | UNREACHABLE(); |
| 1742 | return false; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | |
| 1747 | static bool IsDoubleVFPType(VFPType type) { |
| 1748 | switch (type) { |
| 1749 | case F32: |
| 1750 | return false; |
| 1751 | case F64: |
| 1752 | return true; |
| 1753 | default: |
| 1754 | UNREACHABLE(); |
| 1755 | return false; |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | // Depending on split_last_bit split binary representation of reg_code into Vm:M |
| 1761 | // or M:Vm form (where M is single bit). |
| 1762 | static void SplitRegCode(bool split_last_bit, |
| 1763 | int reg_code, |
| 1764 | int* vm, |
| 1765 | int* m) { |
| 1766 | if (split_last_bit) { |
| 1767 | *m = reg_code & 0x1; |
| 1768 | *vm = reg_code >> 1; |
| 1769 | } else { |
| 1770 | *m = (reg_code & 0x10) >> 4; |
| 1771 | *vm = reg_code & 0x0F; |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | |
| 1776 | // Encode vcvt.src_type.dst_type instruction. |
| 1777 | static Instr EncodeVCVT(const VFPType dst_type, |
| 1778 | const int dst_code, |
| 1779 | const VFPType src_type, |
| 1780 | const int src_code, |
| 1781 | const Condition cond) { |
| 1782 | if (IsIntegerVFPType(dst_type) || IsIntegerVFPType(src_type)) { |
| 1783 | // Conversion between IEEE floating point and 32-bit integer. |
| 1784 | // Instruction details available in ARM DDI 0406B, A8.6.295. |
| 1785 | // cond(31-28) | 11101(27-23)| D(22) | 11(21-20) | 1(19) | opc2(18-16) | |
| 1786 | // Vd(15-12) | 101(11-9) | sz(8) | op(7) | 1(6) | M(5) | 0(4) | Vm(3-0) |
| 1787 | ASSERT(!IsIntegerVFPType(dst_type) || !IsIntegerVFPType(src_type)); |
| 1788 | |
| 1789 | int sz, opc2, D, Vd, M, Vm, op; |
| 1790 | |
| 1791 | if (IsIntegerVFPType(dst_type)) { |
| 1792 | opc2 = IsSignedVFPType(dst_type) ? 0x5 : 0x4; |
| 1793 | sz = IsDoubleVFPType(src_type) ? 0x1 : 0x0; |
| 1794 | op = 1; // round towards zero |
| 1795 | SplitRegCode(!IsDoubleVFPType(src_type), src_code, &Vm, &M); |
| 1796 | SplitRegCode(true, dst_code, &Vd, &D); |
| 1797 | } else { |
| 1798 | ASSERT(IsIntegerVFPType(src_type)); |
| 1799 | |
| 1800 | opc2 = 0x0; |
| 1801 | sz = IsDoubleVFPType(dst_type) ? 0x1 : 0x0; |
| 1802 | op = IsSignedVFPType(src_type) ? 0x1 : 0x0; |
| 1803 | SplitRegCode(true, src_code, &Vm, &M); |
| 1804 | SplitRegCode(!IsDoubleVFPType(dst_type), dst_code, &Vd, &D); |
| 1805 | } |
| 1806 | |
| 1807 | return (cond | 0xE*B24 | B23 | D*B22 | 0x3*B20 | B19 | opc2*B16 | |
| 1808 | Vd*B12 | 0x5*B9 | sz*B8 | op*B7 | B6 | M*B5 | Vm); |
| 1809 | } else { |
| 1810 | // Conversion between IEEE double and single precision. |
| 1811 | // Instruction details available in ARM DDI 0406B, A8.6.298. |
| 1812 | // cond(31-28) | 11101(27-23)| D(22) | 11(21-20) | 0111(19-16) | |
| 1813 | // Vd(15-12) | 101(11-9) | sz(8) | 1(7) | 1(6) | M(5) | 0(4) | Vm(3-0) |
| 1814 | int sz, D, Vd, M, Vm; |
| 1815 | |
| 1816 | ASSERT(IsDoubleVFPType(dst_type) != IsDoubleVFPType(src_type)); |
| 1817 | sz = IsDoubleVFPType(src_type) ? 0x1 : 0x0; |
| 1818 | SplitRegCode(IsDoubleVFPType(src_type), dst_code, &Vd, &D); |
| 1819 | SplitRegCode(!IsDoubleVFPType(src_type), src_code, &Vm, &M); |
| 1820 | |
| 1821 | return (cond | 0xE*B24 | B23 | D*B22 | 0x3*B20 | 0x7*B16 | |
| 1822 | Vd*B12 | 0x5*B9 | sz*B8 | B7 | B6 | M*B5 | Vm); |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | void Assembler::vcvt_f64_s32(const DwVfpRegister dst, |
| 1828 | const SwVfpRegister src, |
| 1829 | const Condition cond) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1830 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1831 | emit(EncodeVCVT(F64, dst.code(), S32, src.code(), cond)); |
| 1832 | } |
| 1833 | |
| 1834 | |
| 1835 | void Assembler::vcvt_f32_s32(const SwVfpRegister dst, |
| 1836 | const SwVfpRegister src, |
| 1837 | const Condition cond) { |
| 1838 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1839 | emit(EncodeVCVT(F32, dst.code(), S32, src.code(), cond)); |
| 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | void Assembler::vcvt_f64_u32(const DwVfpRegister dst, |
| 1844 | const SwVfpRegister src, |
| 1845 | const Condition cond) { |
| 1846 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1847 | emit(EncodeVCVT(F64, dst.code(), U32, src.code(), cond)); |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | void Assembler::vcvt_s32_f64(const SwVfpRegister dst, |
| 1852 | const DwVfpRegister src, |
| 1853 | const Condition cond) { |
| 1854 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1855 | emit(EncodeVCVT(S32, dst.code(), F64, src.code(), cond)); |
| 1856 | } |
| 1857 | |
| 1858 | |
| 1859 | void Assembler::vcvt_u32_f64(const SwVfpRegister dst, |
| 1860 | const DwVfpRegister src, |
| 1861 | const Condition cond) { |
| 1862 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1863 | emit(EncodeVCVT(U32, dst.code(), F64, src.code(), cond)); |
| 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | void Assembler::vcvt_f64_f32(const DwVfpRegister dst, |
| 1868 | const SwVfpRegister src, |
| 1869 | const Condition cond) { |
| 1870 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1871 | emit(EncodeVCVT(F64, dst.code(), F32, src.code(), cond)); |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | void Assembler::vcvt_f32_f64(const SwVfpRegister dst, |
| 1876 | const DwVfpRegister src, |
| 1877 | const Condition cond) { |
| 1878 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1879 | emit(EncodeVCVT(F32, dst.code(), F64, src.code(), cond)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1883 | void Assembler::vadd(const DwVfpRegister dst, |
| 1884 | const DwVfpRegister src1, |
| 1885 | const DwVfpRegister src2, |
| 1886 | const Condition cond) { |
| 1887 | // Dd = vadd(Dn, Dm) double precision floating point addition. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1888 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 1889 | // Instruction details available in ARM DDI 0406A, A8-536. |
| 1890 | // cond(31-28) | 11100(27-23)| D=?(22) | 11(21-20) | Vn(19-16) | |
| 1891 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
| 1892 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1893 | emit(cond | 0xE*B24 | 0x3*B20 | src1.code()*B16 | |
| 1894 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 1895 | } |
| 1896 | |
| 1897 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1898 | void Assembler::vsub(const DwVfpRegister dst, |
| 1899 | const DwVfpRegister src1, |
| 1900 | const DwVfpRegister src2, |
| 1901 | const Condition cond) { |
| 1902 | // Dd = vsub(Dn, Dm) double precision floating point subtraction. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1903 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 1904 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 1905 | // cond(31-28) | 11100(27-23)| D=?(22) | 11(21-20) | Vn(19-16) | |
| 1906 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 1(6) | M=?(5) | 0(4) | Vm(3-0) |
| 1907 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1908 | emit(cond | 0xE*B24 | 0x3*B20 | src1.code()*B16 | |
| 1909 | dst.code()*B12 | 0x5*B9 | B8 | B6 | src2.code()); |
| 1910 | } |
| 1911 | |
| 1912 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1913 | void Assembler::vmul(const DwVfpRegister dst, |
| 1914 | const DwVfpRegister src1, |
| 1915 | const DwVfpRegister src2, |
| 1916 | const Condition cond) { |
| 1917 | // Dd = vmul(Dn, Dm) double precision floating point multiplication. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1918 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 1919 | // Instruction details available in ARM DDI 0406A, A8-784. |
| 1920 | // cond(31-28) | 11100(27-23)| D=?(22) | 10(21-20) | Vn(19-16) | |
| 1921 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=0 | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
| 1922 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1923 | emit(cond | 0xE*B24 | 0x2*B20 | src1.code()*B16 | |
| 1924 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 1925 | } |
| 1926 | |
| 1927 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1928 | void Assembler::vdiv(const DwVfpRegister dst, |
| 1929 | const DwVfpRegister src1, |
| 1930 | const DwVfpRegister src2, |
| 1931 | const Condition cond) { |
| 1932 | // Dd = vdiv(Dn, Dm) double precision floating point division. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1933 | // Dd = D:Vd; Dm=M:Vm; Dn=N:Vm. |
| 1934 | // Instruction details available in ARM DDI 0406A, A8-584. |
| 1935 | // cond(31-28) | 11101(27-23)| D=?(22) | 00(21-20) | Vn(19-16) | |
| 1936 | // Vd(15-12) | 101(11-9) | sz(8)=1 | N(7)=? | 0(6) | M=?(5) | 0(4) | Vm(3-0) |
| 1937 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1938 | emit(cond | 0xE*B24 | B23 | src1.code()*B16 | |
| 1939 | dst.code()*B12 | 0x5*B9 | B8 | src2.code()); |
| 1940 | } |
| 1941 | |
| 1942 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1943 | void Assembler::vcmp(const DwVfpRegister src1, |
| 1944 | const DwVfpRegister src2, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1945 | const SBit s, |
| 1946 | const Condition cond) { |
| 1947 | // vcmp(Dd, Dm) double precision floating point comparison. |
| 1948 | // Instruction details available in ARM DDI 0406A, A8-570. |
| 1949 | // cond(31-28) | 11101 (27-23)| D=?(22) | 11 (21-20) | 0100 (19-16) | |
| 1950 | // Vd(15-12) | 101(11-9) | sz(8)=1 | E(7)=? | 1(6) | M(5)=? | 0(4) | Vm(3-0) |
| 1951 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1952 | emit(cond | 0xE*B24 |B23 | 0x3*B20 | B18 | |
| 1953 | src1.code()*B12 | 0x5*B9 | B8 | B6 | src2.code()); |
| 1954 | } |
| 1955 | |
| 1956 | |
| 1957 | void Assembler::vmrs(Register dst, Condition cond) { |
| 1958 | // Instruction details available in ARM DDI 0406A, A8-652. |
| 1959 | // cond(31-28) | 1110 (27-24) | 1111(23-20)| 0001 (19-16) | |
| 1960 | // Rt(15-12) | 1010 (11-8) | 0(7) | 00 (6-5) | 1(4) | 0000(3-0) |
| 1961 | ASSERT(CpuFeatures::IsEnabled(VFP3)); |
| 1962 | emit(cond | 0xE*B24 | 0xF*B20 | B16 | |
| 1963 | dst.code()*B12 | 0xA*B8 | B4); |
| 1964 | } |
| 1965 | |
| 1966 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1967 | // Pseudo instructions. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1968 | void Assembler::nop(int type) { |
| 1969 | // This is mov rx, rx. |
| 1970 | ASSERT(0 <= type && type <= 14); // mov pc, pc is not a nop. |
| 1971 | emit(al | 13*B21 | type*B12 | type); |
| 1972 | } |
| 1973 | |
| 1974 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1975 | bool Assembler::ImmediateFitsAddrMode1Instruction(int32_t imm32) { |
| 1976 | uint32_t dummy1; |
| 1977 | uint32_t dummy2; |
| 1978 | return fits_shifter(imm32, &dummy1, &dummy2, NULL); |
| 1979 | } |
| 1980 | |
| 1981 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1982 | void Assembler::BlockConstPoolFor(int instructions) { |
| 1983 | BlockConstPoolBefore(pc_offset() + instructions * kInstrSize); |
| 1984 | } |
| 1985 | |
| 1986 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1987 | // Debugging. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1988 | void Assembler::RecordJSReturn() { |
| 1989 | WriteRecordedPositions(); |
| 1990 | CheckBuffer(); |
| 1991 | RecordRelocInfo(RelocInfo::JS_RETURN); |
| 1992 | } |
| 1993 | |
| 1994 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1995 | void Assembler::RecordComment(const char* msg) { |
| 1996 | if (FLAG_debug_code) { |
| 1997 | CheckBuffer(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1998 | RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | void Assembler::RecordPosition(int pos) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2004 | if (pos == RelocInfo::kNoPosition) return; |
| 2005 | ASSERT(pos >= 0); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2006 | current_position_ = pos; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | void Assembler::RecordStatementPosition(int pos) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2011 | if (pos == RelocInfo::kNoPosition) return; |
| 2012 | ASSERT(pos >= 0); |
| 2013 | current_statement_position_ = pos; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | void Assembler::WriteRecordedPositions() { |
| 2018 | // Write the statement position if it is different from what was written last |
| 2019 | // time. |
| 2020 | if (current_statement_position_ != written_statement_position_) { |
| 2021 | CheckBuffer(); |
| 2022 | RecordRelocInfo(RelocInfo::STATEMENT_POSITION, current_statement_position_); |
| 2023 | written_statement_position_ = current_statement_position_; |
| 2024 | } |
| 2025 | |
| 2026 | // Write the position if it is different from what was written last time and |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2027 | // also different from the written statement position. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2028 | if (current_position_ != written_position_ && |
| 2029 | current_position_ != written_statement_position_) { |
| 2030 | CheckBuffer(); |
| 2031 | RecordRelocInfo(RelocInfo::POSITION, current_position_); |
| 2032 | written_position_ = current_position_; |
| 2033 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | void Assembler::GrowBuffer() { |
| 2038 | if (!own_buffer_) FATAL("external code buffer is too small"); |
| 2039 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2040 | // Compute new buffer size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2041 | CodeDesc desc; // the new buffer |
| 2042 | if (buffer_size_ < 4*KB) { |
| 2043 | desc.buffer_size = 4*KB; |
| 2044 | } else if (buffer_size_ < 1*MB) { |
| 2045 | desc.buffer_size = 2*buffer_size_; |
| 2046 | } else { |
| 2047 | desc.buffer_size = buffer_size_ + 1*MB; |
| 2048 | } |
| 2049 | CHECK_GT(desc.buffer_size, 0); // no overflow |
| 2050 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2051 | // Setup new buffer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | desc.buffer = NewArray<byte>(desc.buffer_size); |
| 2053 | |
| 2054 | desc.instr_size = pc_offset(); |
| 2055 | desc.reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| 2056 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2057 | // Copy the data. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2058 | int pc_delta = desc.buffer - buffer_; |
| 2059 | int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_); |
| 2060 | memmove(desc.buffer, buffer_, desc.instr_size); |
| 2061 | memmove(reloc_info_writer.pos() + rc_delta, |
| 2062 | reloc_info_writer.pos(), desc.reloc_size); |
| 2063 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2064 | // Switch buffers. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | DeleteArray(buffer_); |
| 2066 | buffer_ = desc.buffer; |
| 2067 | buffer_size_ = desc.buffer_size; |
| 2068 | pc_ += pc_delta; |
| 2069 | reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
| 2070 | reloc_info_writer.last_pc() + pc_delta); |
| 2071 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2072 | // 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] | 2073 | // 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] | 2074 | // to relocate any emitted relocation entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2075 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2076 | // Relocate pending relocation entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | for (int i = 0; i < num_prinfo_; i++) { |
| 2078 | RelocInfo& rinfo = prinfo_[i]; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2079 | ASSERT(rinfo.rmode() != RelocInfo::COMMENT && |
| 2080 | rinfo.rmode() != RelocInfo::POSITION); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2081 | if (rinfo.rmode() != RelocInfo::JS_RETURN) { |
| 2082 | rinfo.set_pc(rinfo.pc() + pc_delta); |
| 2083 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2088 | void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2089 | RelocInfo rinfo(pc_, rmode, data); // we do not try to reuse pool constants |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2090 | if (rmode >= RelocInfo::JS_RETURN && rmode <= RelocInfo::STATEMENT_POSITION) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2091 | // Adjust code for new modes. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2092 | ASSERT(RelocInfo::IsJSReturn(rmode) |
| 2093 | || RelocInfo::IsComment(rmode) |
| 2094 | || RelocInfo::IsPosition(rmode)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2095 | // These modes do not need an entry in the constant pool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2096 | } else { |
| 2097 | ASSERT(num_prinfo_ < kMaxNumPRInfo); |
| 2098 | prinfo_[num_prinfo_++] = rinfo; |
| 2099 | // 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] | 2100 | // instruction for which we just recorded relocation info. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2101 | BlockConstPoolBefore(pc_offset() + kInstrSize); |
| 2102 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2103 | if (rinfo.rmode() != RelocInfo::NONE) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2104 | // Don't record external references unless the heap will be serialized. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2105 | if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
| 2106 | #ifdef DEBUG |
| 2107 | if (!Serializer::enabled()) { |
| 2108 | Serializer::TooLateToEnableNow(); |
| 2109 | } |
| 2110 | #endif |
| 2111 | if (!Serializer::enabled() && !FLAG_debug_code) { |
| 2112 | return; |
| 2113 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2114 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2115 | ASSERT(buffer_space() >= kMaxRelocSize); // too late to grow buffer here |
| 2116 | reloc_info_writer.Write(&rinfo); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | void Assembler::CheckConstPool(bool force_emit, bool require_jump) { |
| 2122 | // Calculate the offset of the next check. It will be overwritten |
| 2123 | // when a const pool is generated or when const pools are being |
| 2124 | // blocked for a specific range. |
| 2125 | next_buffer_check_ = pc_offset() + kCheckConstInterval; |
| 2126 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2127 | // 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] | 2128 | if (num_prinfo_ == 0) return; |
| 2129 | |
| 2130 | // We emit a constant pool at regular intervals of about kDistBetweenPools |
| 2131 | // or when requested by parameter force_emit (e.g. after each function). |
| 2132 | // We prefer not to emit a jump unless the max distance is reached or if we |
| 2133 | // are running low on slots, which can happen if a lot of constants are being |
| 2134 | // emitted (e.g. --debug-code and many static references). |
| 2135 | int dist = pc_offset() - last_const_pool_end_; |
| 2136 | if (!force_emit && dist < kMaxDistBetweenPools && |
| 2137 | (require_jump || dist < kDistBetweenPools) && |
| 2138 | // TODO(1236125): Cleanup the "magic" number below. We know that |
| 2139 | // the code generation will test every kCheckConstIntervalInst. |
| 2140 | // Thus we are safe as long as we generate less than 7 constant |
| 2141 | // entries per instruction. |
| 2142 | (num_prinfo_ < (kMaxNumPRInfo - (7 * kCheckConstIntervalInst)))) { |
| 2143 | return; |
| 2144 | } |
| 2145 | |
| 2146 | // If we did not return by now, we need to emit the constant pool soon. |
| 2147 | |
| 2148 | // However, some small sequences of instructions must not be broken up by the |
| 2149 | // insertion of a constant pool; such sequences are protected by setting |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2150 | // either const_pool_blocked_nesting_ or no_const_pool_before_, which are |
| 2151 | // both checked here. Also, recursive calls to CheckConstPool are blocked by |
| 2152 | // no_const_pool_before_. |
| 2153 | 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] | 2154 | // Emission is currently blocked; make sure we try again as soon as |
| 2155 | // possible. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2156 | if (const_pool_blocked_nesting_ > 0) { |
| 2157 | next_buffer_check_ = pc_offset() + kInstrSize; |
| 2158 | } else { |
| 2159 | next_buffer_check_ = no_const_pool_before_; |
| 2160 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2161 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2162 | // 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] | 2163 | ASSERT(!force_emit); |
| 2164 | return; |
| 2165 | } |
| 2166 | |
| 2167 | int jump_instr = require_jump ? kInstrSize : 0; |
| 2168 | |
| 2169 | // Check that the code buffer is large enough before emitting the constant |
| 2170 | // pool and relocation information (include the jump over the pool and the |
| 2171 | // constant pool marker). |
| 2172 | int max_needed_space = |
| 2173 | jump_instr + kInstrSize + num_prinfo_*(kInstrSize + kMaxRelocSize); |
| 2174 | while (buffer_space() <= (max_needed_space + kGap)) GrowBuffer(); |
| 2175 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2176 | // Block recursive calls to CheckConstPool. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2177 | BlockConstPoolBefore(pc_offset() + jump_instr + kInstrSize + |
| 2178 | num_prinfo_*kInstrSize); |
| 2179 | // Don't bother to check for the emit calls below. |
| 2180 | next_buffer_check_ = no_const_pool_before_; |
| 2181 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2182 | // Emit jump over constant pool if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2183 | Label after_pool; |
| 2184 | if (require_jump) b(&after_pool); |
| 2185 | |
| 2186 | RecordComment("[ Constant Pool"); |
| 2187 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2188 | // Put down constant pool marker "Undefined instruction" as specified by |
| 2189 | // A3.1 Instruction set encoding. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2190 | emit(0x03000000 | num_prinfo_); |
| 2191 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2192 | // Emit constant pool entries. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | for (int i = 0; i < num_prinfo_; i++) { |
| 2194 | RelocInfo& rinfo = prinfo_[i]; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2195 | ASSERT(rinfo.rmode() != RelocInfo::COMMENT && |
| 2196 | rinfo.rmode() != RelocInfo::POSITION && |
| 2197 | rinfo.rmode() != RelocInfo::STATEMENT_POSITION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2198 | Instr instr = instr_at(rinfo.pc()); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2199 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2200 | // Instruction to patch must be a ldr/str [pc, #offset]. |
| 2201 | // P and U set, B and W clear, Rn == pc, offset12 still 0. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2202 | ASSERT((instr & (7*B25 | P | U | B | W | 15*B16 | Off12Mask)) == |
| 2203 | (2*B25 | P | U | pc.code()*B16)); |
| 2204 | int delta = pc_ - rinfo.pc() - 8; |
| 2205 | ASSERT(delta >= -4); // instr could be ldr pc, [pc, #-4] followed by targ32 |
| 2206 | if (delta < 0) { |
| 2207 | instr &= ~U; |
| 2208 | delta = -delta; |
| 2209 | } |
| 2210 | ASSERT(is_uint12(delta)); |
| 2211 | instr_at_put(rinfo.pc(), instr + delta); |
| 2212 | emit(rinfo.data()); |
| 2213 | } |
| 2214 | num_prinfo_ = 0; |
| 2215 | last_const_pool_end_ = pc_offset(); |
| 2216 | |
| 2217 | RecordComment("]"); |
| 2218 | |
| 2219 | if (after_pool.is_linked()) { |
| 2220 | bind(&after_pool); |
| 2221 | } |
| 2222 | |
| 2223 | // Since a constant pool was just emitted, move the check offset forward by |
| 2224 | // the standard interval. |
| 2225 | next_buffer_check_ = pc_offset() + kCheckConstInterval; |
| 2226 | } |
| 2227 | |
| 2228 | |
| 2229 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame^] | 2230 | |
| 2231 | #endif // V8_TARGET_ARCH_ARM |