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