ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame^] | 28 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
| 29 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | #include "v8.h" |
| 31 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 32 | #if defined(V8_TARGET_ARCH_ARM) |
| 33 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "bootstrapper.h" |
| 35 | #include "codegen-inl.h" |
| 36 | #include "debug.h" |
| 37 | #include "runtime.h" |
| 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 43 | : Assembler(buffer, size), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 45 | allow_stub_calls_(true), |
| 46 | code_object_(Heap::undefined_value()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
| 50 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 51 | // thumb, so we require inter-working support |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 52 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | #error "flag -mthumb-interwork missing" |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | // We do not support thumb inter-working with an arm architecture not supporting |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 58 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 59 | // you can use -march=armv7 or similar. |
| 60 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 61 | # error "For thumb inter-working we require an architecture which supports blx" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | // Using bx does not yield better code, so use it only when required |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 66 | #if defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 67 | #define USE_BX 1 |
| 68 | #endif |
| 69 | |
| 70 | |
| 71 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 72 | #if USE_BX |
| 73 | bx(target, cond); |
| 74 | #else |
| 75 | mov(pc, Operand(target), LeaveCC, cond); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 80 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 81 | Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | #if USE_BX |
| 83 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 84 | bx(ip, cond); |
| 85 | #else |
| 86 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 87 | #endif |
| 88 | } |
| 89 | |
| 90 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 91 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 92 | Condition cond) { |
| 93 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 95 | } |
| 96 | |
| 97 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 98 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 99 | Condition cond) { |
| 100 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | // 'code' is always generated ARM code, never THUMB code |
| 102 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void MacroAssembler::Call(Register target, Condition cond) { |
| 107 | #if USE_BLX |
| 108 | blx(target, cond); |
| 109 | #else |
| 110 | // set lr for return at current pc + 8 |
| 111 | mov(lr, Operand(pc), LeaveCC, cond); |
| 112 | mov(pc, Operand(target), LeaveCC, cond); |
| 113 | #endif |
| 114 | } |
| 115 | |
| 116 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 117 | void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, |
| 118 | Condition cond) { |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 119 | #if USE_BLX |
| 120 | // On ARMv5 and after the recommended call sequence is: |
| 121 | // ldr ip, [pc, #...] |
| 122 | // blx ip |
| 123 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 124 | // The two instructions (ldr and blx) could be separated by a constant |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 125 | // pool and the code would still work. The issue comes from the |
| 126 | // patching code which expect the ldr to be just above the blx. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 127 | { BlockConstPoolScope block_const_pool(this); |
| 128 | // Statement positions are expected to be recorded when the target |
| 129 | // address is loaded. The mov method will automatically record |
| 130 | // positions when pc is the target, since this is not the case here |
| 131 | // we have to do it explicitly. |
| 132 | WriteRecordedPositions(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 133 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 134 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 135 | blx(ip, cond); |
| 136 | } |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 137 | |
| 138 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 139 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | // Set lr for return at current pc + 8. |
| 141 | mov(lr, Operand(pc), LeaveCC, cond); |
| 142 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 143 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 144 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 145 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 146 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 150 | void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode, |
| 151 | Condition cond) { |
| 152 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 154 | } |
| 155 | |
| 156 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 157 | void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, |
| 158 | Condition cond) { |
| 159 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | // 'code' is always generated ARM code, never THUMB code |
| 161 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 162 | } |
| 163 | |
| 164 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 165 | void MacroAssembler::Ret(Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | #if USE_BX |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 167 | bx(lr, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 168 | #else |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 169 | mov(pc, Operand(lr), LeaveCC, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | #endif |
| 171 | } |
| 172 | |
| 173 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 174 | void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) { |
| 175 | LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 176 | cmp(sp, Operand(ip)); |
| 177 | b(lo, on_stack_overflow); |
| 178 | } |
| 179 | |
| 180 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 181 | void MacroAssembler::Drop(int count, Condition cond) { |
| 182 | if (count > 0) { |
| 183 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 188 | void MacroAssembler::Swap(Register reg1, |
| 189 | Register reg2, |
| 190 | Register scratch, |
| 191 | Condition cond) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 192 | if (scratch.is(no_reg)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 193 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 194 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 195 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 196 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 197 | mov(scratch, reg1, LeaveCC, cond); |
| 198 | mov(reg1, reg2, LeaveCC, cond); |
| 199 | mov(reg2, scratch, LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 204 | void MacroAssembler::Call(Label* target) { |
| 205 | bl(target); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 210 | mov(dst, Operand(value)); |
| 211 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 212 | |
| 213 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 214 | void MacroAssembler::Move(Register dst, Register src) { |
| 215 | if (!dst.is(src)) { |
| 216 | mov(dst, src); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 221 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 222 | Condition cond) { |
| 223 | if (!CpuFeatures::IsSupported(ARMv7) || src2.is_single_instruction()) { |
| 224 | and_(dst, src1, src2, LeaveCC, cond); |
| 225 | return; |
| 226 | } |
| 227 | int32_t immediate = src2.immediate(); |
| 228 | if (immediate == 0) { |
| 229 | mov(dst, Operand(0), LeaveCC, cond); |
| 230 | return; |
| 231 | } |
| 232 | if (IsPowerOf2(immediate + 1) && ((immediate & 1) != 0)) { |
| 233 | ubfx(dst, src1, 0, WhichPowerOf2(immediate + 1), cond); |
| 234 | return; |
| 235 | } |
| 236 | and_(dst, src1, src2, LeaveCC, cond); |
| 237 | } |
| 238 | |
| 239 | |
| 240 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 241 | Condition cond) { |
| 242 | ASSERT(lsb < 32); |
| 243 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 244 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 245 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 246 | if (lsb != 0) { |
| 247 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 248 | } |
| 249 | } else { |
| 250 | ubfx(dst, src1, lsb, width, cond); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | |
| 255 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 256 | Condition cond) { |
| 257 | ASSERT(lsb < 32); |
| 258 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 259 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 260 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 261 | int shift_up = 32 - lsb - width; |
| 262 | int shift_down = lsb + shift_up; |
| 263 | if (shift_up != 0) { |
| 264 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 265 | } |
| 266 | if (shift_down != 0) { |
| 267 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 268 | } |
| 269 | } else { |
| 270 | sbfx(dst, src1, lsb, width, cond); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 275 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 276 | ASSERT(lsb < 32); |
| 277 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 278 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 279 | bic(dst, dst, Operand(mask)); |
| 280 | } else { |
| 281 | bfc(dst, lsb, width, cond); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 286 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 287 | Condition cond) { |
| 288 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 289 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 290 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 291 | |
| 292 | // These asserts are required to ensure compatibility with the ARMv7 |
| 293 | // implementation. |
| 294 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 295 | ASSERT(src.rs().is(no_reg)); |
| 296 | |
| 297 | Label done; |
| 298 | int satval = (1 << satpos) - 1; |
| 299 | |
| 300 | if (cond != al) { |
| 301 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 302 | } |
| 303 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 304 | mov(dst, src); |
| 305 | } |
| 306 | tst(dst, Operand(~satval)); |
| 307 | b(eq, &done); |
| 308 | mov(dst, Operand(0), LeaveCC, mi); // 0 if negative. |
| 309 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 310 | bind(&done); |
| 311 | } else { |
| 312 | usat(dst, satpos, src, cond); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 317 | void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) { |
| 318 | // Empty the const pool. |
| 319 | CheckConstPool(true, true); |
| 320 | add(pc, pc, Operand(index, |
| 321 | LSL, |
| 322 | assembler::arm::Instr::kInstrSizeLog2 - kSmiTagSize)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 323 | BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 324 | nop(); // Jump table alignment. |
| 325 | for (int i = 0; i < targets.length(); i++) { |
| 326 | b(targets[i]); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 331 | void MacroAssembler::LoadRoot(Register destination, |
| 332 | Heap::RootListIndex index, |
| 333 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 334 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 338 | void MacroAssembler::StoreRoot(Register source, |
| 339 | Heap::RootListIndex index, |
| 340 | Condition cond) { |
| 341 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 342 | } |
| 343 | |
| 344 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 345 | void MacroAssembler::RecordWriteHelper(Register object, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 346 | Register address, |
| 347 | Register scratch) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 348 | if (FLAG_debug_code) { |
| 349 | // Check that the object is not in new space. |
| 350 | Label not_in_new_space; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 351 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 352 | Abort("new-space object passed to RecordWriteHelper"); |
| 353 | bind(¬_in_new_space); |
| 354 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 355 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 356 | // Calculate page address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 357 | Bfc(object, 0, kPageSizeBits); |
| 358 | |
| 359 | // Calculate region number. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 360 | Ubfx(address, address, Page::kRegionSizeLog2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 361 | kPageSizeBits - Page::kRegionSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 363 | // Mark region dirty. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 364 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | mov(ip, Operand(1)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 366 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 367 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
| 371 | void MacroAssembler::InNewSpace(Register object, |
| 372 | Register scratch, |
| 373 | Condition cc, |
| 374 | Label* branch) { |
| 375 | ASSERT(cc == eq || cc == ne); |
| 376 | and_(scratch, object, Operand(ExternalReference::new_space_mask())); |
| 377 | cmp(scratch, Operand(ExternalReference::new_space_start())); |
| 378 | b(cc, branch); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 383 | // register 'object' contains a heap object pointer. The heap object |
| 384 | // tag is shifted away. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 385 | void MacroAssembler::RecordWrite(Register object, |
| 386 | Operand offset, |
| 387 | Register scratch0, |
| 388 | Register scratch1) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 389 | // The compiled code assumes that record write doesn't change the |
| 390 | // context register, so we check that none of the clobbered |
| 391 | // registers are cp. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 392 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 393 | |
| 394 | Label done; |
| 395 | |
| 396 | // First, test that the object is not in the new space. We cannot set |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 397 | // region marks for new space pages. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 398 | InNewSpace(object, scratch0, eq, &done); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 399 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 400 | // Add offset into the object. |
| 401 | add(scratch0, object, offset); |
| 402 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 403 | // Record the actual write. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 404 | RecordWriteHelper(object, scratch0, scratch1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | |
| 406 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 407 | |
| 408 | // Clobber all input registers when running with the debug-code flag |
| 409 | // turned on to provoke errors. |
| 410 | if (FLAG_debug_code) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 411 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 412 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 413 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 414 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 418 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 419 | // register 'object' contains a heap object pointer. The heap object |
| 420 | // tag is shifted away. |
| 421 | void MacroAssembler::RecordWrite(Register object, |
| 422 | Register address, |
| 423 | Register scratch) { |
| 424 | // The compiled code assumes that record write doesn't change the |
| 425 | // context register, so we check that none of the clobbered |
| 426 | // registers are cp. |
| 427 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 428 | |
| 429 | Label done; |
| 430 | |
| 431 | // First, test that the object is not in the new space. We cannot set |
| 432 | // region marks for new space pages. |
| 433 | InNewSpace(object, scratch, eq, &done); |
| 434 | |
| 435 | // Record the actual write. |
| 436 | RecordWriteHelper(object, address, scratch); |
| 437 | |
| 438 | bind(&done); |
| 439 | |
| 440 | // Clobber all input registers when running with the debug-code flag |
| 441 | // turned on to provoke errors. |
| 442 | if (FLAG_debug_code) { |
| 443 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 444 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 445 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 450 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 451 | const MemOperand& src, Condition cond) { |
| 452 | ASSERT(src.rm().is(no_reg)); |
| 453 | ASSERT(!dst1.is(lr)); // r14. |
| 454 | ASSERT_EQ(0, dst1.code() % 2); |
| 455 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 456 | |
| 457 | // Generate two ldr instructions if ldrd is not available. |
| 458 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 459 | CpuFeatures::Scope scope(ARMv7); |
| 460 | ldrd(dst1, dst2, src, cond); |
| 461 | } else { |
| 462 | MemOperand src2(src); |
| 463 | src2.set_offset(src2.offset() + 4); |
| 464 | if (dst1.is(src.rn())) { |
| 465 | ldr(dst2, src2, cond); |
| 466 | ldr(dst1, src, cond); |
| 467 | } else { |
| 468 | ldr(dst1, src, cond); |
| 469 | ldr(dst2, src2, cond); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void MacroAssembler::Strd(Register src1, Register src2, |
| 476 | const MemOperand& dst, Condition cond) { |
| 477 | ASSERT(dst.rm().is(no_reg)); |
| 478 | ASSERT(!src1.is(lr)); // r14. |
| 479 | ASSERT_EQ(0, src1.code() % 2); |
| 480 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 481 | |
| 482 | // Generate two str instructions if strd is not available. |
| 483 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 484 | CpuFeatures::Scope scope(ARMv7); |
| 485 | strd(src1, src2, dst, cond); |
| 486 | } else { |
| 487 | MemOperand dst2(dst); |
| 488 | dst2.set_offset(dst2.offset() + 4); |
| 489 | str(src1, dst, cond); |
| 490 | str(src2, dst2, cond); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 495 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 496 | // r0-r3: preserved |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 497 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 498 | mov(ip, Operand(Smi::FromInt(type))); |
| 499 | push(ip); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 500 | mov(ip, Operand(CodeObject())); |
| 501 | push(ip); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 502 | add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 506 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 507 | // r0: preserved |
| 508 | // r1: preserved |
| 509 | // r2: preserved |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 511 | // Drop the execution stack down to the frame pointer and restore |
| 512 | // the caller frame pointer and return address. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 513 | mov(sp, fp); |
| 514 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 518 | void MacroAssembler::EnterExitFrame() { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 519 | // Compute the argv pointer and keep it in a callee-saved register. |
| 520 | // r0 is argc. |
| 521 | add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 522 | sub(r6, r6, Operand(kPointerSize)); |
| 523 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 524 | // Compute callee's stack pointer before making changes and save it as |
| 525 | // ip register so that it is restored as sp register on exit, thereby |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 526 | // popping the args. |
| 527 | |
| 528 | // ip = sp + kPointerSize * #args; |
| 529 | add(ip, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 530 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 531 | // Prepare the stack to be aligned when calling into C. After this point there |
| 532 | // are 5 pushes before the call into C, so the stack needs to be aligned after |
| 533 | // 5 pushes. |
| 534 | int frame_alignment = ActivationFrameAlignment(); |
| 535 | int frame_alignment_mask = frame_alignment - 1; |
| 536 | if (frame_alignment != kPointerSize) { |
| 537 | // The following code needs to be more general if this assert does not hold. |
| 538 | ASSERT(frame_alignment == 2 * kPointerSize); |
| 539 | // With 5 pushes left the frame must be unaligned at this point. |
| 540 | mov(r7, Operand(Smi::FromInt(0))); |
| 541 | tst(sp, Operand((frame_alignment - kPointerSize) & frame_alignment_mask)); |
| 542 | push(r7, eq); // Push if aligned to make it unaligned. |
| 543 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 544 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 545 | // Push in reverse order: caller_fp, sp_on_exit, and caller_pc. |
| 546 | stm(db_w, sp, fp.bit() | ip.bit() | lr.bit()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 547 | mov(fp, Operand(sp)); // Setup new frame pointer. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 548 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 549 | mov(ip, Operand(CodeObject())); |
| 550 | push(ip); // Accessed from ExitFrame::code_slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 551 | |
| 552 | // Save the frame pointer and the context in top. |
| 553 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 554 | str(fp, MemOperand(ip)); |
| 555 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 556 | str(cp, MemOperand(ip)); |
| 557 | |
| 558 | // Setup argc and the builtin function in callee-saved registers. |
| 559 | mov(r4, Operand(r0)); |
| 560 | mov(r5, Operand(r1)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 564 | void MacroAssembler::InitializeNewString(Register string, |
| 565 | Register length, |
| 566 | Heap::RootListIndex map_index, |
| 567 | Register scratch1, |
| 568 | Register scratch2) { |
| 569 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 570 | LoadRoot(scratch2, map_index); |
| 571 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 572 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 573 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 574 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 575 | } |
| 576 | |
| 577 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 578 | int MacroAssembler::ActivationFrameAlignment() { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 579 | #if defined(V8_HOST_ARCH_ARM) |
| 580 | // Running on the real platform. Use the alignment as mandated by the local |
| 581 | // environment. |
| 582 | // Note: This will break if we ever start generating snapshots on one ARM |
| 583 | // platform for another ARM platform with a different alignment. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 584 | return OS::ActivationFrameAlignment(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 585 | #else // defined(V8_HOST_ARCH_ARM) |
| 586 | // If we are using the simulator then we should always align to the expected |
| 587 | // alignment. As the simulator is used to generate snapshots we do not know |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 588 | // if the target platform will need alignment, so this is controlled from a |
| 589 | // flag. |
| 590 | return FLAG_sim_stack_alignment; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 591 | #endif // defined(V8_HOST_ARCH_ARM) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 595 | void MacroAssembler::LeaveExitFrame() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 596 | // Clear top frame. |
| 597 | mov(r3, Operand(0)); |
| 598 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 599 | str(r3, MemOperand(ip)); |
| 600 | |
| 601 | // Restore current context from top and clear it in debug mode. |
| 602 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 603 | ldr(cp, MemOperand(ip)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 604 | #ifdef DEBUG |
| 605 | str(r3, MemOperand(ip)); |
| 606 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 607 | |
| 608 | // Pop the arguments, restore registers, and return. |
| 609 | mov(sp, Operand(fp)); // respect ABI stack constraint |
| 610 | ldm(ia, sp, fp.bit() | sp.bit() | pc.bit()); |
| 611 | } |
| 612 | |
| 613 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 614 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 615 | const ParameterCount& actual, |
| 616 | Handle<Code> code_constant, |
| 617 | Register code_reg, |
| 618 | Label* done, |
| 619 | InvokeFlag flag) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 620 | bool definitely_matches = false; |
| 621 | Label regular_invoke; |
| 622 | |
| 623 | // Check whether the expected and actual arguments count match. If not, |
| 624 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 625 | // r0: actual arguments count |
| 626 | // r1: function (passed through to callee) |
| 627 | // r2: expected arguments count |
| 628 | // r3: callee code entry |
| 629 | |
| 630 | // The code below is made a lot easier because the calling code already sets |
| 631 | // up actual and expected registers according to the contract if values are |
| 632 | // passed in registers. |
| 633 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 634 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 635 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 636 | |
| 637 | if (expected.is_immediate()) { |
| 638 | ASSERT(actual.is_immediate()); |
| 639 | if (expected.immediate() == actual.immediate()) { |
| 640 | definitely_matches = true; |
| 641 | } else { |
| 642 | mov(r0, Operand(actual.immediate())); |
| 643 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 644 | if (expected.immediate() == sentinel) { |
| 645 | // Don't worry about adapting arguments for builtins that |
| 646 | // don't want that done. Skip adaption code by making it look |
| 647 | // like we have a match between expected and actual number of |
| 648 | // arguments. |
| 649 | definitely_matches = true; |
| 650 | } else { |
| 651 | mov(r2, Operand(expected.immediate())); |
| 652 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 653 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 654 | } else { |
| 655 | if (actual.is_immediate()) { |
| 656 | cmp(expected.reg(), Operand(actual.immediate())); |
| 657 | b(eq, ®ular_invoke); |
| 658 | mov(r0, Operand(actual.immediate())); |
| 659 | } else { |
| 660 | cmp(expected.reg(), Operand(actual.reg())); |
| 661 | b(eq, ®ular_invoke); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (!definitely_matches) { |
| 666 | if (!code_constant.is_null()) { |
| 667 | mov(r3, Operand(code_constant)); |
| 668 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 669 | } |
| 670 | |
| 671 | Handle<Code> adaptor = |
| 672 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 673 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 674 | Call(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 675 | b(done); |
| 676 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 677 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 678 | } |
| 679 | bind(®ular_invoke); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
| 683 | |
| 684 | void MacroAssembler::InvokeCode(Register code, |
| 685 | const ParameterCount& expected, |
| 686 | const ParameterCount& actual, |
| 687 | InvokeFlag flag) { |
| 688 | Label done; |
| 689 | |
| 690 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); |
| 691 | if (flag == CALL_FUNCTION) { |
| 692 | Call(code); |
| 693 | } else { |
| 694 | ASSERT(flag == JUMP_FUNCTION); |
| 695 | Jump(code); |
| 696 | } |
| 697 | |
| 698 | // Continue here if InvokePrologue does handle the invocation due to |
| 699 | // mismatched parameter counts. |
| 700 | bind(&done); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 705 | const ParameterCount& expected, |
| 706 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 707 | RelocInfo::Mode rmode, |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 708 | InvokeFlag flag) { |
| 709 | Label done; |
| 710 | |
| 711 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 712 | if (flag == CALL_FUNCTION) { |
| 713 | Call(code, rmode); |
| 714 | } else { |
| 715 | Jump(code, rmode); |
| 716 | } |
| 717 | |
| 718 | // Continue here if InvokePrologue does handle the invocation due to |
| 719 | // mismatched parameter counts. |
| 720 | bind(&done); |
| 721 | } |
| 722 | |
| 723 | |
| 724 | void MacroAssembler::InvokeFunction(Register fun, |
| 725 | const ParameterCount& actual, |
| 726 | InvokeFlag flag) { |
| 727 | // Contract with called JS functions requires that function is passed in r1. |
| 728 | ASSERT(fun.is(r1)); |
| 729 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 730 | Register expected_reg = r2; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 731 | Register code_reg = r3; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 732 | |
| 733 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 734 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 735 | ldr(expected_reg, |
| 736 | FieldMemOperand(code_reg, |
| 737 | SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 738 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 739 | ldr(code_reg, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 740 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 741 | |
| 742 | ParameterCount expected(expected_reg); |
| 743 | InvokeCode(code_reg, expected, actual, flag); |
| 744 | } |
| 745 | |
| 746 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 747 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 748 | const ParameterCount& actual, |
| 749 | InvokeFlag flag) { |
| 750 | ASSERT(function->is_compiled()); |
| 751 | |
| 752 | // Get the function and setup the context. |
| 753 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 754 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 755 | |
| 756 | // Invoke the cached code. |
| 757 | Handle<Code> code(function->code()); |
| 758 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 759 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 760 | } |
| 761 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 762 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 763 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 764 | void MacroAssembler::DebugBreak() { |
| 765 | ASSERT(allow_stub_calls()); |
| 766 | mov(r0, Operand(0)); |
| 767 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak))); |
| 768 | CEntryStub ces(1); |
| 769 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 770 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 771 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 772 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 773 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 774 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 775 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 776 | // Adjust this code if not the case. |
| 777 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | // The pc (return address) is passed in register lr. |
| 779 | if (try_location == IN_JAVASCRIPT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | if (type == TRY_CATCH_HANDLER) { |
| 781 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 782 | } else { |
| 783 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 784 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 785 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 786 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 787 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 788 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 789 | // Save the current handler as the next handler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 790 | mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 791 | ldr(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 792 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 793 | push(r1); |
| 794 | // Link this handler as the new current one. |
| 795 | str(sp, MemOperand(r3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 796 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 797 | // Must preserve r0-r4, r5-r7 are available. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 798 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 799 | // The frame pointer does not point to a JS frame so we save NULL |
| 800 | // for fp. We expect the code throwing an exception to check fp |
| 801 | // before dereferencing it to restore the context. |
| 802 | mov(ip, Operand(0)); // To save a NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | mov(r6, Operand(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 804 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 805 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 806 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 807 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 808 | // Save the current handler as the next handler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 809 | mov(r7, Operand(ExternalReference(Top::k_handler_address))); |
| 810 | ldr(r6, MemOperand(r7)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 811 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 812 | push(r6); |
| 813 | // Link this handler as the new current one. |
| 814 | str(sp, MemOperand(r7)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
| 818 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 819 | void MacroAssembler::PopTryHandler() { |
| 820 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 821 | pop(r1); |
| 822 | mov(ip, Operand(ExternalReference(Top::k_handler_address))); |
| 823 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 824 | str(r1, MemOperand(ip)); |
| 825 | } |
| 826 | |
| 827 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 828 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 829 | Register scratch, |
| 830 | Label* miss) { |
| 831 | Label same_contexts; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 833 | ASSERT(!holder_reg.is(scratch)); |
| 834 | ASSERT(!holder_reg.is(ip)); |
| 835 | ASSERT(!scratch.is(ip)); |
| 836 | |
| 837 | // Load current lexical context from the stack frame. |
| 838 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 839 | // In debug mode, make sure the lexical context is set. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 840 | #ifdef DEBUG |
| 841 | cmp(scratch, Operand(0)); |
| 842 | Check(ne, "we should not have an empty lexical context"); |
| 843 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 844 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 845 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 847 | ldr(scratch, FieldMemOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 848 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 849 | |
| 850 | // Check the context is a global context. |
| 851 | if (FLAG_debug_code) { |
| 852 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 853 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 854 | // that ip is clobbered as part of cmp with an object Operand. |
| 855 | push(holder_reg); // Temporarily save holder on the stack. |
| 856 | // Read the first word and compare to the global_context_map. |
| 857 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 858 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 859 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 860 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 861 | pop(holder_reg); // Restore holder. |
| 862 | } |
| 863 | |
| 864 | // Check if both contexts are the same. |
| 865 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 866 | cmp(scratch, Operand(ip)); |
| 867 | b(eq, &same_contexts); |
| 868 | |
| 869 | // Check the context is a global context. |
| 870 | if (FLAG_debug_code) { |
| 871 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 872 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 873 | // that ip is clobbered as part of cmp with an object Operand. |
| 874 | push(holder_reg); // Temporarily save holder on the stack. |
| 875 | mov(holder_reg, ip); // Move ip to its holding place. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 876 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 877 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 878 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 879 | |
| 880 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 881 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 882 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 883 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 884 | // Restore ip is not needed. ip is reloaded below. |
| 885 | pop(holder_reg); // Restore holder. |
| 886 | // Restore ip to holder's context. |
| 887 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 888 | } |
| 889 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 890 | // Check that the security token in the calling global object is |
| 891 | // compatible with the security token in the receiving global |
| 892 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 893 | int token_offset = Context::kHeaderSize + |
| 894 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 895 | |
| 896 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 897 | ldr(ip, FieldMemOperand(ip, token_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 898 | cmp(scratch, Operand(ip)); |
| 899 | b(ne, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 900 | |
| 901 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 905 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 906 | Register result, |
| 907 | Register scratch1, |
| 908 | Register scratch2, |
| 909 | Label* gc_required, |
| 910 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 911 | ASSERT(!result.is(scratch1)); |
| 912 | ASSERT(!scratch1.is(scratch2)); |
| 913 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 914 | // Make object size into bytes. |
| 915 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 916 | object_size *= kPointerSize; |
| 917 | } |
| 918 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 919 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 920 | // Load address of new object into result and allocation top address into |
| 921 | // scratch1. |
| 922 | ExternalReference new_space_allocation_top = |
| 923 | ExternalReference::new_space_allocation_top_address(); |
| 924 | mov(scratch1, Operand(new_space_allocation_top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 925 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 926 | ldr(result, MemOperand(scratch1)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 927 | } else if (FLAG_debug_code) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 928 | // Assert that result actually contains top on entry. scratch2 is used |
| 929 | // immediately below so this use of scratch2 does not cause difference with |
| 930 | // respect to register content between debug and release mode. |
| 931 | ldr(scratch2, MemOperand(scratch1)); |
| 932 | cmp(result, scratch2); |
| 933 | Check(eq, "Unexpected allocation top"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 934 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 935 | |
| 936 | // Calculate new top and bail out if new space is exhausted. Use result |
| 937 | // to calculate the new top. |
| 938 | ExternalReference new_space_allocation_limit = |
| 939 | ExternalReference::new_space_allocation_limit_address(); |
| 940 | mov(scratch2, Operand(new_space_allocation_limit)); |
| 941 | ldr(scratch2, MemOperand(scratch2)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 942 | add(result, result, Operand(object_size)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 943 | cmp(result, Operand(scratch2)); |
| 944 | b(hi, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 945 | str(result, MemOperand(scratch1)); |
| 946 | |
| 947 | // Tag and adjust back to start of new object. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 948 | if ((flags & TAG_OBJECT) != 0) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 949 | sub(result, result, Operand(object_size - kHeapObjectTag)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 950 | } else { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 951 | sub(result, result, Operand(object_size)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
| 955 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 956 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 957 | Register result, |
| 958 | Register scratch1, |
| 959 | Register scratch2, |
| 960 | Label* gc_required, |
| 961 | AllocationFlags flags) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 962 | ASSERT(!result.is(scratch1)); |
| 963 | ASSERT(!scratch1.is(scratch2)); |
| 964 | |
| 965 | // Load address of new object into result and allocation top address into |
| 966 | // scratch1. |
| 967 | ExternalReference new_space_allocation_top = |
| 968 | ExternalReference::new_space_allocation_top_address(); |
| 969 | mov(scratch1, Operand(new_space_allocation_top)); |
| 970 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 971 | ldr(result, MemOperand(scratch1)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 972 | } else if (FLAG_debug_code) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 973 | // Assert that result actually contains top on entry. scratch2 is used |
| 974 | // immediately below so this use of scratch2 does not cause difference with |
| 975 | // respect to register content between debug and release mode. |
| 976 | ldr(scratch2, MemOperand(scratch1)); |
| 977 | cmp(result, scratch2); |
| 978 | Check(eq, "Unexpected allocation top"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | // Calculate new top and bail out if new space is exhausted. Use result |
| 982 | // to calculate the new top. Object size is in words so a shift is required to |
| 983 | // get the number of bytes |
| 984 | ExternalReference new_space_allocation_limit = |
| 985 | ExternalReference::new_space_allocation_limit_address(); |
| 986 | mov(scratch2, Operand(new_space_allocation_limit)); |
| 987 | ldr(scratch2, MemOperand(scratch2)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 988 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 989 | add(result, result, Operand(object_size, LSL, kPointerSizeLog2)); |
| 990 | } else { |
| 991 | add(result, result, Operand(object_size)); |
| 992 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 993 | cmp(result, Operand(scratch2)); |
| 994 | b(hi, gc_required); |
| 995 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 996 | // Update allocation top. result temporarily holds the new top. |
| 997 | if (FLAG_debug_code) { |
| 998 | tst(result, Operand(kObjectAlignmentMask)); |
| 999 | Check(eq, "Unaligned allocation in new space"); |
| 1000 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1001 | str(result, MemOperand(scratch1)); |
| 1002 | |
| 1003 | // Adjust back to start of new object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1004 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1005 | sub(result, result, Operand(object_size, LSL, kPointerSizeLog2)); |
| 1006 | } else { |
| 1007 | sub(result, result, Operand(object_size)); |
| 1008 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1009 | |
| 1010 | // Tag object if requested. |
| 1011 | if ((flags & TAG_OBJECT) != 0) { |
| 1012 | add(result, result, Operand(kHeapObjectTag)); |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1018 | Register scratch) { |
| 1019 | ExternalReference new_space_allocation_top = |
| 1020 | ExternalReference::new_space_allocation_top_address(); |
| 1021 | |
| 1022 | // Make sure the object has no tag before resetting top. |
| 1023 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1024 | #ifdef DEBUG |
| 1025 | // Check that the object un-allocated is below the current top. |
| 1026 | mov(scratch, Operand(new_space_allocation_top)); |
| 1027 | ldr(scratch, MemOperand(scratch)); |
| 1028 | cmp(object, scratch); |
| 1029 | Check(lt, "Undo allocation of non allocated memory"); |
| 1030 | #endif |
| 1031 | // Write the address of the object to un-allocate as the current top. |
| 1032 | mov(scratch, Operand(new_space_allocation_top)); |
| 1033 | str(object, MemOperand(scratch)); |
| 1034 | } |
| 1035 | |
| 1036 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1037 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1038 | Register length, |
| 1039 | Register scratch1, |
| 1040 | Register scratch2, |
| 1041 | Register scratch3, |
| 1042 | Label* gc_required) { |
| 1043 | // Calculate the number of bytes needed for the characters in the string while |
| 1044 | // observing object alignment. |
| 1045 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1046 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1047 | add(scratch1, scratch1, |
| 1048 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1049 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1050 | |
| 1051 | // Allocate two-byte string in new space. |
| 1052 | AllocateInNewSpace(scratch1, |
| 1053 | result, |
| 1054 | scratch2, |
| 1055 | scratch3, |
| 1056 | gc_required, |
| 1057 | TAG_OBJECT); |
| 1058 | |
| 1059 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1060 | InitializeNewString(result, |
| 1061 | length, |
| 1062 | Heap::kStringMapRootIndex, |
| 1063 | scratch1, |
| 1064 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1069 | Register length, |
| 1070 | Register scratch1, |
| 1071 | Register scratch2, |
| 1072 | Register scratch3, |
| 1073 | Label* gc_required) { |
| 1074 | // Calculate the number of bytes needed for the characters in the string while |
| 1075 | // observing object alignment. |
| 1076 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1077 | ASSERT(kCharSize == 1); |
| 1078 | add(scratch1, length, |
| 1079 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1080 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1081 | |
| 1082 | // Allocate ASCII string in new space. |
| 1083 | AllocateInNewSpace(scratch1, |
| 1084 | result, |
| 1085 | scratch2, |
| 1086 | scratch3, |
| 1087 | gc_required, |
| 1088 | TAG_OBJECT); |
| 1089 | |
| 1090 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1091 | InitializeNewString(result, |
| 1092 | length, |
| 1093 | Heap::kAsciiStringMapRootIndex, |
| 1094 | scratch1, |
| 1095 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1100 | Register length, |
| 1101 | Register scratch1, |
| 1102 | Register scratch2, |
| 1103 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1104 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1105 | result, |
| 1106 | scratch1, |
| 1107 | scratch2, |
| 1108 | gc_required, |
| 1109 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1110 | |
| 1111 | InitializeNewString(result, |
| 1112 | length, |
| 1113 | Heap::kConsStringMapRootIndex, |
| 1114 | scratch1, |
| 1115 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1120 | Register length, |
| 1121 | Register scratch1, |
| 1122 | Register scratch2, |
| 1123 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1124 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1125 | result, |
| 1126 | scratch1, |
| 1127 | scratch2, |
| 1128 | gc_required, |
| 1129 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1130 | |
| 1131 | InitializeNewString(result, |
| 1132 | length, |
| 1133 | Heap::kConsAsciiStringMapRootIndex, |
| 1134 | scratch1, |
| 1135 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1139 | void MacroAssembler::CompareObjectType(Register object, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1140 | Register map, |
| 1141 | Register type_reg, |
| 1142 | InstanceType type) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1143 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1144 | CompareInstanceType(map, type_reg, type); |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | void MacroAssembler::CompareInstanceType(Register map, |
| 1149 | Register type_reg, |
| 1150 | InstanceType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1151 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1152 | cmp(type_reg, Operand(type)); |
| 1153 | } |
| 1154 | |
| 1155 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1156 | void MacroAssembler::CheckMap(Register obj, |
| 1157 | Register scratch, |
| 1158 | Handle<Map> map, |
| 1159 | Label* fail, |
| 1160 | bool is_heap_object) { |
| 1161 | if (!is_heap_object) { |
| 1162 | BranchOnSmi(obj, fail); |
| 1163 | } |
| 1164 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1165 | mov(ip, Operand(map)); |
| 1166 | cmp(scratch, ip); |
| 1167 | b(ne, fail); |
| 1168 | } |
| 1169 | |
| 1170 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1171 | void MacroAssembler::CheckMap(Register obj, |
| 1172 | Register scratch, |
| 1173 | Heap::RootListIndex index, |
| 1174 | Label* fail, |
| 1175 | bool is_heap_object) { |
| 1176 | if (!is_heap_object) { |
| 1177 | BranchOnSmi(obj, fail); |
| 1178 | } |
| 1179 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1180 | LoadRoot(ip, index); |
| 1181 | cmp(scratch, ip); |
| 1182 | b(ne, fail); |
| 1183 | } |
| 1184 | |
| 1185 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1186 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1187 | Register result, |
| 1188 | Register scratch, |
| 1189 | Label* miss) { |
| 1190 | // Check that the receiver isn't a smi. |
| 1191 | BranchOnSmi(function, miss); |
| 1192 | |
| 1193 | // Check that the function really is a function. Load map into result reg. |
| 1194 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1195 | b(ne, miss); |
| 1196 | |
| 1197 | // Make sure that the function has an instance prototype. |
| 1198 | Label non_instance; |
| 1199 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1200 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1201 | b(ne, &non_instance); |
| 1202 | |
| 1203 | // Get the prototype or initial map from the function. |
| 1204 | ldr(result, |
| 1205 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1206 | |
| 1207 | // If the prototype or initial map is the hole, don't return it and |
| 1208 | // simply miss the cache instead. This will allow us to allocate a |
| 1209 | // prototype object on-demand in the runtime system. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1210 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1211 | cmp(result, ip); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1212 | b(eq, miss); |
| 1213 | |
| 1214 | // If the function does not have an initial map, we're done. |
| 1215 | Label done; |
| 1216 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1217 | b(ne, &done); |
| 1218 | |
| 1219 | // Get the prototype from the initial map. |
| 1220 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1221 | jmp(&done); |
| 1222 | |
| 1223 | // Non-instance prototype: Fetch prototype from constructor field |
| 1224 | // in initial map. |
| 1225 | bind(&non_instance); |
| 1226 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1227 | |
| 1228 | // All done. |
| 1229 | bind(&done); |
| 1230 | } |
| 1231 | |
| 1232 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1233 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1234 | ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1235 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1239 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
| 1240 | ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
| 1241 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1242 | } |
| 1243 | |
| 1244 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1245 | void MacroAssembler::StubReturn(int argc, Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | ASSERT(argc >= 1 && generating_stub()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1247 | if (argc > 1) { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1248 | add(sp, sp, Operand((argc - 1) * kPointerSize), LeaveCC, cond); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1249 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1250 | Ret(cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1253 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1254 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1255 | if (num_arguments > 0) { |
| 1256 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1257 | } |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1258 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1262 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1263 | // If the hash field contains an array index pick it out. The assert checks |
| 1264 | // that the constants for the maximum number of digits for an array index |
| 1265 | // cached in the hash field and the number of bits reserved for it does not |
| 1266 | // conflict. |
| 1267 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1268 | (1 << String::kArrayIndexValueBits)); |
| 1269 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1270 | // the low kHashShift bits. |
| 1271 | STATIC_ASSERT(kSmiTag == 0); |
| 1272 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 1273 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 1274 | } |
| 1275 | |
| 1276 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1277 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 1278 | Register outHighReg, |
| 1279 | Register outLowReg) { |
| 1280 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 1281 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1282 | vmov(s15, r7); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1283 | vcvt_f64_s32(d7, s15); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1284 | vmov(outLowReg, outHighReg, d7); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1288 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 1289 | DwVfpRegister result, |
| 1290 | Register scratch1, |
| 1291 | Register scratch2, |
| 1292 | Register heap_number_map, |
| 1293 | SwVfpRegister scratch3, |
| 1294 | Label* not_number, |
| 1295 | ObjectToDoubleFlags flags) { |
| 1296 | Label done; |
| 1297 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 1298 | Label not_smi; |
| 1299 | BranchOnNotSmi(object, ¬_smi); |
| 1300 | // Remove smi tag and convert to double. |
| 1301 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 1302 | vmov(scratch3, scratch1); |
| 1303 | vcvt_f64_s32(result, scratch3); |
| 1304 | b(&done); |
| 1305 | bind(¬_smi); |
| 1306 | } |
| 1307 | // Check for heap number and load double value from it. |
| 1308 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1309 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1310 | cmp(scratch1, heap_number_map); |
| 1311 | b(ne, not_number); |
| 1312 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 1313 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 1314 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1315 | Sbfx(scratch1, |
| 1316 | scratch1, |
| 1317 | HeapNumber::kExponentShift, |
| 1318 | HeapNumber::kExponentBits); |
| 1319 | // All-one value sign extend to -1. |
| 1320 | cmp(scratch1, Operand(-1)); |
| 1321 | b(eq, not_number); |
| 1322 | } |
| 1323 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 1324 | bind(&done); |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 1329 | DwVfpRegister value, |
| 1330 | Register scratch1, |
| 1331 | SwVfpRegister scratch2) { |
| 1332 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 1333 | vmov(scratch2, scratch1); |
| 1334 | vcvt_f64_s32(value, scratch2); |
| 1335 | } |
| 1336 | |
| 1337 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame^] | 1338 | // Tries to get a signed int32 out of a double precision floating point heap |
| 1339 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 1340 | // 32bits signed integer range. |
| 1341 | void MacroAssembler::ConvertToInt32(Register source, |
| 1342 | Register dest, |
| 1343 | Register scratch, |
| 1344 | Register scratch2, |
| 1345 | Label *not_int32) { |
| 1346 | if (CpuFeatures::IsSupported(VFP3)) { |
| 1347 | CpuFeatures::Scope scope(VFP3); |
| 1348 | sub(scratch, source, Operand(kHeapObjectTag)); |
| 1349 | vldr(d0, scratch, HeapNumber::kValueOffset); |
| 1350 | vcvt_s32_f64(s0, d0); |
| 1351 | vmov(dest, s0); |
| 1352 | // Signed vcvt instruction will saturate to the minimum (0x80000000) or |
| 1353 | // maximun (0x7fffffff) signed 32bits integer when the double is out of |
| 1354 | // range. When substracting one, the minimum signed integer becomes the |
| 1355 | // maximun signed integer. |
| 1356 | sub(scratch, dest, Operand(1)); |
| 1357 | cmp(scratch, Operand(LONG_MAX - 1)); |
| 1358 | // If equal then dest was LONG_MAX, if greater dest was LONG_MIN. |
| 1359 | b(ge, not_int32); |
| 1360 | } else { |
| 1361 | // This code is faster for doubles that are in the ranges -0x7fffffff to |
| 1362 | // -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to |
| 1363 | // the range of signed int32 values that are not Smis. Jumps to the label |
| 1364 | // 'not_int32' if the double isn't in the range -0x80000000.0 to |
| 1365 | // 0x80000000.0 (excluding the endpoints). |
| 1366 | Label right_exponent, done; |
| 1367 | // Get exponent word. |
| 1368 | ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 1369 | // Get exponent alone in scratch2. |
| 1370 | Ubfx(scratch2, |
| 1371 | scratch, |
| 1372 | HeapNumber::kExponentShift, |
| 1373 | HeapNumber::kExponentBits); |
| 1374 | // Load dest with zero. We use this either for the final shift or |
| 1375 | // for the answer. |
| 1376 | mov(dest, Operand(0)); |
| 1377 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 1378 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 1379 | // the exponent that we are fastest at and also the highest exponent we can |
| 1380 | // handle here. |
| 1381 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 1382 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 1383 | // split it up to avoid a constant pool entry. You can't do that in general |
| 1384 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 1385 | // range 0-2047 so there is no overflow. |
| 1386 | int fudge_factor = 0x400; |
| 1387 | sub(scratch2, scratch2, Operand(fudge_factor)); |
| 1388 | cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
| 1389 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 1390 | // logic. |
| 1391 | b(eq, &right_exponent); |
| 1392 | // If the exponent is higher than that then go to slow case. This catches |
| 1393 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 1394 | b(gt, not_int32); |
| 1395 | |
| 1396 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 1397 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 1398 | // it rounds to zero. |
| 1399 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 1400 | sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
| 1401 | // Dest already has a Smi zero. |
| 1402 | b(lt, &done); |
| 1403 | |
| 1404 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 1405 | // get how much to shift down. |
| 1406 | rsb(dest, scratch2, Operand(30)); |
| 1407 | |
| 1408 | bind(&right_exponent); |
| 1409 | // Get the top bits of the mantissa. |
| 1410 | and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 1411 | // Put back the implicit 1. |
| 1412 | orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 1413 | // Shift up the mantissa bits to take up the space the exponent used to |
| 1414 | // take. We just orred in the implicit bit so that took care of one and |
| 1415 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 1416 | // distance. |
| 1417 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1418 | mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 1419 | // Put sign in zero flag. |
| 1420 | tst(scratch, Operand(HeapNumber::kSignMask)); |
| 1421 | // Get the second half of the double. For some exponents we don't |
| 1422 | // actually need this because the bits get shifted out again, but |
| 1423 | // it's probably slower to test than just to do it. |
| 1424 | ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 1425 | // Shift down 22 bits to get the last 10 bits. |
| 1426 | orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 1427 | // Move down according to the exponent. |
| 1428 | mov(dest, Operand(scratch, LSR, dest)); |
| 1429 | // Fix sign if sign bit was set. |
| 1430 | rsb(dest, dest, Operand(0), LeaveCC, ne); |
| 1431 | bind(&done); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1436 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 1437 | Register src, |
| 1438 | int num_least_bits) { |
| 1439 | if (CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1440 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1441 | } else { |
| 1442 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 1443 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1448 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1449 | // All parameters are on the stack. r0 has the return value after call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1450 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1451 | // If the expected number of arguments of the runtime function is |
| 1452 | // constant, we check that the actual number of arguments match the |
| 1453 | // expectation. |
| 1454 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1455 | IllegalOperation(num_arguments); |
| 1456 | return; |
| 1457 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1458 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1459 | // TODO(1236192): Most runtime routines don't need the number of |
| 1460 | // arguments passed in because it is constant. At some point we |
| 1461 | // should remove this need and make the runtime routine entry code |
| 1462 | // smarter. |
| 1463 | mov(r0, Operand(num_arguments)); |
| 1464 | mov(r1, Operand(ExternalReference(f))); |
| 1465 | CEntryStub stub(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1466 | CallStub(&stub); |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 1471 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 1472 | } |
| 1473 | |
| 1474 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1475 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 1476 | int num_arguments) { |
| 1477 | mov(r0, Operand(num_arguments)); |
| 1478 | mov(r1, Operand(ext)); |
| 1479 | |
| 1480 | CEntryStub stub(1); |
| 1481 | CallStub(&stub); |
| 1482 | } |
| 1483 | |
| 1484 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1485 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1486 | int num_arguments, |
| 1487 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1488 | // TODO(1236192): Most runtime routines don't need the number of |
| 1489 | // arguments passed in because it is constant. At some point we |
| 1490 | // should remove this need and make the runtime routine entry code |
| 1491 | // smarter. |
| 1492 | mov(r0, Operand(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1493 | JumpToExternalReference(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1497 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1498 | int num_arguments, |
| 1499 | int result_size) { |
| 1500 | TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1505 | #if defined(__thumb__) |
| 1506 | // Thumb mode builtin. |
| 1507 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1508 | #endif |
| 1509 | mov(r1, Operand(builtin)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1510 | CEntryStub stub(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1511 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1515 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1516 | InvokeJSFlags flags) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1517 | GetBuiltinEntry(r2, id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | if (flags == CALL_JS) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1519 | Call(r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1520 | } else { |
| 1521 | ASSERT(flags == JUMP_JS); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1522 | Jump(r2); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1527 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 1528 | Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1529 | // Load the builtins object into target register. |
| 1530 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1531 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1532 | // Load the JavaScript builtin function from the builtins object. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1533 | ldr(target, FieldMemOperand(target, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1534 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 1535 | } |
| 1536 | |
| 1537 | |
| 1538 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 1539 | ASSERT(!target.is(r1)); |
| 1540 | GetBuiltinFunction(r1, id); |
| 1541 | // Load the code entry point from the builtins object. |
| 1542 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1546 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 1547 | Register scratch1, Register scratch2) { |
| 1548 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1549 | mov(scratch1, Operand(value)); |
| 1550 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1551 | str(scratch1, MemOperand(scratch2)); |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | |
| 1556 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 1557 | Register scratch1, Register scratch2) { |
| 1558 | ASSERT(value > 0); |
| 1559 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1560 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1561 | ldr(scratch1, MemOperand(scratch2)); |
| 1562 | add(scratch1, scratch1, Operand(value)); |
| 1563 | str(scratch1, MemOperand(scratch2)); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 1569 | Register scratch1, Register scratch2) { |
| 1570 | ASSERT(value > 0); |
| 1571 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1572 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1573 | ldr(scratch1, MemOperand(scratch2)); |
| 1574 | sub(scratch1, scratch1, Operand(value)); |
| 1575 | str(scratch1, MemOperand(scratch2)); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1580 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 1581 | if (FLAG_debug_code) |
| 1582 | Check(cc, msg); |
| 1583 | } |
| 1584 | |
| 1585 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1586 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 1587 | Heap::RootListIndex index) { |
| 1588 | if (FLAG_debug_code) { |
| 1589 | LoadRoot(ip, index); |
| 1590 | cmp(reg, ip); |
| 1591 | Check(eq, "Register did not match expected root"); |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1596 | void MacroAssembler::AssertFastElements(Register elements) { |
| 1597 | if (FLAG_debug_code) { |
| 1598 | ASSERT(!elements.is(ip)); |
| 1599 | Label ok; |
| 1600 | push(elements); |
| 1601 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 1602 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 1603 | cmp(elements, ip); |
| 1604 | b(eq, &ok); |
| 1605 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 1606 | cmp(elements, ip); |
| 1607 | b(eq, &ok); |
| 1608 | Abort("JSObject with fast elements map has slow elements"); |
| 1609 | bind(&ok); |
| 1610 | pop(elements); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1615 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 1616 | Label L; |
| 1617 | b(cc, &L); |
| 1618 | Abort(msg); |
| 1619 | // will not return here |
| 1620 | bind(&L); |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void MacroAssembler::Abort(const char* msg) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1625 | Label abort_start; |
| 1626 | bind(&abort_start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1627 | // We want to pass the msg string like a smi to avoid GC |
| 1628 | // problems, however msg is not guaranteed to be aligned |
| 1629 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1630 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1631 | // from the real pointer as a smi. |
| 1632 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 1633 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 1634 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 1635 | #ifdef DEBUG |
| 1636 | if (msg != NULL) { |
| 1637 | RecordComment("Abort message: "); |
| 1638 | RecordComment(msg); |
| 1639 | } |
| 1640 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1641 | // Disable stub call restrictions to always allow calls to abort. |
| 1642 | set_allow_stub_calls(true); |
| 1643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1644 | mov(r0, Operand(p0)); |
| 1645 | push(r0); |
| 1646 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1647 | push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1648 | CallRuntime(Runtime::kAbort, 2); |
| 1649 | // will not return here |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1650 | if (is_const_pool_blocked()) { |
| 1651 | // If the calling code cares about the exact number of |
| 1652 | // instructions generated, we insert padding here to keep the size |
| 1653 | // of the Abort macro constant. |
| 1654 | static const int kExpectedAbortInstructions = 10; |
| 1655 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 1656 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 1657 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 1658 | nop(); |
| 1659 | } |
| 1660 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1663 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1664 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 1665 | if (context_chain_length > 0) { |
| 1666 | // Move up the chain of contexts to the context containing the slot. |
| 1667 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1668 | // Load the function context (which is the incoming, outer context). |
| 1669 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 1670 | for (int i = 1; i < context_chain_length; i++) { |
| 1671 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1672 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 1673 | } |
| 1674 | // The context may be an intermediate context, not a function context. |
| 1675 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1676 | } else { // Slot is in the current function context. |
| 1677 | // The context may be an intermediate context, not a function context. |
| 1678 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1683 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 1684 | Register reg2, |
| 1685 | Label* on_not_both_smi) { |
| 1686 | ASSERT_EQ(0, kSmiTag); |
| 1687 | tst(reg1, Operand(kSmiTagMask)); |
| 1688 | tst(reg2, Operand(kSmiTagMask), eq); |
| 1689 | b(ne, on_not_both_smi); |
| 1690 | } |
| 1691 | |
| 1692 | |
| 1693 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 1694 | Register reg2, |
| 1695 | Label* on_either_smi) { |
| 1696 | ASSERT_EQ(0, kSmiTag); |
| 1697 | tst(reg1, Operand(kSmiTagMask)); |
| 1698 | tst(reg2, Operand(kSmiTagMask), ne); |
| 1699 | b(eq, on_either_smi); |
| 1700 | } |
| 1701 | |
| 1702 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1703 | void MacroAssembler::AbortIfSmi(Register object) { |
| 1704 | ASSERT_EQ(0, kSmiTag); |
| 1705 | tst(object, Operand(kSmiTagMask)); |
| 1706 | Assert(ne, "Operand is a smi"); |
| 1707 | } |
| 1708 | |
| 1709 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1710 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 1711 | Register first, |
| 1712 | Register second, |
| 1713 | Register scratch1, |
| 1714 | Register scratch2, |
| 1715 | Label* failure) { |
| 1716 | // Test that both first and second are sequential ASCII strings. |
| 1717 | // Assume that they are non-smis. |
| 1718 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 1719 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 1720 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 1721 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1722 | |
| 1723 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 1724 | scratch2, |
| 1725 | scratch1, |
| 1726 | scratch2, |
| 1727 | failure); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 1731 | Register second, |
| 1732 | Register scratch1, |
| 1733 | Register scratch2, |
| 1734 | Label* failure) { |
| 1735 | // Check that neither is a smi. |
| 1736 | ASSERT_EQ(0, kSmiTag); |
| 1737 | and_(scratch1, first, Operand(second)); |
| 1738 | tst(scratch1, Operand(kSmiTagMask)); |
| 1739 | b(eq, failure); |
| 1740 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 1741 | second, |
| 1742 | scratch1, |
| 1743 | scratch2, |
| 1744 | failure); |
| 1745 | } |
| 1746 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1747 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1748 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 1749 | // is full and a scavenge is needed. |
| 1750 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 1751 | Register scratch1, |
| 1752 | Register scratch2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1753 | Register heap_number_map, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1754 | Label* gc_required) { |
| 1755 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 1756 | // object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1757 | AllocateInNewSpace(HeapNumber::kSize, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1758 | result, |
| 1759 | scratch1, |
| 1760 | scratch2, |
| 1761 | gc_required, |
| 1762 | TAG_OBJECT); |
| 1763 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1764 | // Store heap number map in the allocated object. |
| 1765 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1766 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1770 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 1771 | DwVfpRegister value, |
| 1772 | Register scratch1, |
| 1773 | Register scratch2, |
| 1774 | Register heap_number_map, |
| 1775 | Label* gc_required) { |
| 1776 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 1777 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 1778 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 1779 | } |
| 1780 | |
| 1781 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1782 | // Copies a fixed number of fields of heap objects from src to dst. |
| 1783 | void MacroAssembler::CopyFields(Register dst, |
| 1784 | Register src, |
| 1785 | RegList temps, |
| 1786 | int field_count) { |
| 1787 | // At least one bit set in the first 15 registers. |
| 1788 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 1789 | ASSERT((temps & dst.bit()) == 0); |
| 1790 | ASSERT((temps & src.bit()) == 0); |
| 1791 | // Primitive implementation using only one temporary register. |
| 1792 | |
| 1793 | Register tmp = no_reg; |
| 1794 | // Find a temp register in temps list. |
| 1795 | for (int i = 0; i < 15; i++) { |
| 1796 | if ((temps & (1 << i)) != 0) { |
| 1797 | tmp.set_code(i); |
| 1798 | break; |
| 1799 | } |
| 1800 | } |
| 1801 | ASSERT(!tmp.is(no_reg)); |
| 1802 | |
| 1803 | for (int i = 0; i < field_count; i++) { |
| 1804 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 1805 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1810 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 1811 | Register source, // Input. |
| 1812 | Register scratch) { |
| 1813 | ASSERT(!zeros.is(source) || !source.is(zeros)); |
| 1814 | ASSERT(!zeros.is(scratch)); |
| 1815 | ASSERT(!scratch.is(ip)); |
| 1816 | ASSERT(!source.is(ip)); |
| 1817 | ASSERT(!zeros.is(ip)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1818 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 1819 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 1820 | #else |
| 1821 | mov(zeros, Operand(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1822 | Move(scratch, source); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1823 | // Top 16. |
| 1824 | tst(scratch, Operand(0xffff0000)); |
| 1825 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 1826 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 1827 | // Top 8. |
| 1828 | tst(scratch, Operand(0xff000000)); |
| 1829 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 1830 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 1831 | // Top 4. |
| 1832 | tst(scratch, Operand(0xf0000000)); |
| 1833 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 1834 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 1835 | // Top 2. |
| 1836 | tst(scratch, Operand(0xc0000000)); |
| 1837 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 1838 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 1839 | // Top bit. |
| 1840 | tst(scratch, Operand(0x80000000u)); |
| 1841 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 1842 | #endif |
| 1843 | } |
| 1844 | |
| 1845 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1846 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1847 | Register first, |
| 1848 | Register second, |
| 1849 | Register scratch1, |
| 1850 | Register scratch2, |
| 1851 | Label* failure) { |
| 1852 | int kFlatAsciiStringMask = |
| 1853 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 1854 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1855 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 1856 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 1857 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 1858 | // Ignore second test if first test failed. |
| 1859 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 1860 | b(ne, failure); |
| 1861 | } |
| 1862 | |
| 1863 | |
| 1864 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 1865 | Register scratch, |
| 1866 | Label* failure) { |
| 1867 | int kFlatAsciiStringMask = |
| 1868 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 1869 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1870 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 1871 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 1872 | b(ne, failure); |
| 1873 | } |
| 1874 | |
| 1875 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1876 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1877 | int frame_alignment = ActivationFrameAlignment(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1878 | // Up to four simple arguments are passed in registers r0..r3. |
| 1879 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1880 | if (frame_alignment > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1881 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 1882 | // and the original value of sp. |
| 1883 | mov(scratch, sp); |
| 1884 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1885 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1886 | and_(sp, sp, Operand(-frame_alignment)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1887 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 1888 | } else { |
| 1889 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 1895 | int num_arguments) { |
| 1896 | mov(ip, Operand(function)); |
| 1897 | CallCFunction(ip, num_arguments); |
| 1898 | } |
| 1899 | |
| 1900 | |
| 1901 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1902 | // Make sure that the stack is aligned before calling a C function unless |
| 1903 | // running in the simulator. The simulator has its own alignment check which |
| 1904 | // provides more information. |
| 1905 | #if defined(V8_HOST_ARCH_ARM) |
| 1906 | if (FLAG_debug_code) { |
| 1907 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 1908 | int frame_alignment_mask = frame_alignment - 1; |
| 1909 | if (frame_alignment > kPointerSize) { |
| 1910 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1911 | Label alignment_as_expected; |
| 1912 | tst(sp, Operand(frame_alignment_mask)); |
| 1913 | b(eq, &alignment_as_expected); |
| 1914 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 1915 | // re-entering here. |
| 1916 | stop("Unexpected alignment"); |
| 1917 | bind(&alignment_as_expected); |
| 1918 | } |
| 1919 | } |
| 1920 | #endif |
| 1921 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1922 | // Just call directly. The function called cannot cause a GC, or |
| 1923 | // allow preemption, so the return address in the link register |
| 1924 | // stays correct. |
| 1925 | Call(function); |
| 1926 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
| 1927 | if (OS::ActivationFrameAlignment() > kPointerSize) { |
| 1928 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 1929 | } else { |
| 1930 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1935 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1936 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 1937 | : address_(address), |
| 1938 | instructions_(instructions), |
| 1939 | size_(instructions * Assembler::kInstrSize), |
| 1940 | masm_(address, size_ + Assembler::kGap) { |
| 1941 | // Create a new macro assembler pointing to the address of the code to patch. |
| 1942 | // The size is adjusted with kGap on order for the assembler to generate size |
| 1943 | // bytes of instructions without failing with buffer size constraints. |
| 1944 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | CodePatcher::~CodePatcher() { |
| 1949 | // Indicate that code has changed. |
| 1950 | CPU::FlushICache(address_, size_); |
| 1951 | |
| 1952 | // Check that the code was patched as expected. |
| 1953 | ASSERT(masm_.pc_ == address_ + size_); |
| 1954 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | void CodePatcher::Emit(Instr x) { |
| 1959 | masm()->emit(x); |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | void CodePatcher::Emit(Address addr) { |
| 1964 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 1965 | } |
| 1966 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1967 | |
| 1968 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1970 | |
| 1971 | #endif // V8_TARGET_ARCH_ARM |