erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 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" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 35 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 42 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 43 | : Assembler(arg_isolate, buffer, size), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 45 | allow_stub_calls_(true), |
| 46 | has_frame_(false) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 47 | if (isolate() != NULL) { |
| 48 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 49 | isolate()); |
| 50 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | void MacroAssembler::Jump(Register target, Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | bx(target, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 59 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 60 | Condition cond) { |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 61 | mov(ip, Operand(target, rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | bx(ip, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 66 | void MacroAssembler::Jump(Address target, RelocInfo::Mode rmode, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 67 | Condition cond) { |
| 68 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 70 | } |
| 71 | |
| 72 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 73 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 74 | Condition cond) { |
| 75 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | // 'code' is always generated ARM code, never THUMB code |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 77 | ALLOW_HANDLE_DEREF(isolate(), "embedding raw address"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 79 | } |
| 80 | |
| 81 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 82 | int MacroAssembler::CallSize(Register target, Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 83 | return kInstrSize; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | void MacroAssembler::Call(Register target, Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 88 | // Block constant pool for the call instruction sequence. |
| 89 | BlockConstPoolScope block_const_pool(this); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 90 | Label start; |
| 91 | bind(&start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | blx(target, cond); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 93 | ASSERT_EQ(CallSize(target, cond), SizeOfCodeGeneratedSince(&start)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 97 | int MacroAssembler::CallSize( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 98 | Address target, RelocInfo::Mode rmode, Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 99 | int size = 2 * kInstrSize; |
| 100 | Instr mov_instr = cond | MOV | LeaveCC; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 101 | intptr_t immediate = reinterpret_cast<intptr_t>(target); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 102 | if (!Operand(immediate, rmode).is_single_instruction(this, mov_instr)) { |
| 103 | size += kInstrSize; |
| 104 | } |
| 105 | return size; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | int MacroAssembler::CallSizeNotPredictableCodeSize( |
| 110 | Address target, RelocInfo::Mode rmode, Condition cond) { |
| 111 | int size = 2 * kInstrSize; |
| 112 | Instr mov_instr = cond | MOV | LeaveCC; |
| 113 | intptr_t immediate = reinterpret_cast<intptr_t>(target); |
| 114 | if (!Operand(immediate, rmode).is_single_instruction(NULL, mov_instr)) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 115 | size += kInstrSize; |
| 116 | } |
| 117 | return size; |
| 118 | } |
| 119 | |
| 120 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 121 | void MacroAssembler::Call(Address target, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 122 | RelocInfo::Mode rmode, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 123 | Condition cond, |
| 124 | TargetAddressStorageMode mode) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 125 | // Block constant pool for the call instruction sequence. |
| 126 | BlockConstPoolScope block_const_pool(this); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 127 | Label start; |
| 128 | bind(&start); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 129 | |
| 130 | bool old_predictable_code_size = predictable_code_size(); |
| 131 | if (mode == NEVER_INLINE_TARGET_ADDRESS) { |
| 132 | set_predictable_code_size(true); |
| 133 | } |
| 134 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 135 | // Call sequence on V7 or later may be : |
| 136 | // movw ip, #... @ call address low 16 |
| 137 | // movt ip, #... @ call address high 16 |
| 138 | // blx ip |
| 139 | // @ return address |
| 140 | // Or for pre-V7 or values that may be back-patched |
| 141 | // to avoid ICache flushes: |
| 142 | // ldr ip, [pc, #...] @ call address |
| 143 | // blx ip |
| 144 | // @ return address |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 145 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 146 | // Statement positions are expected to be recorded when the target |
| 147 | // address is loaded. The mov method will automatically record |
| 148 | // positions when pc is the target, since this is not the case here |
| 149 | // we have to do it explicitly. |
| 150 | positions_recorder()->WriteRecordedPositions(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 151 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 152 | mov(ip, Operand(reinterpret_cast<int32_t>(target), rmode)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 153 | blx(ip, cond); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 154 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 155 | ASSERT_EQ(CallSize(target, rmode, cond), SizeOfCodeGeneratedSince(&start)); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 156 | if (mode == NEVER_INLINE_TARGET_ADDRESS) { |
| 157 | set_predictable_code_size(old_predictable_code_size); |
| 158 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 162 | int MacroAssembler::CallSize(Handle<Code> code, |
| 163 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 164 | TypeFeedbackId ast_id, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 165 | Condition cond) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 166 | ALLOW_HANDLE_DEREF(isolate(), "using raw address"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 167 | return CallSize(reinterpret_cast<Address>(code.location()), rmode, cond); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | void MacroAssembler::Call(Handle<Code> code, |
| 172 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 173 | TypeFeedbackId ast_id, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 174 | Condition cond, |
| 175 | TargetAddressStorageMode mode) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 176 | Label start; |
| 177 | bind(&start); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 178 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 179 | if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 180 | SetRecordedAstId(ast_id); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 181 | rmode = RelocInfo::CODE_TARGET_WITH_ID; |
| 182 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | // 'code' is always generated ARM code, never THUMB code |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 184 | ALLOW_HANDLE_DEREF(isolate(), "embedding raw address"); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 185 | Call(reinterpret_cast<Address>(code.location()), rmode, cond, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 189 | void MacroAssembler::Ret(Condition cond) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 190 | bx(lr, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 194 | void MacroAssembler::Drop(int count, Condition cond) { |
| 195 | if (count > 0) { |
| 196 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
| 200 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 201 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 202 | Drop(drop, cond); |
| 203 | Ret(cond); |
| 204 | } |
| 205 | |
| 206 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 207 | void MacroAssembler::Swap(Register reg1, |
| 208 | Register reg2, |
| 209 | Register scratch, |
| 210 | Condition cond) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 211 | if (scratch.is(no_reg)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 212 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 213 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 214 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 215 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 216 | mov(scratch, reg1, LeaveCC, cond); |
| 217 | mov(reg1, reg2, LeaveCC, cond); |
| 218 | mov(reg2, scratch, LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 223 | void MacroAssembler::Call(Label* target) { |
| 224 | bl(target); |
| 225 | } |
| 226 | |
| 227 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 228 | void MacroAssembler::Push(Handle<Object> handle) { |
| 229 | mov(ip, Operand(handle)); |
| 230 | push(ip); |
| 231 | } |
| 232 | |
| 233 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 234 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 235 | mov(dst, Operand(value)); |
| 236 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 237 | |
| 238 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 239 | void MacroAssembler::Move(Register dst, Register src, Condition cond) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 240 | if (!dst.is(src)) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 241 | mov(dst, src, LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 246 | void MacroAssembler::Move(DwVfpRegister dst, DwVfpRegister src) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 247 | if (!dst.is(src)) { |
| 248 | vmov(dst, src); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 253 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 254 | Condition cond) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 255 | if (!src2.is_reg() && |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 256 | !src2.must_output_reloc_info(this) && |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 257 | src2.immediate() == 0) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 258 | mov(dst, Operand::Zero(), LeaveCC, cond); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 259 | } else if (!src2.is_single_instruction(this) && |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 260 | !src2.must_output_reloc_info(this) && |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 261 | CpuFeatures::IsSupported(ARMv7) && |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 262 | IsPowerOf2(src2.immediate() + 1)) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 263 | ubfx(dst, src1, 0, |
| 264 | WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 265 | } else { |
| 266 | and_(dst, src1, src2, LeaveCC, cond); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 267 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
| 271 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 272 | Condition cond) { |
| 273 | ASSERT(lsb < 32); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 274 | if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 275 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 276 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 277 | if (lsb != 0) { |
| 278 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 279 | } |
| 280 | } else { |
| 281 | ubfx(dst, src1, lsb, width, cond); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
| 286 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 287 | Condition cond) { |
| 288 | ASSERT(lsb < 32); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 289 | if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 290 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 291 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 292 | int shift_up = 32 - lsb - width; |
| 293 | int shift_down = lsb + shift_up; |
| 294 | if (shift_up != 0) { |
| 295 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 296 | } |
| 297 | if (shift_down != 0) { |
| 298 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 299 | } |
| 300 | } else { |
| 301 | sbfx(dst, src1, lsb, width, cond); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 306 | void MacroAssembler::Bfi(Register dst, |
| 307 | Register src, |
| 308 | Register scratch, |
| 309 | int lsb, |
| 310 | int width, |
| 311 | Condition cond) { |
| 312 | ASSERT(0 <= lsb && lsb < 32); |
| 313 | ASSERT(0 <= width && width < 32); |
| 314 | ASSERT(lsb + width < 32); |
| 315 | ASSERT(!scratch.is(dst)); |
| 316 | if (width == 0) return; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 317 | if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 318 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 319 | bic(dst, dst, Operand(mask)); |
| 320 | and_(scratch, src, Operand((1 << width) - 1)); |
| 321 | mov(scratch, Operand(scratch, LSL, lsb)); |
| 322 | orr(dst, dst, scratch); |
| 323 | } else { |
| 324 | bfi(dst, src, lsb, width, cond); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 329 | void MacroAssembler::Bfc(Register dst, Register src, int lsb, int width, |
| 330 | Condition cond) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 331 | ASSERT(lsb < 32); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 332 | if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 333 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 334 | bic(dst, src, Operand(mask)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 335 | } else { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 336 | Move(dst, src, cond); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 337 | bfc(dst, lsb, width, cond); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 342 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 343 | Condition cond) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 344 | if (!CpuFeatures::IsSupported(ARMv7) || predictable_code_size()) { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 345 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 346 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 347 | |
| 348 | // These asserts are required to ensure compatibility with the ARMv7 |
| 349 | // implementation. |
| 350 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 351 | ASSERT(src.rs().is(no_reg)); |
| 352 | |
| 353 | Label done; |
| 354 | int satval = (1 << satpos) - 1; |
| 355 | |
| 356 | if (cond != al) { |
| 357 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 358 | } |
| 359 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 360 | mov(dst, src); |
| 361 | } |
| 362 | tst(dst, Operand(~satval)); |
| 363 | b(eq, &done); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 364 | mov(dst, Operand::Zero(), LeaveCC, mi); // 0 if negative. |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 365 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 366 | bind(&done); |
| 367 | } else { |
| 368 | usat(dst, satpos, src, cond); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 373 | void MacroAssembler::LoadRoot(Register destination, |
| 374 | Heap::RootListIndex index, |
| 375 | Condition cond) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 376 | if (CpuFeatures::IsSupported(MOVW_MOVT_IMMEDIATE_LOADS) && |
ulan@chromium.org | fae3da5 | 2012-12-03 15:37:23 +0000 | [diff] [blame] | 377 | !Heap::RootCanBeWrittenAfterInitialization(index) && |
| 378 | !predictable_code_size()) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 379 | Handle<Object> root(isolate()->heap()->roots_array_start()[index], |
| 380 | isolate()); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 381 | if (!isolate()->heap()->InNewSpace(*root)) { |
| 382 | // The CPU supports fast immediate values, and this root will never |
| 383 | // change. We will load it as a relocatable immediate value. |
| 384 | mov(destination, Operand(root), LeaveCC, cond); |
| 385 | return; |
| 386 | } |
| 387 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 388 | ldr(destination, MemOperand(kRootRegister, index << kPointerSizeLog2), cond); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 392 | void MacroAssembler::StoreRoot(Register source, |
| 393 | Heap::RootListIndex index, |
| 394 | Condition cond) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 395 | str(source, MemOperand(kRootRegister, index << kPointerSizeLog2), cond); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 399 | void MacroAssembler::LoadHeapObject(Register result, |
| 400 | Handle<HeapObject> object) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 401 | ALLOW_HANDLE_DEREF(isolate(), "using raw address"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 402 | if (isolate()->heap()->InNewSpace(*object)) { |
| 403 | Handle<JSGlobalPropertyCell> cell = |
| 404 | isolate()->factory()->NewJSGlobalPropertyCell(object); |
| 405 | mov(result, Operand(cell)); |
| 406 | ldr(result, FieldMemOperand(result, JSGlobalPropertyCell::kValueOffset)); |
| 407 | } else { |
| 408 | mov(result, Operand(object)); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 413 | void MacroAssembler::InNewSpace(Register object, |
| 414 | Register scratch, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 415 | Condition cond, |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 416 | Label* branch) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 417 | ASSERT(cond == eq || cond == ne); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 418 | and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate()))); |
| 419 | cmp(scratch, Operand(ExternalReference::new_space_start(isolate()))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 420 | b(cond, branch); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 424 | void MacroAssembler::RecordWriteField( |
| 425 | Register object, |
| 426 | int offset, |
| 427 | Register value, |
| 428 | Register dst, |
| 429 | LinkRegisterStatus lr_status, |
| 430 | SaveFPRegsMode save_fp, |
| 431 | RememberedSetAction remembered_set_action, |
| 432 | SmiCheck smi_check) { |
| 433 | // First, check if a write barrier is even needed. The tests below |
| 434 | // catch stores of Smis. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 435 | Label done; |
| 436 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 437 | // Skip barrier if writing a smi. |
| 438 | if (smi_check == INLINE_SMI_CHECK) { |
| 439 | JumpIfSmi(value, &done); |
| 440 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 441 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 442 | // Although the object register is tagged, the offset is relative to the start |
| 443 | // of the object, so so offset must be a multiple of kPointerSize. |
| 444 | ASSERT(IsAligned(offset, kPointerSize)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 445 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 446 | add(dst, object, Operand(offset - kHeapObjectTag)); |
| 447 | if (emit_debug_code()) { |
| 448 | Label ok; |
| 449 | tst(dst, Operand((1 << kPointerSizeLog2) - 1)); |
| 450 | b(eq, &ok); |
| 451 | stop("Unaligned cell in write barrier"); |
| 452 | bind(&ok); |
| 453 | } |
| 454 | |
| 455 | RecordWrite(object, |
| 456 | dst, |
| 457 | value, |
| 458 | lr_status, |
| 459 | save_fp, |
| 460 | remembered_set_action, |
| 461 | OMIT_SMI_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | |
| 463 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 464 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 465 | // Clobber clobbered input registers when running with the debug-code flag |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 466 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 467 | if (emit_debug_code()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 468 | mov(value, Operand(BitCast<int32_t>(kZapValue + 4))); |
| 469 | mov(dst, Operand(BitCast<int32_t>(kZapValue + 8))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 470 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 474 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 475 | // register 'object' contains a heap object pointer. The heap object |
| 476 | // tag is shifted away. |
| 477 | void MacroAssembler::RecordWrite(Register object, |
| 478 | Register address, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | Register value, |
| 480 | LinkRegisterStatus lr_status, |
| 481 | SaveFPRegsMode fp_mode, |
| 482 | RememberedSetAction remembered_set_action, |
| 483 | SmiCheck smi_check) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 484 | // The compiled code assumes that record write doesn't change the |
| 485 | // context register, so we check that none of the clobbered |
| 486 | // registers are cp. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 487 | ASSERT(!address.is(cp) && !value.is(cp)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 488 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 489 | if (emit_debug_code()) { |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 490 | ldr(ip, MemOperand(address)); |
| 491 | cmp(ip, value); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 492 | Check(eq, "Wrong address or value passed to RecordWrite"); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 493 | } |
| 494 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 495 | Label done; |
| 496 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 497 | if (smi_check == INLINE_SMI_CHECK) { |
| 498 | ASSERT_EQ(0, kSmiTag); |
| 499 | tst(value, Operand(kSmiTagMask)); |
| 500 | b(eq, &done); |
| 501 | } |
| 502 | |
| 503 | CheckPageFlag(value, |
| 504 | value, // Used as scratch. |
| 505 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 506 | eq, |
| 507 | &done); |
| 508 | CheckPageFlag(object, |
| 509 | value, // Used as scratch. |
| 510 | MemoryChunk::kPointersFromHereAreInterestingMask, |
| 511 | eq, |
| 512 | &done); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 513 | |
| 514 | // Record the actual write. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 515 | if (lr_status == kLRHasNotBeenSaved) { |
| 516 | push(lr); |
| 517 | } |
| 518 | RecordWriteStub stub(object, value, address, remembered_set_action, fp_mode); |
| 519 | CallStub(&stub); |
| 520 | if (lr_status == kLRHasNotBeenSaved) { |
| 521 | pop(lr); |
| 522 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 523 | |
| 524 | bind(&done); |
| 525 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 526 | // Clobber clobbered registers when running with the debug-code flag |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 527 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 528 | if (emit_debug_code()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 529 | mov(address, Operand(BitCast<int32_t>(kZapValue + 12))); |
| 530 | mov(value, Operand(BitCast<int32_t>(kZapValue + 16))); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | |
| 535 | void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. |
| 536 | Register address, |
| 537 | Register scratch, |
| 538 | SaveFPRegsMode fp_mode, |
| 539 | RememberedSetFinalAction and_then) { |
| 540 | Label done; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 541 | if (emit_debug_code()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 542 | Label ok; |
| 543 | JumpIfNotInNewSpace(object, scratch, &ok); |
| 544 | stop("Remembered set pointer is in new space"); |
| 545 | bind(&ok); |
| 546 | } |
| 547 | // Load store buffer top. |
| 548 | ExternalReference store_buffer = |
| 549 | ExternalReference::store_buffer_top(isolate()); |
| 550 | mov(ip, Operand(store_buffer)); |
| 551 | ldr(scratch, MemOperand(ip)); |
| 552 | // Store pointer to buffer and increment buffer top. |
| 553 | str(address, MemOperand(scratch, kPointerSize, PostIndex)); |
| 554 | // Write back new top of buffer. |
| 555 | str(scratch, MemOperand(ip)); |
| 556 | // Call stub on end of buffer. |
| 557 | // Check for end of buffer. |
| 558 | tst(scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); |
| 559 | if (and_then == kFallThroughAtEnd) { |
| 560 | b(eq, &done); |
| 561 | } else { |
| 562 | ASSERT(and_then == kReturnAtEnd); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 563 | Ret(eq); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 564 | } |
| 565 | push(lr); |
| 566 | StoreBufferOverflowStub store_buffer_overflow = |
| 567 | StoreBufferOverflowStub(fp_mode); |
| 568 | CallStub(&store_buffer_overflow); |
| 569 | pop(lr); |
| 570 | bind(&done); |
| 571 | if (and_then == kReturnAtEnd) { |
| 572 | Ret(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | |
| 576 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 577 | // Push and pop all registers that can hold pointers. |
| 578 | void MacroAssembler::PushSafepointRegisters() { |
| 579 | // Safepoints expect a block of contiguous register values starting with r0: |
| 580 | ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters); |
| 581 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 582 | // stack, so adjust the stack for unsaved registers. |
| 583 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 584 | ASSERT(num_unsaved >= 0); |
| 585 | sub(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 586 | stm(db_w, sp, kSafepointSavedRegisters); |
| 587 | } |
| 588 | |
| 589 | |
| 590 | void MacroAssembler::PopSafepointRegisters() { |
| 591 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 592 | ldm(ia_w, sp, kSafepointSavedRegisters); |
| 593 | add(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 594 | } |
| 595 | |
| 596 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 597 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 598 | // Number of d-regs not known at snapshot time. |
| 599 | ASSERT(!Serializer::enabled()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 600 | PushSafepointRegisters(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 601 | sub(sp, sp, Operand(DwVfpRegister::NumAllocatableRegisters() * |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 602 | kDoubleSize)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 603 | for (int i = 0; i < DwVfpRegister::NumAllocatableRegisters(); i++) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 604 | vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | |
| 609 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 610 | // Number of d-regs not known at snapshot time. |
| 611 | ASSERT(!Serializer::enabled()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 612 | for (int i = 0; i < DwVfpRegister::NumAllocatableRegisters(); i++) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 613 | vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 614 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 615 | add(sp, sp, Operand(DwVfpRegister::NumAllocatableRegisters() * |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 616 | kDoubleSize)); |
| 617 | PopSafepointRegisters(); |
| 618 | } |
| 619 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 620 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src, |
| 621 | Register dst) { |
| 622 | str(src, SafepointRegistersAndDoublesSlot(dst)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 626 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 627 | str(src, SafepointRegisterSlot(dst)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 631 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 632 | ldr(dst, SafepointRegisterSlot(src)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 636 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 637 | // The registers are pushed starting with the highest encoding, |
| 638 | // which means that lowest encodings are closest to the stack pointer. |
| 639 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 640 | return reg_code; |
| 641 | } |
| 642 | |
| 643 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 644 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 645 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 646 | } |
| 647 | |
| 648 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 649 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 650 | // Number of d-regs not known at snapshot time. |
| 651 | ASSERT(!Serializer::enabled()); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 652 | // General purpose registers are pushed last on the stack. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 653 | int doubles_size = DwVfpRegister::NumAllocatableRegisters() * kDoubleSize; |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 654 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 655 | return MemOperand(sp, doubles_size + register_offset); |
| 656 | } |
| 657 | |
| 658 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 659 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 660 | const MemOperand& src, Condition cond) { |
| 661 | ASSERT(src.rm().is(no_reg)); |
| 662 | ASSERT(!dst1.is(lr)); // r14. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 663 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 664 | // V8 does not use this addressing mode, so the fallback code |
| 665 | // below doesn't support it yet. |
| 666 | ASSERT((src.am() != PreIndex) && (src.am() != NegPreIndex)); |
| 667 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 668 | // Generate two ldr instructions if ldrd is not available. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 669 | if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() && |
| 670 | (dst1.code() % 2 == 0) && (dst1.code() + 1 == dst2.code())) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 671 | CpuFeatureScope scope(this, ARMv7); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 672 | ldrd(dst1, dst2, src, cond); |
| 673 | } else { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 674 | if ((src.am() == Offset) || (src.am() == NegOffset)) { |
| 675 | MemOperand src2(src); |
| 676 | src2.set_offset(src2.offset() + 4); |
| 677 | if (dst1.is(src.rn())) { |
| 678 | ldr(dst2, src2, cond); |
| 679 | ldr(dst1, src, cond); |
| 680 | } else { |
| 681 | ldr(dst1, src, cond); |
| 682 | ldr(dst2, src2, cond); |
| 683 | } |
| 684 | } else { // PostIndex or NegPostIndex. |
| 685 | ASSERT((src.am() == PostIndex) || (src.am() == NegPostIndex)); |
| 686 | if (dst1.is(src.rn())) { |
| 687 | ldr(dst2, MemOperand(src.rn(), 4, Offset), cond); |
| 688 | ldr(dst1, src, cond); |
| 689 | } else { |
| 690 | MemOperand src2(src); |
| 691 | src2.set_offset(src2.offset() - 4); |
| 692 | ldr(dst1, MemOperand(src.rn(), 4, PostIndex), cond); |
| 693 | ldr(dst2, src2, cond); |
| 694 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | |
| 700 | void MacroAssembler::Strd(Register src1, Register src2, |
| 701 | const MemOperand& dst, Condition cond) { |
| 702 | ASSERT(dst.rm().is(no_reg)); |
| 703 | ASSERT(!src1.is(lr)); // r14. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 704 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 705 | // V8 does not use this addressing mode, so the fallback code |
| 706 | // below doesn't support it yet. |
| 707 | ASSERT((dst.am() != PreIndex) && (dst.am() != NegPreIndex)); |
| 708 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 709 | // Generate two str instructions if strd is not available. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 710 | if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size() && |
| 711 | (src1.code() % 2 == 0) && (src1.code() + 1 == src2.code())) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 712 | CpuFeatureScope scope(this, ARMv7); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 713 | strd(src1, src2, dst, cond); |
| 714 | } else { |
| 715 | MemOperand dst2(dst); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 716 | if ((dst.am() == Offset) || (dst.am() == NegOffset)) { |
| 717 | dst2.set_offset(dst2.offset() + 4); |
| 718 | str(src1, dst, cond); |
| 719 | str(src2, dst2, cond); |
| 720 | } else { // PostIndex or NegPostIndex. |
| 721 | ASSERT((dst.am() == PostIndex) || (dst.am() == NegPostIndex)); |
| 722 | dst2.set_offset(dst2.offset() - 4); |
| 723 | str(src1, MemOperand(dst.rn(), 4, PostIndex), cond); |
| 724 | str(src2, dst2, cond); |
| 725 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 730 | void MacroAssembler::VFPEnsureFPSCRState(Register scratch) { |
| 731 | // If needed, restore wanted bits of FPSCR. |
| 732 | Label fpscr_done; |
| 733 | vmrs(scratch); |
| 734 | tst(scratch, Operand(kVFPDefaultNaNModeControlBit)); |
| 735 | b(ne, &fpscr_done); |
| 736 | orr(scratch, scratch, Operand(kVFPDefaultNaNModeControlBit)); |
| 737 | vmsr(scratch); |
| 738 | bind(&fpscr_done); |
| 739 | } |
| 740 | |
| 741 | void MacroAssembler::VFPCanonicalizeNaN(const DwVfpRegister value, |
| 742 | const Condition cond) { |
| 743 | vsub(value, value, kDoubleRegZero, cond); |
| 744 | } |
| 745 | |
| 746 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 747 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 748 | const DwVfpRegister src2, |
| 749 | const Condition cond) { |
| 750 | // Compare and move FPSCR flags to the normal condition flags. |
| 751 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 752 | } |
| 753 | |
| 754 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 755 | const double src2, |
| 756 | const Condition cond) { |
| 757 | // Compare and move FPSCR flags to the normal condition flags. |
| 758 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 759 | } |
| 760 | |
| 761 | |
| 762 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 763 | const DwVfpRegister src2, |
| 764 | const Register fpscr_flags, |
| 765 | const Condition cond) { |
| 766 | // Compare and load FPSCR. |
| 767 | vcmp(src1, src2, cond); |
| 768 | vmrs(fpscr_flags, cond); |
| 769 | } |
| 770 | |
| 771 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 772 | const double src2, |
| 773 | const Register fpscr_flags, |
| 774 | const Condition cond) { |
| 775 | // Compare and load FPSCR. |
| 776 | vcmp(src1, src2, cond); |
| 777 | vmrs(fpscr_flags, cond); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 778 | } |
| 779 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 780 | void MacroAssembler::Vmov(const DwVfpRegister dst, |
| 781 | const double imm, |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 782 | const Register scratch) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 783 | static const DoubleRepresentation minus_zero(-0.0); |
| 784 | static const DoubleRepresentation zero(0.0); |
| 785 | DoubleRepresentation value(imm); |
| 786 | // Handle special values first. |
| 787 | if (value.bits == zero.bits) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 788 | vmov(dst, kDoubleRegZero); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 789 | } else if (value.bits == minus_zero.bits) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 790 | vneg(dst, kDoubleRegZero); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 791 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 792 | vmov(dst, imm, scratch); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 796 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 797 | void MacroAssembler::ConvertNumberToInt32(Register object, |
| 798 | Register dst, |
| 799 | Register heap_number_map, |
| 800 | Register scratch1, |
| 801 | Register scratch2, |
| 802 | Register scratch3, |
| 803 | DwVfpRegister double_scratch1, |
| 804 | DwVfpRegister double_scratch2, |
| 805 | Label* not_number) { |
| 806 | Label done; |
| 807 | UntagAndJumpIfSmi(dst, object, &done); |
| 808 | JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 809 | vldr(double_scratch1, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 810 | ECMAToInt32(dst, double_scratch1, |
| 811 | scratch1, scratch2, scratch3, double_scratch2); |
| 812 | |
| 813 | bind(&done); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | void MacroAssembler::LoadNumber(Register object, |
| 818 | DwVfpRegister dst, |
| 819 | Register heap_number_map, |
| 820 | Register scratch, |
| 821 | Label* not_number) { |
| 822 | Label is_smi, done; |
| 823 | |
| 824 | UntagAndJumpIfSmi(scratch, object, &is_smi); |
| 825 | JumpIfNotHeapNumber(object, heap_number_map, scratch, not_number); |
| 826 | |
| 827 | vldr(dst, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 828 | b(&done); |
| 829 | |
| 830 | // Handle loading a double from a smi. |
| 831 | bind(&is_smi); |
| 832 | vmov(dst.high(), scratch); |
| 833 | vcvt_f64_s32(dst, dst.high()); |
| 834 | |
| 835 | bind(&done); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | void MacroAssembler::LoadNumberAsInt32Double(Register object, |
| 840 | DwVfpRegister double_dst, |
| 841 | Register heap_number_map, |
| 842 | Register scratch, |
| 843 | DwVfpRegister double_scratch, |
| 844 | Label* not_int32) { |
| 845 | ASSERT(!scratch.is(object)); |
| 846 | ASSERT(!heap_number_map.is(object) && !heap_number_map.is(scratch)); |
| 847 | |
| 848 | Label done, obj_is_not_smi; |
| 849 | |
| 850 | UntagAndJumpIfNotSmi(scratch, object, &obj_is_not_smi); |
| 851 | vmov(double_scratch.low(), scratch); |
| 852 | vcvt_f64_s32(double_dst, double_scratch.low()); |
| 853 | b(&done); |
| 854 | |
| 855 | bind(&obj_is_not_smi); |
| 856 | JumpIfNotHeapNumber(object, heap_number_map, scratch, not_int32); |
| 857 | |
| 858 | // Load the number. |
| 859 | // Load the double value. |
| 860 | vldr(double_dst, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 861 | |
| 862 | TestDoubleIsInt32(double_dst, double_scratch); |
| 863 | // Jump to not_int32 if the operation did not succeed. |
| 864 | b(ne, not_int32); |
| 865 | |
| 866 | bind(&done); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | void MacroAssembler::LoadNumberAsInt32(Register object, |
| 871 | Register dst, |
| 872 | Register heap_number_map, |
| 873 | Register scratch, |
| 874 | DwVfpRegister double_scratch0, |
| 875 | DwVfpRegister double_scratch1, |
| 876 | Label* not_int32) { |
| 877 | ASSERT(!dst.is(object)); |
| 878 | ASSERT(!scratch.is(object)); |
| 879 | |
| 880 | Label done, maybe_undefined; |
| 881 | |
| 882 | UntagAndJumpIfSmi(dst, object, &done); |
| 883 | |
| 884 | JumpIfNotHeapNumber(object, heap_number_map, scratch, &maybe_undefined); |
| 885 | |
| 886 | // Object is a heap number. |
| 887 | // Convert the floating point value to a 32-bit integer. |
| 888 | // Load the double value. |
| 889 | vldr(double_scratch0, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 890 | |
| 891 | TryDoubleToInt32Exact(dst, double_scratch0, double_scratch1); |
| 892 | // Jump to not_int32 if the operation did not succeed. |
| 893 | b(ne, not_int32); |
| 894 | b(&done); |
| 895 | |
| 896 | bind(&maybe_undefined); |
| 897 | CompareRoot(object, Heap::kUndefinedValueRootIndex); |
| 898 | b(ne, not_int32); |
| 899 | // |undefined| is truncated to 0. |
| 900 | mov(dst, Operand(Smi::FromInt(0))); |
| 901 | // Fall through. |
| 902 | |
| 903 | bind(&done); |
| 904 | } |
| 905 | |
| 906 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 907 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 908 | // r0-r3: preserved |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 909 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 910 | mov(ip, Operand(Smi::FromInt(type))); |
| 911 | push(ip); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 912 | mov(ip, Operand(CodeObject())); |
| 913 | push(ip); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 914 | 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] | 915 | } |
| 916 | |
| 917 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 918 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 919 | // r0: preserved |
| 920 | // r1: preserved |
| 921 | // r2: preserved |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 922 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 923 | // Drop the execution stack down to the frame pointer and restore |
| 924 | // the caller frame pointer and return address. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 925 | mov(sp, fp); |
| 926 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 930 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 931 | // Set up the frame structure on the stack. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 932 | ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 933 | ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 934 | ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 935 | Push(lr, fp); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 936 | mov(fp, Operand(sp)); // Set up new frame pointer. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 937 | // Reserve room for saved entry sp and code object. |
| 938 | sub(sp, sp, Operand(2 * kPointerSize)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 939 | if (emit_debug_code()) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 940 | mov(ip, Operand::Zero()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 941 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 942 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 943 | mov(ip, Operand(CodeObject())); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 944 | str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 945 | |
| 946 | // Save the frame pointer and the context in top. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 947 | mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 948 | str(fp, MemOperand(ip)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 949 | mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 950 | str(cp, MemOperand(ip)); |
| 951 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 952 | // Optionally save all double registers. |
| 953 | if (save_doubles) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 954 | SaveFPRegs(sp, ip); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 955 | // Note that d0 will be accessible at |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 956 | // fp - 2 * kPointerSize - DwVfpRegister::kMaxNumRegisters * kDoubleSize, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 957 | // since the sp slot and code slot were pushed after the fp. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 958 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 959 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 960 | // Reserve place for the return address and stack space and align the frame |
| 961 | // preparing for calling the runtime function. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 962 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 963 | sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 964 | if (frame_alignment > 0) { |
| 965 | ASSERT(IsPowerOf2(frame_alignment)); |
| 966 | and_(sp, sp, Operand(-frame_alignment)); |
| 967 | } |
| 968 | |
| 969 | // Set the exit frame sp value to point just before the return address |
| 970 | // location. |
| 971 | add(ip, sp, Operand(kPointerSize)); |
| 972 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 976 | void MacroAssembler::InitializeNewString(Register string, |
| 977 | Register length, |
| 978 | Heap::RootListIndex map_index, |
| 979 | Register scratch1, |
| 980 | Register scratch2) { |
| 981 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 982 | LoadRoot(scratch2, map_index); |
| 983 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 984 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 985 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 986 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 987 | } |
| 988 | |
| 989 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 990 | int MacroAssembler::ActivationFrameAlignment() { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 991 | #if defined(V8_HOST_ARCH_ARM) |
| 992 | // Running on the real platform. Use the alignment as mandated by the local |
| 993 | // environment. |
| 994 | // Note: This will break if we ever start generating snapshots on one ARM |
| 995 | // platform for another ARM platform with a different alignment. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 996 | return OS::ActivationFrameAlignment(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 997 | #else // defined(V8_HOST_ARCH_ARM) |
| 998 | // If we are using the simulator then we should always align to the expected |
| 999 | // 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] | 1000 | // if the target platform will need alignment, so this is controlled from a |
| 1001 | // flag. |
| 1002 | return FLAG_sim_stack_alignment; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1003 | #endif // defined(V8_HOST_ARCH_ARM) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1007 | void MacroAssembler::LeaveExitFrame(bool save_doubles, |
| 1008 | Register argument_count) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1009 | // Optionally restore all double registers. |
| 1010 | if (save_doubles) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1011 | // Calculate the stack location of the saved doubles and restore them. |
| 1012 | const int offset = 2 * kPointerSize; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1013 | sub(r3, fp, |
| 1014 | Operand(offset + DwVfpRegister::kMaxNumRegisters * kDoubleSize)); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1015 | RestoreFPRegs(r3, ip); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1018 | // Clear top frame. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1019 | mov(r3, Operand::Zero()); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1020 | mov(ip, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1021 | str(r3, MemOperand(ip)); |
| 1022 | |
| 1023 | // Restore current context from top and clear it in debug mode. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1024 | mov(ip, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1025 | ldr(cp, MemOperand(ip)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1026 | #ifdef DEBUG |
| 1027 | str(r3, MemOperand(ip)); |
| 1028 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1029 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1030 | // Tear down the exit frame, pop the arguments, and return. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1031 | mov(sp, Operand(fp)); |
| 1032 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1033 | if (argument_count.is_valid()) { |
| 1034 | add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2)); |
| 1035 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1038 | void MacroAssembler::GetCFunctionDoubleResult(const DwVfpRegister dst) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1039 | if (use_eabi_hardfloat()) { |
| 1040 | Move(dst, d0); |
| 1041 | } else { |
| 1042 | vmov(dst, r0, r1); |
| 1043 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1046 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1047 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 1048 | // This macro takes the dst register to make the code more readable |
| 1049 | // at the call sites. However, the dst register has to be r5 to |
| 1050 | // follow the calling convention which requires the call type to be |
| 1051 | // in r5. |
| 1052 | ASSERT(dst.is(r5)); |
| 1053 | if (call_kind == CALL_AS_FUNCTION) { |
| 1054 | mov(dst, Operand(Smi::FromInt(1))); |
| 1055 | } else { |
| 1056 | mov(dst, Operand(Smi::FromInt(0))); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1061 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1062 | const ParameterCount& actual, |
| 1063 | Handle<Code> code_constant, |
| 1064 | Register code_reg, |
| 1065 | Label* done, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1066 | bool* definitely_mismatches, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1067 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1068 | const CallWrapper& call_wrapper, |
| 1069 | CallKind call_kind) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1070 | bool definitely_matches = false; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1071 | *definitely_mismatches = false; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1072 | Label regular_invoke; |
| 1073 | |
| 1074 | // Check whether the expected and actual arguments count match. If not, |
| 1075 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 1076 | // r0: actual arguments count |
| 1077 | // r1: function (passed through to callee) |
| 1078 | // r2: expected arguments count |
| 1079 | // r3: callee code entry |
| 1080 | |
| 1081 | // The code below is made a lot easier because the calling code already sets |
| 1082 | // up actual and expected registers according to the contract if values are |
| 1083 | // passed in registers. |
| 1084 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 1085 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 1086 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 1087 | |
| 1088 | if (expected.is_immediate()) { |
| 1089 | ASSERT(actual.is_immediate()); |
| 1090 | if (expected.immediate() == actual.immediate()) { |
| 1091 | definitely_matches = true; |
| 1092 | } else { |
| 1093 | mov(r0, Operand(actual.immediate())); |
| 1094 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1095 | if (expected.immediate() == sentinel) { |
| 1096 | // Don't worry about adapting arguments for builtins that |
| 1097 | // don't want that done. Skip adaption code by making it look |
| 1098 | // like we have a match between expected and actual number of |
| 1099 | // arguments. |
| 1100 | definitely_matches = true; |
| 1101 | } else { |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1102 | *definitely_mismatches = true; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1103 | mov(r2, Operand(expected.immediate())); |
| 1104 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1105 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1106 | } else { |
| 1107 | if (actual.is_immediate()) { |
| 1108 | cmp(expected.reg(), Operand(actual.immediate())); |
| 1109 | b(eq, ®ular_invoke); |
| 1110 | mov(r0, Operand(actual.immediate())); |
| 1111 | } else { |
| 1112 | cmp(expected.reg(), Operand(actual.reg())); |
| 1113 | b(eq, ®ular_invoke); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (!definitely_matches) { |
| 1118 | if (!code_constant.is_null()) { |
| 1119 | mov(r3, Operand(code_constant)); |
| 1120 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1121 | } |
| 1122 | |
| 1123 | Handle<Code> adaptor = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1124 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1125 | if (flag == CALL_FUNCTION) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1126 | call_wrapper.BeforeCall(CallSize(adaptor)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1127 | SetCallKind(r5, call_kind); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1128 | Call(adaptor); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1129 | call_wrapper.AfterCall(); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1130 | if (!*definitely_mismatches) { |
| 1131 | b(done); |
| 1132 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1133 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1134 | SetCallKind(r5, call_kind); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1135 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1136 | } |
| 1137 | bind(®ular_invoke); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | void MacroAssembler::InvokeCode(Register code, |
| 1143 | const ParameterCount& expected, |
| 1144 | const ParameterCount& actual, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1145 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1146 | const CallWrapper& call_wrapper, |
| 1147 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1148 | // You can't call a function without a valid frame. |
| 1149 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 1150 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1151 | Label done; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1152 | bool definitely_mismatches = false; |
| 1153 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
| 1154 | &done, &definitely_mismatches, flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1155 | call_wrapper, call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1156 | if (!definitely_mismatches) { |
| 1157 | if (flag == CALL_FUNCTION) { |
| 1158 | call_wrapper.BeforeCall(CallSize(code)); |
| 1159 | SetCallKind(r5, call_kind); |
| 1160 | Call(code); |
| 1161 | call_wrapper.AfterCall(); |
| 1162 | } else { |
| 1163 | ASSERT(flag == JUMP_FUNCTION); |
| 1164 | SetCallKind(r5, call_kind); |
| 1165 | Jump(code); |
| 1166 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1167 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1168 | // Continue here if InvokePrologue does handle the invocation due to |
| 1169 | // mismatched parameter counts. |
| 1170 | bind(&done); |
| 1171 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 1176 | const ParameterCount& expected, |
| 1177 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1178 | RelocInfo::Mode rmode, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1179 | InvokeFlag flag, |
| 1180 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1181 | // You can't call a function without a valid frame. |
| 1182 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 1183 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1184 | Label done; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1185 | bool definitely_mismatches = false; |
| 1186 | InvokePrologue(expected, actual, code, no_reg, |
| 1187 | &done, &definitely_mismatches, flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1188 | NullCallWrapper(), call_kind); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1189 | if (!definitely_mismatches) { |
| 1190 | if (flag == CALL_FUNCTION) { |
| 1191 | SetCallKind(r5, call_kind); |
| 1192 | Call(code, rmode); |
| 1193 | } else { |
| 1194 | SetCallKind(r5, call_kind); |
| 1195 | Jump(code, rmode); |
| 1196 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1197 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1198 | // Continue here if InvokePrologue does handle the invocation due to |
| 1199 | // mismatched parameter counts. |
| 1200 | bind(&done); |
| 1201 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | void MacroAssembler::InvokeFunction(Register fun, |
| 1206 | const ParameterCount& actual, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1207 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1208 | const CallWrapper& call_wrapper, |
| 1209 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1210 | // You can't call a function without a valid frame. |
| 1211 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 1212 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1213 | // Contract with called JS functions requires that function is passed in r1. |
| 1214 | ASSERT(fun.is(r1)); |
| 1215 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1216 | Register expected_reg = r2; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1217 | Register code_reg = r3; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1218 | |
| 1219 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 1220 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1221 | ldr(expected_reg, |
| 1222 | FieldMemOperand(code_reg, |
| 1223 | SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1224 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1225 | ldr(code_reg, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1226 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1227 | |
| 1228 | ParameterCount expected(expected_reg); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1229 | InvokeCode(code_reg, expected, actual, flag, call_wrapper, call_kind); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1233 | void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1234 | const ParameterCount& expected, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1235 | const ParameterCount& actual, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1236 | InvokeFlag flag, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1237 | const CallWrapper& call_wrapper, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1238 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1239 | // You can't call a function without a valid frame. |
| 1240 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 1241 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1242 | // Get the function and setup the context. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1243 | LoadHeapObject(r1, function); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1244 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1245 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1246 | // We call indirectly through the code field in the function to |
| 1247 | // allow recompilation to take effect without changing any of the |
| 1248 | // call sites. |
| 1249 | ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1250 | InvokeCode(r3, expected, actual, flag, call_wrapper, call_kind); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1253 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1254 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 1255 | Register map, |
| 1256 | Register scratch, |
| 1257 | Label* fail) { |
| 1258 | ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 1259 | IsInstanceJSObjectType(map, scratch, fail); |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 1264 | Register scratch, |
| 1265 | Label* fail) { |
| 1266 | ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1267 | cmp(scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1268 | b(lt, fail); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1269 | cmp(scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1270 | b(gt, fail); |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | void MacroAssembler::IsObjectJSStringType(Register object, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1275 | Register scratch, |
| 1276 | Label* fail) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1277 | ASSERT(kNotStringTag != 0); |
| 1278 | |
| 1279 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1280 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1281 | tst(scratch, Operand(kIsNotStringMask)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1282 | b(ne, fail); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1286 | void MacroAssembler::IsObjectNameType(Register object, |
| 1287 | Register scratch, |
| 1288 | Label* fail) { |
| 1289 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1290 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1291 | cmp(scratch, Operand(LAST_NAME_TYPE)); |
| 1292 | b(hi, fail); |
| 1293 | } |
| 1294 | |
| 1295 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1296 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1297 | void MacroAssembler::DebugBreak() { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1298 | mov(r0, Operand::Zero()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1299 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate()))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1300 | CEntryStub ces(1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1301 | ASSERT(AllowThisStubCall(&ces)); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1302 | Call(ces.GetCode(isolate()), RelocInfo::DEBUG_BREAK); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1303 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1304 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1305 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1306 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1307 | void MacroAssembler::PushTryHandler(StackHandler::Kind kind, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1308 | int handler_index) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1309 | // Adjust this code if not the case. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1310 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1311 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1312 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1313 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1314 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1315 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1316 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1317 | // For the JSEntry handler, we must preserve r0-r4, r5-r7 are available. |
| 1318 | // We will build up the handler from the bottom by pushing on the stack. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1319 | // Set up the code object (r5) and the state (r6) for pushing. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1320 | unsigned state = |
| 1321 | StackHandler::IndexField::encode(handler_index) | |
| 1322 | StackHandler::KindField::encode(kind); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1323 | mov(r5, Operand(CodeObject())); |
| 1324 | mov(r6, Operand(state)); |
| 1325 | |
| 1326 | // Push the frame pointer, context, state, and code object. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1327 | if (kind == StackHandler::JS_ENTRY) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1328 | mov(r7, Operand(Smi::FromInt(0))); // Indicates no context. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1329 | mov(ip, Operand::Zero()); // NULL frame pointer. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1330 | stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() | ip.bit()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1331 | } else { |
| 1332 | stm(db_w, sp, r5.bit() | r6.bit() | cp.bit() | fp.bit()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | // Link the current handler as the next handler. |
| 1336 | mov(r6, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1337 | ldr(r5, MemOperand(r6)); |
| 1338 | push(r5); |
| 1339 | // Set this new handler as the current one. |
| 1340 | str(sp, MemOperand(r6)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1344 | void MacroAssembler::PopTryHandler() { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1345 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1346 | pop(r1); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1347 | mov(ip, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1348 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1349 | str(r1, MemOperand(ip)); |
| 1350 | } |
| 1351 | |
| 1352 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1353 | void MacroAssembler::JumpToHandlerEntry() { |
| 1354 | // Compute the handler entry address and jump to it. The handler table is |
| 1355 | // a fixed array of (smi-tagged) code offsets. |
| 1356 | // r0 = exception, r1 = code object, r2 = state. |
| 1357 | ldr(r3, FieldMemOperand(r1, Code::kHandlerTableOffset)); // Handler table. |
| 1358 | add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 1359 | mov(r2, Operand(r2, LSR, StackHandler::kKindWidth)); // Handler index. |
| 1360 | ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2)); // Smi-tagged offset. |
| 1361 | add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start. |
| 1362 | add(pc, r1, Operand(r2, ASR, kSmiTagSize)); // Jump. |
| 1363 | } |
| 1364 | |
| 1365 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1366 | void MacroAssembler::Throw(Register value) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1367 | // Adjust this code if not the case. |
| 1368 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1369 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1370 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1371 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1372 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1373 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1374 | |
| 1375 | // The exception is expected in r0. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1376 | if (!value.is(r0)) { |
| 1377 | mov(r0, value); |
| 1378 | } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1379 | // Drop the stack pointer to the top of the top handler. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1380 | mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1381 | ldr(sp, MemOperand(r3)); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1382 | // Restore the next handler. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1383 | pop(r2); |
| 1384 | str(r2, MemOperand(r3)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1385 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1386 | // Get the code object (r1) and state (r2). Restore the context and frame |
| 1387 | // pointer. |
| 1388 | ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1389 | |
| 1390 | // If the handler is a JS frame, restore the context to the frame. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1391 | // (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp |
| 1392 | // or cp. |
| 1393 | tst(cp, cp); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1394 | str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1395 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1396 | JumpToHandlerEntry(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1400 | void MacroAssembler::ThrowUncatchable(Register value) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1401 | // Adjust this code if not the case. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1402 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1403 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1404 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1405 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1406 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1407 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1408 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1409 | // The exception is expected in r0. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1410 | if (!value.is(r0)) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1411 | mov(r0, value); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1412 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1413 | // Drop the stack pointer to the top of the top stack handler. |
| 1414 | mov(r3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 1415 | ldr(sp, MemOperand(r3)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1416 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1417 | // Unwind the handlers until the ENTRY handler is found. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1418 | Label fetch_next, check_kind; |
| 1419 | jmp(&check_kind); |
| 1420 | bind(&fetch_next); |
| 1421 | ldr(sp, MemOperand(sp, StackHandlerConstants::kNextOffset)); |
| 1422 | |
| 1423 | bind(&check_kind); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1424 | STATIC_ASSERT(StackHandler::JS_ENTRY == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1425 | ldr(r2, MemOperand(sp, StackHandlerConstants::kStateOffset)); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1426 | tst(r2, Operand(StackHandler::KindField::kMask)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1427 | b(ne, &fetch_next); |
| 1428 | |
| 1429 | // Set the top handler address to next handler past the top ENTRY handler. |
| 1430 | pop(r2); |
| 1431 | str(r2, MemOperand(r3)); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1432 | // Get the code object (r1) and state (r2). Clear the context and frame |
| 1433 | // pointer (0 was saved in the handler). |
| 1434 | ldm(ia_w, sp, r1.bit() | r2.bit() | cp.bit() | fp.bit()); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1435 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1436 | JumpToHandlerEntry(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1440 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1441 | Register scratch, |
| 1442 | Label* miss) { |
| 1443 | Label same_contexts; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1445 | ASSERT(!holder_reg.is(scratch)); |
| 1446 | ASSERT(!holder_reg.is(ip)); |
| 1447 | ASSERT(!scratch.is(ip)); |
| 1448 | |
| 1449 | // Load current lexical context from the stack frame. |
| 1450 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1451 | // In debug mode, make sure the lexical context is set. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1452 | #ifdef DEBUG |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1453 | cmp(scratch, Operand::Zero()); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1454 | Check(ne, "we should not have an empty lexical context"); |
| 1455 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1457 | // Load the native context of the current context. |
| 1458 | int offset = |
| 1459 | Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1460 | ldr(scratch, FieldMemOperand(scratch, offset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1461 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1462 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1463 | // Check the context is a native context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1464 | if (emit_debug_code()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1465 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1466 | // that ip is clobbered as part of cmp with an object Operand. |
| 1467 | push(holder_reg); // Temporarily save holder on the stack. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1468 | // Read the first word and compare to the native_context_map. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1469 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1470 | LoadRoot(ip, Heap::kNativeContextMapRootIndex); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1471 | cmp(holder_reg, ip); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1472 | Check(eq, "JSGlobalObject::native_context should be a native context."); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1473 | pop(holder_reg); // Restore holder. |
| 1474 | } |
| 1475 | |
| 1476 | // Check if both contexts are the same. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1477 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1478 | cmp(scratch, Operand(ip)); |
| 1479 | b(eq, &same_contexts); |
| 1480 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1481 | // Check the context is a native context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1482 | if (emit_debug_code()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1483 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1484 | // that ip is clobbered as part of cmp with an object Operand. |
| 1485 | push(holder_reg); // Temporarily save holder on the stack. |
| 1486 | mov(holder_reg, ip); // Move ip to its holding place. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1487 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1488 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1489 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 1490 | |
| 1491 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1492 | LoadRoot(ip, Heap::kNativeContextMapRootIndex); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1493 | cmp(holder_reg, ip); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1494 | Check(eq, "JSGlobalObject::native_context should be a native context."); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1495 | // Restore ip is not needed. ip is reloaded below. |
| 1496 | pop(holder_reg); // Restore holder. |
| 1497 | // Restore ip to holder's context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1498 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1501 | // Check that the security token in the calling global object is |
| 1502 | // compatible with the security token in the receiving global |
| 1503 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1504 | int token_offset = Context::kHeaderSize + |
| 1505 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1506 | |
| 1507 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 1508 | ldr(ip, FieldMemOperand(ip, token_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1509 | cmp(scratch, Operand(ip)); |
| 1510 | b(ne, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1511 | |
| 1512 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1516 | void MacroAssembler::GetNumberHash(Register t0, Register scratch) { |
| 1517 | // First of all we assign the hash seed to scratch. |
| 1518 | LoadRoot(scratch, Heap::kHashSeedRootIndex); |
| 1519 | SmiUntag(scratch); |
| 1520 | |
| 1521 | // Xor original key with a seed. |
| 1522 | eor(t0, t0, Operand(scratch)); |
| 1523 | |
| 1524 | // Compute the hash code from the untagged key. This must be kept in sync |
| 1525 | // with ComputeIntegerHash in utils.h. |
| 1526 | // |
| 1527 | // hash = ~hash + (hash << 15); |
| 1528 | mvn(scratch, Operand(t0)); |
| 1529 | add(t0, scratch, Operand(t0, LSL, 15)); |
| 1530 | // hash = hash ^ (hash >> 12); |
| 1531 | eor(t0, t0, Operand(t0, LSR, 12)); |
| 1532 | // hash = hash + (hash << 2); |
| 1533 | add(t0, t0, Operand(t0, LSL, 2)); |
| 1534 | // hash = hash ^ (hash >> 4); |
| 1535 | eor(t0, t0, Operand(t0, LSR, 4)); |
| 1536 | // hash = hash * 2057; |
| 1537 | mov(scratch, Operand(t0, LSL, 11)); |
| 1538 | add(t0, t0, Operand(t0, LSL, 3)); |
| 1539 | add(t0, t0, scratch); |
| 1540 | // hash = hash ^ (hash >> 16); |
| 1541 | eor(t0, t0, Operand(t0, LSR, 16)); |
| 1542 | } |
| 1543 | |
| 1544 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1545 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 1546 | Register elements, |
| 1547 | Register key, |
| 1548 | Register result, |
| 1549 | Register t0, |
| 1550 | Register t1, |
| 1551 | Register t2) { |
| 1552 | // Register use: |
| 1553 | // |
| 1554 | // elements - holds the slow-case elements of the receiver on entry. |
| 1555 | // Unchanged unless 'result' is the same register. |
| 1556 | // |
| 1557 | // key - holds the smi key on entry. |
| 1558 | // Unchanged unless 'result' is the same register. |
| 1559 | // |
| 1560 | // result - holds the result on exit if the load succeeded. |
| 1561 | // Allowed to be the same as 'key' or 'result'. |
| 1562 | // Unchanged on bailout so 'key' or 'result' can be used |
| 1563 | // in further computation. |
| 1564 | // |
| 1565 | // Scratch registers: |
| 1566 | // |
| 1567 | // t0 - holds the untagged key on entry and holds the hash once computed. |
| 1568 | // |
| 1569 | // t1 - used to hold the capacity mask of the dictionary |
| 1570 | // |
| 1571 | // t2 - used for the index into the dictionary. |
| 1572 | Label done; |
| 1573 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1574 | GetNumberHash(t0, t1); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1575 | |
| 1576 | // Compute the capacity mask. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1577 | ldr(t1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1578 | mov(t1, Operand(t1, ASR, kSmiTagSize)); // convert smi to int |
| 1579 | sub(t1, t1, Operand(1)); |
| 1580 | |
| 1581 | // Generate an unrolled loop that performs a few probes before giving up. |
| 1582 | static const int kProbes = 4; |
| 1583 | for (int i = 0; i < kProbes; i++) { |
| 1584 | // Use t2 for index calculations and keep the hash intact in t0. |
| 1585 | mov(t2, t0); |
| 1586 | // Compute the masked index: (hash + i + i * i) & mask. |
| 1587 | if (i > 0) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1588 | add(t2, t2, Operand(SeededNumberDictionary::GetProbeOffset(i))); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1589 | } |
| 1590 | and_(t2, t2, Operand(t1)); |
| 1591 | |
| 1592 | // Scale the index by multiplying by the element size. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1593 | ASSERT(SeededNumberDictionary::kEntrySize == 3); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1594 | add(t2, t2, Operand(t2, LSL, 1)); // t2 = t2 * 3 |
| 1595 | |
| 1596 | // Check if the key is identical to the name. |
| 1597 | add(t2, elements, Operand(t2, LSL, kPointerSizeLog2)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1598 | ldr(ip, FieldMemOperand(t2, SeededNumberDictionary::kElementsStartOffset)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1599 | cmp(key, Operand(ip)); |
| 1600 | if (i != kProbes - 1) { |
| 1601 | b(eq, &done); |
| 1602 | } else { |
| 1603 | b(ne, miss); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | bind(&done); |
| 1608 | // Check that the value is a normal property. |
| 1609 | // t2: elements + (index * kPointerSize) |
| 1610 | const int kDetailsOffset = |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1611 | SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1612 | ldr(t1, FieldMemOperand(t2, kDetailsOffset)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1613 | tst(t1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask))); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1614 | b(ne, miss); |
| 1615 | |
| 1616 | // Get the value at the masked, scaled index and return. |
| 1617 | const int kValueOffset = |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1618 | SeededNumberDictionary::kElementsStartOffset + kPointerSize; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1619 | ldr(result, FieldMemOperand(t2, kValueOffset)); |
| 1620 | } |
| 1621 | |
| 1622 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1623 | void MacroAssembler::Allocate(int object_size, |
| 1624 | Register result, |
| 1625 | Register scratch1, |
| 1626 | Register scratch2, |
| 1627 | Label* gc_required, |
| 1628 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1629 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1630 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1631 | // Trash the registers to simulate an allocation failure. |
| 1632 | mov(result, Operand(0x7091)); |
| 1633 | mov(scratch1, Operand(0x7191)); |
| 1634 | mov(scratch2, Operand(0x7291)); |
| 1635 | } |
| 1636 | jmp(gc_required); |
| 1637 | return; |
| 1638 | } |
| 1639 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1640 | ASSERT(!result.is(scratch1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1641 | ASSERT(!result.is(scratch2)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1642 | ASSERT(!scratch1.is(scratch2)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1643 | ASSERT(!scratch1.is(ip)); |
| 1644 | ASSERT(!scratch2.is(ip)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1645 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1646 | // Make object size into bytes. |
| 1647 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1648 | object_size *= kPointerSize; |
| 1649 | } |
| 1650 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 1651 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1652 | // Check relative positions of allocation top and limit addresses. |
| 1653 | // The values must be adjacent in memory to allow the use of LDM. |
| 1654 | // Also, assert that the registers are numbered such that the values |
| 1655 | // are loaded in the correct order. |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1656 | ExternalReference allocation_top = |
| 1657 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 1658 | ExternalReference allocation_limit = |
| 1659 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 1660 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1661 | intptr_t top = |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1662 | reinterpret_cast<intptr_t>(allocation_top.address()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1663 | intptr_t limit = |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1664 | reinterpret_cast<intptr_t>(allocation_limit.address()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1665 | ASSERT((limit - top) == kPointerSize); |
| 1666 | ASSERT(result.code() < ip.code()); |
| 1667 | |
| 1668 | // Set up allocation top address and object size registers. |
| 1669 | Register topaddr = scratch1; |
| 1670 | Register obj_size_reg = scratch2; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1671 | mov(topaddr, Operand(allocation_top)); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1672 | Operand obj_size_operand = Operand(object_size); |
| 1673 | if (!obj_size_operand.is_single_instruction(this)) { |
| 1674 | // We are about to steal IP, so we need to load this value first |
| 1675 | mov(obj_size_reg, obj_size_operand); |
| 1676 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1677 | |
| 1678 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1679 | // does not need ip for implicit literal generation. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1680 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1681 | // Load allocation top into result and allocation limit into ip. |
| 1682 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1683 | } else { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1684 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1685 | // Assert that result actually contains top on entry. ip is used |
| 1686 | // immediately below so this use of ip does not cause difference with |
| 1687 | // respect to register content between debug and release mode. |
| 1688 | ldr(ip, MemOperand(topaddr)); |
| 1689 | cmp(result, ip); |
| 1690 | Check(eq, "Unexpected allocation top"); |
| 1691 | } |
| 1692 | // Load allocation limit into ip. Result already contains allocation top. |
| 1693 | ldr(ip, MemOperand(topaddr, limit - top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1694 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1695 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1696 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1697 | // Align the next allocation. Storing the filler map without checking top is |
| 1698 | // always safe because the limit of the heap is always aligned. |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1699 | ASSERT((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1700 | ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| 1701 | and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC); |
| 1702 | Label aligned; |
| 1703 | b(eq, &aligned); |
| 1704 | mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 1705 | str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex)); |
| 1706 | bind(&aligned); |
| 1707 | } |
| 1708 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1709 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1710 | // to calculate the new top. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 1711 | if (obj_size_operand.is_single_instruction(this)) { |
| 1712 | // We can add the size as an immediate |
| 1713 | add(scratch2, result, obj_size_operand, SetCC); |
| 1714 | } else { |
| 1715 | // Doesn't fit in an immediate, we have to use the register |
| 1716 | add(scratch2, result, obj_size_reg, SetCC); |
| 1717 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1718 | b(cs, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1719 | cmp(scratch2, Operand(ip)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1720 | b(hi, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1721 | str(scratch2, MemOperand(topaddr)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1722 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1723 | // Tag object if requested. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1724 | if ((flags & TAG_OBJECT) != 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1725 | add(result, result, Operand(kHeapObjectTag)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1730 | void MacroAssembler::Allocate(Register object_size, |
| 1731 | Register result, |
| 1732 | Register scratch1, |
| 1733 | Register scratch2, |
| 1734 | Label* gc_required, |
| 1735 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1736 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1737 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1738 | // Trash the registers to simulate an allocation failure. |
| 1739 | mov(result, Operand(0x7091)); |
| 1740 | mov(scratch1, Operand(0x7191)); |
| 1741 | mov(scratch2, Operand(0x7291)); |
| 1742 | } |
| 1743 | jmp(gc_required); |
| 1744 | return; |
| 1745 | } |
| 1746 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1747 | // Assert that the register arguments are different and that none of |
| 1748 | // them are ip. ip is used explicitly in the code generated below. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1749 | ASSERT(!result.is(scratch1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1750 | ASSERT(!result.is(scratch2)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1751 | ASSERT(!scratch1.is(scratch2)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1752 | ASSERT(!object_size.is(ip)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1753 | ASSERT(!result.is(ip)); |
| 1754 | ASSERT(!scratch1.is(ip)); |
| 1755 | ASSERT(!scratch2.is(ip)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1756 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1757 | // Check relative positions of allocation top and limit addresses. |
| 1758 | // The values must be adjacent in memory to allow the use of LDM. |
| 1759 | // Also, assert that the registers are numbered such that the values |
| 1760 | // are loaded in the correct order. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1761 | ExternalReference allocation_top = |
| 1762 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 1763 | ExternalReference allocation_limit = |
| 1764 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | intptr_t top = |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1766 | reinterpret_cast<intptr_t>(allocation_top.address()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | intptr_t limit = |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1768 | reinterpret_cast<intptr_t>(allocation_limit.address()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | ASSERT((limit - top) == kPointerSize); |
| 1770 | ASSERT(result.code() < ip.code()); |
| 1771 | |
| 1772 | // Set up allocation top address. |
| 1773 | Register topaddr = scratch1; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1774 | mov(topaddr, Operand(allocation_top)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | |
| 1776 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1777 | // does not need ip for implicit literal generation. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1778 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1779 | // Load allocation top into result and allocation limit into ip. |
| 1780 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1781 | } else { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1782 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1783 | // Assert that result actually contains top on entry. ip is used |
| 1784 | // immediately below so this use of ip does not cause difference with |
| 1785 | // respect to register content between debug and release mode. |
| 1786 | ldr(ip, MemOperand(topaddr)); |
| 1787 | cmp(result, ip); |
| 1788 | Check(eq, "Unexpected allocation top"); |
| 1789 | } |
| 1790 | // Load allocation limit into ip. Result already contains allocation top. |
| 1791 | ldr(ip, MemOperand(topaddr, limit - top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1794 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1795 | // Align the next allocation. Storing the filler map without checking top is |
| 1796 | // always safe because the limit of the heap is always aligned. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1797 | ASSERT((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1798 | ASSERT(kPointerAlignment * 2 == kDoubleAlignment); |
| 1799 | and_(scratch2, result, Operand(kDoubleAlignmentMask), SetCC); |
| 1800 | Label aligned; |
| 1801 | b(eq, &aligned); |
| 1802 | mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 1803 | str(scratch2, MemOperand(result, kDoubleSize / 2, PostIndex)); |
| 1804 | bind(&aligned); |
| 1805 | } |
| 1806 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1807 | // Calculate new top and bail out if new space is exhausted. Use result |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1808 | // to calculate the new top. Object size may be in words so a shift is |
| 1809 | // required to get the number of bytes. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1810 | if ((flags & SIZE_IN_WORDS) != 0) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1811 | add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1812 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1813 | add(scratch2, result, Operand(object_size), SetCC); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1814 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1815 | b(cs, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1816 | cmp(scratch2, Operand(ip)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1817 | b(hi, gc_required); |
| 1818 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1819 | // Update allocation top. result temporarily holds the new top. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1820 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1821 | tst(scratch2, Operand(kObjectAlignmentMask)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1822 | Check(eq, "Unaligned allocation in new space"); |
| 1823 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1824 | str(scratch2, MemOperand(topaddr)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1825 | |
| 1826 | // Tag object if requested. |
| 1827 | if ((flags & TAG_OBJECT) != 0) { |
| 1828 | add(result, result, Operand(kHeapObjectTag)); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | |
| 1833 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1834 | Register scratch) { |
| 1835 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1836 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1837 | |
| 1838 | // Make sure the object has no tag before resetting top. |
| 1839 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1840 | #ifdef DEBUG |
| 1841 | // Check that the object un-allocated is below the current top. |
| 1842 | mov(scratch, Operand(new_space_allocation_top)); |
| 1843 | ldr(scratch, MemOperand(scratch)); |
| 1844 | cmp(object, scratch); |
| 1845 | Check(lt, "Undo allocation of non allocated memory"); |
| 1846 | #endif |
| 1847 | // Write the address of the object to un-allocate as the current top. |
| 1848 | mov(scratch, Operand(new_space_allocation_top)); |
| 1849 | str(object, MemOperand(scratch)); |
| 1850 | } |
| 1851 | |
| 1852 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1853 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1854 | Register length, |
| 1855 | Register scratch1, |
| 1856 | Register scratch2, |
| 1857 | Register scratch3, |
| 1858 | Label* gc_required) { |
| 1859 | // Calculate the number of bytes needed for the characters in the string while |
| 1860 | // observing object alignment. |
| 1861 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1862 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1863 | add(scratch1, scratch1, |
| 1864 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1865 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1866 | |
| 1867 | // Allocate two-byte string in new space. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1868 | Allocate(scratch1, |
| 1869 | result, |
| 1870 | scratch2, |
| 1871 | scratch3, |
| 1872 | gc_required, |
| 1873 | TAG_OBJECT); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1874 | |
| 1875 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1876 | InitializeNewString(result, |
| 1877 | length, |
| 1878 | Heap::kStringMapRootIndex, |
| 1879 | scratch1, |
| 1880 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | |
| 1884 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1885 | Register length, |
| 1886 | Register scratch1, |
| 1887 | Register scratch2, |
| 1888 | Register scratch3, |
| 1889 | Label* gc_required) { |
| 1890 | // Calculate the number of bytes needed for the characters in the string while |
| 1891 | // observing object alignment. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1892 | ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1893 | ASSERT(kCharSize == 1); |
| 1894 | add(scratch1, length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1895 | Operand(kObjectAlignmentMask + SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1896 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1897 | |
| 1898 | // Allocate ASCII string in new space. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1899 | Allocate(scratch1, |
| 1900 | result, |
| 1901 | scratch2, |
| 1902 | scratch3, |
| 1903 | gc_required, |
| 1904 | TAG_OBJECT); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1905 | |
| 1906 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1907 | InitializeNewString(result, |
| 1908 | length, |
| 1909 | Heap::kAsciiStringMapRootIndex, |
| 1910 | scratch1, |
| 1911 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1916 | Register length, |
| 1917 | Register scratch1, |
| 1918 | Register scratch2, |
| 1919 | Label* gc_required) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1920 | Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| 1921 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1922 | |
| 1923 | InitializeNewString(result, |
| 1924 | length, |
| 1925 | Heap::kConsStringMapRootIndex, |
| 1926 | scratch1, |
| 1927 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1932 | Register length, |
| 1933 | Register scratch1, |
| 1934 | Register scratch2, |
| 1935 | Label* gc_required) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 1936 | Label allocate_new_space, install_map; |
| 1937 | AllocationFlags flags = TAG_OBJECT; |
| 1938 | |
| 1939 | ExternalReference high_promotion_mode = ExternalReference:: |
| 1940 | new_space_high_promotion_mode_active_address(isolate()); |
| 1941 | mov(scratch1, Operand(high_promotion_mode)); |
| 1942 | ldr(scratch1, MemOperand(scratch1, 0)); |
| 1943 | cmp(scratch1, Operand::Zero()); |
| 1944 | b(eq, &allocate_new_space); |
| 1945 | |
| 1946 | Allocate(ConsString::kSize, |
| 1947 | result, |
| 1948 | scratch1, |
| 1949 | scratch2, |
| 1950 | gc_required, |
| 1951 | static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE)); |
| 1952 | |
| 1953 | jmp(&install_map); |
| 1954 | |
| 1955 | bind(&allocate_new_space); |
| 1956 | Allocate(ConsString::kSize, |
| 1957 | result, |
| 1958 | scratch1, |
| 1959 | scratch2, |
| 1960 | gc_required, |
| 1961 | flags); |
| 1962 | |
| 1963 | bind(&install_map); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1964 | |
| 1965 | InitializeNewString(result, |
| 1966 | length, |
| 1967 | Heap::kConsAsciiStringMapRootIndex, |
| 1968 | scratch1, |
| 1969 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1973 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
| 1974 | Register length, |
| 1975 | Register scratch1, |
| 1976 | Register scratch2, |
| 1977 | Label* gc_required) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1978 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1979 | TAG_OBJECT); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1980 | |
| 1981 | InitializeNewString(result, |
| 1982 | length, |
| 1983 | Heap::kSlicedStringMapRootIndex, |
| 1984 | scratch1, |
| 1985 | scratch2); |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | void MacroAssembler::AllocateAsciiSlicedString(Register result, |
| 1990 | Register length, |
| 1991 | Register scratch1, |
| 1992 | Register scratch2, |
| 1993 | Label* gc_required) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1994 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1995 | TAG_OBJECT); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1996 | |
| 1997 | InitializeNewString(result, |
| 1998 | length, |
| 1999 | Heap::kSlicedAsciiStringMapRootIndex, |
| 2000 | scratch1, |
| 2001 | scratch2); |
| 2002 | } |
| 2003 | |
| 2004 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2005 | void MacroAssembler::CompareObjectType(Register object, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2006 | Register map, |
| 2007 | Register type_reg, |
| 2008 | InstanceType type) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2009 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2010 | CompareInstanceType(map, type_reg, type); |
| 2011 | } |
| 2012 | |
| 2013 | |
| 2014 | void MacroAssembler::CompareInstanceType(Register map, |
| 2015 | Register type_reg, |
| 2016 | InstanceType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2017 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 2018 | cmp(type_reg, Operand(type)); |
| 2019 | } |
| 2020 | |
| 2021 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2022 | void MacroAssembler::CompareRoot(Register obj, |
| 2023 | Heap::RootListIndex index) { |
| 2024 | ASSERT(!obj.is(ip)); |
| 2025 | LoadRoot(ip, index); |
| 2026 | cmp(obj, ip); |
| 2027 | } |
| 2028 | |
| 2029 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2030 | void MacroAssembler::CheckFastElements(Register map, |
| 2031 | Register scratch, |
| 2032 | Label* fail) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2033 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 2034 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 2035 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 2036 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2037 | ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2038 | cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2039 | b(hi, fail); |
| 2040 | } |
| 2041 | |
| 2042 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2043 | void MacroAssembler::CheckFastObjectElements(Register map, |
| 2044 | Register scratch, |
| 2045 | Label* fail) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2046 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 2047 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 2048 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 2049 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2050 | ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2051 | cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2052 | b(ls, fail); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2053 | cmp(scratch, Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2054 | b(hi, fail); |
| 2055 | } |
| 2056 | |
| 2057 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2058 | void MacroAssembler::CheckFastSmiElements(Register map, |
| 2059 | Register scratch, |
| 2060 | Label* fail) { |
| 2061 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 2062 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2063 | ldrb(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2064 | cmp(scratch, Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2065 | b(hi, fail); |
| 2066 | } |
| 2067 | |
| 2068 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2069 | void MacroAssembler::StoreNumberToDoubleElements(Register value_reg, |
| 2070 | Register key_reg, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2071 | Register elements_reg, |
| 2072 | Register scratch1, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2073 | Label* fail, |
| 2074 | int elements_offset) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2075 | Label smi_value, store; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2076 | |
| 2077 | // Handle smi values specially. |
| 2078 | JumpIfSmi(value_reg, &smi_value); |
| 2079 | |
| 2080 | // Ensure that the object is a heap number |
| 2081 | CheckMap(value_reg, |
| 2082 | scratch1, |
| 2083 | isolate()->factory()->heap_number_map(), |
| 2084 | fail, |
| 2085 | DONT_DO_SMI_CHECK); |
| 2086 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2087 | vldr(d0, FieldMemOperand(value_reg, HeapNumber::kValueOffset)); |
| 2088 | // Force a canonical NaN. |
| 2089 | if (emit_debug_code()) { |
| 2090 | vmrs(ip); |
| 2091 | tst(ip, Operand(kVFPDefaultNaNModeControlBit)); |
| 2092 | Assert(ne, "Default NaN mode not set"); |
| 2093 | } |
| 2094 | VFPCanonicalizeNaN(d0); |
| 2095 | b(&store); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2096 | |
| 2097 | bind(&smi_value); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2098 | Register untagged_value = scratch1; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2099 | SmiUntag(untagged_value, value_reg); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2100 | vmov(s2, untagged_value); |
| 2101 | vcvt_f64_s32(d0, s2); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2102 | |
| 2103 | bind(&store); |
| 2104 | add(scratch1, elements_reg, |
| 2105 | Operand(key_reg, LSL, kDoubleSizeLog2 - kSmiTagSize)); |
| 2106 | vstr(d0, FieldMemOperand(scratch1, |
| 2107 | FixedDoubleArray::kHeaderSize - elements_offset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2111 | void MacroAssembler::CompareMap(Register obj, |
| 2112 | Register scratch, |
| 2113 | Handle<Map> map, |
| 2114 | Label* early_success, |
| 2115 | CompareMapMode mode) { |
| 2116 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2117 | CompareMap(scratch, map, early_success, mode); |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | void MacroAssembler::CompareMap(Register obj_map, |
| 2122 | Handle<Map> map, |
| 2123 | Label* early_success, |
| 2124 | CompareMapMode mode) { |
| 2125 | cmp(obj_map, Operand(map)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2126 | if (mode == ALLOW_ELEMENT_TRANSITION_MAPS) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2127 | ElementsKind kind = map->elements_kind(); |
| 2128 | if (IsFastElementsKind(kind)) { |
| 2129 | bool packed = IsFastPackedElementsKind(kind); |
| 2130 | Map* current_map = *map; |
| 2131 | while (CanTransitionToMoreGeneralFastElementsKind(kind, packed)) { |
| 2132 | kind = GetNextMoreGeneralFastElementsKind(kind, packed); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2133 | current_map = current_map->LookupElementsTransitionMap(kind); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2134 | if (!current_map) break; |
| 2135 | b(eq, early_success); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2136 | cmp(obj_map, Operand(Handle<Map>(current_map))); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2137 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2143 | void MacroAssembler::CheckMap(Register obj, |
| 2144 | Register scratch, |
| 2145 | Handle<Map> map, |
| 2146 | Label* fail, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2147 | SmiCheckType smi_check_type, |
| 2148 | CompareMapMode mode) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2149 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2150 | JumpIfSmi(obj, fail); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2151 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2152 | |
| 2153 | Label success; |
| 2154 | CompareMap(obj, scratch, map, &success, mode); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2155 | b(ne, fail); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2156 | bind(&success); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2160 | void MacroAssembler::CheckMap(Register obj, |
| 2161 | Register scratch, |
| 2162 | Heap::RootListIndex index, |
| 2163 | Label* fail, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2164 | SmiCheckType smi_check_type) { |
| 2165 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2166 | JumpIfSmi(obj, fail); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2167 | } |
| 2168 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 2169 | LoadRoot(ip, index); |
| 2170 | cmp(scratch, ip); |
| 2171 | b(ne, fail); |
| 2172 | } |
| 2173 | |
| 2174 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2175 | void MacroAssembler::DispatchMap(Register obj, |
| 2176 | Register scratch, |
| 2177 | Handle<Map> map, |
| 2178 | Handle<Code> success, |
| 2179 | SmiCheckType smi_check_type) { |
| 2180 | Label fail; |
| 2181 | if (smi_check_type == DO_SMI_CHECK) { |
| 2182 | JumpIfSmi(obj, &fail); |
| 2183 | } |
| 2184 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 2185 | mov(ip, Operand(map)); |
| 2186 | cmp(scratch, ip); |
| 2187 | Jump(success, RelocInfo::CODE_TARGET, eq); |
| 2188 | bind(&fail); |
| 2189 | } |
| 2190 | |
| 2191 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2192 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 2193 | Register result, |
| 2194 | Register scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2195 | Label* miss, |
| 2196 | bool miss_on_bound_function) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2197 | // Check that the receiver isn't a smi. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2198 | JumpIfSmi(function, miss); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Check that the function really is a function. Load map into result reg. |
| 2201 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 2202 | b(ne, miss); |
| 2203 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2204 | if (miss_on_bound_function) { |
| 2205 | ldr(scratch, |
| 2206 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 2207 | ldr(scratch, |
| 2208 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 2209 | tst(scratch, |
| 2210 | Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction))); |
| 2211 | b(ne, miss); |
| 2212 | } |
| 2213 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2214 | // Make sure that the function has an instance prototype. |
| 2215 | Label non_instance; |
| 2216 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 2217 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 2218 | b(ne, &non_instance); |
| 2219 | |
| 2220 | // Get the prototype or initial map from the function. |
| 2221 | ldr(result, |
| 2222 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2223 | |
| 2224 | // If the prototype or initial map is the hole, don't return it and |
| 2225 | // simply miss the cache instead. This will allow us to allocate a |
| 2226 | // prototype object on-demand in the runtime system. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2227 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 2228 | cmp(result, ip); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2229 | b(eq, miss); |
| 2230 | |
| 2231 | // If the function does not have an initial map, we're done. |
| 2232 | Label done; |
| 2233 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 2234 | b(ne, &done); |
| 2235 | |
| 2236 | // Get the prototype from the initial map. |
| 2237 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2238 | jmp(&done); |
| 2239 | |
| 2240 | // Non-instance prototype: Fetch prototype from constructor field |
| 2241 | // in initial map. |
| 2242 | bind(&non_instance); |
| 2243 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 2244 | |
| 2245 | // All done. |
| 2246 | bind(&done); |
| 2247 | } |
| 2248 | |
| 2249 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 2250 | void MacroAssembler::CallStub(CodeStub* stub, |
| 2251 | TypeFeedbackId ast_id, |
| 2252 | Condition cond) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2253 | ASSERT(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2254 | Call(stub->GetCode(isolate()), RelocInfo::CODE_TARGET, ast_id, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2258 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2259 | ASSERT(allow_stub_calls_ || |
| 2260 | stub->CompilingCallsToThisStubIsGCSafe(isolate())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2261 | Jump(stub->GetCode(isolate()), RelocInfo::CODE_TARGET, cond); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2265 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 2266 | return ref0.address() - ref1.address(); |
| 2267 | } |
| 2268 | |
| 2269 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2270 | void MacroAssembler::CallApiFunctionAndReturn(ExternalReference function, |
| 2271 | int stack_space) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2272 | ExternalReference next_address = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2273 | ExternalReference::handle_scope_next_address(isolate()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2274 | const int kNextOffset = 0; |
| 2275 | const int kLimitOffset = AddressOffset( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2276 | ExternalReference::handle_scope_limit_address(isolate()), |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2277 | next_address); |
| 2278 | const int kLevelOffset = AddressOffset( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2279 | ExternalReference::handle_scope_level_address(isolate()), |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2280 | next_address); |
| 2281 | |
| 2282 | // Allocate HandleScope in callee-save registers. |
| 2283 | mov(r7, Operand(next_address)); |
| 2284 | ldr(r4, MemOperand(r7, kNextOffset)); |
| 2285 | ldr(r5, MemOperand(r7, kLimitOffset)); |
| 2286 | ldr(r6, MemOperand(r7, kLevelOffset)); |
| 2287 | add(r6, r6, Operand(1)); |
| 2288 | str(r6, MemOperand(r7, kLevelOffset)); |
| 2289 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 2290 | if (FLAG_log_timer_events) { |
| 2291 | FrameScope frame(this, StackFrame::MANUAL); |
| 2292 | PushSafepointRegisters(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2293 | PrepareCallCFunction(1, r0); |
| 2294 | mov(r0, Operand(ExternalReference::isolate_address(isolate()))); |
| 2295 | CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 2296 | PopSafepointRegisters(); |
| 2297 | } |
| 2298 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2299 | // Native call returns to the DirectCEntry stub which redirects to the |
| 2300 | // return address pushed on stack (could have moved after GC). |
| 2301 | // DirectCEntry stub itself is generated early and never moves. |
| 2302 | DirectCEntryStub stub; |
| 2303 | stub.GenerateCall(this, function); |
| 2304 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 2305 | if (FLAG_log_timer_events) { |
| 2306 | FrameScope frame(this, StackFrame::MANUAL); |
| 2307 | PushSafepointRegisters(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2308 | PrepareCallCFunction(1, r0); |
| 2309 | mov(r0, Operand(ExternalReference::isolate_address(isolate()))); |
| 2310 | CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 2311 | PopSafepointRegisters(); |
| 2312 | } |
| 2313 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2314 | Label promote_scheduled_exception; |
| 2315 | Label delete_allocated_handles; |
| 2316 | Label leave_exit_frame; |
| 2317 | |
| 2318 | // If result is non-zero, dereference to get the result value |
| 2319 | // otherwise set it to undefined. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2320 | cmp(r0, Operand::Zero()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2321 | LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 2322 | ldr(r0, MemOperand(r0), ne); |
| 2323 | |
| 2324 | // No more valid handles (the result handle was the last one). Restore |
| 2325 | // previous handle scope. |
| 2326 | str(r4, MemOperand(r7, kNextOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2327 | if (emit_debug_code()) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2328 | ldr(r1, MemOperand(r7, kLevelOffset)); |
| 2329 | cmp(r1, r6); |
| 2330 | Check(eq, "Unexpected level after return from api call"); |
| 2331 | } |
| 2332 | sub(r6, r6, Operand(1)); |
| 2333 | str(r6, MemOperand(r7, kLevelOffset)); |
| 2334 | ldr(ip, MemOperand(r7, kLimitOffset)); |
| 2335 | cmp(r5, ip); |
| 2336 | b(ne, &delete_allocated_handles); |
| 2337 | |
| 2338 | // Check if the function scheduled an exception. |
| 2339 | bind(&leave_exit_frame); |
| 2340 | LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2341 | mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2342 | ldr(r5, MemOperand(ip)); |
| 2343 | cmp(r4, r5); |
| 2344 | b(ne, &promote_scheduled_exception); |
| 2345 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2346 | // LeaveExitFrame expects unwind space to be in a register. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2347 | mov(r4, Operand(stack_space)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2348 | LeaveExitFrame(false, r4); |
| 2349 | mov(pc, lr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2350 | |
| 2351 | bind(&promote_scheduled_exception); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2352 | TailCallExternalReference( |
| 2353 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), |
| 2354 | 0, |
| 2355 | 1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2356 | |
| 2357 | // HandleScope limit has changed. Delete allocated extensions. |
| 2358 | bind(&delete_allocated_handles); |
| 2359 | str(r5, MemOperand(r7, kLimitOffset)); |
| 2360 | mov(r4, r0); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2361 | PrepareCallCFunction(1, r5); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2362 | mov(r0, Operand(ExternalReference::isolate_address(isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2363 | CallCFunction( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2364 | ExternalReference::delete_handle_scope_extensions(isolate()), 1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2365 | mov(r0, r4); |
| 2366 | jmp(&leave_exit_frame); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2370 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
| 2371 | if (!has_frame_ && stub->SometimesSetsUpAFrame()) return false; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2372 | return allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe(isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2376 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 2377 | if (num_arguments > 0) { |
| 2378 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 2379 | } |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2380 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2384 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 2385 | // If the hash field contains an array index pick it out. The assert checks |
| 2386 | // that the constants for the maximum number of digits for an array index |
| 2387 | // cached in the hash field and the number of bits reserved for it does not |
| 2388 | // conflict. |
| 2389 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 2390 | (1 << String::kArrayIndexValueBits)); |
| 2391 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 2392 | // the low kHashShift bits. |
| 2393 | STATIC_ASSERT(kSmiTag == 0); |
| 2394 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 2395 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 2396 | } |
| 2397 | |
| 2398 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2399 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 2400 | Register outHighReg, |
| 2401 | Register outLowReg) { |
| 2402 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 2403 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2404 | vmov(s15, r7); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2405 | vcvt_f64_s32(d7, s15); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2406 | vmov(outLowReg, outHighReg, d7); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2410 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 2411 | DwVfpRegister result, |
| 2412 | Register scratch1, |
| 2413 | Register scratch2, |
| 2414 | Register heap_number_map, |
| 2415 | SwVfpRegister scratch3, |
| 2416 | Label* not_number, |
| 2417 | ObjectToDoubleFlags flags) { |
| 2418 | Label done; |
| 2419 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 2420 | Label not_smi; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2421 | JumpIfNotSmi(object, ¬_smi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2422 | // Remove smi tag and convert to double. |
| 2423 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 2424 | vmov(scratch3, scratch1); |
| 2425 | vcvt_f64_s32(result, scratch3); |
| 2426 | b(&done); |
| 2427 | bind(¬_smi); |
| 2428 | } |
| 2429 | // Check for heap number and load double value from it. |
| 2430 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2431 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 2432 | cmp(scratch1, heap_number_map); |
| 2433 | b(ne, not_number); |
| 2434 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 2435 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 2436 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 2437 | Sbfx(scratch1, |
| 2438 | scratch1, |
| 2439 | HeapNumber::kExponentShift, |
| 2440 | HeapNumber::kExponentBits); |
| 2441 | // All-one value sign extend to -1. |
| 2442 | cmp(scratch1, Operand(-1)); |
| 2443 | b(eq, not_number); |
| 2444 | } |
| 2445 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 2446 | bind(&done); |
| 2447 | } |
| 2448 | |
| 2449 | |
| 2450 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 2451 | DwVfpRegister value, |
| 2452 | Register scratch1, |
| 2453 | SwVfpRegister scratch2) { |
| 2454 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 2455 | vmov(scratch2, scratch1); |
| 2456 | vcvt_f64_s32(value, scratch2); |
| 2457 | } |
| 2458 | |
| 2459 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2460 | void MacroAssembler::TestDoubleIsInt32(DwVfpRegister double_input, |
| 2461 | DwVfpRegister double_scratch) { |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 2462 | ASSERT(!double_input.is(double_scratch)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2463 | vcvt_s32_f64(double_scratch.low(), double_input); |
| 2464 | vcvt_f64_s32(double_scratch, double_scratch.low()); |
| 2465 | VFPCompareAndSetFlags(double_input, double_scratch); |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | void MacroAssembler::TryDoubleToInt32Exact(Register result, |
| 2470 | DwVfpRegister double_input, |
| 2471 | DwVfpRegister double_scratch) { |
| 2472 | ASSERT(!double_input.is(double_scratch)); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 2473 | vcvt_s32_f64(double_scratch.low(), double_input); |
| 2474 | vmov(result, double_scratch.low()); |
| 2475 | vcvt_f64_s32(double_scratch, double_scratch.low()); |
| 2476 | VFPCompareAndSetFlags(double_input, double_scratch); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2480 | void MacroAssembler::TryInt32Floor(Register result, |
| 2481 | DwVfpRegister double_input, |
| 2482 | Register input_high, |
| 2483 | DwVfpRegister double_scratch, |
| 2484 | Label* done, |
| 2485 | Label* exact) { |
| 2486 | ASSERT(!result.is(input_high)); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2487 | ASSERT(!double_input.is(double_scratch)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2488 | Label negative, exception; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2489 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2490 | // Test for NaN and infinities. |
| 2491 | Sbfx(result, input_high, |
| 2492 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 2493 | cmp(result, Operand(-1)); |
| 2494 | b(eq, &exception); |
| 2495 | // Test for values that can be exactly represented as a |
| 2496 | // signed 32-bit integer. |
| 2497 | TryDoubleToInt32Exact(result, double_input, double_scratch); |
| 2498 | // If exact, return (result already fetched). |
| 2499 | b(eq, exact); |
| 2500 | cmp(input_high, Operand::Zero()); |
| 2501 | b(mi, &negative); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2502 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2503 | // Input is in ]+0, +inf[. |
| 2504 | // If result equals 0x7fffffff input was out of range or |
| 2505 | // in ]0x7fffffff, 0x80000000[. We ignore this last case which |
| 2506 | // could fits into an int32, that means we always think input was |
| 2507 | // out of range and always go to exception. |
| 2508 | // If result < 0x7fffffff, go to done, result fetched. |
| 2509 | cmn(result, Operand(1)); |
| 2510 | b(mi, &exception); |
| 2511 | b(done); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2512 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2513 | // Input is in ]-inf, -0[. |
| 2514 | // If x is a non integer negative number, |
| 2515 | // floor(x) <=> round_to_zero(x) - 1. |
| 2516 | bind(&negative); |
| 2517 | sub(result, result, Operand(1), SetCC); |
| 2518 | // If result is still negative, go to done, result fetched. |
| 2519 | // Else, we had an overflow and we fall through exception. |
| 2520 | b(mi, done); |
| 2521 | bind(&exception); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2525 | void MacroAssembler::ECMAToInt32(Register result, |
| 2526 | DwVfpRegister double_input, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2527 | Register scratch, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2528 | Register scratch_high, |
| 2529 | Register scratch_low, |
| 2530 | DwVfpRegister double_scratch) { |
| 2531 | ASSERT(!scratch_high.is(result)); |
| 2532 | ASSERT(!scratch_low.is(result)); |
| 2533 | ASSERT(!scratch_low.is(scratch_high)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2534 | ASSERT(!scratch.is(result) && |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2535 | !scratch.is(scratch_high) && |
| 2536 | !scratch.is(scratch_low)); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 2537 | ASSERT(!double_input.is(double_scratch)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2538 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2539 | Label out_of_range, only_low, negate, done; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2540 | |
| 2541 | vcvt_s32_f64(double_scratch.low(), double_input); |
| 2542 | vmov(result, double_scratch.low()); |
| 2543 | |
| 2544 | // If result is not saturated (0x7fffffff or 0x80000000), we are done. |
| 2545 | sub(scratch, result, Operand(1)); |
| 2546 | cmp(scratch, Operand(0x7ffffffe)); |
| 2547 | b(lt, &done); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2548 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2549 | vmov(scratch_low, scratch_high, double_input); |
| 2550 | Ubfx(scratch, scratch_high, |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2551 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 2552 | // Load scratch with exponent - 1. This is faster than loading |
| 2553 | // with exponent because Bias + 1 = 1024 which is an *ARM* immediate value. |
| 2554 | sub(scratch, scratch, Operand(HeapNumber::kExponentBias + 1)); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2555 | // If exponent is greater than or equal to 84, the 32 less significant |
| 2556 | // bits are 0s (2^84 = 1, 52 significant bits, 32 uncoded bits), |
| 2557 | // the result is 0. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2558 | // Compare exponent with 84 (compare exponent - 1 with 83). |
| 2559 | cmp(scratch, Operand(83)); |
| 2560 | b(ge, &out_of_range); |
| 2561 | |
| 2562 | // If we reach this code, 31 <= exponent <= 83. |
| 2563 | // So, we don't have to handle cases where 0 <= exponent <= 20 for |
| 2564 | // which we would need to shift right the high part of the mantissa. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2565 | // Scratch contains exponent - 1. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2566 | // Load scratch with 52 - exponent (load with 51 - (exponent - 1)). |
| 2567 | rsb(scratch, scratch, Operand(51), SetCC); |
| 2568 | b(ls, &only_low); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2569 | // 21 <= exponent <= 51, shift scratch_low and scratch_high |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2570 | // to generate the result. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2571 | mov(scratch_low, Operand(scratch_low, LSR, scratch)); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2572 | // Scratch contains: 52 - exponent. |
| 2573 | // We needs: exponent - 20. |
| 2574 | // So we use: 32 - scratch = 32 - 52 + exponent = exponent - 20. |
| 2575 | rsb(scratch, scratch, Operand(32)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2576 | Ubfx(result, scratch_high, |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2577 | 0, HeapNumber::kMantissaBitsInTopWord); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2578 | // Set the implicit 1 before the mantissa part in scratch_high. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2579 | orr(result, result, Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2580 | orr(result, scratch_low, Operand(result, LSL, scratch)); |
| 2581 | b(&negate); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2582 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2583 | bind(&out_of_range); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2584 | mov(result, Operand::Zero()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2585 | b(&done); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2586 | |
| 2587 | bind(&only_low); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2588 | // 52 <= exponent <= 83, shift only scratch_low. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2589 | // On entry, scratch contains: 52 - exponent. |
| 2590 | rsb(scratch, scratch, Operand::Zero()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2591 | mov(result, Operand(scratch_low, LSL, scratch)); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2592 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2593 | bind(&negate); |
| 2594 | // If input was positive, scratch_high ASR 31 equals 0 and |
| 2595 | // scratch_high LSR 31 equals zero. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2596 | // New result = (result eor 0) + 0 = result. |
| 2597 | // If the input was negative, we have to negate the result. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2598 | // Input_high ASR 31 equals 0xffffffff and scratch_high LSR 31 equals 1. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2599 | // New result = (result eor 0xffffffff) + 1 = 0 - result. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2600 | eor(result, result, Operand(scratch_high, ASR, 31)); |
| 2601 | add(result, result, Operand(scratch_high, LSR, 31)); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2602 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2603 | bind(&done); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2607 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 2608 | Register src, |
| 2609 | int num_least_bits) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2610 | if (CpuFeatures::IsSupported(ARMv7) && !predictable_code_size()) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2611 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2612 | } else { |
| 2613 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 2614 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 2615 | } |
| 2616 | } |
| 2617 | |
| 2618 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2619 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 2620 | Register src, |
| 2621 | int num_least_bits) { |
| 2622 | and_(dst, src, Operand((1 << num_least_bits) - 1)); |
| 2623 | } |
| 2624 | |
| 2625 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2626 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 2627 | int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2628 | // 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] | 2629 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2630 | // If the expected number of arguments of the runtime function is |
| 2631 | // constant, we check that the actual number of arguments match the |
| 2632 | // expectation. |
| 2633 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 2634 | IllegalOperation(num_arguments); |
| 2635 | return; |
| 2636 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2637 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2638 | // TODO(1236192): Most runtime routines don't need the number of |
| 2639 | // arguments passed in because it is constant. At some point we |
| 2640 | // should remove this need and make the runtime routine entry code |
| 2641 | // smarter. |
| 2642 | mov(r0, Operand(num_arguments)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2643 | mov(r1, Operand(ExternalReference(f, isolate()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2644 | CEntryStub stub(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2645 | CallStub(&stub); |
| 2646 | } |
| 2647 | |
| 2648 | |
| 2649 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 2650 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 2651 | } |
| 2652 | |
| 2653 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2654 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2655 | const Runtime::Function* function = Runtime::FunctionForId(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2656 | mov(r0, Operand(function->nargs)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2657 | mov(r1, Operand(ExternalReference(function, isolate()))); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2658 | CEntryStub stub(1, kSaveFPRegs); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2659 | CallStub(&stub); |
| 2660 | } |
| 2661 | |
| 2662 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2663 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 2664 | int num_arguments) { |
| 2665 | mov(r0, Operand(num_arguments)); |
| 2666 | mov(r1, Operand(ext)); |
| 2667 | |
| 2668 | CEntryStub stub(1); |
| 2669 | CallStub(&stub); |
| 2670 | } |
| 2671 | |
| 2672 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2673 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2674 | int num_arguments, |
| 2675 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2676 | // TODO(1236192): Most runtime routines don't need the number of |
| 2677 | // arguments passed in because it is constant. At some point we |
| 2678 | // should remove this need and make the runtime routine entry code |
| 2679 | // smarter. |
| 2680 | mov(r0, Operand(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2681 | JumpToExternalReference(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2685 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 2686 | int num_arguments, |
| 2687 | int result_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2688 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 2689 | num_arguments, |
| 2690 | result_size); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | |
| 2694 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | #if defined(__thumb__) |
| 2696 | // Thumb mode builtin. |
| 2697 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2698 | #endif |
| 2699 | mov(r1, Operand(builtin)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2700 | CEntryStub stub(1); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2701 | Jump(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2705 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2706 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2707 | const CallWrapper& call_wrapper) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2708 | // You can't call a builtin without a valid frame. |
| 2709 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2710 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2711 | GetBuiltinEntry(r2, id); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2712 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2713 | call_wrapper.BeforeCall(CallSize(r2)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2714 | SetCallKind(r5, CALL_AS_METHOD); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2715 | Call(r2); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2716 | call_wrapper.AfterCall(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2717 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2718 | ASSERT(flag == JUMP_FUNCTION); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2719 | SetCallKind(r5, CALL_AS_METHOD); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2720 | Jump(r2); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2725 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2726 | Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2727 | // Load the builtins object into target register. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2728 | ldr(target, |
| 2729 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2730 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2731 | // Load the JavaScript builtin function from the builtins object. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2732 | ldr(target, FieldMemOperand(target, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2733 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2734 | } |
| 2735 | |
| 2736 | |
| 2737 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 2738 | ASSERT(!target.is(r1)); |
| 2739 | GetBuiltinFunction(r1, id); |
| 2740 | // Load the code entry point from the builtins object. |
| 2741 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2745 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 2746 | Register scratch1, Register scratch2) { |
| 2747 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2748 | mov(scratch1, Operand(value)); |
| 2749 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2750 | str(scratch1, MemOperand(scratch2)); |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | |
| 2755 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 2756 | Register scratch1, Register scratch2) { |
| 2757 | ASSERT(value > 0); |
| 2758 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2759 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2760 | ldr(scratch1, MemOperand(scratch2)); |
| 2761 | add(scratch1, scratch1, Operand(value)); |
| 2762 | str(scratch1, MemOperand(scratch2)); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 2768 | Register scratch1, Register scratch2) { |
| 2769 | ASSERT(value > 0); |
| 2770 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2771 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2772 | ldr(scratch1, MemOperand(scratch2)); |
| 2773 | sub(scratch1, scratch1, Operand(value)); |
| 2774 | str(scratch1, MemOperand(scratch2)); |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2779 | void MacroAssembler::Assert(Condition cond, const char* msg) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2780 | if (emit_debug_code()) |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2781 | Check(cond, msg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2785 | void MacroAssembler::AssertFastElements(Register elements) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2786 | if (emit_debug_code()) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2787 | ASSERT(!elements.is(ip)); |
| 2788 | Label ok; |
| 2789 | push(elements); |
| 2790 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 2791 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2792 | cmp(elements, ip); |
| 2793 | b(eq, &ok); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2794 | LoadRoot(ip, Heap::kFixedDoubleArrayMapRootIndex); |
| 2795 | cmp(elements, ip); |
| 2796 | b(eq, &ok); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2797 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2798 | cmp(elements, ip); |
| 2799 | b(eq, &ok); |
| 2800 | Abort("JSObject with fast elements map has slow elements"); |
| 2801 | bind(&ok); |
| 2802 | pop(elements); |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2807 | void MacroAssembler::Check(Condition cond, const char* msg) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2808 | Label L; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2809 | b(cond, &L); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2810 | Abort(msg); |
| 2811 | // will not return here |
| 2812 | bind(&L); |
| 2813 | } |
| 2814 | |
| 2815 | |
| 2816 | void MacroAssembler::Abort(const char* msg) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2817 | Label abort_start; |
| 2818 | bind(&abort_start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2819 | // We want to pass the msg string like a smi to avoid GC |
| 2820 | // problems, however msg is not guaranteed to be aligned |
| 2821 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2822 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2823 | // from the real pointer as a smi. |
| 2824 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2825 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2826 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2827 | #ifdef DEBUG |
| 2828 | if (msg != NULL) { |
| 2829 | RecordComment("Abort message: "); |
| 2830 | RecordComment(msg); |
| 2831 | } |
| 2832 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2833 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2834 | mov(r0, Operand(p0)); |
| 2835 | push(r0); |
| 2836 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2837 | push(r0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2838 | // Disable stub call restrictions to always allow calls to abort. |
| 2839 | if (!has_frame_) { |
| 2840 | // We don't actually want to generate a pile of code for this, so just |
| 2841 | // claim there is a stack frame, without generating one. |
| 2842 | FrameScope scope(this, StackFrame::NONE); |
| 2843 | CallRuntime(Runtime::kAbort, 2); |
| 2844 | } else { |
| 2845 | CallRuntime(Runtime::kAbort, 2); |
| 2846 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2847 | // will not return here |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2848 | if (is_const_pool_blocked()) { |
| 2849 | // If the calling code cares about the exact number of |
| 2850 | // instructions generated, we insert padding here to keep the size |
| 2851 | // of the Abort macro constant. |
| 2852 | static const int kExpectedAbortInstructions = 10; |
| 2853 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 2854 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 2855 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 2856 | nop(); |
| 2857 | } |
| 2858 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2861 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2862 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2863 | if (context_chain_length > 0) { |
| 2864 | // Move up the chain of contexts to the context containing the slot. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2865 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2866 | for (int i = 1; i < context_chain_length; i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2867 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2868 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2869 | } else { |
| 2870 | // Slot is in the current function context. Move it into the |
| 2871 | // destination register in case we store into it (the write barrier |
| 2872 | // cannot be allowed to destroy the context in esi). |
| 2873 | mov(dst, cp); |
| 2874 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 2878 | void MacroAssembler::LoadTransitionedArrayMapConditional( |
| 2879 | ElementsKind expected_kind, |
| 2880 | ElementsKind transitioned_kind, |
| 2881 | Register map_in_out, |
| 2882 | Register scratch, |
| 2883 | Label* no_map_match) { |
| 2884 | // Load the global or builtins object from the current context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2885 | ldr(scratch, |
| 2886 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2887 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 2888 | |
| 2889 | // Check that the function's map is the same as the expected cached map. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2890 | ldr(scratch, |
| 2891 | MemOperand(scratch, |
| 2892 | Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX))); |
| 2893 | size_t offset = expected_kind * kPointerSize + |
| 2894 | FixedArrayBase::kHeaderSize; |
danno@chromium.org | c31a3c0 | 2012-06-15 09:40:41 +0000 | [diff] [blame] | 2895 | ldr(ip, FieldMemOperand(scratch, offset)); |
| 2896 | cmp(map_in_out, ip); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 2897 | b(ne, no_map_match); |
| 2898 | |
| 2899 | // Use the transitioned cached map. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2900 | offset = transitioned_kind * kPointerSize + |
| 2901 | FixedArrayBase::kHeaderSize; |
| 2902 | ldr(map_in_out, FieldMemOperand(scratch, offset)); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | void MacroAssembler::LoadInitialArrayMap( |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2907 | Register function_in, Register scratch, |
| 2908 | Register map_out, bool can_have_holes) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2909 | ASSERT(!function_in.is(map_out)); |
| 2910 | Label done; |
| 2911 | ldr(map_out, FieldMemOperand(function_in, |
| 2912 | JSFunction::kPrototypeOrInitialMapOffset)); |
| 2913 | if (!FLAG_smi_only_arrays) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2914 | ElementsKind kind = can_have_holes ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS; |
| 2915 | LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
| 2916 | kind, |
| 2917 | map_out, |
| 2918 | scratch, |
| 2919 | &done); |
| 2920 | } else if (can_have_holes) { |
| 2921 | LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
| 2922 | FAST_HOLEY_SMI_ELEMENTS, |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 2923 | map_out, |
| 2924 | scratch, |
| 2925 | &done); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2926 | } |
| 2927 | bind(&done); |
| 2928 | } |
| 2929 | |
| 2930 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2931 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2932 | // Load the global or builtins object from the current context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2933 | ldr(function, |
| 2934 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2935 | // Load the native context from the global or builtins object. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2936 | ldr(function, FieldMemOperand(function, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2937 | GlobalObject::kNativeContextOffset)); |
| 2938 | // Load the function from the native context. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2939 | ldr(function, MemOperand(function, Context::SlotOffset(index))); |
| 2940 | } |
| 2941 | |
| 2942 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2943 | void MacroAssembler::LoadArrayFunction(Register function) { |
| 2944 | // Load the global or builtins object from the current context. |
| 2945 | ldr(function, |
| 2946 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2947 | // Load the global context from the global or builtins object. |
| 2948 | ldr(function, |
| 2949 | FieldMemOperand(function, GlobalObject::kGlobalContextOffset)); |
| 2950 | // Load the array function from the native context. |
| 2951 | ldr(function, |
| 2952 | MemOperand(function, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2953 | } |
| 2954 | |
| 2955 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2956 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2957 | Register map, |
| 2958 | Register scratch) { |
| 2959 | // Load the initial map. The global functions all have initial maps. |
| 2960 | ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2961 | if (emit_debug_code()) { |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2962 | Label ok, fail; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2963 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2964 | b(&ok); |
| 2965 | bind(&fail); |
| 2966 | Abort("Global functions must have initial map"); |
| 2967 | bind(&ok); |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2972 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2973 | Register reg, |
| 2974 | Register scratch, |
| 2975 | Label* not_power_of_two_or_zero) { |
| 2976 | sub(scratch, reg, Operand(1), SetCC); |
| 2977 | b(mi, not_power_of_two_or_zero); |
| 2978 | tst(scratch, reg); |
| 2979 | b(ne, not_power_of_two_or_zero); |
| 2980 | } |
| 2981 | |
| 2982 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2983 | void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg( |
| 2984 | Register reg, |
| 2985 | Register scratch, |
| 2986 | Label* zero_and_neg, |
| 2987 | Label* not_power_of_two) { |
| 2988 | sub(scratch, reg, Operand(1), SetCC); |
| 2989 | b(mi, zero_and_neg); |
| 2990 | tst(scratch, reg); |
| 2991 | b(ne, not_power_of_two); |
| 2992 | } |
| 2993 | |
| 2994 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2995 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 2996 | Register reg2, |
| 2997 | Label* on_not_both_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2998 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2999 | tst(reg1, Operand(kSmiTagMask)); |
| 3000 | tst(reg2, Operand(kSmiTagMask), eq); |
| 3001 | b(ne, on_not_both_smi); |
| 3002 | } |
| 3003 | |
| 3004 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 3005 | void MacroAssembler::UntagAndJumpIfSmi( |
| 3006 | Register dst, Register src, Label* smi_case) { |
| 3007 | STATIC_ASSERT(kSmiTag == 0); |
| 3008 | mov(dst, Operand(src, ASR, kSmiTagSize), SetCC); |
| 3009 | b(cc, smi_case); // Shifter carry is not set for a smi. |
| 3010 | } |
| 3011 | |
| 3012 | |
| 3013 | void MacroAssembler::UntagAndJumpIfNotSmi( |
| 3014 | Register dst, Register src, Label* non_smi_case) { |
| 3015 | STATIC_ASSERT(kSmiTag == 0); |
| 3016 | mov(dst, Operand(src, ASR, kSmiTagSize), SetCC); |
| 3017 | b(cs, non_smi_case); // Shifter carry is set for a non-smi. |
| 3018 | } |
| 3019 | |
| 3020 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3021 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 3022 | Register reg2, |
| 3023 | Label* on_either_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3024 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3025 | tst(reg1, Operand(kSmiTagMask)); |
| 3026 | tst(reg2, Operand(kSmiTagMask), ne); |
| 3027 | b(eq, on_either_smi); |
| 3028 | } |
| 3029 | |
| 3030 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3031 | void MacroAssembler::AssertNotSmi(Register object) { |
| 3032 | if (emit_debug_code()) { |
| 3033 | STATIC_ASSERT(kSmiTag == 0); |
| 3034 | tst(object, Operand(kSmiTagMask)); |
| 3035 | Check(ne, "Operand is a smi"); |
| 3036 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3040 | void MacroAssembler::AssertSmi(Register object) { |
| 3041 | if (emit_debug_code()) { |
| 3042 | STATIC_ASSERT(kSmiTag == 0); |
| 3043 | tst(object, Operand(kSmiTagMask)); |
| 3044 | Check(eq, "Operand is not smi"); |
| 3045 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3049 | void MacroAssembler::AssertString(Register object) { |
| 3050 | if (emit_debug_code()) { |
| 3051 | STATIC_ASSERT(kSmiTag == 0); |
| 3052 | tst(object, Operand(kSmiTagMask)); |
| 3053 | Check(ne, "Operand is a smi and not a string"); |
| 3054 | push(object); |
| 3055 | ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3056 | CompareInstanceType(object, object, FIRST_NONSTRING_TYPE); |
| 3057 | pop(object); |
| 3058 | Check(lo, "Operand is not a string"); |
| 3059 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3063 | void MacroAssembler::AssertName(Register object) { |
| 3064 | if (emit_debug_code()) { |
| 3065 | STATIC_ASSERT(kSmiTag == 0); |
| 3066 | tst(object, Operand(kSmiTagMask)); |
| 3067 | Check(ne, "Operand is a smi and not a name"); |
| 3068 | push(object); |
| 3069 | ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3070 | CompareInstanceType(object, object, LAST_NAME_TYPE); |
| 3071 | pop(object); |
| 3072 | Check(le, "Operand is not a name"); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3077 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3078 | void MacroAssembler::AssertIsRoot(Register reg, Heap::RootListIndex index) { |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3079 | if (emit_debug_code()) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3080 | CompareRoot(reg, index); |
| 3081 | Check(eq, "HeapNumberMap register clobbered."); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3082 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3086 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 3087 | Register heap_number_map, |
| 3088 | Register scratch, |
| 3089 | Label* on_not_heap_number) { |
| 3090 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3091 | AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3092 | cmp(scratch, heap_number_map); |
| 3093 | b(ne, on_not_heap_number); |
| 3094 | } |
| 3095 | |
| 3096 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3097 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 3098 | Register first, |
| 3099 | Register second, |
| 3100 | Register scratch1, |
| 3101 | Register scratch2, |
| 3102 | Label* failure) { |
| 3103 | // Test that both first and second are sequential ASCII strings. |
| 3104 | // Assume that they are non-smis. |
| 3105 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 3106 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 3107 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 3108 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3109 | |
| 3110 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 3111 | scratch2, |
| 3112 | scratch1, |
| 3113 | scratch2, |
| 3114 | failure); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 3118 | Register second, |
| 3119 | Register scratch1, |
| 3120 | Register scratch2, |
| 3121 | Label* failure) { |
| 3122 | // Check that neither is a smi. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3123 | STATIC_ASSERT(kSmiTag == 0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3124 | and_(scratch1, first, Operand(second)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3125 | JumpIfSmi(scratch1, failure); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3126 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 3127 | second, |
| 3128 | scratch1, |
| 3129 | scratch2, |
| 3130 | failure); |
| 3131 | } |
| 3132 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3133 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3134 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 3135 | // is full and a scavenge is needed. |
| 3136 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 3137 | Register scratch1, |
| 3138 | Register scratch2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3139 | Register heap_number_map, |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3140 | Label* gc_required, |
| 3141 | TaggingMode tagging_mode) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3142 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 3143 | // object. |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3144 | Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required, |
| 3145 | tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3146 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3147 | // Store heap number map in the allocated object. |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3148 | AssertIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3149 | if (tagging_mode == TAG_RESULT) { |
| 3150 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
| 3151 | } else { |
| 3152 | str(heap_number_map, MemOperand(result, HeapObject::kMapOffset)); |
| 3153 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 3157 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 3158 | DwVfpRegister value, |
| 3159 | Register scratch1, |
| 3160 | Register scratch2, |
| 3161 | Register heap_number_map, |
| 3162 | Label* gc_required) { |
| 3163 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 3164 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 3165 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 3166 | } |
| 3167 | |
| 3168 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3169 | // Copies a fixed number of fields of heap objects from src to dst. |
| 3170 | void MacroAssembler::CopyFields(Register dst, |
| 3171 | Register src, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3172 | DwVfpRegister double_scratch, |
| 3173 | SwVfpRegister single_scratch, |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3174 | int field_count) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3175 | int double_count = field_count / (DwVfpRegister::kSizeInBytes / kPointerSize); |
| 3176 | for (int i = 0; i < double_count; i++) { |
| 3177 | vldr(double_scratch, FieldMemOperand(src, i * DwVfpRegister::kSizeInBytes)); |
| 3178 | vstr(double_scratch, FieldMemOperand(dst, i * DwVfpRegister::kSizeInBytes)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3179 | } |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3180 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3181 | STATIC_ASSERT(SwVfpRegister::kSizeInBytes == kPointerSize); |
| 3182 | STATIC_ASSERT(2 * SwVfpRegister::kSizeInBytes == DwVfpRegister::kSizeInBytes); |
| 3183 | |
| 3184 | int remain = field_count % (DwVfpRegister::kSizeInBytes / kPointerSize); |
| 3185 | if (remain != 0) { |
| 3186 | vldr(single_scratch, |
| 3187 | FieldMemOperand(src, (field_count - 1) * kPointerSize)); |
| 3188 | vstr(single_scratch, |
| 3189 | FieldMemOperand(dst, (field_count - 1) * kPointerSize)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3194 | void MacroAssembler::CopyBytes(Register src, |
| 3195 | Register dst, |
| 3196 | Register length, |
| 3197 | Register scratch) { |
| 3198 | Label align_loop, align_loop_1, word_loop, byte_loop, byte_loop_1, done; |
| 3199 | |
| 3200 | // Align src before copying in word size chunks. |
| 3201 | bind(&align_loop); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3202 | cmp(length, Operand::Zero()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3203 | b(eq, &done); |
| 3204 | bind(&align_loop_1); |
| 3205 | tst(src, Operand(kPointerSize - 1)); |
| 3206 | b(eq, &word_loop); |
| 3207 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 3208 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3209 | sub(length, length, Operand(1), SetCC); |
| 3210 | b(ne, &byte_loop_1); |
| 3211 | |
| 3212 | // Copy bytes in word size chunks. |
| 3213 | bind(&word_loop); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3214 | if (emit_debug_code()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3215 | tst(src, Operand(kPointerSize - 1)); |
| 3216 | Assert(eq, "Expecting alignment for CopyBytes"); |
| 3217 | } |
| 3218 | cmp(length, Operand(kPointerSize)); |
| 3219 | b(lt, &byte_loop); |
| 3220 | ldr(scratch, MemOperand(src, kPointerSize, PostIndex)); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3221 | if (CpuFeatures::IsSupported(UNALIGNED_ACCESSES)) { |
| 3222 | str(scratch, MemOperand(dst, kPointerSize, PostIndex)); |
| 3223 | } else { |
| 3224 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3225 | mov(scratch, Operand(scratch, LSR, 8)); |
| 3226 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3227 | mov(scratch, Operand(scratch, LSR, 8)); |
| 3228 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3229 | mov(scratch, Operand(scratch, LSR, 8)); |
| 3230 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3231 | } |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3232 | sub(length, length, Operand(kPointerSize)); |
| 3233 | b(&word_loop); |
| 3234 | |
| 3235 | // Copy the last bytes if any left. |
| 3236 | bind(&byte_loop); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3237 | cmp(length, Operand::Zero()); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3238 | b(eq, &done); |
| 3239 | bind(&byte_loop_1); |
| 3240 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 3241 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 3242 | sub(length, length, Operand(1), SetCC); |
| 3243 | b(ne, &byte_loop_1); |
| 3244 | bind(&done); |
| 3245 | } |
| 3246 | |
| 3247 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3248 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 3249 | Register end_offset, |
| 3250 | Register filler) { |
| 3251 | Label loop, entry; |
| 3252 | b(&entry); |
| 3253 | bind(&loop); |
| 3254 | str(filler, MemOperand(start_offset, kPointerSize, PostIndex)); |
| 3255 | bind(&entry); |
| 3256 | cmp(start_offset, end_offset); |
| 3257 | b(lt, &loop); |
| 3258 | } |
| 3259 | |
| 3260 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 3261 | void MacroAssembler::CheckFor32DRegs(Register scratch) { |
| 3262 | mov(scratch, Operand(ExternalReference::cpu_features())); |
| 3263 | ldr(scratch, MemOperand(scratch)); |
| 3264 | tst(scratch, Operand(1u << VFP32DREGS)); |
| 3265 | } |
| 3266 | |
| 3267 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3268 | void MacroAssembler::SaveFPRegs(Register location, Register scratch) { |
| 3269 | CheckFor32DRegs(scratch); |
| 3270 | vstm(db_w, location, d16, d31, ne); |
| 3271 | sub(location, location, Operand(16 * kDoubleSize), LeaveCC, eq); |
| 3272 | vstm(db_w, location, d0, d15); |
| 3273 | } |
| 3274 | |
| 3275 | |
| 3276 | void MacroAssembler::RestoreFPRegs(Register location, Register scratch) { |
| 3277 | CheckFor32DRegs(scratch); |
| 3278 | vldm(ia_w, location, d0, d15); |
| 3279 | vldm(ia_w, location, d16, d31, ne); |
| 3280 | add(location, location, Operand(16 * kDoubleSize), LeaveCC, eq); |
| 3281 | } |
| 3282 | |
| 3283 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3284 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 3285 | Register first, |
| 3286 | Register second, |
| 3287 | Register scratch1, |
| 3288 | Register scratch2, |
| 3289 | Label* failure) { |
| 3290 | int kFlatAsciiStringMask = |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3291 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3292 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 3293 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 3294 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 3295 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 3296 | // Ignore second test if first test failed. |
| 3297 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 3298 | b(ne, failure); |
| 3299 | } |
| 3300 | |
| 3301 | |
| 3302 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 3303 | Register scratch, |
| 3304 | Label* failure) { |
| 3305 | int kFlatAsciiStringMask = |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3306 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3307 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 3308 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 3309 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 3310 | b(ne, failure); |
| 3311 | } |
| 3312 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3313 | static const int kRegisterPassedArguments = 4; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3314 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3315 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3316 | int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments, |
| 3317 | int num_double_arguments) { |
| 3318 | int stack_passed_words = 0; |
| 3319 | if (use_eabi_hardfloat()) { |
| 3320 | // In the hard floating point calling convention, we can use |
| 3321 | // all double registers to pass doubles. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3322 | if (num_double_arguments > DoubleRegister::NumRegisters()) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3323 | stack_passed_words += |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3324 | 2 * (num_double_arguments - DoubleRegister::NumRegisters()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3325 | } |
| 3326 | } else { |
| 3327 | // In the soft floating point calling convention, every double |
| 3328 | // argument is passed using two registers. |
| 3329 | num_reg_arguments += 2 * num_double_arguments; |
| 3330 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3331 | // Up to four simple arguments are passed in registers r0..r3. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3332 | if (num_reg_arguments > kRegisterPassedArguments) { |
| 3333 | stack_passed_words += num_reg_arguments - kRegisterPassedArguments; |
| 3334 | } |
| 3335 | return stack_passed_words; |
| 3336 | } |
| 3337 | |
| 3338 | |
| 3339 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 3340 | int num_double_arguments, |
| 3341 | Register scratch) { |
| 3342 | int frame_alignment = ActivationFrameAlignment(); |
| 3343 | int stack_passed_arguments = CalculateStackPassedWords( |
| 3344 | num_reg_arguments, num_double_arguments); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3345 | if (frame_alignment > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3346 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 3347 | // and the original value of sp. |
| 3348 | mov(scratch, sp); |
| 3349 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3350 | ASSERT(IsPowerOf2(frame_alignment)); |
| 3351 | and_(sp, sp, Operand(-frame_alignment)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3352 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3353 | } else { |
| 3354 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3359 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 3360 | Register scratch) { |
| 3361 | PrepareCallCFunction(num_reg_arguments, 0, scratch); |
| 3362 | } |
| 3363 | |
| 3364 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3365 | void MacroAssembler::SetCallCDoubleArguments(DwVfpRegister dreg) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3366 | if (use_eabi_hardfloat()) { |
| 3367 | Move(d0, dreg); |
| 3368 | } else { |
| 3369 | vmov(r0, r1, dreg); |
| 3370 | } |
| 3371 | } |
| 3372 | |
| 3373 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3374 | void MacroAssembler::SetCallCDoubleArguments(DwVfpRegister dreg1, |
| 3375 | DwVfpRegister dreg2) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3376 | if (use_eabi_hardfloat()) { |
| 3377 | if (dreg2.is(d0)) { |
| 3378 | ASSERT(!dreg1.is(d1)); |
| 3379 | Move(d1, dreg2); |
| 3380 | Move(d0, dreg1); |
| 3381 | } else { |
| 3382 | Move(d0, dreg1); |
| 3383 | Move(d1, dreg2); |
| 3384 | } |
| 3385 | } else { |
| 3386 | vmov(r0, r1, dreg1); |
| 3387 | vmov(r2, r3, dreg2); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3392 | void MacroAssembler::SetCallCDoubleArguments(DwVfpRegister dreg, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3393 | Register reg) { |
| 3394 | if (use_eabi_hardfloat()) { |
| 3395 | Move(d0, dreg); |
| 3396 | Move(r0, reg); |
| 3397 | } else { |
| 3398 | Move(r2, reg); |
| 3399 | vmov(r0, r1, dreg); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | |
| 3404 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3405 | int num_reg_arguments, |
| 3406 | int num_double_arguments) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3407 | mov(ip, Operand(function)); |
| 3408 | CallCFunctionHelper(ip, num_reg_arguments, num_double_arguments); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | |
| 3412 | void MacroAssembler::CallCFunction(Register function, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3413 | int num_reg_arguments, |
| 3414 | int num_double_arguments) { |
| 3415 | CallCFunctionHelper(function, num_reg_arguments, num_double_arguments); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3419 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3420 | int num_arguments) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3421 | CallCFunction(function, num_arguments, 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3424 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3425 | void MacroAssembler::CallCFunction(Register function, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3426 | int num_arguments) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3427 | CallCFunction(function, num_arguments, 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3431 | void MacroAssembler::CallCFunctionHelper(Register function, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3432 | int num_reg_arguments, |
| 3433 | int num_double_arguments) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3434 | ASSERT(has_frame()); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3435 | // Make sure that the stack is aligned before calling a C function unless |
| 3436 | // running in the simulator. The simulator has its own alignment check which |
| 3437 | // provides more information. |
| 3438 | #if defined(V8_HOST_ARCH_ARM) |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3439 | if (emit_debug_code()) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3440 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 3441 | int frame_alignment_mask = frame_alignment - 1; |
| 3442 | if (frame_alignment > kPointerSize) { |
| 3443 | ASSERT(IsPowerOf2(frame_alignment)); |
| 3444 | Label alignment_as_expected; |
| 3445 | tst(sp, Operand(frame_alignment_mask)); |
| 3446 | b(eq, &alignment_as_expected); |
| 3447 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 3448 | // re-entering here. |
| 3449 | stop("Unexpected alignment"); |
| 3450 | bind(&alignment_as_expected); |
| 3451 | } |
| 3452 | } |
| 3453 | #endif |
| 3454 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3455 | // Just call directly. The function called cannot cause a GC, or |
| 3456 | // allow preemption, so the return address in the link register |
| 3457 | // stays correct. |
| 3458 | Call(function); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3459 | int stack_passed_arguments = CalculateStackPassedWords( |
| 3460 | num_reg_arguments, num_double_arguments); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 3461 | if (ActivationFrameAlignment() > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3462 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3463 | } else { |
| 3464 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3469 | void MacroAssembler::GetRelocatedValueLocation(Register ldr_location, |
| 3470 | Register result) { |
| 3471 | const uint32_t kLdrOffsetMask = (1 << 12) - 1; |
| 3472 | const int32_t kPCRegOffset = 2 * kPointerSize; |
| 3473 | ldr(result, MemOperand(ldr_location)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3474 | if (emit_debug_code()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3475 | // Check that the instruction is a ldr reg, [pc + offset] . |
| 3476 | and_(result, result, Operand(kLdrPCPattern)); |
| 3477 | cmp(result, Operand(kLdrPCPattern)); |
| 3478 | Check(eq, "The instruction to patch should be a load from pc."); |
| 3479 | // Result was clobbered. Restore it. |
| 3480 | ldr(result, MemOperand(ldr_location)); |
| 3481 | } |
| 3482 | // Get the address of the constant. |
| 3483 | and_(result, result, Operand(kLdrOffsetMask)); |
| 3484 | add(result, ldr_location, Operand(result)); |
| 3485 | add(result, result, Operand(kPCRegOffset)); |
| 3486 | } |
| 3487 | |
| 3488 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3489 | void MacroAssembler::CheckPageFlag( |
| 3490 | Register object, |
| 3491 | Register scratch, |
| 3492 | int mask, |
| 3493 | Condition cc, |
| 3494 | Label* condition_met) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3495 | Bfc(scratch, object, 0, kPageSizeBits); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3496 | ldr(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset)); |
| 3497 | tst(scratch, Operand(mask)); |
| 3498 | b(cc, condition_met); |
| 3499 | } |
| 3500 | |
| 3501 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 3502 | void MacroAssembler::CheckMapDeprecated(Handle<Map> map, |
| 3503 | Register scratch, |
| 3504 | Label* if_deprecated) { |
| 3505 | if (map->CanBeDeprecated()) { |
| 3506 | mov(scratch, Operand(map)); |
| 3507 | ldr(scratch, FieldMemOperand(scratch, Map::kBitField3Offset)); |
| 3508 | tst(scratch, Operand(Smi::FromInt(Map::Deprecated::kMask))); |
| 3509 | b(ne, if_deprecated); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3514 | void MacroAssembler::JumpIfBlack(Register object, |
| 3515 | Register scratch0, |
| 3516 | Register scratch1, |
| 3517 | Label* on_black) { |
| 3518 | HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern. |
| 3519 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 3520 | } |
| 3521 | |
| 3522 | |
| 3523 | void MacroAssembler::HasColor(Register object, |
| 3524 | Register bitmap_scratch, |
| 3525 | Register mask_scratch, |
| 3526 | Label* has_color, |
| 3527 | int first_bit, |
| 3528 | int second_bit) { |
| 3529 | ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, no_reg)); |
| 3530 | |
| 3531 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 3532 | |
| 3533 | Label other_color, word_boundary; |
| 3534 | ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3535 | tst(ip, Operand(mask_scratch)); |
| 3536 | b(first_bit == 1 ? eq : ne, &other_color); |
| 3537 | // Shift left 1 by adding. |
| 3538 | add(mask_scratch, mask_scratch, Operand(mask_scratch), SetCC); |
| 3539 | b(eq, &word_boundary); |
| 3540 | tst(ip, Operand(mask_scratch)); |
| 3541 | b(second_bit == 1 ? ne : eq, has_color); |
| 3542 | jmp(&other_color); |
| 3543 | |
| 3544 | bind(&word_boundary); |
| 3545 | ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize)); |
| 3546 | tst(ip, Operand(1)); |
| 3547 | b(second_bit == 1 ? ne : eq, has_color); |
| 3548 | bind(&other_color); |
| 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | // Detect some, but not all, common pointer-free objects. This is used by the |
| 3553 | // incremental write barrier which doesn't care about oddballs (they are always |
| 3554 | // marked black immediately so this code is not hit). |
| 3555 | void MacroAssembler::JumpIfDataObject(Register value, |
| 3556 | Register scratch, |
| 3557 | Label* not_data_object) { |
| 3558 | Label is_data_object; |
| 3559 | ldr(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 3560 | CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 3561 | b(eq, &is_data_object); |
| 3562 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 3563 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 3564 | // If it's a string and it's not a cons string then it's an object containing |
| 3565 | // no GC pointers. |
| 3566 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 3567 | tst(scratch, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 3568 | b(ne, not_data_object); |
| 3569 | bind(&is_data_object); |
| 3570 | } |
| 3571 | |
| 3572 | |
| 3573 | void MacroAssembler::GetMarkBits(Register addr_reg, |
| 3574 | Register bitmap_reg, |
| 3575 | Register mask_reg) { |
| 3576 | ASSERT(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg)); |
| 3577 | and_(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask)); |
| 3578 | Ubfx(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2); |
| 3579 | const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2; |
| 3580 | Ubfx(ip, addr_reg, kLowBits, kPageSizeBits - kLowBits); |
| 3581 | add(bitmap_reg, bitmap_reg, Operand(ip, LSL, kPointerSizeLog2)); |
| 3582 | mov(ip, Operand(1)); |
| 3583 | mov(mask_reg, Operand(ip, LSL, mask_reg)); |
| 3584 | } |
| 3585 | |
| 3586 | |
| 3587 | void MacroAssembler::EnsureNotWhite( |
| 3588 | Register value, |
| 3589 | Register bitmap_scratch, |
| 3590 | Register mask_scratch, |
| 3591 | Register load_scratch, |
| 3592 | Label* value_is_white_and_not_data) { |
| 3593 | ASSERT(!AreAliased(value, bitmap_scratch, mask_scratch, ip)); |
| 3594 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 3595 | |
| 3596 | // If the value is black or grey we don't need to do anything. |
| 3597 | ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 3598 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 3599 | ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 3600 | ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 3601 | |
| 3602 | Label done; |
| 3603 | |
| 3604 | // Since both black and grey have a 1 in the first position and white does |
| 3605 | // not have a 1 there we only need to check one bit. |
| 3606 | ldr(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3607 | tst(mask_scratch, load_scratch); |
| 3608 | b(ne, &done); |
| 3609 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3610 | if (emit_debug_code()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3611 | // Check for impossible bit pattern. |
| 3612 | Label ok; |
| 3613 | // LSL may overflow, making the check conservative. |
| 3614 | tst(load_scratch, Operand(mask_scratch, LSL, 1)); |
| 3615 | b(eq, &ok); |
| 3616 | stop("Impossible marking bit pattern"); |
| 3617 | bind(&ok); |
| 3618 | } |
| 3619 | |
| 3620 | // Value is white. We check whether it is data that doesn't need scanning. |
| 3621 | // Currently only checks for HeapNumber and non-cons strings. |
| 3622 | Register map = load_scratch; // Holds map while checking type. |
| 3623 | Register length = load_scratch; // Holds length of object after testing type. |
| 3624 | Label is_data_object; |
| 3625 | |
| 3626 | // Check for heap-number |
| 3627 | ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 3628 | CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 3629 | mov(length, Operand(HeapNumber::kSize), LeaveCC, eq); |
| 3630 | b(eq, &is_data_object); |
| 3631 | |
| 3632 | // Check for strings. |
| 3633 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 3634 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 3635 | // If it's a string and it's not a cons string then it's an object containing |
| 3636 | // no GC pointers. |
| 3637 | Register instance_type = load_scratch; |
| 3638 | ldrb(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 3639 | tst(instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 3640 | b(ne, value_is_white_and_not_data); |
| 3641 | // It's a non-indirect (non-cons and non-slice) string. |
| 3642 | // If it's external, the length is just ExternalString::kSize. |
| 3643 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 3644 | // External strings are the only ones with the kExternalStringTag bit |
| 3645 | // set. |
| 3646 | ASSERT_EQ(0, kSeqStringTag & kExternalStringTag); |
| 3647 | ASSERT_EQ(0, kConsStringTag & kExternalStringTag); |
| 3648 | tst(instance_type, Operand(kExternalStringTag)); |
| 3649 | mov(length, Operand(ExternalString::kSize), LeaveCC, ne); |
| 3650 | b(ne, &is_data_object); |
| 3651 | |
| 3652 | // Sequential string, either ASCII or UC16. |
| 3653 | // For ASCII (char-size of 1) we shift the smi tag away to get the length. |
| 3654 | // For UC16 (char-size of 2) we just leave the smi tag in place, thereby |
| 3655 | // getting the length multiplied by 2. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3656 | ASSERT(kOneByteStringTag == 4 && kStringEncodingMask == 4); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3657 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 3658 | ldr(ip, FieldMemOperand(value, String::kLengthOffset)); |
| 3659 | tst(instance_type, Operand(kStringEncodingMask)); |
| 3660 | mov(ip, Operand(ip, LSR, 1), LeaveCC, ne); |
| 3661 | add(length, ip, Operand(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 3662 | and_(length, length, Operand(~kObjectAlignmentMask)); |
| 3663 | |
| 3664 | bind(&is_data_object); |
| 3665 | // Value is a data object, and it is white. Mark it black. Since we know |
| 3666 | // that the object is white we can make it black by flipping one bit. |
| 3667 | ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3668 | orr(ip, ip, Operand(mask_scratch)); |
| 3669 | str(ip, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3670 | |
| 3671 | and_(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask)); |
| 3672 | ldr(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 3673 | add(ip, ip, Operand(length)); |
| 3674 | str(ip, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 3675 | |
| 3676 | bind(&done); |
| 3677 | } |
| 3678 | |
| 3679 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3680 | void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) { |
| 3681 | Usat(output_reg, 8, Operand(input_reg)); |
| 3682 | } |
| 3683 | |
| 3684 | |
| 3685 | void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 3686 | DwVfpRegister input_reg, |
| 3687 | DwVfpRegister temp_double_reg) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3688 | Label above_zero; |
| 3689 | Label done; |
| 3690 | Label in_bounds; |
| 3691 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3692 | Vmov(temp_double_reg, 0.0); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3693 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3694 | b(gt, &above_zero); |
| 3695 | |
| 3696 | // Double value is less than zero, NaN or Inf, return 0. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3697 | mov(result_reg, Operand::Zero()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3698 | b(al, &done); |
| 3699 | |
| 3700 | // Double value is >= 255, return 255. |
| 3701 | bind(&above_zero); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3702 | Vmov(temp_double_reg, 255.0, result_reg); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3703 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3704 | b(le, &in_bounds); |
| 3705 | mov(result_reg, Operand(255)); |
| 3706 | b(al, &done); |
| 3707 | |
| 3708 | // In 0-255 range, round and truncate. |
| 3709 | bind(&in_bounds); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3710 | // Save FPSCR. |
| 3711 | vmrs(ip); |
| 3712 | // Set rounding mode to round to the nearest integer by clearing bits[23:22]. |
| 3713 | bic(result_reg, ip, Operand(kVFPRoundingModeMask)); |
| 3714 | vmsr(result_reg); |
| 3715 | vcvt_s32_f64(input_reg.low(), input_reg, kFPSCRRounding); |
| 3716 | vmov(result_reg, input_reg.low()); |
| 3717 | // Restore FPSCR. |
| 3718 | vmsr(ip); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3719 | bind(&done); |
| 3720 | } |
| 3721 | |
| 3722 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3723 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3724 | Register descriptors) { |
| 3725 | ldr(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3729 | void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3730 | ldr(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3731 | DecodeField<Map::NumberOfOwnDescriptorsBits>(dst); |
| 3732 | } |
| 3733 | |
| 3734 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3735 | void MacroAssembler::EnumLength(Register dst, Register map) { |
| 3736 | STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); |
| 3737 | ldr(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
| 3738 | and_(dst, dst, Operand(Smi::FromInt(Map::EnumLengthBits::kMask))); |
| 3739 | } |
| 3740 | |
| 3741 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3742 | void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3743 | Register empty_fixed_array_value = r6; |
| 3744 | LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3745 | Label next, start; |
| 3746 | mov(r2, r0); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3747 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3748 | // Check if the enum length field is properly initialized, indicating that |
| 3749 | // there is an enum cache. |
| 3750 | ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 3751 | |
| 3752 | EnumLength(r3, r1); |
| 3753 | cmp(r3, Operand(Smi::FromInt(Map::kInvalidEnumCache))); |
| 3754 | b(eq, call_runtime); |
| 3755 | |
| 3756 | jmp(&start); |
| 3757 | |
| 3758 | bind(&next); |
| 3759 | ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 3760 | |
| 3761 | // For all objects but the receiver, check that the cache is empty. |
| 3762 | EnumLength(r3, r1); |
| 3763 | cmp(r3, Operand(Smi::FromInt(0))); |
| 3764 | b(ne, call_runtime); |
| 3765 | |
| 3766 | bind(&start); |
| 3767 | |
| 3768 | // Check that there are no elements. Register r2 contains the current JS |
| 3769 | // object we've reached through the prototype chain. |
| 3770 | ldr(r2, FieldMemOperand(r2, JSObject::kElementsOffset)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3771 | cmp(r2, empty_fixed_array_value); |
| 3772 | b(ne, call_runtime); |
| 3773 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 3774 | ldr(r2, FieldMemOperand(r1, Map::kPrototypeOffset)); |
| 3775 | cmp(r2, null_value); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 3776 | b(ne, &next); |
| 3777 | } |
| 3778 | |
| 3779 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3780 | void MacroAssembler::TestJSArrayForAllocationSiteInfo( |
| 3781 | Register receiver_reg, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 3782 | Register scratch_reg) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3783 | Label no_info_available; |
| 3784 | ExternalReference new_space_start = |
| 3785 | ExternalReference::new_space_start(isolate()); |
| 3786 | ExternalReference new_space_allocation_top = |
| 3787 | ExternalReference::new_space_allocation_top_address(isolate()); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3788 | add(scratch_reg, receiver_reg, |
| 3789 | Operand(JSArray::kSize + AllocationSiteInfo::kSize - kHeapObjectTag)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3790 | cmp(scratch_reg, Operand(new_space_start)); |
| 3791 | b(lt, &no_info_available); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3792 | mov(ip, Operand(new_space_allocation_top)); |
| 3793 | ldr(ip, MemOperand(ip)); |
| 3794 | cmp(scratch_reg, ip); |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 3795 | b(gt, &no_info_available); |
| 3796 | ldr(scratch_reg, MemOperand(scratch_reg, -AllocationSiteInfo::kSize)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3797 | cmp(scratch_reg, |
| 3798 | Operand(Handle<Map>(isolate()->heap()->allocation_site_info_map()))); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3799 | bind(&no_info_available); |
| 3800 | } |
| 3801 | |
| 3802 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3803 | #ifdef DEBUG |
| 3804 | bool AreAliased(Register reg1, |
| 3805 | Register reg2, |
| 3806 | Register reg3, |
| 3807 | Register reg4, |
| 3808 | Register reg5, |
| 3809 | Register reg6) { |
| 3810 | int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() + |
| 3811 | reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid(); |
| 3812 | |
| 3813 | RegList regs = 0; |
| 3814 | if (reg1.is_valid()) regs |= reg1.bit(); |
| 3815 | if (reg2.is_valid()) regs |= reg2.bit(); |
| 3816 | if (reg3.is_valid()) regs |= reg3.bit(); |
| 3817 | if (reg4.is_valid()) regs |= reg4.bit(); |
| 3818 | if (reg5.is_valid()) regs |= reg5.bit(); |
| 3819 | if (reg6.is_valid()) regs |= reg6.bit(); |
| 3820 | int n_of_non_aliasing_regs = NumRegs(regs); |
| 3821 | |
| 3822 | return n_of_valid_regs != n_of_non_aliasing_regs; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3823 | } |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 3824 | #endif |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3825 | |
| 3826 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3827 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 3828 | : address_(address), |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3829 | size_(instructions * Assembler::kInstrSize), |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3830 | masm_(NULL, address, size_ + Assembler::kGap) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3831 | // Create a new macro assembler pointing to the address of the code to patch. |
| 3832 | // The size is adjusted with kGap on order for the assembler to generate size |
| 3833 | // bytes of instructions without failing with buffer size constraints. |
| 3834 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3835 | } |
| 3836 | |
| 3837 | |
| 3838 | CodePatcher::~CodePatcher() { |
| 3839 | // Indicate that code has changed. |
| 3840 | CPU::FlushICache(address_, size_); |
| 3841 | |
| 3842 | // Check that the code was patched as expected. |
| 3843 | ASSERT(masm_.pc_ == address_ + size_); |
| 3844 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3845 | } |
| 3846 | |
| 3847 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3848 | void CodePatcher::Emit(Instr instr) { |
| 3849 | masm()->emit(instr); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | |
| 3853 | void CodePatcher::Emit(Address addr) { |
| 3854 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 3855 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3856 | |
| 3857 | |
| 3858 | void CodePatcher::EmitCondition(Condition cond) { |
| 3859 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 3860 | instr = (instr & ~kCondMask) | cond; |
| 3861 | masm_.emit(instr); |
| 3862 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3863 | |
| 3864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3865 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3866 | |
| 3867 | #endif // V8_TARGET_ARCH_ARM |