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