ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1 | // Copyright 2011 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), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 45 | allow_stub_calls_(true) { |
| 46 | if (isolate() != NULL) { |
| 47 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 48 | isolate()); |
| 49 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
| 53 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 54 | // thumb, so we require inter-working support |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 55 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | #error "flag -mthumb-interwork missing" |
| 57 | #endif |
| 58 | |
| 59 | |
| 60 | // We do not support thumb inter-working with an arm architecture not supporting |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 61 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 62 | // you can use -march=armv7 or similar. |
| 63 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 64 | # error "For thumb inter-working we require an architecture which supports blx" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 68 | // Using bx does not yield better code, so use it only when required |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 69 | #if defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | #define USE_BX 1 |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 75 | #if USE_BX |
| 76 | bx(target, cond); |
| 77 | #else |
| 78 | mov(pc, Operand(target), LeaveCC, cond); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 83 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 84 | Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 85 | #if USE_BX |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 86 | mov(ip, Operand(target, rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | bx(ip, cond); |
| 88 | #else |
| 89 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 94 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 95 | Condition cond) { |
| 96 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 98 | } |
| 99 | |
| 100 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 101 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 102 | Condition cond) { |
| 103 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 104 | // 'code' is always generated ARM code, never THUMB code |
| 105 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 106 | } |
| 107 | |
| 108 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 109 | int MacroAssembler::CallSize(Register target, Condition cond) { |
| 110 | #if USE_BLX |
| 111 | return kInstrSize; |
| 112 | #else |
| 113 | return 2 * kInstrSize; |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | void MacroAssembler::Call(Register target, Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 119 | // Block constant pool for the call instruction sequence. |
| 120 | BlockConstPoolScope block_const_pool(this); |
| 121 | #ifdef DEBUG |
| 122 | int pre_position = pc_offset(); |
| 123 | #endif |
| 124 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | #if USE_BLX |
| 126 | blx(target, cond); |
| 127 | #else |
| 128 | // set lr for return at current pc + 8 |
| 129 | mov(lr, Operand(pc), LeaveCC, cond); |
| 130 | mov(pc, Operand(target), LeaveCC, cond); |
| 131 | #endif |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 132 | |
| 133 | #ifdef DEBUG |
| 134 | int post_position = pc_offset(); |
| 135 | CHECK_EQ(pre_position + CallSize(target, cond), post_position); |
| 136 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 140 | int MacroAssembler::CallSize( |
| 141 | intptr_t target, RelocInfo::Mode rmode, Condition cond) { |
| 142 | int size = 2 * kInstrSize; |
| 143 | Instr mov_instr = cond | MOV | LeaveCC; |
| 144 | if (!Operand(target, rmode).is_single_instruction(mov_instr)) { |
| 145 | size += kInstrSize; |
| 146 | } |
| 147 | return size; |
| 148 | } |
| 149 | |
| 150 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 151 | void MacroAssembler::Call(intptr_t target, |
| 152 | RelocInfo::Mode rmode, |
| 153 | Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 154 | // Block constant pool for the call instruction sequence. |
| 155 | BlockConstPoolScope block_const_pool(this); |
| 156 | #ifdef DEBUG |
| 157 | int pre_position = pc_offset(); |
| 158 | #endif |
| 159 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 160 | #if USE_BLX |
| 161 | // On ARMv5 and after the recommended call sequence is: |
| 162 | // ldr ip, [pc, #...] |
| 163 | // blx ip |
| 164 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 165 | // Statement positions are expected to be recorded when the target |
| 166 | // address is loaded. The mov method will automatically record |
| 167 | // positions when pc is the target, since this is not the case here |
| 168 | // we have to do it explicitly. |
| 169 | positions_recorder()->WriteRecordedPositions(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 170 | |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 171 | mov(ip, Operand(target, rmode)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 172 | blx(ip, cond); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 173 | |
| 174 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 175 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | // Set lr for return at current pc + 8. |
| 177 | mov(lr, Operand(pc), LeaveCC, cond); |
| 178 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 179 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 180 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 181 | #endif |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 182 | |
| 183 | #ifdef DEBUG |
| 184 | int post_position = pc_offset(); |
| 185 | CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 186 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 190 | int MacroAssembler::CallSize( |
| 191 | byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 192 | return CallSize(reinterpret_cast<intptr_t>(target), rmode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 196 | void MacroAssembler::Call( |
| 197 | byte* target, RelocInfo::Mode rmode, Condition cond) { |
| 198 | #ifdef DEBUG |
| 199 | int pre_position = pc_offset(); |
| 200 | #endif |
| 201 | |
| 202 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 203 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 204 | |
| 205 | #ifdef DEBUG |
| 206 | int post_position = pc_offset(); |
| 207 | CHECK_EQ(pre_position + CallSize(target, rmode, cond), post_position); |
| 208 | #endif |
| 209 | } |
| 210 | |
| 211 | |
| 212 | int MacroAssembler::CallSize( |
| 213 | Handle<Code> code, RelocInfo::Mode rmode, Condition cond) { |
| 214 | return CallSize(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 215 | } |
| 216 | |
| 217 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 218 | void MacroAssembler::CallWithAstId(Handle<Code> code, |
| 219 | RelocInfo::Mode rmode, |
| 220 | unsigned ast_id, |
| 221 | Condition cond) { |
| 222 | #ifdef DEBUG |
| 223 | int pre_position = pc_offset(); |
| 224 | #endif |
| 225 | |
| 226 | ASSERT(rmode == RelocInfo::CODE_TARGET_WITH_ID); |
| 227 | ASSERT(ast_id != kNoASTId); |
| 228 | ASSERT(ast_id_for_reloc_info_ == kNoASTId); |
| 229 | ast_id_for_reloc_info_ = ast_id; |
| 230 | // 'code' is always generated ARM code, never THUMB code |
| 231 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 232 | |
| 233 | #ifdef DEBUG |
| 234 | int post_position = pc_offset(); |
| 235 | CHECK_EQ(pre_position + CallSize(code, rmode, cond), post_position); |
| 236 | #endif |
| 237 | } |
| 238 | |
| 239 | |
| 240 | void MacroAssembler::Call(Handle<Code> code, |
| 241 | RelocInfo::Mode rmode, |
| 242 | Condition cond) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 243 | #ifdef DEBUG |
| 244 | int pre_position = pc_offset(); |
| 245 | #endif |
| 246 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 247 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | // 'code' is always generated ARM code, never THUMB code |
| 249 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 250 | |
| 251 | #ifdef DEBUG |
| 252 | int post_position = pc_offset(); |
| 253 | CHECK_EQ(pre_position + CallSize(code, rmode, cond), post_position); |
| 254 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 258 | void MacroAssembler::Ret(Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 259 | #if USE_BX |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 260 | bx(lr, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | #else |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 262 | mov(pc, Operand(lr), LeaveCC, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | #endif |
| 264 | } |
| 265 | |
| 266 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 267 | void MacroAssembler::Drop(int count, Condition cond) { |
| 268 | if (count > 0) { |
| 269 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 274 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 275 | Drop(drop, cond); |
| 276 | Ret(cond); |
| 277 | } |
| 278 | |
| 279 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 280 | void MacroAssembler::Swap(Register reg1, |
| 281 | Register reg2, |
| 282 | Register scratch, |
| 283 | Condition cond) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 284 | if (scratch.is(no_reg)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 285 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 286 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 287 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 288 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 289 | mov(scratch, reg1, LeaveCC, cond); |
| 290 | mov(reg1, reg2, LeaveCC, cond); |
| 291 | mov(reg2, scratch, LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 296 | void MacroAssembler::Call(Label* target) { |
| 297 | bl(target); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 302 | mov(dst, Operand(value)); |
| 303 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 304 | |
| 305 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 306 | void MacroAssembler::Move(Register dst, Register src) { |
| 307 | if (!dst.is(src)) { |
| 308 | mov(dst, src); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 313 | void MacroAssembler::Move(DoubleRegister dst, DoubleRegister src) { |
| 314 | ASSERT(CpuFeatures::IsSupported(VFP3)); |
| 315 | CpuFeatures::Scope scope(VFP3); |
| 316 | if (!dst.is(src)) { |
| 317 | vmov(dst, src); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 322 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 323 | Condition cond) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 324 | if (!src2.is_reg() && |
| 325 | !src2.must_use_constant_pool() && |
| 326 | src2.immediate() == 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 327 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, cond); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 328 | |
| 329 | } else if (!src2.is_single_instruction() && |
| 330 | !src2.must_use_constant_pool() && |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 331 | CpuFeatures::IsSupported(ARMv7) && |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 332 | IsPowerOf2(src2.immediate() + 1)) { |
| 333 | ubfx(dst, src1, 0, WhichPowerOf2(src2.immediate() + 1), cond); |
| 334 | |
| 335 | } else { |
| 336 | and_(dst, src1, src2, LeaveCC, cond); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 337 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | |
| 341 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 342 | Condition cond) { |
| 343 | ASSERT(lsb < 32); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 344 | if (!CpuFeatures::IsSupported(ARMv7)) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 345 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 346 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 347 | if (lsb != 0) { |
| 348 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 349 | } |
| 350 | } else { |
| 351 | ubfx(dst, src1, lsb, width, cond); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 357 | Condition cond) { |
| 358 | ASSERT(lsb < 32); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 359 | if (!CpuFeatures::IsSupported(ARMv7)) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 360 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 361 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 362 | int shift_up = 32 - lsb - width; |
| 363 | int shift_down = lsb + shift_up; |
| 364 | if (shift_up != 0) { |
| 365 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 366 | } |
| 367 | if (shift_down != 0) { |
| 368 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 369 | } |
| 370 | } else { |
| 371 | sbfx(dst, src1, lsb, width, cond); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 376 | void MacroAssembler::Bfi(Register dst, |
| 377 | Register src, |
| 378 | Register scratch, |
| 379 | int lsb, |
| 380 | int width, |
| 381 | Condition cond) { |
| 382 | ASSERT(0 <= lsb && lsb < 32); |
| 383 | ASSERT(0 <= width && width < 32); |
| 384 | ASSERT(lsb + width < 32); |
| 385 | ASSERT(!scratch.is(dst)); |
| 386 | if (width == 0) return; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 387 | if (!CpuFeatures::IsSupported(ARMv7)) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 388 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 389 | bic(dst, dst, Operand(mask)); |
| 390 | and_(scratch, src, Operand((1 << width) - 1)); |
| 391 | mov(scratch, Operand(scratch, LSL, lsb)); |
| 392 | orr(dst, dst, scratch); |
| 393 | } else { |
| 394 | bfi(dst, src, lsb, width, cond); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 399 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 400 | ASSERT(lsb < 32); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 401 | if (!CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 402 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 403 | bic(dst, dst, Operand(mask)); |
| 404 | } else { |
| 405 | bfc(dst, lsb, width, cond); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 410 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 411 | Condition cond) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 412 | if (!CpuFeatures::IsSupported(ARMv7)) { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 413 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 414 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 415 | |
| 416 | // These asserts are required to ensure compatibility with the ARMv7 |
| 417 | // implementation. |
| 418 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 419 | ASSERT(src.rs().is(no_reg)); |
| 420 | |
| 421 | Label done; |
| 422 | int satval = (1 << satpos) - 1; |
| 423 | |
| 424 | if (cond != al) { |
| 425 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 426 | } |
| 427 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 428 | mov(dst, src); |
| 429 | } |
| 430 | tst(dst, Operand(~satval)); |
| 431 | b(eq, &done); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 432 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, mi); // 0 if negative. |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 433 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 434 | bind(&done); |
| 435 | } else { |
| 436 | usat(dst, satpos, src, cond); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 441 | void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) { |
| 442 | // Empty the const pool. |
| 443 | CheckConstPool(true, true); |
| 444 | add(pc, pc, Operand(index, |
| 445 | LSL, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 446 | Instruction::kInstrSizeLog2 - kSmiTagSize)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 447 | BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 448 | nop(); // Jump table alignment. |
| 449 | for (int i = 0; i < targets.length(); i++) { |
| 450 | b(targets[i]); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 455 | void MacroAssembler::LoadRoot(Register destination, |
| 456 | Heap::RootListIndex index, |
| 457 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 458 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 462 | void MacroAssembler::StoreRoot(Register source, |
| 463 | Heap::RootListIndex index, |
| 464 | Condition cond) { |
| 465 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 466 | } |
| 467 | |
| 468 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 469 | void MacroAssembler::RecordWriteHelper(Register object, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 470 | Register address, |
| 471 | Register scratch) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 472 | if (emit_debug_code()) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 473 | // Check that the object is not in new space. |
| 474 | Label not_in_new_space; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 475 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 476 | Abort("new-space object passed to RecordWriteHelper"); |
| 477 | bind(¬_in_new_space); |
| 478 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 479 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 480 | // Calculate page address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 481 | Bfc(object, 0, kPageSizeBits); |
| 482 | |
| 483 | // Calculate region number. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 484 | Ubfx(address, address, Page::kRegionSizeLog2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 485 | kPageSizeBits - Page::kRegionSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 487 | // Mark region dirty. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 488 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | mov(ip, Operand(1)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 490 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 491 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
| 495 | void MacroAssembler::InNewSpace(Register object, |
| 496 | Register scratch, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 497 | Condition cond, |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 498 | Label* branch) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 499 | ASSERT(cond == eq || cond == ne); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 500 | and_(scratch, object, Operand(ExternalReference::new_space_mask(isolate()))); |
| 501 | cmp(scratch, Operand(ExternalReference::new_space_start(isolate()))); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 502 | b(cond, branch); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
| 506 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 507 | // register 'object' contains a heap object pointer. The heap object |
| 508 | // tag is shifted away. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 509 | void MacroAssembler::RecordWrite(Register object, |
| 510 | Operand offset, |
| 511 | Register scratch0, |
| 512 | Register scratch1) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 513 | // The compiled code assumes that record write doesn't change the |
| 514 | // context register, so we check that none of the clobbered |
| 515 | // registers are cp. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 516 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 517 | |
| 518 | Label done; |
| 519 | |
| 520 | // First, test that the object is not in the new space. We cannot set |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 521 | // region marks for new space pages. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 522 | InNewSpace(object, scratch0, eq, &done); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 523 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 524 | // Add offset into the object. |
| 525 | add(scratch0, object, offset); |
| 526 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 527 | // Record the actual write. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 528 | RecordWriteHelper(object, scratch0, scratch1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | |
| 530 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 531 | |
| 532 | // Clobber all input registers when running with the debug-code flag |
| 533 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 534 | if (emit_debug_code()) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 535 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 536 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 537 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 538 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 542 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 543 | // register 'object' contains a heap object pointer. The heap object |
| 544 | // tag is shifted away. |
| 545 | void MacroAssembler::RecordWrite(Register object, |
| 546 | Register address, |
| 547 | Register scratch) { |
| 548 | // The compiled code assumes that record write doesn't change the |
| 549 | // context register, so we check that none of the clobbered |
| 550 | // registers are cp. |
| 551 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 552 | |
| 553 | Label done; |
| 554 | |
| 555 | // First, test that the object is not in the new space. We cannot set |
| 556 | // region marks for new space pages. |
| 557 | InNewSpace(object, scratch, eq, &done); |
| 558 | |
| 559 | // Record the actual write. |
| 560 | RecordWriteHelper(object, address, scratch); |
| 561 | |
| 562 | bind(&done); |
| 563 | |
| 564 | // Clobber all input registers when running with the debug-code flag |
| 565 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 566 | if (emit_debug_code()) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 567 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 568 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 569 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 574 | // Push and pop all registers that can hold pointers. |
| 575 | void MacroAssembler::PushSafepointRegisters() { |
| 576 | // Safepoints expect a block of contiguous register values starting with r0: |
| 577 | ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters); |
| 578 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 579 | // stack, so adjust the stack for unsaved registers. |
| 580 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 581 | ASSERT(num_unsaved >= 0); |
| 582 | sub(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 583 | stm(db_w, sp, kSafepointSavedRegisters); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void MacroAssembler::PopSafepointRegisters() { |
| 588 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 589 | ldm(ia_w, sp, kSafepointSavedRegisters); |
| 590 | add(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 591 | } |
| 592 | |
| 593 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 594 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
| 595 | PushSafepointRegisters(); |
| 596 | sub(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 597 | kDoubleSize)); |
| 598 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 599 | vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | |
| 604 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
| 605 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 606 | vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 607 | } |
| 608 | add(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 609 | kDoubleSize)); |
| 610 | PopSafepointRegisters(); |
| 611 | } |
| 612 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 613 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src, |
| 614 | Register dst) { |
| 615 | str(src, SafepointRegistersAndDoublesSlot(dst)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 619 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 620 | str(src, SafepointRegisterSlot(dst)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 624 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 625 | ldr(dst, SafepointRegisterSlot(src)); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 629 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 630 | // The registers are pushed starting with the highest encoding, |
| 631 | // which means that lowest encodings are closest to the stack pointer. |
| 632 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 633 | return reg_code; |
| 634 | } |
| 635 | |
| 636 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 637 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 638 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 639 | } |
| 640 | |
| 641 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 642 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
| 643 | // General purpose registers are pushed last on the stack. |
| 644 | int doubles_size = DwVfpRegister::kNumAllocatableRegisters * kDoubleSize; |
| 645 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 646 | return MemOperand(sp, doubles_size + register_offset); |
| 647 | } |
| 648 | |
| 649 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 650 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 651 | const MemOperand& src, Condition cond) { |
| 652 | ASSERT(src.rm().is(no_reg)); |
| 653 | ASSERT(!dst1.is(lr)); // r14. |
| 654 | ASSERT_EQ(0, dst1.code() % 2); |
| 655 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 656 | |
| 657 | // Generate two ldr instructions if ldrd is not available. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 658 | if (CpuFeatures::IsSupported(ARMv7)) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 659 | CpuFeatures::Scope scope(ARMv7); |
| 660 | ldrd(dst1, dst2, src, cond); |
| 661 | } else { |
| 662 | MemOperand src2(src); |
| 663 | src2.set_offset(src2.offset() + 4); |
| 664 | if (dst1.is(src.rn())) { |
| 665 | ldr(dst2, src2, cond); |
| 666 | ldr(dst1, src, cond); |
| 667 | } else { |
| 668 | ldr(dst1, src, cond); |
| 669 | ldr(dst2, src2, cond); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | |
| 675 | void MacroAssembler::Strd(Register src1, Register src2, |
| 676 | const MemOperand& dst, Condition cond) { |
| 677 | ASSERT(dst.rm().is(no_reg)); |
| 678 | ASSERT(!src1.is(lr)); // r14. |
| 679 | ASSERT_EQ(0, src1.code() % 2); |
| 680 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 681 | |
| 682 | // Generate two str instructions if strd is not available. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 683 | if (CpuFeatures::IsSupported(ARMv7)) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 684 | CpuFeatures::Scope scope(ARMv7); |
| 685 | strd(src1, src2, dst, cond); |
| 686 | } else { |
| 687 | MemOperand dst2(dst); |
| 688 | dst2.set_offset(dst2.offset() + 4); |
| 689 | str(src1, dst, cond); |
| 690 | str(src2, dst2, cond); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 695 | void MacroAssembler::ClearFPSCRBits(const uint32_t bits_to_clear, |
| 696 | const Register scratch, |
| 697 | const Condition cond) { |
| 698 | vmrs(scratch, cond); |
| 699 | bic(scratch, scratch, Operand(bits_to_clear), LeaveCC, cond); |
| 700 | vmsr(scratch, cond); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 705 | const DwVfpRegister src2, |
| 706 | const Condition cond) { |
| 707 | // Compare and move FPSCR flags to the normal condition flags. |
| 708 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 709 | } |
| 710 | |
| 711 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 712 | const double src2, |
| 713 | const Condition cond) { |
| 714 | // Compare and move FPSCR flags to the normal condition flags. |
| 715 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 720 | const DwVfpRegister src2, |
| 721 | const Register fpscr_flags, |
| 722 | const Condition cond) { |
| 723 | // Compare and load FPSCR. |
| 724 | vcmp(src1, src2, cond); |
| 725 | vmrs(fpscr_flags, cond); |
| 726 | } |
| 727 | |
| 728 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 729 | const double src2, |
| 730 | const Register fpscr_flags, |
| 731 | const Condition cond) { |
| 732 | // Compare and load FPSCR. |
| 733 | vcmp(src1, src2, cond); |
| 734 | vmrs(fpscr_flags, cond); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 738 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 739 | // r0-r3: preserved |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 740 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 741 | mov(ip, Operand(Smi::FromInt(type))); |
| 742 | push(ip); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 743 | mov(ip, Operand(CodeObject())); |
| 744 | push(ip); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 745 | 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] | 746 | } |
| 747 | |
| 748 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 749 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 750 | // r0: preserved |
| 751 | // r1: preserved |
| 752 | // r2: preserved |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 753 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 754 | // Drop the execution stack down to the frame pointer and restore |
| 755 | // the caller frame pointer and return address. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 756 | mov(sp, fp); |
| 757 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 761 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 762 | // Setup the frame structure on the stack. |
| 763 | ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 764 | ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 765 | ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 766 | Push(lr, fp); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 767 | mov(fp, Operand(sp)); // Setup new frame pointer. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 768 | // Reserve room for saved entry sp and code object. |
| 769 | sub(sp, sp, Operand(2 * kPointerSize)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 770 | if (emit_debug_code()) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 771 | mov(ip, Operand(0)); |
| 772 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 773 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 774 | mov(ip, Operand(CodeObject())); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 775 | str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 776 | |
| 777 | // Save the frame pointer and the context in top. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 778 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 779 | str(fp, MemOperand(ip)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 780 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 781 | str(cp, MemOperand(ip)); |
| 782 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 783 | // Optionally save all double registers. |
| 784 | if (save_doubles) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 785 | DwVfpRegister first = d0; |
| 786 | DwVfpRegister last = |
| 787 | DwVfpRegister::from_code(DwVfpRegister::kNumRegisters - 1); |
| 788 | vstm(db_w, sp, first, last); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 789 | // Note that d0 will be accessible at |
| 790 | // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, |
| 791 | // 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] | 792 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 793 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 794 | // Reserve place for the return address and stack space and align the frame |
| 795 | // preparing for calling the runtime function. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 796 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 797 | sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 798 | if (frame_alignment > 0) { |
| 799 | ASSERT(IsPowerOf2(frame_alignment)); |
| 800 | and_(sp, sp, Operand(-frame_alignment)); |
| 801 | } |
| 802 | |
| 803 | // Set the exit frame sp value to point just before the return address |
| 804 | // location. |
| 805 | add(ip, sp, Operand(kPointerSize)); |
| 806 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 810 | void MacroAssembler::InitializeNewString(Register string, |
| 811 | Register length, |
| 812 | Heap::RootListIndex map_index, |
| 813 | Register scratch1, |
| 814 | Register scratch2) { |
| 815 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 816 | LoadRoot(scratch2, map_index); |
| 817 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 818 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 819 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 820 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 821 | } |
| 822 | |
| 823 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 824 | int MacroAssembler::ActivationFrameAlignment() { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 825 | #if defined(V8_HOST_ARCH_ARM) |
| 826 | // Running on the real platform. Use the alignment as mandated by the local |
| 827 | // environment. |
| 828 | // Note: This will break if we ever start generating snapshots on one ARM |
| 829 | // platform for another ARM platform with a different alignment. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 830 | return OS::ActivationFrameAlignment(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 831 | #else // defined(V8_HOST_ARCH_ARM) |
| 832 | // If we are using the simulator then we should always align to the expected |
| 833 | // 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] | 834 | // if the target platform will need alignment, so this is controlled from a |
| 835 | // flag. |
| 836 | return FLAG_sim_stack_alignment; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 837 | #endif // defined(V8_HOST_ARCH_ARM) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 841 | void MacroAssembler::LeaveExitFrame(bool save_doubles, |
| 842 | Register argument_count) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 843 | // Optionally restore all double registers. |
| 844 | if (save_doubles) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 845 | // Calculate the stack location of the saved doubles and restore them. |
| 846 | const int offset = 2 * kPointerSize; |
| 847 | sub(r3, fp, Operand(offset + DwVfpRegister::kNumRegisters * kDoubleSize)); |
| 848 | DwVfpRegister first = d0; |
| 849 | DwVfpRegister last = |
| 850 | DwVfpRegister::from_code(DwVfpRegister::kNumRegisters - 1); |
| 851 | vldm(ia, r3, first, last); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 852 | } |
| 853 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 854 | // Clear top frame. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 855 | mov(r3, Operand(0, RelocInfo::NONE)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 856 | mov(ip, Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 857 | str(r3, MemOperand(ip)); |
| 858 | |
| 859 | // Restore current context from top and clear it in debug mode. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 860 | mov(ip, Operand(ExternalReference(Isolate::k_context_address, isolate()))); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 861 | ldr(cp, MemOperand(ip)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 862 | #ifdef DEBUG |
| 863 | str(r3, MemOperand(ip)); |
| 864 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 865 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 866 | // Tear down the exit frame, pop the arguments, and return. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 867 | mov(sp, Operand(fp)); |
| 868 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 869 | if (argument_count.is_valid()) { |
| 870 | add(sp, sp, Operand(argument_count, LSL, kPointerSizeLog2)); |
| 871 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 872 | } |
| 873 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 874 | void MacroAssembler::GetCFunctionDoubleResult(const DoubleRegister dst) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 875 | if (use_eabi_hardfloat()) { |
| 876 | Move(dst, d0); |
| 877 | } else { |
| 878 | vmov(dst, r0, r1); |
| 879 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 880 | } |
| 881 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 882 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 883 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 884 | const ParameterCount& actual, |
| 885 | Handle<Code> code_constant, |
| 886 | Register code_reg, |
| 887 | Label* done, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 888 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 889 | const CallWrapper& call_wrapper) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 890 | bool definitely_matches = false; |
| 891 | Label regular_invoke; |
| 892 | |
| 893 | // Check whether the expected and actual arguments count match. If not, |
| 894 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 895 | // r0: actual arguments count |
| 896 | // r1: function (passed through to callee) |
| 897 | // r2: expected arguments count |
| 898 | // r3: callee code entry |
| 899 | |
| 900 | // The code below is made a lot easier because the calling code already sets |
| 901 | // up actual and expected registers according to the contract if values are |
| 902 | // passed in registers. |
| 903 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 904 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 905 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 906 | |
| 907 | if (expected.is_immediate()) { |
| 908 | ASSERT(actual.is_immediate()); |
| 909 | if (expected.immediate() == actual.immediate()) { |
| 910 | definitely_matches = true; |
| 911 | } else { |
| 912 | mov(r0, Operand(actual.immediate())); |
| 913 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 914 | if (expected.immediate() == sentinel) { |
| 915 | // Don't worry about adapting arguments for builtins that |
| 916 | // don't want that done. Skip adaption code by making it look |
| 917 | // like we have a match between expected and actual number of |
| 918 | // arguments. |
| 919 | definitely_matches = true; |
| 920 | } else { |
| 921 | mov(r2, Operand(expected.immediate())); |
| 922 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 923 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 924 | } else { |
| 925 | if (actual.is_immediate()) { |
| 926 | cmp(expected.reg(), Operand(actual.immediate())); |
| 927 | b(eq, ®ular_invoke); |
| 928 | mov(r0, Operand(actual.immediate())); |
| 929 | } else { |
| 930 | cmp(expected.reg(), Operand(actual.reg())); |
| 931 | b(eq, ®ular_invoke); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (!definitely_matches) { |
| 936 | if (!code_constant.is_null()) { |
| 937 | mov(r3, Operand(code_constant)); |
| 938 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 939 | } |
| 940 | |
| 941 | Handle<Code> adaptor = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 942 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 943 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 944 | call_wrapper.BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 945 | Call(adaptor, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 946 | call_wrapper.AfterCall(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 947 | b(done); |
| 948 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 949 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 950 | } |
| 951 | bind(®ular_invoke); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
| 955 | |
| 956 | void MacroAssembler::InvokeCode(Register code, |
| 957 | const ParameterCount& expected, |
| 958 | const ParameterCount& actual, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 959 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 960 | const CallWrapper& call_wrapper) { |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 961 | Label done; |
| 962 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 963 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 964 | call_wrapper); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 965 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 966 | call_wrapper.BeforeCall(CallSize(code)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 967 | Call(code); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 968 | call_wrapper.AfterCall(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 969 | } else { |
| 970 | ASSERT(flag == JUMP_FUNCTION); |
| 971 | Jump(code); |
| 972 | } |
| 973 | |
| 974 | // Continue here if InvokePrologue does handle the invocation due to |
| 975 | // mismatched parameter counts. |
| 976 | bind(&done); |
| 977 | } |
| 978 | |
| 979 | |
| 980 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 981 | const ParameterCount& expected, |
| 982 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 983 | RelocInfo::Mode rmode, |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 984 | InvokeFlag flag) { |
| 985 | Label done; |
| 986 | |
| 987 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 988 | if (flag == CALL_FUNCTION) { |
| 989 | Call(code, rmode); |
| 990 | } else { |
| 991 | Jump(code, rmode); |
| 992 | } |
| 993 | |
| 994 | // Continue here if InvokePrologue does handle the invocation due to |
| 995 | // mismatched parameter counts. |
| 996 | bind(&done); |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | void MacroAssembler::InvokeFunction(Register fun, |
| 1001 | const ParameterCount& actual, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1002 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1003 | const CallWrapper& call_wrapper) { |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1004 | // Contract with called JS functions requires that function is passed in r1. |
| 1005 | ASSERT(fun.is(r1)); |
| 1006 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1007 | Register expected_reg = r2; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1008 | Register code_reg = r3; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1009 | |
| 1010 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 1011 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1012 | ldr(expected_reg, |
| 1013 | FieldMemOperand(code_reg, |
| 1014 | SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1015 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1016 | ldr(code_reg, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1017 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1018 | |
| 1019 | ParameterCount expected(expected_reg); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1020 | InvokeCode(code_reg, expected, actual, flag, call_wrapper); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1024 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 1025 | const ParameterCount& actual, |
| 1026 | InvokeFlag flag) { |
| 1027 | ASSERT(function->is_compiled()); |
| 1028 | |
| 1029 | // Get the function and setup the context. |
| 1030 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 1031 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 1032 | |
| 1033 | // Invoke the cached code. |
| 1034 | Handle<Code> code(function->code()); |
| 1035 | ParameterCount expected(function->shared()->formal_parameter_count()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1036 | if (V8::UseCrankshaft()) { |
| 1037 | // TODO(kasperl): For now, we always call indirectly through the |
| 1038 | // code field in the function to allow recompilation to take effect |
| 1039 | // without changing any of the call sites. |
| 1040 | ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 1041 | InvokeCode(r3, expected, actual, flag); |
| 1042 | } else { |
| 1043 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 1044 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1047 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1048 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 1049 | Register map, |
| 1050 | Register scratch, |
| 1051 | Label* fail) { |
| 1052 | ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 1053 | IsInstanceJSObjectType(map, scratch, fail); |
| 1054 | } |
| 1055 | |
| 1056 | |
| 1057 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 1058 | Register scratch, |
| 1059 | Label* fail) { |
| 1060 | ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1061 | cmp(scratch, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1062 | b(lt, fail); |
| 1063 | cmp(scratch, Operand(LAST_JS_OBJECT_TYPE)); |
| 1064 | b(gt, fail); |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | void MacroAssembler::IsObjectJSStringType(Register object, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1069 | Register scratch, |
| 1070 | Label* fail) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1071 | ASSERT(kNotStringTag != 0); |
| 1072 | |
| 1073 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1074 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1075 | tst(scratch, Operand(kIsNotStringMask)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1076 | b(ne, fail); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1080 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1081 | void MacroAssembler::DebugBreak() { |
| 1082 | ASSERT(allow_stub_calls()); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1083 | mov(r0, Operand(0, RelocInfo::NONE)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1084 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak, isolate()))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1085 | CEntryStub ces(1); |
| 1086 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 1087 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1088 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1089 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1091 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 1092 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1093 | // Adjust this code if not the case. |
| 1094 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1095 | // The pc (return address) is passed in register lr. |
| 1096 | if (try_location == IN_JAVASCRIPT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1097 | if (type == TRY_CATCH_HANDLER) { |
| 1098 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 1099 | } else { |
| 1100 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 1101 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1102 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1103 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1104 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1105 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 1106 | // Save the current handler as the next handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1107 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1108 | ldr(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1109 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1110 | push(r1); |
| 1111 | // Link this handler as the new current one. |
| 1112 | str(sp, MemOperand(r3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1113 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1114 | // Must preserve r0-r4, r5-r7 are available. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1115 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1116 | // The frame pointer does not point to a JS frame so we save NULL |
| 1117 | // for fp. We expect the code throwing an exception to check fp |
| 1118 | // before dereferencing it to restore the context. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1119 | mov(ip, Operand(0, RelocInfo::NONE)); // To save a NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1120 | mov(r6, Operand(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1121 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 1122 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 1123 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1124 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 1125 | // Save the current handler as the next handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1126 | mov(r7, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1127 | ldr(r6, MemOperand(r7)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1128 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1129 | push(r6); |
| 1130 | // Link this handler as the new current one. |
| 1131 | str(sp, MemOperand(r7)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1136 | void MacroAssembler::PopTryHandler() { |
| 1137 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 1138 | pop(r1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1139 | mov(ip, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1140 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1141 | str(r1, MemOperand(ip)); |
| 1142 | } |
| 1143 | |
| 1144 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1145 | void MacroAssembler::Throw(Register value) { |
| 1146 | // r0 is expected to hold the exception. |
| 1147 | if (!value.is(r0)) { |
| 1148 | mov(r0, value); |
| 1149 | } |
| 1150 | |
| 1151 | // Adjust this code if not the case. |
| 1152 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1153 | |
| 1154 | // Drop the sp to the top of the handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1155 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1156 | ldr(sp, MemOperand(r3)); |
| 1157 | |
| 1158 | // Restore the next handler and frame pointer, discard handler state. |
| 1159 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1160 | pop(r2); |
| 1161 | str(r2, MemOperand(r3)); |
| 1162 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1163 | ldm(ia_w, sp, r3.bit() | fp.bit()); // r3: discarded state. |
| 1164 | |
| 1165 | // Before returning we restore the context from the frame pointer if |
| 1166 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1167 | // JS entry frame. |
| 1168 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1169 | // Set cp to NULL if fp is NULL. |
| 1170 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1171 | // Restore cp otherwise. |
| 1172 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1173 | #ifdef DEBUG |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1174 | if (emit_debug_code()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1175 | mov(lr, Operand(pc)); |
| 1176 | } |
| 1177 | #endif |
| 1178 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1179 | pop(pc); |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 1184 | Register value) { |
| 1185 | // Adjust this code if not the case. |
| 1186 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 1187 | |
| 1188 | // r0 is expected to hold the exception. |
| 1189 | if (!value.is(r0)) { |
| 1190 | mov(r0, value); |
| 1191 | } |
| 1192 | |
| 1193 | // Drop sp to the top stack handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1194 | mov(r3, Operand(ExternalReference(Isolate::k_handler_address, isolate()))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1195 | ldr(sp, MemOperand(r3)); |
| 1196 | |
| 1197 | // Unwind the handlers until the ENTRY handler is found. |
| 1198 | Label loop, done; |
| 1199 | bind(&loop); |
| 1200 | // Load the type of the current stack handler. |
| 1201 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 1202 | ldr(r2, MemOperand(sp, kStateOffset)); |
| 1203 | cmp(r2, Operand(StackHandler::ENTRY)); |
| 1204 | b(eq, &done); |
| 1205 | // Fetch the next handler in the list. |
| 1206 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 1207 | ldr(sp, MemOperand(sp, kNextOffset)); |
| 1208 | jmp(&loop); |
| 1209 | bind(&done); |
| 1210 | |
| 1211 | // Set the top handler address to next handler past the current ENTRY handler. |
| 1212 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 1213 | pop(r2); |
| 1214 | str(r2, MemOperand(r3)); |
| 1215 | |
| 1216 | if (type == OUT_OF_MEMORY) { |
| 1217 | // Set external caught exception to false. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1218 | ExternalReference external_caught( |
| 1219 | Isolate::k_external_caught_exception_address, isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1220 | mov(r0, Operand(false, RelocInfo::NONE)); |
| 1221 | mov(r2, Operand(external_caught)); |
| 1222 | str(r0, MemOperand(r2)); |
| 1223 | |
| 1224 | // Set pending exception and r0 to out of memory exception. |
| 1225 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 1226 | mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1227 | mov(r2, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 1228 | isolate()))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1229 | str(r0, MemOperand(r2)); |
| 1230 | } |
| 1231 | |
| 1232 | // Stack layout at this point. See also StackHandlerConstants. |
| 1233 | // sp -> state (ENTRY) |
| 1234 | // fp |
| 1235 | // lr |
| 1236 | |
| 1237 | // Discard handler state (r2 is not used) and restore frame pointer. |
| 1238 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 1239 | ldm(ia_w, sp, r2.bit() | fp.bit()); // r2: discarded state. |
| 1240 | // Before returning we restore the context from the frame pointer if |
| 1241 | // not NULL. The frame pointer is NULL in the exception handler of a |
| 1242 | // JS entry frame. |
| 1243 | cmp(fp, Operand(0, RelocInfo::NONE)); |
| 1244 | // Set cp to NULL if fp is NULL. |
| 1245 | mov(cp, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1246 | // Restore cp otherwise. |
| 1247 | ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 1248 | #ifdef DEBUG |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1249 | if (emit_debug_code()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1250 | mov(lr, Operand(pc)); |
| 1251 | } |
| 1252 | #endif |
| 1253 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 1254 | pop(pc); |
| 1255 | } |
| 1256 | |
| 1257 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1258 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1259 | Register scratch, |
| 1260 | Label* miss) { |
| 1261 | Label same_contexts; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1262 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1263 | ASSERT(!holder_reg.is(scratch)); |
| 1264 | ASSERT(!holder_reg.is(ip)); |
| 1265 | ASSERT(!scratch.is(ip)); |
| 1266 | |
| 1267 | // Load current lexical context from the stack frame. |
| 1268 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1269 | // In debug mode, make sure the lexical context is set. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1270 | #ifdef DEBUG |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1271 | cmp(scratch, Operand(0, RelocInfo::NONE)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1272 | Check(ne, "we should not have an empty lexical context"); |
| 1273 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1275 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1277 | ldr(scratch, FieldMemOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1278 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 1279 | |
| 1280 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1281 | if (emit_debug_code()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1282 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1283 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1284 | // that ip is clobbered as part of cmp with an object Operand. |
| 1285 | push(holder_reg); // Temporarily save holder on the stack. |
| 1286 | // Read the first word and compare to the global_context_map. |
| 1287 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1288 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1289 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1290 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1291 | pop(holder_reg); // Restore holder. |
| 1292 | } |
| 1293 | |
| 1294 | // Check if both contexts are the same. |
| 1295 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1296 | cmp(scratch, Operand(ip)); |
| 1297 | b(eq, &same_contexts); |
| 1298 | |
| 1299 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1300 | if (emit_debug_code()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1301 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1302 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1303 | // that ip is clobbered as part of cmp with an object Operand. |
| 1304 | push(holder_reg); // Temporarily save holder on the stack. |
| 1305 | mov(holder_reg, ip); // Move ip to its holding place. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1306 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1307 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1308 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 1309 | |
| 1310 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1311 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1312 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1313 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1314 | // Restore ip is not needed. ip is reloaded below. |
| 1315 | pop(holder_reg); // Restore holder. |
| 1316 | // Restore ip to holder's context. |
| 1317 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1318 | } |
| 1319 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1320 | // Check that the security token in the calling global object is |
| 1321 | // compatible with the security token in the receiving global |
| 1322 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1323 | int token_offset = Context::kHeaderSize + |
| 1324 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1325 | |
| 1326 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 1327 | ldr(ip, FieldMemOperand(ip, token_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1328 | cmp(scratch, Operand(ip)); |
| 1329 | b(ne, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1330 | |
| 1331 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1335 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 1336 | Register result, |
| 1337 | Register scratch1, |
| 1338 | Register scratch2, |
| 1339 | Label* gc_required, |
| 1340 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1341 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1342 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1343 | // Trash the registers to simulate an allocation failure. |
| 1344 | mov(result, Operand(0x7091)); |
| 1345 | mov(scratch1, Operand(0x7191)); |
| 1346 | mov(scratch2, Operand(0x7291)); |
| 1347 | } |
| 1348 | jmp(gc_required); |
| 1349 | return; |
| 1350 | } |
| 1351 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1352 | ASSERT(!result.is(scratch1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1353 | ASSERT(!result.is(scratch2)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1354 | ASSERT(!scratch1.is(scratch2)); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1355 | ASSERT(!scratch1.is(ip)); |
| 1356 | ASSERT(!scratch2.is(ip)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1357 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1358 | // Make object size into bytes. |
| 1359 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1360 | object_size *= kPointerSize; |
| 1361 | } |
| 1362 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 1363 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1364 | // Check relative positions of allocation top and limit addresses. |
| 1365 | // The values must be adjacent in memory to allow the use of LDM. |
| 1366 | // Also, assert that the registers are numbered such that the values |
| 1367 | // are loaded in the correct order. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1368 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1369 | ExternalReference::new_space_allocation_top_address(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1370 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1371 | ExternalReference::new_space_allocation_limit_address(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | intptr_t top = |
| 1373 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1374 | intptr_t limit = |
| 1375 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1376 | ASSERT((limit - top) == kPointerSize); |
| 1377 | ASSERT(result.code() < ip.code()); |
| 1378 | |
| 1379 | // Set up allocation top address and object size registers. |
| 1380 | Register topaddr = scratch1; |
| 1381 | Register obj_size_reg = scratch2; |
| 1382 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1383 | mov(obj_size_reg, Operand(object_size)); |
| 1384 | |
| 1385 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1386 | // does not need ip for implicit literal generation. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1387 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1388 | // Load allocation top into result and allocation limit into ip. |
| 1389 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1390 | } else { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1391 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1392 | // Assert that result actually contains top on entry. ip is used |
| 1393 | // immediately below so this use of ip does not cause difference with |
| 1394 | // respect to register content between debug and release mode. |
| 1395 | ldr(ip, MemOperand(topaddr)); |
| 1396 | cmp(result, ip); |
| 1397 | Check(eq, "Unexpected allocation top"); |
| 1398 | } |
| 1399 | // Load allocation limit into ip. Result already contains allocation top. |
| 1400 | ldr(ip, MemOperand(topaddr, limit - top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1401 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1402 | |
| 1403 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1404 | // to calculate the new top. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1405 | add(scratch2, result, Operand(obj_size_reg), SetCC); |
| 1406 | b(cs, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1407 | cmp(scratch2, Operand(ip)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1408 | b(hi, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1409 | str(scratch2, MemOperand(topaddr)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1410 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1411 | // Tag object if requested. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1412 | if ((flags & TAG_OBJECT) != 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1413 | add(result, result, Operand(kHeapObjectTag)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1418 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1419 | Register result, |
| 1420 | Register scratch1, |
| 1421 | Register scratch2, |
| 1422 | Label* gc_required, |
| 1423 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1424 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1425 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1426 | // Trash the registers to simulate an allocation failure. |
| 1427 | mov(result, Operand(0x7091)); |
| 1428 | mov(scratch1, Operand(0x7191)); |
| 1429 | mov(scratch2, Operand(0x7291)); |
| 1430 | } |
| 1431 | jmp(gc_required); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1435 | // Assert that the register arguments are different and that none of |
| 1436 | // 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] | 1437 | ASSERT(!result.is(scratch1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1438 | ASSERT(!result.is(scratch2)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1439 | ASSERT(!scratch1.is(scratch2)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1440 | ASSERT(!result.is(ip)); |
| 1441 | ASSERT(!scratch1.is(ip)); |
| 1442 | ASSERT(!scratch2.is(ip)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1443 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1444 | // Check relative positions of allocation top and limit addresses. |
| 1445 | // The values must be adjacent in memory to allow the use of LDM. |
| 1446 | // Also, assert that the registers are numbered such that the values |
| 1447 | // are loaded in the correct order. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1448 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1449 | ExternalReference::new_space_allocation_top_address(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1450 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1451 | ExternalReference::new_space_allocation_limit_address(isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1452 | intptr_t top = |
| 1453 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1454 | intptr_t limit = |
| 1455 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1456 | ASSERT((limit - top) == kPointerSize); |
| 1457 | ASSERT(result.code() < ip.code()); |
| 1458 | |
| 1459 | // Set up allocation top address. |
| 1460 | Register topaddr = scratch1; |
| 1461 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1462 | |
| 1463 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1464 | // does not need ip for implicit literal generation. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1465 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1466 | // Load allocation top into result and allocation limit into ip. |
| 1467 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1468 | } else { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1469 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1470 | // Assert that result actually contains top on entry. ip is used |
| 1471 | // immediately below so this use of ip does not cause difference with |
| 1472 | // respect to register content between debug and release mode. |
| 1473 | ldr(ip, MemOperand(topaddr)); |
| 1474 | cmp(result, ip); |
| 1475 | Check(eq, "Unexpected allocation top"); |
| 1476 | } |
| 1477 | // Load allocation limit into ip. Result already contains allocation top. |
| 1478 | ldr(ip, MemOperand(topaddr, limit - top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | // 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] | 1482 | // to calculate the new top. Object size may be in words so a shift is |
| 1483 | // required to get the number of bytes. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1484 | if ((flags & SIZE_IN_WORDS) != 0) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1485 | add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1486 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1487 | add(scratch2, result, Operand(object_size), SetCC); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1488 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1489 | b(cs, gc_required); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1490 | cmp(scratch2, Operand(ip)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1491 | b(hi, gc_required); |
| 1492 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1493 | // Update allocation top. result temporarily holds the new top. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1494 | if (emit_debug_code()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1495 | tst(scratch2, Operand(kObjectAlignmentMask)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1496 | Check(eq, "Unaligned allocation in new space"); |
| 1497 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1498 | str(scratch2, MemOperand(topaddr)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1499 | |
| 1500 | // Tag object if requested. |
| 1501 | if ((flags & TAG_OBJECT) != 0) { |
| 1502 | add(result, result, Operand(kHeapObjectTag)); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1508 | Register scratch) { |
| 1509 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1510 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1511 | |
| 1512 | // Make sure the object has no tag before resetting top. |
| 1513 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1514 | #ifdef DEBUG |
| 1515 | // Check that the object un-allocated is below the current top. |
| 1516 | mov(scratch, Operand(new_space_allocation_top)); |
| 1517 | ldr(scratch, MemOperand(scratch)); |
| 1518 | cmp(object, scratch); |
| 1519 | Check(lt, "Undo allocation of non allocated memory"); |
| 1520 | #endif |
| 1521 | // Write the address of the object to un-allocate as the current top. |
| 1522 | mov(scratch, Operand(new_space_allocation_top)); |
| 1523 | str(object, MemOperand(scratch)); |
| 1524 | } |
| 1525 | |
| 1526 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1527 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1528 | Register length, |
| 1529 | Register scratch1, |
| 1530 | Register scratch2, |
| 1531 | Register scratch3, |
| 1532 | Label* gc_required) { |
| 1533 | // Calculate the number of bytes needed for the characters in the string while |
| 1534 | // observing object alignment. |
| 1535 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1536 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1537 | add(scratch1, scratch1, |
| 1538 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1539 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1540 | |
| 1541 | // Allocate two-byte string in new space. |
| 1542 | AllocateInNewSpace(scratch1, |
| 1543 | result, |
| 1544 | scratch2, |
| 1545 | scratch3, |
| 1546 | gc_required, |
| 1547 | TAG_OBJECT); |
| 1548 | |
| 1549 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1550 | InitializeNewString(result, |
| 1551 | length, |
| 1552 | Heap::kStringMapRootIndex, |
| 1553 | scratch1, |
| 1554 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
| 1558 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1559 | Register length, |
| 1560 | Register scratch1, |
| 1561 | Register scratch2, |
| 1562 | Register scratch3, |
| 1563 | Label* gc_required) { |
| 1564 | // Calculate the number of bytes needed for the characters in the string while |
| 1565 | // observing object alignment. |
| 1566 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1567 | ASSERT(kCharSize == 1); |
| 1568 | add(scratch1, length, |
| 1569 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1570 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1571 | |
| 1572 | // Allocate ASCII string in new space. |
| 1573 | AllocateInNewSpace(scratch1, |
| 1574 | result, |
| 1575 | scratch2, |
| 1576 | scratch3, |
| 1577 | gc_required, |
| 1578 | TAG_OBJECT); |
| 1579 | |
| 1580 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1581 | InitializeNewString(result, |
| 1582 | length, |
| 1583 | Heap::kAsciiStringMapRootIndex, |
| 1584 | scratch1, |
| 1585 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1590 | Register length, |
| 1591 | Register scratch1, |
| 1592 | Register scratch2, |
| 1593 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1594 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1595 | result, |
| 1596 | scratch1, |
| 1597 | scratch2, |
| 1598 | gc_required, |
| 1599 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1600 | |
| 1601 | InitializeNewString(result, |
| 1602 | length, |
| 1603 | Heap::kConsStringMapRootIndex, |
| 1604 | scratch1, |
| 1605 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1610 | Register length, |
| 1611 | Register scratch1, |
| 1612 | Register scratch2, |
| 1613 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1614 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1615 | result, |
| 1616 | scratch1, |
| 1617 | scratch2, |
| 1618 | gc_required, |
| 1619 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1620 | |
| 1621 | InitializeNewString(result, |
| 1622 | length, |
| 1623 | Heap::kConsAsciiStringMapRootIndex, |
| 1624 | scratch1, |
| 1625 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1629 | void MacroAssembler::CompareObjectType(Register object, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1630 | Register map, |
| 1631 | Register type_reg, |
| 1632 | InstanceType type) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1633 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1634 | CompareInstanceType(map, type_reg, type); |
| 1635 | } |
| 1636 | |
| 1637 | |
| 1638 | void MacroAssembler::CompareInstanceType(Register map, |
| 1639 | Register type_reg, |
| 1640 | InstanceType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1641 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1642 | cmp(type_reg, Operand(type)); |
| 1643 | } |
| 1644 | |
| 1645 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1646 | void MacroAssembler::CompareRoot(Register obj, |
| 1647 | Heap::RootListIndex index) { |
| 1648 | ASSERT(!obj.is(ip)); |
| 1649 | LoadRoot(ip, index); |
| 1650 | cmp(obj, ip); |
| 1651 | } |
| 1652 | |
| 1653 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1654 | void MacroAssembler::CheckMap(Register obj, |
| 1655 | Register scratch, |
| 1656 | Handle<Map> map, |
| 1657 | Label* fail, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 1658 | SmiCheckType smi_check_type) { |
| 1659 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1660 | JumpIfSmi(obj, fail); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1661 | } |
| 1662 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1663 | mov(ip, Operand(map)); |
| 1664 | cmp(scratch, ip); |
| 1665 | b(ne, fail); |
| 1666 | } |
| 1667 | |
| 1668 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1669 | void MacroAssembler::CheckMap(Register obj, |
| 1670 | Register scratch, |
| 1671 | Heap::RootListIndex index, |
| 1672 | Label* fail, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 1673 | SmiCheckType smi_check_type) { |
| 1674 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1675 | JumpIfSmi(obj, fail); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1676 | } |
| 1677 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1678 | LoadRoot(ip, index); |
| 1679 | cmp(scratch, ip); |
| 1680 | b(ne, fail); |
| 1681 | } |
| 1682 | |
| 1683 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1684 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1685 | Register result, |
| 1686 | Register scratch, |
| 1687 | Label* miss) { |
| 1688 | // Check that the receiver isn't a smi. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1689 | JumpIfSmi(function, miss); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1690 | |
| 1691 | // Check that the function really is a function. Load map into result reg. |
| 1692 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1693 | b(ne, miss); |
| 1694 | |
| 1695 | // Make sure that the function has an instance prototype. |
| 1696 | Label non_instance; |
| 1697 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1698 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1699 | b(ne, &non_instance); |
| 1700 | |
| 1701 | // Get the prototype or initial map from the function. |
| 1702 | ldr(result, |
| 1703 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1704 | |
| 1705 | // If the prototype or initial map is the hole, don't return it and |
| 1706 | // simply miss the cache instead. This will allow us to allocate a |
| 1707 | // prototype object on-demand in the runtime system. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1708 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1709 | cmp(result, ip); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1710 | b(eq, miss); |
| 1711 | |
| 1712 | // If the function does not have an initial map, we're done. |
| 1713 | Label done; |
| 1714 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1715 | b(ne, &done); |
| 1716 | |
| 1717 | // Get the prototype from the initial map. |
| 1718 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1719 | jmp(&done); |
| 1720 | |
| 1721 | // Non-instance prototype: Fetch prototype from constructor field |
| 1722 | // in initial map. |
| 1723 | bind(&non_instance); |
| 1724 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1725 | |
| 1726 | // All done. |
| 1727 | bind(&done); |
| 1728 | } |
| 1729 | |
| 1730 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1731 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1732 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1733 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1737 | MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub, Condition cond) { |
| 1738 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1739 | Object* result; |
| 1740 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1741 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1742 | } |
| 1743 | Call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET, cond); |
| 1744 | return result; |
| 1745 | } |
| 1746 | |
| 1747 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1748 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1749 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1750 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1751 | } |
| 1752 | |
| 1753 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1754 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { |
| 1755 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1756 | Object* result; |
| 1757 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1758 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1759 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1760 | Jump(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET, cond); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1761 | return result; |
| 1762 | } |
| 1763 | |
| 1764 | |
| 1765 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 1766 | return ref0.address() - ref1.address(); |
| 1767 | } |
| 1768 | |
| 1769 | |
| 1770 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1771 | ExternalReference function, int stack_space) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1772 | ExternalReference next_address = |
| 1773 | ExternalReference::handle_scope_next_address(); |
| 1774 | const int kNextOffset = 0; |
| 1775 | const int kLimitOffset = AddressOffset( |
| 1776 | ExternalReference::handle_scope_limit_address(), |
| 1777 | next_address); |
| 1778 | const int kLevelOffset = AddressOffset( |
| 1779 | ExternalReference::handle_scope_level_address(), |
| 1780 | next_address); |
| 1781 | |
| 1782 | // Allocate HandleScope in callee-save registers. |
| 1783 | mov(r7, Operand(next_address)); |
| 1784 | ldr(r4, MemOperand(r7, kNextOffset)); |
| 1785 | ldr(r5, MemOperand(r7, kLimitOffset)); |
| 1786 | ldr(r6, MemOperand(r7, kLevelOffset)); |
| 1787 | add(r6, r6, Operand(1)); |
| 1788 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1789 | |
| 1790 | // Native call returns to the DirectCEntry stub which redirects to the |
| 1791 | // return address pushed on stack (could have moved after GC). |
| 1792 | // DirectCEntry stub itself is generated early and never moves. |
| 1793 | DirectCEntryStub stub; |
| 1794 | stub.GenerateCall(this, function); |
| 1795 | |
| 1796 | Label promote_scheduled_exception; |
| 1797 | Label delete_allocated_handles; |
| 1798 | Label leave_exit_frame; |
| 1799 | |
| 1800 | // If result is non-zero, dereference to get the result value |
| 1801 | // otherwise set it to undefined. |
| 1802 | cmp(r0, Operand(0)); |
| 1803 | LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1804 | ldr(r0, MemOperand(r0), ne); |
| 1805 | |
| 1806 | // No more valid handles (the result handle was the last one). Restore |
| 1807 | // previous handle scope. |
| 1808 | str(r4, MemOperand(r7, kNextOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1809 | if (emit_debug_code()) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1810 | ldr(r1, MemOperand(r7, kLevelOffset)); |
| 1811 | cmp(r1, r6); |
| 1812 | Check(eq, "Unexpected level after return from api call"); |
| 1813 | } |
| 1814 | sub(r6, r6, Operand(1)); |
| 1815 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1816 | ldr(ip, MemOperand(r7, kLimitOffset)); |
| 1817 | cmp(r5, ip); |
| 1818 | b(ne, &delete_allocated_handles); |
| 1819 | |
| 1820 | // Check if the function scheduled an exception. |
| 1821 | bind(&leave_exit_frame); |
| 1822 | LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1823 | mov(ip, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1824 | ldr(r5, MemOperand(ip)); |
| 1825 | cmp(r4, r5); |
| 1826 | b(ne, &promote_scheduled_exception); |
| 1827 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1828 | // LeaveExitFrame expects unwind space to be in a register. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1829 | mov(r4, Operand(stack_space)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1830 | LeaveExitFrame(false, r4); |
| 1831 | mov(pc, lr); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1832 | |
| 1833 | bind(&promote_scheduled_exception); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1834 | MaybeObject* result |
| 1835 | = TryTailCallExternalReference( |
| 1836 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), |
| 1837 | 0, |
| 1838 | 1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1839 | if (result->IsFailure()) { |
| 1840 | return result; |
| 1841 | } |
| 1842 | |
| 1843 | // HandleScope limit has changed. Delete allocated extensions. |
| 1844 | bind(&delete_allocated_handles); |
| 1845 | str(r5, MemOperand(r7, kLimitOffset)); |
| 1846 | mov(r4, r0); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1847 | PrepareCallCFunction(1, r5); |
| 1848 | mov(r0, Operand(ExternalReference::isolate_address())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1849 | CallCFunction( |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1850 | ExternalReference::delete_handle_scope_extensions(isolate()), 1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1851 | mov(r0, r4); |
| 1852 | jmp(&leave_exit_frame); |
| 1853 | |
| 1854 | return result; |
| 1855 | } |
| 1856 | |
| 1857 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1858 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1859 | if (num_arguments > 0) { |
| 1860 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1861 | } |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1862 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1866 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1867 | // If the hash field contains an array index pick it out. The assert checks |
| 1868 | // that the constants for the maximum number of digits for an array index |
| 1869 | // cached in the hash field and the number of bits reserved for it does not |
| 1870 | // conflict. |
| 1871 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1872 | (1 << String::kArrayIndexValueBits)); |
| 1873 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1874 | // the low kHashShift bits. |
| 1875 | STATIC_ASSERT(kSmiTag == 0); |
| 1876 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 1877 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 1878 | } |
| 1879 | |
| 1880 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1881 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 1882 | Register outHighReg, |
| 1883 | Register outLowReg) { |
| 1884 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 1885 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1886 | vmov(s15, r7); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1887 | vcvt_f64_s32(d7, s15); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1888 | vmov(outLowReg, outHighReg, d7); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1892 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 1893 | DwVfpRegister result, |
| 1894 | Register scratch1, |
| 1895 | Register scratch2, |
| 1896 | Register heap_number_map, |
| 1897 | SwVfpRegister scratch3, |
| 1898 | Label* not_number, |
| 1899 | ObjectToDoubleFlags flags) { |
| 1900 | Label done; |
| 1901 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 1902 | Label not_smi; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1903 | JumpIfNotSmi(object, ¬_smi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1904 | // Remove smi tag and convert to double. |
| 1905 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 1906 | vmov(scratch3, scratch1); |
| 1907 | vcvt_f64_s32(result, scratch3); |
| 1908 | b(&done); |
| 1909 | bind(¬_smi); |
| 1910 | } |
| 1911 | // Check for heap number and load double value from it. |
| 1912 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1913 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1914 | cmp(scratch1, heap_number_map); |
| 1915 | b(ne, not_number); |
| 1916 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 1917 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 1918 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1919 | Sbfx(scratch1, |
| 1920 | scratch1, |
| 1921 | HeapNumber::kExponentShift, |
| 1922 | HeapNumber::kExponentBits); |
| 1923 | // All-one value sign extend to -1. |
| 1924 | cmp(scratch1, Operand(-1)); |
| 1925 | b(eq, not_number); |
| 1926 | } |
| 1927 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 1928 | bind(&done); |
| 1929 | } |
| 1930 | |
| 1931 | |
| 1932 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 1933 | DwVfpRegister value, |
| 1934 | Register scratch1, |
| 1935 | SwVfpRegister scratch2) { |
| 1936 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 1937 | vmov(scratch2, scratch1); |
| 1938 | vcvt_f64_s32(value, scratch2); |
| 1939 | } |
| 1940 | |
| 1941 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1942 | // Tries to get a signed int32 out of a double precision floating point heap |
| 1943 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 1944 | // 32bits signed integer range. |
| 1945 | void MacroAssembler::ConvertToInt32(Register source, |
| 1946 | Register dest, |
| 1947 | Register scratch, |
| 1948 | Register scratch2, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1949 | DwVfpRegister double_scratch, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1950 | Label *not_int32) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1951 | if (CpuFeatures::IsSupported(VFP3)) { |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1952 | CpuFeatures::Scope scope(VFP3); |
| 1953 | sub(scratch, source, Operand(kHeapObjectTag)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1954 | vldr(double_scratch, scratch, HeapNumber::kValueOffset); |
| 1955 | vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 1956 | vmov(dest, double_scratch.low()); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1957 | // Signed vcvt instruction will saturate to the minimum (0x80000000) or |
| 1958 | // maximun (0x7fffffff) signed 32bits integer when the double is out of |
| 1959 | // range. When substracting one, the minimum signed integer becomes the |
| 1960 | // maximun signed integer. |
| 1961 | sub(scratch, dest, Operand(1)); |
| 1962 | cmp(scratch, Operand(LONG_MAX - 1)); |
| 1963 | // If equal then dest was LONG_MAX, if greater dest was LONG_MIN. |
| 1964 | b(ge, not_int32); |
| 1965 | } else { |
| 1966 | // This code is faster for doubles that are in the ranges -0x7fffffff to |
| 1967 | // -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to |
| 1968 | // the range of signed int32 values that are not Smis. Jumps to the label |
| 1969 | // 'not_int32' if the double isn't in the range -0x80000000.0 to |
| 1970 | // 0x80000000.0 (excluding the endpoints). |
| 1971 | Label right_exponent, done; |
| 1972 | // Get exponent word. |
| 1973 | ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 1974 | // Get exponent alone in scratch2. |
| 1975 | Ubfx(scratch2, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1976 | scratch, |
| 1977 | HeapNumber::kExponentShift, |
| 1978 | HeapNumber::kExponentBits); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1979 | // Load dest with zero. We use this either for the final shift or |
| 1980 | // for the answer. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1981 | mov(dest, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1982 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 1983 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 1984 | // the exponent that we are fastest at and also the highest exponent we can |
| 1985 | // handle here. |
| 1986 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 1987 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 1988 | // split it up to avoid a constant pool entry. You can't do that in general |
| 1989 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 1990 | // range 0-2047 so there is no overflow. |
| 1991 | int fudge_factor = 0x400; |
| 1992 | sub(scratch2, scratch2, Operand(fudge_factor)); |
| 1993 | cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
| 1994 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 1995 | // logic. |
| 1996 | b(eq, &right_exponent); |
| 1997 | // If the exponent is higher than that then go to slow case. This catches |
| 1998 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 1999 | b(gt, not_int32); |
| 2000 | |
| 2001 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 2002 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 2003 | // it rounds to zero. |
| 2004 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 2005 | sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
| 2006 | // Dest already has a Smi zero. |
| 2007 | b(lt, &done); |
| 2008 | |
| 2009 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 2010 | // get how much to shift down. |
| 2011 | rsb(dest, scratch2, Operand(30)); |
| 2012 | |
| 2013 | bind(&right_exponent); |
| 2014 | // Get the top bits of the mantissa. |
| 2015 | and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 2016 | // Put back the implicit 1. |
| 2017 | orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 2018 | // Shift up the mantissa bits to take up the space the exponent used to |
| 2019 | // take. We just orred in the implicit bit so that took care of one and |
| 2020 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 2021 | // distance. |
| 2022 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 2023 | mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 2024 | // Put sign in zero flag. |
| 2025 | tst(scratch, Operand(HeapNumber::kSignMask)); |
| 2026 | // Get the second half of the double. For some exponents we don't |
| 2027 | // actually need this because the bits get shifted out again, but |
| 2028 | // it's probably slower to test than just to do it. |
| 2029 | ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 2030 | // Shift down 22 bits to get the last 10 bits. |
| 2031 | orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 2032 | // Move down according to the exponent. |
| 2033 | mov(dest, Operand(scratch, LSR, dest)); |
| 2034 | // Fix sign if sign bit was set. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2035 | rsb(dest, dest, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 2036 | bind(&done); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2041 | void MacroAssembler::EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 2042 | SwVfpRegister result, |
| 2043 | DwVfpRegister double_input, |
| 2044 | Register scratch1, |
| 2045 | Register scratch2, |
| 2046 | CheckForInexactConversion check_inexact) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2047 | ASSERT(CpuFeatures::IsSupported(VFP3)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2048 | CpuFeatures::Scope scope(VFP3); |
| 2049 | Register prev_fpscr = scratch1; |
| 2050 | Register scratch = scratch2; |
| 2051 | |
| 2052 | int32_t check_inexact_conversion = |
| 2053 | (check_inexact == kCheckForInexactConversion) ? kVFPInexactExceptionBit : 0; |
| 2054 | |
| 2055 | // Set custom FPCSR: |
| 2056 | // - Set rounding mode. |
| 2057 | // - Clear vfp cumulative exception flags. |
| 2058 | // - Make sure Flush-to-zero mode control bit is unset. |
| 2059 | vmrs(prev_fpscr); |
| 2060 | bic(scratch, |
| 2061 | prev_fpscr, |
| 2062 | Operand(kVFPExceptionMask | |
| 2063 | check_inexact_conversion | |
| 2064 | kVFPRoundingModeMask | |
| 2065 | kVFPFlushToZeroMask)); |
| 2066 | // 'Round To Nearest' is encoded by 0b00 so no bits need to be set. |
| 2067 | if (rounding_mode != kRoundToNearest) { |
| 2068 | orr(scratch, scratch, Operand(rounding_mode)); |
| 2069 | } |
| 2070 | vmsr(scratch); |
| 2071 | |
| 2072 | // Convert the argument to an integer. |
| 2073 | vcvt_s32_f64(result, |
| 2074 | double_input, |
| 2075 | (rounding_mode == kRoundToZero) ? kDefaultRoundToZero |
| 2076 | : kFPSCRRounding); |
| 2077 | |
| 2078 | // Retrieve FPSCR. |
| 2079 | vmrs(scratch); |
| 2080 | // Restore FPSCR. |
| 2081 | vmsr(prev_fpscr); |
| 2082 | // Check for vfp exceptions. |
| 2083 | tst(scratch, Operand(kVFPExceptionMask | check_inexact_conversion)); |
| 2084 | } |
| 2085 | |
| 2086 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2087 | void MacroAssembler::EmitOutOfInt32RangeTruncate(Register result, |
| 2088 | Register input_high, |
| 2089 | Register input_low, |
| 2090 | Register scratch) { |
| 2091 | Label done, normal_exponent, restore_sign; |
| 2092 | |
| 2093 | // Extract the biased exponent in result. |
| 2094 | Ubfx(result, |
| 2095 | input_high, |
| 2096 | HeapNumber::kExponentShift, |
| 2097 | HeapNumber::kExponentBits); |
| 2098 | |
| 2099 | // Check for Infinity and NaNs, which should return 0. |
| 2100 | cmp(result, Operand(HeapNumber::kExponentMask)); |
| 2101 | mov(result, Operand(0), LeaveCC, eq); |
| 2102 | b(eq, &done); |
| 2103 | |
| 2104 | // Express exponent as delta to (number of mantissa bits + 31). |
| 2105 | sub(result, |
| 2106 | result, |
| 2107 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31), |
| 2108 | SetCC); |
| 2109 | |
| 2110 | // If the delta is strictly positive, all bits would be shifted away, |
| 2111 | // which means that we can return 0. |
| 2112 | b(le, &normal_exponent); |
| 2113 | mov(result, Operand(0)); |
| 2114 | b(&done); |
| 2115 | |
| 2116 | bind(&normal_exponent); |
| 2117 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 2118 | // Calculate shift. |
| 2119 | add(scratch, result, Operand(kShiftBase + HeapNumber::kMantissaBits), SetCC); |
| 2120 | |
| 2121 | // Save the sign. |
| 2122 | Register sign = result; |
| 2123 | result = no_reg; |
| 2124 | and_(sign, input_high, Operand(HeapNumber::kSignMask)); |
| 2125 | |
| 2126 | // Set the implicit 1 before the mantissa part in input_high. |
| 2127 | orr(input_high, |
| 2128 | input_high, |
| 2129 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 2130 | // Shift the mantissa bits to the correct position. |
| 2131 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 2132 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 2133 | mov(input_high, Operand(input_high, LSL, scratch)); |
| 2134 | |
| 2135 | // Replace the shifted bits with bits from the lower mantissa word. |
| 2136 | Label pos_shift, shift_done; |
| 2137 | rsb(scratch, scratch, Operand(32), SetCC); |
| 2138 | b(&pos_shift, ge); |
| 2139 | |
| 2140 | // Negate scratch. |
| 2141 | rsb(scratch, scratch, Operand(0)); |
| 2142 | mov(input_low, Operand(input_low, LSL, scratch)); |
| 2143 | b(&shift_done); |
| 2144 | |
| 2145 | bind(&pos_shift); |
| 2146 | mov(input_low, Operand(input_low, LSR, scratch)); |
| 2147 | |
| 2148 | bind(&shift_done); |
| 2149 | orr(input_high, input_high, Operand(input_low)); |
| 2150 | // Restore sign if necessary. |
| 2151 | cmp(sign, Operand(0)); |
| 2152 | result = sign; |
| 2153 | sign = no_reg; |
| 2154 | rsb(result, input_high, Operand(0), LeaveCC, ne); |
| 2155 | mov(result, input_high, LeaveCC, eq); |
| 2156 | bind(&done); |
| 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | void MacroAssembler::EmitECMATruncate(Register result, |
| 2161 | DwVfpRegister double_input, |
| 2162 | SwVfpRegister single_scratch, |
| 2163 | Register scratch, |
| 2164 | Register input_high, |
| 2165 | Register input_low) { |
| 2166 | CpuFeatures::Scope scope(VFP3); |
| 2167 | ASSERT(!input_high.is(result)); |
| 2168 | ASSERT(!input_low.is(result)); |
| 2169 | ASSERT(!input_low.is(input_high)); |
| 2170 | ASSERT(!scratch.is(result) && |
| 2171 | !scratch.is(input_high) && |
| 2172 | !scratch.is(input_low)); |
| 2173 | ASSERT(!single_scratch.is(double_input.low()) && |
| 2174 | !single_scratch.is(double_input.high())); |
| 2175 | |
| 2176 | Label done; |
| 2177 | |
| 2178 | // Clear cumulative exception flags. |
| 2179 | ClearFPSCRBits(kVFPExceptionMask, scratch); |
| 2180 | // Try a conversion to a signed integer. |
| 2181 | vcvt_s32_f64(single_scratch, double_input); |
| 2182 | vmov(result, single_scratch); |
| 2183 | // Retrieve he FPSCR. |
| 2184 | vmrs(scratch); |
| 2185 | // Check for overflow and NaNs. |
| 2186 | tst(scratch, Operand(kVFPOverflowExceptionBit | |
| 2187 | kVFPUnderflowExceptionBit | |
| 2188 | kVFPInvalidOpExceptionBit)); |
| 2189 | // If we had no exceptions we are done. |
| 2190 | b(eq, &done); |
| 2191 | |
| 2192 | // Load the double value and perform a manual truncation. |
| 2193 | vmov(input_low, input_high, double_input); |
| 2194 | EmitOutOfInt32RangeTruncate(result, |
| 2195 | input_high, |
| 2196 | input_low, |
| 2197 | scratch); |
| 2198 | bind(&done); |
| 2199 | } |
| 2200 | |
| 2201 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2202 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 2203 | Register src, |
| 2204 | int num_least_bits) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2205 | if (CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2206 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2207 | } else { |
| 2208 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 2209 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2214 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 2215 | Register src, |
| 2216 | int num_least_bits) { |
| 2217 | and_(dst, src, Operand((1 << num_least_bits) - 1)); |
| 2218 | } |
| 2219 | |
| 2220 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2221 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 2222 | int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2223 | // 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] | 2224 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2225 | // If the expected number of arguments of the runtime function is |
| 2226 | // constant, we check that the actual number of arguments match the |
| 2227 | // expectation. |
| 2228 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 2229 | IllegalOperation(num_arguments); |
| 2230 | return; |
| 2231 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2232 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2233 | // TODO(1236192): Most runtime routines don't need the number of |
| 2234 | // arguments passed in because it is constant. At some point we |
| 2235 | // should remove this need and make the runtime routine entry code |
| 2236 | // smarter. |
| 2237 | mov(r0, Operand(num_arguments)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2238 | mov(r1, Operand(ExternalReference(f, isolate()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2239 | CEntryStub stub(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2240 | CallStub(&stub); |
| 2241 | } |
| 2242 | |
| 2243 | |
| 2244 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 2245 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 2246 | } |
| 2247 | |
| 2248 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2249 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2250 | const Runtime::Function* function = Runtime::FunctionForId(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | mov(r0, Operand(function->nargs)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2252 | mov(r1, Operand(ExternalReference(function, isolate()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2253 | CEntryStub stub(1); |
| 2254 | stub.SaveDoubles(); |
| 2255 | CallStub(&stub); |
| 2256 | } |
| 2257 | |
| 2258 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2259 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 2260 | int num_arguments) { |
| 2261 | mov(r0, Operand(num_arguments)); |
| 2262 | mov(r1, Operand(ext)); |
| 2263 | |
| 2264 | CEntryStub stub(1); |
| 2265 | CallStub(&stub); |
| 2266 | } |
| 2267 | |
| 2268 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2269 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2270 | int num_arguments, |
| 2271 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2272 | // TODO(1236192): Most runtime routines don't need the number of |
| 2273 | // arguments passed in because it is constant. At some point we |
| 2274 | // should remove this need and make the runtime routine entry code |
| 2275 | // smarter. |
| 2276 | mov(r0, Operand(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2277 | JumpToExternalReference(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2281 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 2282 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 2283 | // TODO(1236192): Most runtime routines don't need the number of |
| 2284 | // arguments passed in because it is constant. At some point we |
| 2285 | // should remove this need and make the runtime routine entry code |
| 2286 | // smarter. |
| 2287 | mov(r0, Operand(num_arguments)); |
| 2288 | return TryJumpToExternalReference(ext); |
| 2289 | } |
| 2290 | |
| 2291 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2292 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 2293 | int num_arguments, |
| 2294 | int result_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2295 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 2296 | num_arguments, |
| 2297 | result_size); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2302 | #if defined(__thumb__) |
| 2303 | // Thumb mode builtin. |
| 2304 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2305 | #endif |
| 2306 | mov(r1, Operand(builtin)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 2307 | CEntryStub stub(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2308 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2312 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 2313 | const ExternalReference& builtin) { |
| 2314 | #if defined(__thumb__) |
| 2315 | // Thumb mode builtin. |
| 2316 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 2317 | #endif |
| 2318 | mov(r1, Operand(builtin)); |
| 2319 | CEntryStub stub(1); |
| 2320 | return TryTailCallStub(&stub); |
| 2321 | } |
| 2322 | |
| 2323 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2324 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2325 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2326 | const CallWrapper& call_wrapper) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2327 | GetBuiltinEntry(r2, id); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2328 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2329 | call_wrapper.BeforeCall(CallSize(r2)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2330 | Call(r2); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2331 | call_wrapper.AfterCall(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2332 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2333 | ASSERT(flag == JUMP_FUNCTION); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2334 | Jump(r2); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2339 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2340 | Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2341 | // Load the builtins object into target register. |
| 2342 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2343 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2344 | // Load the JavaScript builtin function from the builtins object. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2345 | ldr(target, FieldMemOperand(target, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2346 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2347 | } |
| 2348 | |
| 2349 | |
| 2350 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 2351 | ASSERT(!target.is(r1)); |
| 2352 | GetBuiltinFunction(r1, id); |
| 2353 | // Load the code entry point from the builtins object. |
| 2354 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2358 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 2359 | Register scratch1, Register scratch2) { |
| 2360 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2361 | mov(scratch1, Operand(value)); |
| 2362 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2363 | str(scratch1, MemOperand(scratch2)); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | |
| 2368 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 2369 | Register scratch1, Register scratch2) { |
| 2370 | ASSERT(value > 0); |
| 2371 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2372 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2373 | ldr(scratch1, MemOperand(scratch2)); |
| 2374 | add(scratch1, scratch1, Operand(value)); |
| 2375 | str(scratch1, MemOperand(scratch2)); |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | |
| 2380 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 2381 | Register scratch1, Register scratch2) { |
| 2382 | ASSERT(value > 0); |
| 2383 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2384 | mov(scratch2, Operand(ExternalReference(counter))); |
| 2385 | ldr(scratch1, MemOperand(scratch2)); |
| 2386 | sub(scratch1, scratch1, Operand(value)); |
| 2387 | str(scratch1, MemOperand(scratch2)); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2392 | void MacroAssembler::Assert(Condition cond, const char* msg) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2393 | if (emit_debug_code()) |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2394 | Check(cond, msg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2398 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 2399 | Heap::RootListIndex index) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2400 | if (emit_debug_code()) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2401 | LoadRoot(ip, index); |
| 2402 | cmp(reg, ip); |
| 2403 | Check(eq, "Register did not match expected root"); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2408 | void MacroAssembler::AssertFastElements(Register elements) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2409 | if (emit_debug_code()) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2410 | ASSERT(!elements.is(ip)); |
| 2411 | Label ok; |
| 2412 | push(elements); |
| 2413 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 2414 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 2415 | cmp(elements, ip); |
| 2416 | b(eq, &ok); |
| 2417 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 2418 | cmp(elements, ip); |
| 2419 | b(eq, &ok); |
| 2420 | Abort("JSObject with fast elements map has slow elements"); |
| 2421 | bind(&ok); |
| 2422 | pop(elements); |
| 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2427 | void MacroAssembler::Check(Condition cond, const char* msg) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2428 | Label L; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2429 | b(cond, &L); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2430 | Abort(msg); |
| 2431 | // will not return here |
| 2432 | bind(&L); |
| 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | void MacroAssembler::Abort(const char* msg) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2437 | Label abort_start; |
| 2438 | bind(&abort_start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2439 | // We want to pass the msg string like a smi to avoid GC |
| 2440 | // problems, however msg is not guaranteed to be aligned |
| 2441 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2442 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2443 | // from the real pointer as a smi. |
| 2444 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2445 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2446 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2447 | #ifdef DEBUG |
| 2448 | if (msg != NULL) { |
| 2449 | RecordComment("Abort message: "); |
| 2450 | RecordComment(msg); |
| 2451 | } |
| 2452 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2453 | // Disable stub call restrictions to always allow calls to abort. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2454 | AllowStubCallsScope allow_scope(this, true); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2455 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2456 | mov(r0, Operand(p0)); |
| 2457 | push(r0); |
| 2458 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2459 | push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | CallRuntime(Runtime::kAbort, 2); |
| 2461 | // will not return here |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2462 | if (is_const_pool_blocked()) { |
| 2463 | // If the calling code cares about the exact number of |
| 2464 | // instructions generated, we insert padding here to keep the size |
| 2465 | // of the Abort macro constant. |
| 2466 | static const int kExpectedAbortInstructions = 10; |
| 2467 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 2468 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 2469 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 2470 | nop(); |
| 2471 | } |
| 2472 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2475 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2476 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2477 | if (context_chain_length > 0) { |
| 2478 | // Move up the chain of contexts to the context containing the slot. |
| 2479 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2480 | // Load the function context (which is the incoming, outer context). |
| 2481 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2482 | for (int i = 1; i < context_chain_length; i++) { |
| 2483 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2484 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2485 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2486 | } else { |
| 2487 | // Slot is in the current function context. Move it into the |
| 2488 | // destination register in case we store into it (the write barrier |
| 2489 | // cannot be allowed to destroy the context in esi). |
| 2490 | mov(dst, cp); |
| 2491 | } |
| 2492 | |
| 2493 | // We should not have found a 'with' context by walking the context chain |
| 2494 | // (i.e., the static scope chain and runtime context chain do not agree). |
| 2495 | // A variable occurring in such a scope should have slot type LOOKUP and |
| 2496 | // not CONTEXT. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2497 | if (emit_debug_code()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2498 | ldr(ip, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2499 | cmp(dst, ip); |
| 2500 | Check(eq, "Yo dawg, I heard you liked function contexts " |
| 2501 | "so I put function contexts in all your contexts"); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2506 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2507 | // Load the global or builtins object from the current context. |
| 2508 | ldr(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2509 | // Load the global context from the global or builtins object. |
| 2510 | ldr(function, FieldMemOperand(function, |
| 2511 | GlobalObject::kGlobalContextOffset)); |
| 2512 | // Load the function from the global context. |
| 2513 | ldr(function, MemOperand(function, Context::SlotOffset(index))); |
| 2514 | } |
| 2515 | |
| 2516 | |
| 2517 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2518 | Register map, |
| 2519 | Register scratch) { |
| 2520 | // Load the initial map. The global functions all have initial maps. |
| 2521 | ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2522 | if (emit_debug_code()) { |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2523 | Label ok, fail; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 2524 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2525 | b(&ok); |
| 2526 | bind(&fail); |
| 2527 | Abort("Global functions must have initial map"); |
| 2528 | bind(&ok); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2533 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2534 | Register reg, |
| 2535 | Register scratch, |
| 2536 | Label* not_power_of_two_or_zero) { |
| 2537 | sub(scratch, reg, Operand(1), SetCC); |
| 2538 | b(mi, not_power_of_two_or_zero); |
| 2539 | tst(scratch, reg); |
| 2540 | b(ne, not_power_of_two_or_zero); |
| 2541 | } |
| 2542 | |
| 2543 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2544 | void MacroAssembler::JumpIfNotPowerOfTwoOrZeroAndNeg( |
| 2545 | Register reg, |
| 2546 | Register scratch, |
| 2547 | Label* zero_and_neg, |
| 2548 | Label* not_power_of_two) { |
| 2549 | sub(scratch, reg, Operand(1), SetCC); |
| 2550 | b(mi, zero_and_neg); |
| 2551 | tst(scratch, reg); |
| 2552 | b(ne, not_power_of_two); |
| 2553 | } |
| 2554 | |
| 2555 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2556 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 2557 | Register reg2, |
| 2558 | Label* on_not_both_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2559 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2560 | tst(reg1, Operand(kSmiTagMask)); |
| 2561 | tst(reg2, Operand(kSmiTagMask), eq); |
| 2562 | b(ne, on_not_both_smi); |
| 2563 | } |
| 2564 | |
| 2565 | |
| 2566 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 2567 | Register reg2, |
| 2568 | Label* on_either_smi) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2569 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2570 | tst(reg1, Operand(kSmiTagMask)); |
| 2571 | tst(reg2, Operand(kSmiTagMask), ne); |
| 2572 | b(eq, on_either_smi); |
| 2573 | } |
| 2574 | |
| 2575 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2576 | void MacroAssembler::AbortIfSmi(Register object) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2577 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2578 | tst(object, Operand(kSmiTagMask)); |
| 2579 | Assert(ne, "Operand is a smi"); |
| 2580 | } |
| 2581 | |
| 2582 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2583 | void MacroAssembler::AbortIfNotSmi(Register object) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2584 | STATIC_ASSERT(kSmiTag == 0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2585 | tst(object, Operand(kSmiTagMask)); |
| 2586 | Assert(eq, "Operand is not smi"); |
| 2587 | } |
| 2588 | |
| 2589 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2590 | void MacroAssembler::AbortIfNotString(Register object) { |
| 2591 | STATIC_ASSERT(kSmiTag == 0); |
| 2592 | tst(object, Operand(kSmiTagMask)); |
| 2593 | Assert(ne, "Operand is not a string"); |
| 2594 | push(object); |
| 2595 | ldr(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2596 | CompareInstanceType(object, object, FIRST_NONSTRING_TYPE); |
| 2597 | pop(object); |
| 2598 | Assert(lo, "Operand is not a string"); |
| 2599 | } |
| 2600 | |
| 2601 | |
| 2602 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2603 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 2604 | Heap::RootListIndex root_value_index, |
| 2605 | const char* message) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2606 | CompareRoot(src, root_value_index); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2607 | Assert(eq, message); |
| 2608 | } |
| 2609 | |
| 2610 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2611 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 2612 | Register heap_number_map, |
| 2613 | Register scratch, |
| 2614 | Label* on_not_heap_number) { |
| 2615 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2616 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2617 | cmp(scratch, heap_number_map); |
| 2618 | b(ne, on_not_heap_number); |
| 2619 | } |
| 2620 | |
| 2621 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2622 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 2623 | Register first, |
| 2624 | Register second, |
| 2625 | Register scratch1, |
| 2626 | Register scratch2, |
| 2627 | Label* failure) { |
| 2628 | // Test that both first and second are sequential ASCII strings. |
| 2629 | // Assume that they are non-smis. |
| 2630 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 2631 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 2632 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2633 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2634 | |
| 2635 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 2636 | scratch2, |
| 2637 | scratch1, |
| 2638 | scratch2, |
| 2639 | failure); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 2643 | Register second, |
| 2644 | Register scratch1, |
| 2645 | Register scratch2, |
| 2646 | Label* failure) { |
| 2647 | // Check that neither is a smi. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2648 | STATIC_ASSERT(kSmiTag == 0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2649 | and_(scratch1, first, Operand(second)); |
| 2650 | tst(scratch1, Operand(kSmiTagMask)); |
| 2651 | b(eq, failure); |
| 2652 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 2653 | second, |
| 2654 | scratch1, |
| 2655 | scratch2, |
| 2656 | failure); |
| 2657 | } |
| 2658 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2659 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2660 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 2661 | // is full and a scavenge is needed. |
| 2662 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 2663 | Register scratch1, |
| 2664 | Register scratch2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2665 | Register heap_number_map, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2666 | Label* gc_required) { |
| 2667 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 2668 | // object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2669 | AllocateInNewSpace(HeapNumber::kSize, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2670 | result, |
| 2671 | scratch1, |
| 2672 | scratch2, |
| 2673 | gc_required, |
| 2674 | TAG_OBJECT); |
| 2675 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2676 | // Store heap number map in the allocated object. |
| 2677 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2678 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2682 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 2683 | DwVfpRegister value, |
| 2684 | Register scratch1, |
| 2685 | Register scratch2, |
| 2686 | Register heap_number_map, |
| 2687 | Label* gc_required) { |
| 2688 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 2689 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 2690 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 2691 | } |
| 2692 | |
| 2693 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2694 | // Copies a fixed number of fields of heap objects from src to dst. |
| 2695 | void MacroAssembler::CopyFields(Register dst, |
| 2696 | Register src, |
| 2697 | RegList temps, |
| 2698 | int field_count) { |
| 2699 | // At least one bit set in the first 15 registers. |
| 2700 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 2701 | ASSERT((temps & dst.bit()) == 0); |
| 2702 | ASSERT((temps & src.bit()) == 0); |
| 2703 | // Primitive implementation using only one temporary register. |
| 2704 | |
| 2705 | Register tmp = no_reg; |
| 2706 | // Find a temp register in temps list. |
| 2707 | for (int i = 0; i < 15; i++) { |
| 2708 | if ((temps & (1 << i)) != 0) { |
| 2709 | tmp.set_code(i); |
| 2710 | break; |
| 2711 | } |
| 2712 | } |
| 2713 | ASSERT(!tmp.is(no_reg)); |
| 2714 | |
| 2715 | for (int i = 0; i < field_count; i++) { |
| 2716 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 2717 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2722 | void MacroAssembler::CopyBytes(Register src, |
| 2723 | Register dst, |
| 2724 | Register length, |
| 2725 | Register scratch) { |
| 2726 | Label align_loop, align_loop_1, word_loop, byte_loop, byte_loop_1, done; |
| 2727 | |
| 2728 | // Align src before copying in word size chunks. |
| 2729 | bind(&align_loop); |
| 2730 | cmp(length, Operand(0)); |
| 2731 | b(eq, &done); |
| 2732 | bind(&align_loop_1); |
| 2733 | tst(src, Operand(kPointerSize - 1)); |
| 2734 | b(eq, &word_loop); |
| 2735 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2736 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2737 | sub(length, length, Operand(1), SetCC); |
| 2738 | b(ne, &byte_loop_1); |
| 2739 | |
| 2740 | // Copy bytes in word size chunks. |
| 2741 | bind(&word_loop); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2742 | if (emit_debug_code()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2743 | tst(src, Operand(kPointerSize - 1)); |
| 2744 | Assert(eq, "Expecting alignment for CopyBytes"); |
| 2745 | } |
| 2746 | cmp(length, Operand(kPointerSize)); |
| 2747 | b(lt, &byte_loop); |
| 2748 | ldr(scratch, MemOperand(src, kPointerSize, PostIndex)); |
| 2749 | #if CAN_USE_UNALIGNED_ACCESSES |
| 2750 | str(scratch, MemOperand(dst, kPointerSize, PostIndex)); |
| 2751 | #else |
| 2752 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2753 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2754 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2755 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2756 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2757 | mov(scratch, Operand(scratch, LSR, 8)); |
| 2758 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2759 | #endif |
| 2760 | sub(length, length, Operand(kPointerSize)); |
| 2761 | b(&word_loop); |
| 2762 | |
| 2763 | // Copy the last bytes if any left. |
| 2764 | bind(&byte_loop); |
| 2765 | cmp(length, Operand(0)); |
| 2766 | b(eq, &done); |
| 2767 | bind(&byte_loop_1); |
| 2768 | ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 2769 | strb(scratch, MemOperand(dst, 1, PostIndex)); |
| 2770 | sub(length, length, Operand(1), SetCC); |
| 2771 | b(ne, &byte_loop_1); |
| 2772 | bind(&done); |
| 2773 | } |
| 2774 | |
| 2775 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2776 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 2777 | Register source, // Input. |
| 2778 | Register scratch) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2779 | ASSERT(!zeros.is(source) || !source.is(scratch)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2780 | ASSERT(!zeros.is(scratch)); |
| 2781 | ASSERT(!scratch.is(ip)); |
| 2782 | ASSERT(!source.is(ip)); |
| 2783 | ASSERT(!zeros.is(ip)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2784 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 2785 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 2786 | #else |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2787 | mov(zeros, Operand(0, RelocInfo::NONE)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 2788 | Move(scratch, source); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2789 | // Top 16. |
| 2790 | tst(scratch, Operand(0xffff0000)); |
| 2791 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 2792 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 2793 | // Top 8. |
| 2794 | tst(scratch, Operand(0xff000000)); |
| 2795 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 2796 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 2797 | // Top 4. |
| 2798 | tst(scratch, Operand(0xf0000000)); |
| 2799 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 2800 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 2801 | // Top 2. |
| 2802 | tst(scratch, Operand(0xc0000000)); |
| 2803 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 2804 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 2805 | // Top bit. |
| 2806 | tst(scratch, Operand(0x80000000u)); |
| 2807 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 2808 | #endif |
| 2809 | } |
| 2810 | |
| 2811 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2812 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 2813 | Register first, |
| 2814 | Register second, |
| 2815 | Register scratch1, |
| 2816 | Register scratch2, |
| 2817 | Label* failure) { |
| 2818 | int kFlatAsciiStringMask = |
| 2819 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2820 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2821 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 2822 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 2823 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 2824 | // Ignore second test if first test failed. |
| 2825 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 2826 | b(ne, failure); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 2831 | Register scratch, |
| 2832 | Label* failure) { |
| 2833 | int kFlatAsciiStringMask = |
| 2834 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2835 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2836 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 2837 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 2838 | b(ne, failure); |
| 2839 | } |
| 2840 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2841 | static const int kRegisterPassedArguments = 4; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2842 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2843 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2844 | int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments, |
| 2845 | int num_double_arguments) { |
| 2846 | int stack_passed_words = 0; |
| 2847 | if (use_eabi_hardfloat()) { |
| 2848 | // In the hard floating point calling convention, we can use |
| 2849 | // all double registers to pass doubles. |
| 2850 | if (num_double_arguments > DoubleRegister::kNumRegisters) { |
| 2851 | stack_passed_words += |
| 2852 | 2 * (num_double_arguments - DoubleRegister::kNumRegisters); |
| 2853 | } |
| 2854 | } else { |
| 2855 | // In the soft floating point calling convention, every double |
| 2856 | // argument is passed using two registers. |
| 2857 | num_reg_arguments += 2 * num_double_arguments; |
| 2858 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2859 | // Up to four simple arguments are passed in registers r0..r3. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2860 | if (num_reg_arguments > kRegisterPassedArguments) { |
| 2861 | stack_passed_words += num_reg_arguments - kRegisterPassedArguments; |
| 2862 | } |
| 2863 | return stack_passed_words; |
| 2864 | } |
| 2865 | |
| 2866 | |
| 2867 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 2868 | int num_double_arguments, |
| 2869 | Register scratch) { |
| 2870 | int frame_alignment = ActivationFrameAlignment(); |
| 2871 | int stack_passed_arguments = CalculateStackPassedWords( |
| 2872 | num_reg_arguments, num_double_arguments); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2873 | if (frame_alignment > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2874 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 2875 | // and the original value of sp. |
| 2876 | mov(scratch, sp); |
| 2877 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2878 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2879 | and_(sp, sp, Operand(-frame_alignment)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2880 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2881 | } else { |
| 2882 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2887 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 2888 | Register scratch) { |
| 2889 | PrepareCallCFunction(num_reg_arguments, 0, scratch); |
| 2890 | } |
| 2891 | |
| 2892 | |
| 2893 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg) { |
| 2894 | if (use_eabi_hardfloat()) { |
| 2895 | Move(d0, dreg); |
| 2896 | } else { |
| 2897 | vmov(r0, r1, dreg); |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | |
| 2902 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg1, |
| 2903 | DoubleRegister dreg2) { |
| 2904 | if (use_eabi_hardfloat()) { |
| 2905 | if (dreg2.is(d0)) { |
| 2906 | ASSERT(!dreg1.is(d1)); |
| 2907 | Move(d1, dreg2); |
| 2908 | Move(d0, dreg1); |
| 2909 | } else { |
| 2910 | Move(d0, dreg1); |
| 2911 | Move(d1, dreg2); |
| 2912 | } |
| 2913 | } else { |
| 2914 | vmov(r0, r1, dreg1); |
| 2915 | vmov(r2, r3, dreg2); |
| 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | |
| 2920 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg, |
| 2921 | Register reg) { |
| 2922 | if (use_eabi_hardfloat()) { |
| 2923 | Move(d0, dreg); |
| 2924 | Move(r0, reg); |
| 2925 | } else { |
| 2926 | Move(r2, reg); |
| 2927 | vmov(r0, r1, dreg); |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | |
| 2932 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2933 | int num_reg_arguments, |
| 2934 | int num_double_arguments) { |
| 2935 | CallCFunctionHelper(no_reg, |
| 2936 | function, |
| 2937 | ip, |
| 2938 | num_reg_arguments, |
| 2939 | num_double_arguments); |
| 2940 | } |
| 2941 | |
| 2942 | |
| 2943 | void MacroAssembler::CallCFunction(Register function, |
| 2944 | Register scratch, |
| 2945 | int num_reg_arguments, |
| 2946 | int num_double_arguments) { |
| 2947 | CallCFunctionHelper(function, |
| 2948 | ExternalReference::the_hole_value_location(isolate()), |
| 2949 | scratch, |
| 2950 | num_reg_arguments, |
| 2951 | num_double_arguments); |
| 2952 | } |
| 2953 | |
| 2954 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2955 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2956 | int num_arguments) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2957 | CallCFunction(function, num_arguments, 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2960 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2961 | void MacroAssembler::CallCFunction(Register function, |
| 2962 | Register scratch, |
| 2963 | int num_arguments) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2964 | CallCFunction(function, scratch, num_arguments, 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2968 | void MacroAssembler::CallCFunctionHelper(Register function, |
| 2969 | ExternalReference function_reference, |
| 2970 | Register scratch, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2971 | int num_reg_arguments, |
| 2972 | int num_double_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2973 | // Make sure that the stack is aligned before calling a C function unless |
| 2974 | // running in the simulator. The simulator has its own alignment check which |
| 2975 | // provides more information. |
| 2976 | #if defined(V8_HOST_ARCH_ARM) |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2977 | if (emit_debug_code()) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2978 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2979 | int frame_alignment_mask = frame_alignment - 1; |
| 2980 | if (frame_alignment > kPointerSize) { |
| 2981 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2982 | Label alignment_as_expected; |
| 2983 | tst(sp, Operand(frame_alignment_mask)); |
| 2984 | b(eq, &alignment_as_expected); |
| 2985 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 2986 | // re-entering here. |
| 2987 | stop("Unexpected alignment"); |
| 2988 | bind(&alignment_as_expected); |
| 2989 | } |
| 2990 | } |
| 2991 | #endif |
| 2992 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2993 | // Just call directly. The function called cannot cause a GC, or |
| 2994 | // allow preemption, so the return address in the link register |
| 2995 | // stays correct. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2996 | if (function.is(no_reg)) { |
| 2997 | mov(scratch, Operand(function_reference)); |
| 2998 | function = scratch; |
| 2999 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3000 | Call(function); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3001 | int stack_passed_arguments = CalculateStackPassedWords( |
| 3002 | num_reg_arguments, num_double_arguments); |
ricow@chromium.org | dcebac0 | 2011-04-20 09:44:50 +0000 | [diff] [blame] | 3003 | if (ActivationFrameAlignment() > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3004 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 3005 | } else { |
| 3006 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3011 | void MacroAssembler::GetRelocatedValueLocation(Register ldr_location, |
| 3012 | Register result) { |
| 3013 | const uint32_t kLdrOffsetMask = (1 << 12) - 1; |
| 3014 | const int32_t kPCRegOffset = 2 * kPointerSize; |
| 3015 | ldr(result, MemOperand(ldr_location)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3016 | if (emit_debug_code()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3017 | // Check that the instruction is a ldr reg, [pc + offset] . |
| 3018 | and_(result, result, Operand(kLdrPCPattern)); |
| 3019 | cmp(result, Operand(kLdrPCPattern)); |
| 3020 | Check(eq, "The instruction to patch should be a load from pc."); |
| 3021 | // Result was clobbered. Restore it. |
| 3022 | ldr(result, MemOperand(ldr_location)); |
| 3023 | } |
| 3024 | // Get the address of the constant. |
| 3025 | and_(result, result, Operand(kLdrOffsetMask)); |
| 3026 | add(result, ldr_location, Operand(result)); |
| 3027 | add(result, result, Operand(kPCRegOffset)); |
| 3028 | } |
| 3029 | |
| 3030 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame^] | 3031 | void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) { |
| 3032 | Usat(output_reg, 8, Operand(input_reg)); |
| 3033 | } |
| 3034 | |
| 3035 | |
| 3036 | void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
| 3037 | DoubleRegister input_reg, |
| 3038 | DoubleRegister temp_double_reg) { |
| 3039 | Label above_zero; |
| 3040 | Label done; |
| 3041 | Label in_bounds; |
| 3042 | |
| 3043 | vmov(temp_double_reg, 0.0); |
| 3044 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3045 | b(gt, &above_zero); |
| 3046 | |
| 3047 | // Double value is less than zero, NaN or Inf, return 0. |
| 3048 | mov(result_reg, Operand(0)); |
| 3049 | b(al, &done); |
| 3050 | |
| 3051 | // Double value is >= 255, return 255. |
| 3052 | bind(&above_zero); |
| 3053 | vmov(temp_double_reg, 255.0); |
| 3054 | VFPCompareAndSetFlags(input_reg, temp_double_reg); |
| 3055 | b(le, &in_bounds); |
| 3056 | mov(result_reg, Operand(255)); |
| 3057 | b(al, &done); |
| 3058 | |
| 3059 | // In 0-255 range, round and truncate. |
| 3060 | bind(&in_bounds); |
| 3061 | vmov(temp_double_reg, 0.5); |
| 3062 | vadd(temp_double_reg, input_reg, temp_double_reg); |
| 3063 | vcvt_u32_f64(s0, temp_double_reg); |
| 3064 | vmov(result_reg, s0); |
| 3065 | bind(&done); |
| 3066 | } |
| 3067 | |
| 3068 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3069 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 3070 | : address_(address), |
| 3071 | instructions_(instructions), |
| 3072 | size_(instructions * Assembler::kInstrSize), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3073 | masm_(Isolate::Current(), address, size_ + Assembler::kGap) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3074 | // Create a new macro assembler pointing to the address of the code to patch. |
| 3075 | // The size is adjusted with kGap on order for the assembler to generate size |
| 3076 | // bytes of instructions without failing with buffer size constraints. |
| 3077 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3078 | } |
| 3079 | |
| 3080 | |
| 3081 | CodePatcher::~CodePatcher() { |
| 3082 | // Indicate that code has changed. |
| 3083 | CPU::FlushICache(address_, size_); |
| 3084 | |
| 3085 | // Check that the code was patched as expected. |
| 3086 | ASSERT(masm_.pc_ == address_ + size_); |
| 3087 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 3088 | } |
| 3089 | |
| 3090 | |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3091 | void CodePatcher::Emit(Instr instr) { |
| 3092 | masm()->emit(instr); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | |
| 3096 | void CodePatcher::Emit(Address addr) { |
| 3097 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 3098 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3099 | |
| 3100 | |
| 3101 | void CodePatcher::EmitCondition(Condition cond) { |
| 3102 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 3103 | instr = (instr & ~kCondMask) | cond; |
| 3104 | masm_.emit(instr); |
| 3105 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 3106 | |
| 3107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3108 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3109 | |
| 3110 | #endif // V8_TARGET_ARCH_ARM |