2011-01-25 07:49:39 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2010-09-02 08:30:52 +00:00
|
|
|
#include <limits.h> // For LONG_MIN, LONG_MAX.
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "v8.h"
|
|
|
|
|
2010-05-17 15:41:35 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_ARM)
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
|
|
|
#include "codegen-inl.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "runtime.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
MacroAssembler::MacroAssembler(void* buffer, int size)
|
|
|
|
: Assembler(buffer, size),
|
2008-07-30 08:49:36 +00:00
|
|
|
generating_stub_(false),
|
2009-02-25 16:52:15 +00:00
|
|
|
allow_stub_calls_(true),
|
|
|
|
code_object_(Heap::undefined_value()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We always generate arm code, never thumb code, even if V8 is compiled to
|
|
|
|
// thumb, so we require inter-working support
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(__thumb__) && !defined(USE_THUMB_INTERWORK)
|
2008-07-03 15:10:15 +00:00
|
|
|
#error "flag -mthumb-interwork missing"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// We do not support thumb inter-working with an arm architecture not supporting
|
2009-09-16 08:48:17 +00:00
|
|
|
// the blx instruction (below v5t). If you know what CPU you are compiling for
|
|
|
|
// you can use -march=armv7 or similar.
|
|
|
|
#if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS)
|
|
|
|
# error "For thumb inter-working we require an architecture which supports blx"
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Using bx does not yield better code, so use it only when required
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(USE_THUMB_INTERWORK)
|
2008-07-03 15:10:15 +00:00
|
|
|
#define USE_BX 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Jump(Register target, Condition cond) {
|
|
|
|
#if USE_BX
|
|
|
|
bx(target, cond);
|
|
|
|
#else
|
|
|
|
mov(pc, Operand(target), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#if USE_BX
|
|
|
|
mov(ip, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
bx(ip, cond);
|
|
|
|
#else
|
|
|
|
mov(pc, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(!RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
Jump(reinterpret_cast<intptr_t>(target), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
// 'code' is always generated ARM code, never THUMB code
|
|
|
|
Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Call(Register target, Condition cond) {
|
|
|
|
#if USE_BLX
|
|
|
|
blx(target, cond);
|
|
|
|
#else
|
|
|
|
// set lr for return at current pc + 8
|
|
|
|
mov(lr, Operand(pc), LeaveCC, cond);
|
|
|
|
mov(pc, Operand(target), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
2010-03-19 14:05:11 +00:00
|
|
|
#if USE_BLX
|
|
|
|
// On ARMv5 and after the recommended call sequence is:
|
|
|
|
// ldr ip, [pc, #...]
|
|
|
|
// blx ip
|
|
|
|
|
2010-04-22 07:35:43 +00:00
|
|
|
// The two instructions (ldr and blx) could be separated by a constant
|
|
|
|
// pool and the code would still work. The issue comes from the
|
|
|
|
// patching code which expect the ldr to be just above the blx.
|
|
|
|
{ BlockConstPoolScope block_const_pool(this);
|
2010-04-21 09:43:45 +00:00
|
|
|
// Statement positions are expected to be recorded when the target
|
|
|
|
// address is loaded. The mov method will automatically record
|
|
|
|
// positions when pc is the target, since this is not the case here
|
|
|
|
// we have to do it explicitly.
|
2010-11-04 15:12:03 +00:00
|
|
|
positions_recorder()->WriteRecordedPositions();
|
2010-04-21 09:43:45 +00:00
|
|
|
|
|
|
|
mov(ip, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
blx(ip, cond);
|
|
|
|
}
|
2010-03-19 14:05:11 +00:00
|
|
|
|
|
|
|
ASSERT(kCallTargetAddressOffset == 2 * kInstrSize);
|
|
|
|
#else
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set lr for return at current pc + 8.
|
|
|
|
mov(lr, Operand(pc), LeaveCC, cond);
|
|
|
|
// Emit a ldr<cond> pc, [pc + offset of target in constant pool].
|
|
|
|
mov(pc, Operand(target, rmode), LeaveCC, cond);
|
2010-03-19 14:05:11 +00:00
|
|
|
|
2009-09-14 06:57:24 +00:00
|
|
|
ASSERT(kCallTargetAddressOffset == kInstrSize);
|
2010-03-19 14:05:11 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(!RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
Call(reinterpret_cast<intptr_t>(target), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
// 'code' is always generated ARM code, never THUMB code
|
|
|
|
Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:30:23 +00:00
|
|
|
void MacroAssembler::Ret(Condition cond) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#if USE_BX
|
2009-04-16 09:30:23 +00:00
|
|
|
bx(lr, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
#else
|
2009-04-16 09:30:23 +00:00
|
|
|
mov(pc, Operand(lr), LeaveCC, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 08:48:26 +00:00
|
|
|
void MacroAssembler::Drop(int count, Condition cond) {
|
|
|
|
if (count > 0) {
|
|
|
|
add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond);
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 10:52:50 +00:00
|
|
|
void MacroAssembler::Ret(int drop, Condition cond) {
|
|
|
|
Drop(drop, cond);
|
|
|
|
Ret(cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
void MacroAssembler::Swap(Register reg1,
|
|
|
|
Register reg2,
|
|
|
|
Register scratch,
|
|
|
|
Condition cond) {
|
2010-04-08 22:30:30 +00:00
|
|
|
if (scratch.is(no_reg)) {
|
2010-05-27 13:48:52 +00:00
|
|
|
eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
|
|
|
|
eor(reg2, reg2, Operand(reg1), LeaveCC, cond);
|
|
|
|
eor(reg1, reg1, Operand(reg2), LeaveCC, cond);
|
2010-04-08 22:30:30 +00:00
|
|
|
} else {
|
2010-05-27 13:48:52 +00:00
|
|
|
mov(scratch, reg1, LeaveCC, cond);
|
|
|
|
mov(reg1, reg2, LeaveCC, cond);
|
|
|
|
mov(reg2, scratch, LeaveCC, cond);
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
void MacroAssembler::Call(Label* target) {
|
|
|
|
bl(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Move(Register dst, Handle<Object> value) {
|
|
|
|
mov(dst, Operand(value));
|
|
|
|
}
|
2009-11-25 09:05:30 +00:00
|
|
|
|
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
void MacroAssembler::Move(Register dst, Register src) {
|
|
|
|
if (!dst.is(src)) {
|
|
|
|
mov(dst, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-14 11:20:36 +00:00
|
|
|
void MacroAssembler::And(Register dst, Register src1, const Operand& src2,
|
|
|
|
Condition cond) {
|
2010-11-04 15:30:04 +00:00
|
|
|
if (!src2.is_reg() &&
|
|
|
|
!src2.must_use_constant_pool() &&
|
|
|
|
src2.immediate() == 0) {
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, cond);
|
2010-11-04 15:30:04 +00:00
|
|
|
|
|
|
|
} else if (!src2.is_single_instruction() &&
|
|
|
|
!src2.must_use_constant_pool() &&
|
|
|
|
CpuFeatures::IsSupported(ARMv7) &&
|
|
|
|
IsPowerOf2(src2.immediate() + 1)) {
|
|
|
|
ubfx(dst, src1, 0, WhichPowerOf2(src2.immediate() + 1), cond);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
and_(dst, src1, src2, LeaveCC, cond);
|
2010-06-14 11:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(lsb < 32);
|
|
|
|
if (!CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
|
|
|
|
and_(dst, src1, Operand(mask), LeaveCC, cond);
|
|
|
|
if (lsb != 0) {
|
|
|
|
mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ubfx(dst, src1, lsb, width, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(lsb < 32);
|
|
|
|
if (!CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
|
|
|
|
and_(dst, src1, Operand(mask), LeaveCC, cond);
|
|
|
|
int shift_up = 32 - lsb - width;
|
|
|
|
int shift_down = lsb + shift_up;
|
|
|
|
if (shift_up != 0) {
|
|
|
|
mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond);
|
|
|
|
}
|
|
|
|
if (shift_down != 0) {
|
|
|
|
mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sbfx(dst, src1, lsb, width, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 10:45:37 +00:00
|
|
|
void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) {
|
|
|
|
ASSERT(lsb < 32);
|
|
|
|
if (!CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
|
|
|
|
bic(dst, dst, Operand(mask));
|
|
|
|
} else {
|
|
|
|
bfc(dst, lsb, width, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-21 07:42:51 +00:00
|
|
|
void MacroAssembler::Usat(Register dst, int satpos, const Operand& src,
|
|
|
|
Condition cond) {
|
|
|
|
if (!CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
ASSERT(!dst.is(pc) && !src.rm().is(pc));
|
|
|
|
ASSERT((satpos >= 0) && (satpos <= 31));
|
|
|
|
|
|
|
|
// These asserts are required to ensure compatibility with the ARMv7
|
|
|
|
// implementation.
|
|
|
|
ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL));
|
|
|
|
ASSERT(src.rs().is(no_reg));
|
|
|
|
|
|
|
|
Label done;
|
|
|
|
int satval = (1 << satpos) - 1;
|
|
|
|
|
|
|
|
if (cond != al) {
|
|
|
|
b(NegateCondition(cond), &done); // Skip saturate if !condition.
|
|
|
|
}
|
|
|
|
if (!(src.is_reg() && dst.is(src.rm()))) {
|
|
|
|
mov(dst, src);
|
|
|
|
}
|
|
|
|
tst(dst, Operand(~satval));
|
|
|
|
b(eq, &done);
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, mi); // 0 if negative.
|
2010-07-21 07:42:51 +00:00
|
|
|
mov(dst, Operand(satval), LeaveCC, pl); // satval if positive.
|
|
|
|
bind(&done);
|
|
|
|
} else {
|
|
|
|
usat(dst, satpos, src, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 08:37:58 +00:00
|
|
|
void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) {
|
|
|
|
// Empty the const pool.
|
|
|
|
CheckConstPool(true, true);
|
|
|
|
add(pc, pc, Operand(index,
|
|
|
|
LSL,
|
|
|
|
assembler::arm::Instr::kInstrSizeLog2 - kSmiTagSize));
|
2009-09-14 06:57:24 +00:00
|
|
|
BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize);
|
2008-12-10 08:37:58 +00:00
|
|
|
nop(); // Jump table alignment.
|
|
|
|
for (int i = 0; i < targets.length(); i++) {
|
|
|
|
b(targets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-24 11:57:57 +00:00
|
|
|
void MacroAssembler::LoadRoot(Register destination,
|
|
|
|
Heap::RootListIndex index,
|
|
|
|
Condition cond) {
|
2010-02-04 09:11:43 +00:00
|
|
|
ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond);
|
2009-08-24 11:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 09:35:18 +00:00
|
|
|
void MacroAssembler::StoreRoot(Register source,
|
|
|
|
Heap::RootListIndex index,
|
|
|
|
Condition cond) {
|
|
|
|
str(source, MemOperand(roots, index << kPointerSizeLog2), cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 11:06:59 +00:00
|
|
|
void MacroAssembler::RecordWriteHelper(Register object,
|
2010-06-30 12:27:49 +00:00
|
|
|
Register address,
|
|
|
|
Register scratch) {
|
2010-05-04 11:06:59 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Check that the object is not in new space.
|
|
|
|
Label not_in_new_space;
|
2010-06-30 12:27:49 +00:00
|
|
|
InNewSpace(object, scratch, ne, ¬_in_new_space);
|
2010-05-04 11:06:59 +00:00
|
|
|
Abort("new-space object passed to RecordWriteHelper");
|
|
|
|
bind(¬_in_new_space);
|
|
|
|
}
|
2010-02-01 13:20:43 +00:00
|
|
|
|
2010-05-27 12:30:45 +00:00
|
|
|
// Calculate page address.
|
2010-06-17 10:45:37 +00:00
|
|
|
Bfc(object, 0, kPageSizeBits);
|
|
|
|
|
|
|
|
// Calculate region number.
|
2010-06-30 12:27:49 +00:00
|
|
|
Ubfx(address, address, Page::kRegionSizeLog2,
|
2010-06-17 10:45:37 +00:00
|
|
|
kPageSizeBits - Page::kRegionSizeLog2);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-27 12:30:45 +00:00
|
|
|
// Mark region dirty.
|
2010-06-30 12:27:49 +00:00
|
|
|
ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset));
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(ip, Operand(1));
|
2010-06-30 12:27:49 +00:00
|
|
|
orr(scratch, scratch, Operand(ip, LSL, address));
|
|
|
|
str(scratch, MemOperand(object, Page::kDirtyFlagOffset));
|
2010-05-04 11:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InNewSpace(Register object,
|
|
|
|
Register scratch,
|
|
|
|
Condition cc,
|
|
|
|
Label* branch) {
|
|
|
|
ASSERT(cc == eq || cc == ne);
|
|
|
|
and_(scratch, object, Operand(ExternalReference::new_space_mask()));
|
|
|
|
cmp(scratch, Operand(ExternalReference::new_space_start()));
|
|
|
|
b(cc, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Will clobber 4 registers: object, offset, scratch, ip. The
|
|
|
|
// register 'object' contains a heap object pointer. The heap object
|
|
|
|
// tag is shifted away.
|
2010-06-17 10:45:37 +00:00
|
|
|
void MacroAssembler::RecordWrite(Register object,
|
|
|
|
Operand offset,
|
|
|
|
Register scratch0,
|
|
|
|
Register scratch1) {
|
2010-05-04 11:06:59 +00:00
|
|
|
// The compiled code assumes that record write doesn't change the
|
|
|
|
// context register, so we check that none of the clobbered
|
|
|
|
// registers are cp.
|
2010-06-17 10:45:37 +00:00
|
|
|
ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp));
|
2010-05-04 11:06:59 +00:00
|
|
|
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
// First, test that the object is not in the new space. We cannot set
|
2010-05-27 12:30:45 +00:00
|
|
|
// region marks for new space pages.
|
2010-06-17 10:45:37 +00:00
|
|
|
InNewSpace(object, scratch0, eq, &done);
|
2010-05-04 11:06:59 +00:00
|
|
|
|
2010-06-30 12:27:49 +00:00
|
|
|
// Add offset into the object.
|
|
|
|
add(scratch0, object, offset);
|
|
|
|
|
2010-05-04 11:06:59 +00:00
|
|
|
// Record the actual write.
|
2010-06-30 12:27:49 +00:00
|
|
|
RecordWriteHelper(object, scratch0, scratch1);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
bind(&done);
|
2010-02-02 07:58:09 +00:00
|
|
|
|
|
|
|
// Clobber all input registers when running with the debug-code flag
|
|
|
|
// turned on to provoke errors.
|
|
|
|
if (FLAG_debug_code) {
|
2010-03-12 10:20:01 +00:00
|
|
|
mov(object, Operand(BitCast<int32_t>(kZapValue)));
|
2010-06-17 10:45:37 +00:00
|
|
|
mov(scratch0, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
mov(scratch1, Operand(BitCast<int32_t>(kZapValue)));
|
2010-02-02 07:58:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-30 12:27:49 +00:00
|
|
|
// Will clobber 4 registers: object, address, scratch, ip. The
|
|
|
|
// register 'object' contains a heap object pointer. The heap object
|
|
|
|
// tag is shifted away.
|
|
|
|
void MacroAssembler::RecordWrite(Register object,
|
|
|
|
Register address,
|
|
|
|
Register scratch) {
|
|
|
|
// The compiled code assumes that record write doesn't change the
|
|
|
|
// context register, so we check that none of the clobbered
|
|
|
|
// registers are cp.
|
|
|
|
ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp));
|
|
|
|
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
// First, test that the object is not in the new space. We cannot set
|
|
|
|
// region marks for new space pages.
|
|
|
|
InNewSpace(object, scratch, eq, &done);
|
|
|
|
|
|
|
|
// Record the actual write.
|
|
|
|
RecordWriteHelper(object, address, scratch);
|
|
|
|
|
|
|
|
bind(&done);
|
|
|
|
|
|
|
|
// Clobber all input registers when running with the debug-code flag
|
|
|
|
// turned on to provoke errors.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
mov(object, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
mov(address, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
mov(scratch, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Push and pop all registers that can hold pointers.
|
|
|
|
void MacroAssembler::PushSafepointRegisters() {
|
|
|
|
// Safepoints expect a block of contiguous register values starting with r0:
|
|
|
|
ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters);
|
|
|
|
// Safepoints expect a block of kNumSafepointRegisters values on the
|
|
|
|
// stack, so adjust the stack for unsaved registers.
|
|
|
|
const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
|
|
|
|
ASSERT(num_unsaved >= 0);
|
|
|
|
sub(sp, sp, Operand(num_unsaved * kPointerSize));
|
|
|
|
stm(db_w, sp, kSafepointSavedRegisters);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::PopSafepointRegisters() {
|
|
|
|
const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters;
|
|
|
|
ldm(ia_w, sp, kSafepointSavedRegisters);
|
|
|
|
add(sp, sp, Operand(num_unsaved * kPointerSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-14 08:49:52 +00:00
|
|
|
void MacroAssembler::PushSafepointRegistersAndDoubles() {
|
|
|
|
PushSafepointRegisters();
|
|
|
|
sub(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters *
|
|
|
|
kDoubleSize));
|
|
|
|
for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) {
|
|
|
|
vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::PopSafepointRegistersAndDoubles() {
|
|
|
|
for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) {
|
|
|
|
vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize);
|
|
|
|
}
|
|
|
|
add(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters *
|
|
|
|
kDoubleSize));
|
|
|
|
PopSafepointRegisters();
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
void MacroAssembler::StoreToSafepointRegisterSlot(Register reg) {
|
|
|
|
str(reg, SafepointRegisterSlot(reg));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
int MacroAssembler::SafepointRegisterStackIndex(int reg_code) {
|
|
|
|
// The registers are pushed starting with the highest encoding,
|
|
|
|
// which means that lowest encodings are closest to the stack pointer.
|
|
|
|
ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters);
|
|
|
|
return reg_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) {
|
2011-01-20 08:08:36 +00:00
|
|
|
return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize);
|
2011-01-19 14:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-26 11:19:39 +00:00
|
|
|
void MacroAssembler::Ldrd(Register dst1, Register dst2,
|
|
|
|
const MemOperand& src, Condition cond) {
|
|
|
|
ASSERT(src.rm().is(no_reg));
|
|
|
|
ASSERT(!dst1.is(lr)); // r14.
|
|
|
|
ASSERT_EQ(0, dst1.code() % 2);
|
|
|
|
ASSERT_EQ(dst1.code() + 1, dst2.code());
|
|
|
|
|
|
|
|
// Generate two ldr instructions if ldrd is not available.
|
|
|
|
if (CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
CpuFeatures::Scope scope(ARMv7);
|
|
|
|
ldrd(dst1, dst2, src, cond);
|
|
|
|
} else {
|
|
|
|
MemOperand src2(src);
|
|
|
|
src2.set_offset(src2.offset() + 4);
|
|
|
|
if (dst1.is(src.rn())) {
|
|
|
|
ldr(dst2, src2, cond);
|
|
|
|
ldr(dst1, src, cond);
|
|
|
|
} else {
|
|
|
|
ldr(dst1, src, cond);
|
|
|
|
ldr(dst2, src2, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Strd(Register src1, Register src2,
|
|
|
|
const MemOperand& dst, Condition cond) {
|
|
|
|
ASSERT(dst.rm().is(no_reg));
|
|
|
|
ASSERT(!src1.is(lr)); // r14.
|
|
|
|
ASSERT_EQ(0, src1.code() % 2);
|
|
|
|
ASSERT_EQ(src1.code() + 1, src2.code());
|
|
|
|
|
|
|
|
// Generate two str instructions if strd is not available.
|
|
|
|
if (CpuFeatures::IsSupported(ARMv7)) {
|
|
|
|
CpuFeatures::Scope scope(ARMv7);
|
|
|
|
strd(src1, src2, dst, cond);
|
|
|
|
} else {
|
|
|
|
MemOperand dst2(dst);
|
|
|
|
dst2.set_offset(dst2.offset() + 4);
|
|
|
|
str(src1, dst, cond);
|
|
|
|
str(src2, dst2, cond);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 12:45:25 +00:00
|
|
|
void MacroAssembler::ClearFPSCRBits(const uint32_t bits_to_clear,
|
|
|
|
const Register scratch,
|
|
|
|
const Condition cond) {
|
|
|
|
vmrs(scratch, cond);
|
|
|
|
bic(scratch, scratch, Operand(bits_to_clear), LeaveCC, cond);
|
|
|
|
vmsr(scratch, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
|
|
|
|
const DwVfpRegister src2,
|
|
|
|
const Condition cond) {
|
|
|
|
// Compare and move FPSCR flags to the normal condition flags.
|
2011-01-12 07:47:13 +00:00
|
|
|
VFPCompareAndLoadFlags(src1, src2, pc, cond);
|
2011-01-11 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1,
|
|
|
|
const double src2,
|
|
|
|
const Condition cond) {
|
|
|
|
// Compare and move FPSCR flags to the normal condition flags.
|
2011-01-12 07:47:13 +00:00
|
|
|
VFPCompareAndLoadFlags(src1, src2, pc, cond);
|
2011-01-11 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
|
|
|
|
const DwVfpRegister src2,
|
|
|
|
const Register fpscr_flags,
|
|
|
|
const Condition cond) {
|
|
|
|
// Compare and load FPSCR.
|
|
|
|
vcmp(src1, src2, cond);
|
2011-01-12 07:47:13 +00:00
|
|
|
vmrs(fpscr_flags, cond);
|
2011-01-11 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1,
|
|
|
|
const double src2,
|
|
|
|
const Register fpscr_flags,
|
|
|
|
const Condition cond) {
|
|
|
|
// Compare and load FPSCR.
|
|
|
|
vcmp(src1, src2, cond);
|
2011-01-12 07:47:13 +00:00
|
|
|
vmrs(fpscr_flags, cond);
|
2011-01-10 08:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
void MacroAssembler::EnterFrame(StackFrame::Type type) {
|
2008-09-12 03:29:06 +00:00
|
|
|
// r0-r3: preserved
|
|
|
|
stm(db_w, sp, cp.bit() | fp.bit() | lr.bit());
|
|
|
|
mov(ip, Operand(Smi::FromInt(type)));
|
|
|
|
push(ip);
|
2009-02-25 16:52:15 +00:00
|
|
|
mov(ip, Operand(CodeObject()));
|
|
|
|
push(ip);
|
2008-09-12 03:29:06 +00:00
|
|
|
add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP.
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
void MacroAssembler::LeaveFrame(StackFrame::Type type) {
|
2008-09-12 03:29:06 +00:00
|
|
|
// r0: preserved
|
|
|
|
// r1: preserved
|
|
|
|
// r2: preserved
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
// Drop the execution stack down to the frame pointer and restore
|
|
|
|
// the caller frame pointer and return address.
|
2008-09-12 03:29:06 +00:00
|
|
|
mov(sp, fp);
|
|
|
|
ldm(ia_w, sp, fp.bit() | lr.bit());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void MacroAssembler::EnterExitFrame(bool save_doubles) {
|
2011-01-25 07:49:39 +00:00
|
|
|
// Compute the argv pointer in a callee-saved register.
|
|
|
|
add(r6, sp, Operand(r0, LSL, kPointerSizeLog2));
|
|
|
|
sub(r6, r6, Operand(kPointerSize));
|
|
|
|
|
|
|
|
// Setup the frame structure on the stack.
|
|
|
|
ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement);
|
|
|
|
ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset);
|
|
|
|
ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset);
|
|
|
|
Push(lr, fp);
|
2010-02-08 13:44:49 +00:00
|
|
|
mov(fp, Operand(sp)); // Setup new frame pointer.
|
2011-01-25 07:49:39 +00:00
|
|
|
// Reserve room for saved entry sp and code object.
|
|
|
|
sub(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
mov(ip, Operand(0));
|
|
|
|
str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
|
|
|
|
}
|
2010-02-08 13:44:49 +00:00
|
|
|
mov(ip, Operand(CodeObject()));
|
2011-01-25 07:49:39 +00:00
|
|
|
str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset));
|
2008-09-23 08:19:26 +00:00
|
|
|
|
|
|
|
// Save the frame pointer and the context in top.
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address)));
|
|
|
|
str(fp, MemOperand(ip));
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_context_address)));
|
|
|
|
str(cp, MemOperand(ip));
|
|
|
|
|
|
|
|
// Setup argc and the builtin function in callee-saved registers.
|
|
|
|
mov(r4, Operand(r0));
|
|
|
|
mov(r5, Operand(r1));
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Optionally save all double registers.
|
|
|
|
if (save_doubles) {
|
2011-01-25 07:49:39 +00:00
|
|
|
sub(sp, sp, Operand(DwVfpRegister::kNumRegisters * kDoubleSize));
|
|
|
|
const int offset = -2 * kPointerSize;
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) {
|
|
|
|
DwVfpRegister reg = DwVfpRegister::from_code(i);
|
2011-01-25 07:49:39 +00:00
|
|
|
vstr(reg, fp, offset - ((i + 1) * kDoubleSize));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-01-25 07:49:39 +00:00
|
|
|
// Note that d0 will be accessible at
|
|
|
|
// fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize,
|
|
|
|
// since the sp slot and code slot were pushed after the fp.
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2011-01-25 07:49:39 +00:00
|
|
|
|
|
|
|
// Reserve place for the return address and align the frame preparing for
|
|
|
|
// calling the runtime function.
|
|
|
|
const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
|
|
|
|
sub(sp, sp, Operand(kPointerSize));
|
|
|
|
if (frame_alignment > 0) {
|
|
|
|
ASSERT(IsPowerOf2(frame_alignment));
|
|
|
|
and_(sp, sp, Operand(-frame_alignment));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the exit frame sp value to point just before the return address
|
|
|
|
// location.
|
|
|
|
add(ip, sp, Operand(kPointerSize));
|
|
|
|
str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset));
|
2008-09-23 08:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 14:49:50 +00:00
|
|
|
void MacroAssembler::InitializeNewString(Register string,
|
|
|
|
Register length,
|
|
|
|
Heap::RootListIndex map_index,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2) {
|
|
|
|
mov(scratch1, Operand(length, LSL, kSmiTagSize));
|
|
|
|
LoadRoot(scratch2, map_index);
|
|
|
|
str(scratch1, FieldMemOperand(string, String::kLengthOffset));
|
|
|
|
mov(scratch1, Operand(String::kEmptyHashField));
|
|
|
|
str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
|
|
|
|
str(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 09:34:47 +00:00
|
|
|
int MacroAssembler::ActivationFrameAlignment() {
|
2009-10-02 13:36:20 +00:00
|
|
|
#if defined(V8_HOST_ARCH_ARM)
|
|
|
|
// Running on the real platform. Use the alignment as mandated by the local
|
|
|
|
// environment.
|
|
|
|
// Note: This will break if we ever start generating snapshots on one ARM
|
|
|
|
// platform for another ARM platform with a different alignment.
|
2010-04-15 09:34:47 +00:00
|
|
|
return OS::ActivationFrameAlignment();
|
2009-10-02 13:36:20 +00:00
|
|
|
#else // defined(V8_HOST_ARCH_ARM)
|
|
|
|
// If we are using the simulator then we should always align to the expected
|
|
|
|
// alignment. As the simulator is used to generate snapshots we do not know
|
2010-04-15 09:34:47 +00:00
|
|
|
// if the target platform will need alignment, so this is controlled from a
|
|
|
|
// flag.
|
|
|
|
return FLAG_sim_stack_alignment;
|
2009-10-02 13:36:20 +00:00
|
|
|
#endif // defined(V8_HOST_ARCH_ARM)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void MacroAssembler::LeaveExitFrame(bool save_doubles) {
|
|
|
|
// Optionally restore all double registers.
|
|
|
|
if (save_doubles) {
|
|
|
|
for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) {
|
|
|
|
DwVfpRegister reg = DwVfpRegister::from_code(i);
|
2011-01-25 07:49:39 +00:00
|
|
|
const int offset = -2 * kPointerSize;
|
|
|
|
vldr(reg, fp, offset - ((i + 1) * kDoubleSize));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-23 08:19:26 +00:00
|
|
|
// Clear top frame.
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(r3, Operand(0, RelocInfo::NONE));
|
2008-09-23 08:19:26 +00:00
|
|
|
mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address)));
|
|
|
|
str(r3, MemOperand(ip));
|
|
|
|
|
|
|
|
// Restore current context from top and clear it in debug mode.
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_context_address)));
|
|
|
|
ldr(cp, MemOperand(ip));
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
str(r3, MemOperand(ip));
|
|
|
|
#endif
|
2008-09-23 08:19:26 +00:00
|
|
|
|
2011-01-25 07:49:39 +00:00
|
|
|
// Tear down the exit frame, pop the arguments, and return. Callee-saved
|
|
|
|
// register r4 still holds argc.
|
|
|
|
mov(sp, Operand(fp));
|
|
|
|
ldm(ia_w, sp, fp.bit() | lr.bit());
|
|
|
|
add(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
|
|
|
|
mov(pc, lr);
|
2008-09-23 08:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-06 10:02:49 +00:00
|
|
|
void MacroAssembler::InvokePrologue(const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
|
|
|
Handle<Code> code_constant,
|
|
|
|
Register code_reg,
|
|
|
|
Label* done,
|
2011-01-11 14:11:03 +00:00
|
|
|
InvokeFlag flag,
|
|
|
|
PostCallGenerator* post_call_generator) {
|
2008-09-12 03:29:06 +00:00
|
|
|
bool definitely_matches = false;
|
|
|
|
Label regular_invoke;
|
|
|
|
|
|
|
|
// Check whether the expected and actual arguments count match. If not,
|
|
|
|
// setup registers according to contract with ArgumentsAdaptorTrampoline:
|
|
|
|
// r0: actual arguments count
|
|
|
|
// r1: function (passed through to callee)
|
|
|
|
// r2: expected arguments count
|
|
|
|
// r3: callee code entry
|
|
|
|
|
|
|
|
// The code below is made a lot easier because the calling code already sets
|
|
|
|
// up actual and expected registers according to the contract if values are
|
|
|
|
// passed in registers.
|
|
|
|
ASSERT(actual.is_immediate() || actual.reg().is(r0));
|
|
|
|
ASSERT(expected.is_immediate() || expected.reg().is(r2));
|
|
|
|
ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3));
|
|
|
|
|
|
|
|
if (expected.is_immediate()) {
|
|
|
|
ASSERT(actual.is_immediate());
|
|
|
|
if (expected.immediate() == actual.immediate()) {
|
|
|
|
definitely_matches = true;
|
|
|
|
} else {
|
|
|
|
mov(r0, Operand(actual.immediate()));
|
2008-09-16 07:24:46 +00:00
|
|
|
const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
|
|
|
|
if (expected.immediate() == sentinel) {
|
|
|
|
// Don't worry about adapting arguments for builtins that
|
|
|
|
// don't want that done. Skip adaption code by making it look
|
|
|
|
// like we have a match between expected and actual number of
|
|
|
|
// arguments.
|
|
|
|
definitely_matches = true;
|
|
|
|
} else {
|
|
|
|
mov(r2, Operand(expected.immediate()));
|
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
}
|
2008-08-06 10:02:49 +00:00
|
|
|
} else {
|
2008-09-12 03:29:06 +00:00
|
|
|
if (actual.is_immediate()) {
|
|
|
|
cmp(expected.reg(), Operand(actual.immediate()));
|
|
|
|
b(eq, ®ular_invoke);
|
|
|
|
mov(r0, Operand(actual.immediate()));
|
|
|
|
} else {
|
|
|
|
cmp(expected.reg(), Operand(actual.reg()));
|
|
|
|
b(eq, ®ular_invoke);
|
2008-08-06 10:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
|
|
|
|
if (!definitely_matches) {
|
|
|
|
if (!code_constant.is_null()) {
|
|
|
|
mov(r3, Operand(code_constant));
|
|
|
|
add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Code> adaptor =
|
|
|
|
Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline));
|
|
|
|
if (flag == CALL_FUNCTION) {
|
2008-09-22 13:57:03 +00:00
|
|
|
Call(adaptor, RelocInfo::CODE_TARGET);
|
2011-01-11 14:11:03 +00:00
|
|
|
if (post_call_generator != NULL) post_call_generator->Generate();
|
2008-09-12 03:29:06 +00:00
|
|
|
b(done);
|
|
|
|
} else {
|
2008-09-22 13:57:03 +00:00
|
|
|
Jump(adaptor, RelocInfo::CODE_TARGET);
|
2008-09-12 03:29:06 +00:00
|
|
|
}
|
|
|
|
bind(®ular_invoke);
|
|
|
|
}
|
2008-08-06 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeCode(Register code,
|
|
|
|
const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
2011-01-11 14:11:03 +00:00
|
|
|
InvokeFlag flag,
|
|
|
|
PostCallGenerator* post_call_generator) {
|
2008-08-06 10:02:49 +00:00
|
|
|
Label done;
|
|
|
|
|
2011-01-11 14:11:03 +00:00
|
|
|
InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag,
|
|
|
|
post_call_generator);
|
2008-08-06 10:02:49 +00:00
|
|
|
if (flag == CALL_FUNCTION) {
|
|
|
|
Call(code);
|
2011-01-11 14:11:03 +00:00
|
|
|
if (post_call_generator != NULL) post_call_generator->Generate();
|
2008-08-06 10:02:49 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(flag == JUMP_FUNCTION);
|
|
|
|
Jump(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue here if InvokePrologue does handle the invocation due to
|
|
|
|
// mismatched parameter counts.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeCode(Handle<Code> code,
|
|
|
|
const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
2008-09-22 13:57:03 +00:00
|
|
|
RelocInfo::Mode rmode,
|
2008-08-06 10:02:49 +00:00
|
|
|
InvokeFlag flag) {
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
InvokePrologue(expected, actual, code, no_reg, &done, flag);
|
|
|
|
if (flag == CALL_FUNCTION) {
|
|
|
|
Call(code, rmode);
|
|
|
|
} else {
|
|
|
|
Jump(code, rmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue here if InvokePrologue does handle the invocation due to
|
|
|
|
// mismatched parameter counts.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeFunction(Register fun,
|
|
|
|
const ParameterCount& actual,
|
2011-01-11 14:11:03 +00:00
|
|
|
InvokeFlag flag,
|
|
|
|
PostCallGenerator* post_call_generator) {
|
2008-08-06 10:02:49 +00:00
|
|
|
// Contract with called JS functions requires that function is passed in r1.
|
|
|
|
ASSERT(fun.is(r1));
|
|
|
|
|
|
|
|
Register expected_reg = r2;
|
2008-09-12 03:29:06 +00:00
|
|
|
Register code_reg = r3;
|
2008-08-06 10:02:49 +00:00
|
|
|
|
|
|
|
ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
|
|
|
|
ldr(expected_reg,
|
|
|
|
FieldMemOperand(code_reg,
|
|
|
|
SharedFunctionInfo::kFormalParameterCountOffset));
|
2010-05-27 12:30:45 +00:00
|
|
|
mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize));
|
2008-08-06 10:02:49 +00:00
|
|
|
ldr(code_reg,
|
2010-08-20 07:10:18 +00:00
|
|
|
FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
|
2008-08-06 10:02:49 +00:00
|
|
|
|
|
|
|
ParameterCount expected(expected_reg);
|
2011-01-11 14:11:03 +00:00
|
|
|
InvokeCode(code_reg, expected, actual, flag, post_call_generator);
|
2008-08-06 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 12:32:27 +00:00
|
|
|
void MacroAssembler::InvokeFunction(JSFunction* function,
|
|
|
|
const ParameterCount& actual,
|
|
|
|
InvokeFlag flag) {
|
|
|
|
ASSERT(function->is_compiled());
|
|
|
|
|
|
|
|
// Get the function and setup the context.
|
|
|
|
mov(r1, Operand(Handle<JSFunction>(function)));
|
|
|
|
ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
|
|
|
|
|
|
|
|
// Invoke the cached code.
|
|
|
|
Handle<Code> code(function->code());
|
|
|
|
ParameterCount expected(function->shared()->formal_parameter_count());
|
2010-12-07 11:31:57 +00:00
|
|
|
if (V8::UseCrankshaft()) {
|
|
|
|
// TODO(kasperl): For now, we always call indirectly through the
|
|
|
|
// code field in the function to allow recompilation to take effect
|
|
|
|
// without changing any of the call sites.
|
|
|
|
ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
|
|
|
|
InvokeCode(r3, expected, actual, flag);
|
|
|
|
} else {
|
|
|
|
InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag);
|
|
|
|
}
|
2010-02-15 12:32:27 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 13:44:49 +00:00
|
|
|
|
2010-12-21 10:52:50 +00:00
|
|
|
void MacroAssembler::IsObjectJSObjectType(Register heap_object,
|
|
|
|
Register map,
|
|
|
|
Register scratch,
|
|
|
|
Label* fail) {
|
|
|
|
ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
|
|
|
|
IsInstanceJSObjectType(map, scratch, fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::IsInstanceJSObjectType(Register map,
|
|
|
|
Register scratch,
|
|
|
|
Label* fail) {
|
|
|
|
ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
|
|
|
cmp(scratch, Operand(FIRST_JS_OBJECT_TYPE));
|
|
|
|
b(lt, fail);
|
|
|
|
cmp(scratch, Operand(LAST_JS_OBJECT_TYPE));
|
|
|
|
b(gt, fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::IsObjectJSStringType(Register object,
|
|
|
|
Register scratch,
|
|
|
|
Label* fail) {
|
|
|
|
ASSERT(kNotStringTag != 0);
|
|
|
|
|
|
|
|
ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
|
|
|
|
ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
|
|
|
|
tst(scratch, Operand(kIsNotStringMask));
|
|
|
|
b(nz, fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-27 07:08:03 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-02-08 13:44:49 +00:00
|
|
|
void MacroAssembler::DebugBreak() {
|
|
|
|
ASSERT(allow_stub_calls());
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(r0, Operand(0, RelocInfo::NONE));
|
2010-02-08 13:44:49 +00:00
|
|
|
mov(r1, Operand(ExternalReference(Runtime::kDebugBreak)));
|
|
|
|
CEntryStub ces(1);
|
|
|
|
Call(ces.GetCode(), RelocInfo::DEBUG_BREAK);
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-10 09:00:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::PushTryHandler(CodeLocation try_location,
|
|
|
|
HandlerType type) {
|
2009-06-10 09:00:07 +00:00
|
|
|
// Adjust this code if not the case.
|
|
|
|
ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
// The pc (return address) is passed in register lr.
|
|
|
|
if (try_location == IN_JAVASCRIPT) {
|
|
|
|
if (type == TRY_CATCH_HANDLER) {
|
|
|
|
mov(r3, Operand(StackHandler::TRY_CATCH));
|
|
|
|
} else {
|
|
|
|
mov(r3, Operand(StackHandler::TRY_FINALLY));
|
|
|
|
}
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kFPOffset == 2 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kPCOffset == 3 * kPointerSize);
|
|
|
|
stm(db_w, sp, r3.bit() | fp.bit() | lr.bit());
|
|
|
|
// Save the current handler as the next handler.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r3, Operand(ExternalReference(Top::k_handler_address)));
|
|
|
|
ldr(r1, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kNextOffset == 0);
|
|
|
|
push(r1);
|
|
|
|
// Link this handler as the new current one.
|
|
|
|
str(sp, MemOperand(r3));
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2008-09-12 03:29:06 +00:00
|
|
|
// Must preserve r0-r4, r5-r7 are available.
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(try_location == IN_JS_ENTRY);
|
2009-06-10 09:00:07 +00:00
|
|
|
// The frame pointer does not point to a JS frame so we save NULL
|
|
|
|
// for fp. We expect the code throwing an exception to check fp
|
|
|
|
// before dereferencing it to restore the context.
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(ip, Operand(0, RelocInfo::NONE)); // To save a NULL frame pointer.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r6, Operand(StackHandler::ENTRY));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kFPOffset == 2 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kPCOffset == 3 * kPointerSize);
|
|
|
|
stm(db_w, sp, r6.bit() | ip.bit() | lr.bit());
|
|
|
|
// Save the current handler as the next handler.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r7, Operand(ExternalReference(Top::k_handler_address)));
|
|
|
|
ldr(r6, MemOperand(r7));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kNextOffset == 0);
|
|
|
|
push(r6);
|
|
|
|
// Link this handler as the new current one.
|
|
|
|
str(sp, MemOperand(r7));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
void MacroAssembler::PopTryHandler() {
|
|
|
|
ASSERT_EQ(0, StackHandlerConstants::kNextOffset);
|
|
|
|
pop(r1);
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_handler_address)));
|
|
|
|
add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
|
|
|
|
str(r1, MemOperand(ip));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
|
2008-10-21 22:40:14 +00:00
|
|
|
Register scratch,
|
|
|
|
Label* miss) {
|
2008-10-21 20:11:50 +00:00
|
|
|
Label same_contexts;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(!holder_reg.is(scratch));
|
2008-10-21 20:11:50 +00:00
|
|
|
ASSERT(!holder_reg.is(ip));
|
|
|
|
ASSERT(!scratch.is(ip));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
// Load current lexical context from the stack frame.
|
|
|
|
ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
|
|
|
// In debug mode, make sure the lexical context is set.
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
2010-09-07 11:09:45 +00:00
|
|
|
cmp(scratch, Operand(0, RelocInfo::NONE));
|
2009-04-22 09:25:41 +00:00
|
|
|
Check(ne, "we should not have an empty lexical context");
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
// Load the global context of the current context.
|
2008-07-03 15:10:15 +00:00
|
|
|
int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
|
|
|
|
ldr(scratch, FieldMemOperand(scratch, offset));
|
2008-10-21 20:11:50 +00:00
|
|
|
ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset));
|
|
|
|
|
|
|
|
// Check the context is a global context.
|
|
|
|
if (FLAG_debug_code) {
|
2008-10-21 22:40:14 +00:00
|
|
|
// TODO(119): avoid push(holder_reg)/pop(holder_reg)
|
|
|
|
// Cannot use ip as a temporary in this verification code. Due to the fact
|
|
|
|
// that ip is clobbered as part of cmp with an object Operand.
|
|
|
|
push(holder_reg); // Temporarily save holder on the stack.
|
2008-10-21 20:11:50 +00:00
|
|
|
// Read the first word and compare to the global_context_map.
|
2008-10-21 22:40:14 +00:00
|
|
|
ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kGlobalContextMapRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(eq, "JSGlobalObject::global_context should be a global context.");
|
2008-10-21 22:40:14 +00:00
|
|
|
pop(holder_reg); // Restore holder.
|
2008-10-21 20:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if both contexts are the same.
|
|
|
|
ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
|
|
|
|
cmp(scratch, Operand(ip));
|
|
|
|
b(eq, &same_contexts);
|
|
|
|
|
|
|
|
// Check the context is a global context.
|
|
|
|
if (FLAG_debug_code) {
|
2008-10-21 22:40:14 +00:00
|
|
|
// TODO(119): avoid push(holder_reg)/pop(holder_reg)
|
|
|
|
// Cannot use ip as a temporary in this verification code. Due to the fact
|
|
|
|
// that ip is clobbered as part of cmp with an object Operand.
|
|
|
|
push(holder_reg); // Temporarily save holder on the stack.
|
|
|
|
mov(holder_reg, ip); // Move ip to its holding place.
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kNullValueRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(ne, "JSGlobalProxy::context() should not be null.");
|
|
|
|
|
2008-10-21 22:40:14 +00:00
|
|
|
ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kGlobalContextMapRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(eq, "JSGlobalObject::global_context should be a global context.");
|
2008-10-21 22:40:14 +00:00
|
|
|
// Restore ip is not needed. ip is reloaded below.
|
|
|
|
pop(holder_reg); // Restore holder.
|
2008-10-21 20:11:50 +00:00
|
|
|
// Restore ip to holder's context.
|
|
|
|
ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Check that the security token in the calling global object is
|
|
|
|
// compatible with the security token in the receiving global
|
|
|
|
// object.
|
2008-10-21 20:11:50 +00:00
|
|
|
int token_offset = Context::kHeaderSize +
|
|
|
|
Context::SECURITY_TOKEN_INDEX * kPointerSize;
|
|
|
|
|
|
|
|
ldr(scratch, FieldMemOperand(scratch, token_offset));
|
|
|
|
ldr(ip, FieldMemOperand(ip, token_offset));
|
2008-07-03 15:10:15 +00:00
|
|
|
cmp(scratch, Operand(ip));
|
|
|
|
b(ne, miss);
|
2008-10-21 20:11:50 +00:00
|
|
|
|
|
|
|
bind(&same_contexts);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-30 09:24:46 +00:00
|
|
|
void MacroAssembler::AllocateInNewSpace(int object_size,
|
|
|
|
Register result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required,
|
|
|
|
AllocationFlags flags) {
|
2010-10-20 12:01:17 +00:00
|
|
|
if (!FLAG_inline_new) {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Trash the registers to simulate an allocation failure.
|
|
|
|
mov(result, Operand(0x7091));
|
|
|
|
mov(scratch1, Operand(0x7191));
|
|
|
|
mov(scratch2, Operand(0x7291));
|
|
|
|
}
|
|
|
|
jmp(gc_required);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-01 07:36:46 +00:00
|
|
|
ASSERT(!result.is(scratch1));
|
2010-12-06 09:59:08 +00:00
|
|
|
ASSERT(!result.is(scratch2));
|
2009-09-01 07:36:46 +00:00
|
|
|
ASSERT(!scratch1.is(scratch2));
|
|
|
|
|
2010-05-07 14:06:55 +00:00
|
|
|
// Make object size into bytes.
|
|
|
|
if ((flags & SIZE_IN_WORDS) != 0) {
|
|
|
|
object_size *= kPointerSize;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(0, object_size & kObjectAlignmentMask);
|
|
|
|
|
2010-12-06 09:59:08 +00:00
|
|
|
// Check relative positions of allocation top and limit addresses.
|
|
|
|
// The values must be adjacent in memory to allow the use of LDM.
|
|
|
|
// Also, assert that the registers are numbered such that the values
|
|
|
|
// are loaded in the correct order.
|
2009-09-01 07:36:46 +00:00
|
|
|
ExternalReference new_space_allocation_top =
|
|
|
|
ExternalReference::new_space_allocation_top_address();
|
2010-12-06 09:59:08 +00:00
|
|
|
ExternalReference new_space_allocation_limit =
|
|
|
|
ExternalReference::new_space_allocation_limit_address();
|
|
|
|
intptr_t top =
|
|
|
|
reinterpret_cast<intptr_t>(new_space_allocation_top.address());
|
|
|
|
intptr_t limit =
|
|
|
|
reinterpret_cast<intptr_t>(new_space_allocation_limit.address());
|
|
|
|
ASSERT((limit - top) == kPointerSize);
|
|
|
|
ASSERT(result.code() < ip.code());
|
|
|
|
|
|
|
|
// Set up allocation top address and object size registers.
|
|
|
|
Register topaddr = scratch1;
|
|
|
|
Register obj_size_reg = scratch2;
|
|
|
|
mov(topaddr, Operand(new_space_allocation_top));
|
|
|
|
mov(obj_size_reg, Operand(object_size));
|
|
|
|
|
|
|
|
// This code stores a temporary value in ip. This is OK, as the code below
|
|
|
|
// does not need ip for implicit literal generation.
|
2009-09-07 09:44:29 +00:00
|
|
|
if ((flags & RESULT_CONTAINS_TOP) == 0) {
|
2010-12-06 09:59:08 +00:00
|
|
|
// Load allocation top into result and allocation limit into ip.
|
|
|
|
ldm(ia, topaddr, result.bit() | ip.bit());
|
|
|
|
} else {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Assert that result actually contains top on entry. ip is used
|
|
|
|
// immediately below so this use of ip does not cause difference with
|
|
|
|
// respect to register content between debug and release mode.
|
|
|
|
ldr(ip, MemOperand(topaddr));
|
|
|
|
cmp(result, ip);
|
|
|
|
Check(eq, "Unexpected allocation top");
|
|
|
|
}
|
|
|
|
// Load allocation limit into ip. Result already contains allocation top.
|
|
|
|
ldr(ip, MemOperand(topaddr, limit - top));
|
2009-09-07 09:44:29 +00:00
|
|
|
}
|
2009-09-01 07:36:46 +00:00
|
|
|
|
|
|
|
// Calculate new top and bail out if new space is exhausted. Use result
|
|
|
|
// to calculate the new top.
|
2010-12-06 09:59:08 +00:00
|
|
|
add(scratch2, result, Operand(obj_size_reg));
|
|
|
|
cmp(scratch2, Operand(ip));
|
2009-09-01 07:36:46 +00:00
|
|
|
b(hi, gc_required);
|
2010-12-06 09:59:08 +00:00
|
|
|
str(scratch2, MemOperand(topaddr));
|
2009-09-01 07:36:46 +00:00
|
|
|
|
2010-12-06 09:59:08 +00:00
|
|
|
// Tag object if requested.
|
2009-09-07 09:44:29 +00:00
|
|
|
if ((flags & TAG_OBJECT) != 0) {
|
2010-12-06 09:59:08 +00:00
|
|
|
add(result, result, Operand(kHeapObjectTag));
|
2009-09-01 07:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-30 09:24:46 +00:00
|
|
|
void MacroAssembler::AllocateInNewSpace(Register object_size,
|
|
|
|
Register result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required,
|
|
|
|
AllocationFlags flags) {
|
2010-10-20 12:01:17 +00:00
|
|
|
if (!FLAG_inline_new) {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Trash the registers to simulate an allocation failure.
|
|
|
|
mov(result, Operand(0x7091));
|
|
|
|
mov(scratch1, Operand(0x7191));
|
|
|
|
mov(scratch2, Operand(0x7291));
|
|
|
|
}
|
|
|
|
jmp(gc_required);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-10 14:10:54 +00:00
|
|
|
// Assert that the register arguments are different and that none of
|
|
|
|
// them are ip. ip is used explicitly in the code generated below.
|
2009-09-02 11:13:44 +00:00
|
|
|
ASSERT(!result.is(scratch1));
|
2010-12-06 09:59:08 +00:00
|
|
|
ASSERT(!result.is(scratch2));
|
2009-09-02 11:13:44 +00:00
|
|
|
ASSERT(!scratch1.is(scratch2));
|
2010-12-10 14:10:54 +00:00
|
|
|
ASSERT(!result.is(ip));
|
|
|
|
ASSERT(!scratch1.is(ip));
|
|
|
|
ASSERT(!scratch2.is(ip));
|
2009-09-02 11:13:44 +00:00
|
|
|
|
2010-12-06 09:59:08 +00:00
|
|
|
// Check relative positions of allocation top and limit addresses.
|
|
|
|
// The values must be adjacent in memory to allow the use of LDM.
|
|
|
|
// Also, assert that the registers are numbered such that the values
|
|
|
|
// are loaded in the correct order.
|
2009-09-02 11:13:44 +00:00
|
|
|
ExternalReference new_space_allocation_top =
|
|
|
|
ExternalReference::new_space_allocation_top_address();
|
2010-12-06 09:59:08 +00:00
|
|
|
ExternalReference new_space_allocation_limit =
|
|
|
|
ExternalReference::new_space_allocation_limit_address();
|
|
|
|
intptr_t top =
|
|
|
|
reinterpret_cast<intptr_t>(new_space_allocation_top.address());
|
|
|
|
intptr_t limit =
|
|
|
|
reinterpret_cast<intptr_t>(new_space_allocation_limit.address());
|
|
|
|
ASSERT((limit - top) == kPointerSize);
|
|
|
|
ASSERT(result.code() < ip.code());
|
|
|
|
|
|
|
|
// Set up allocation top address.
|
|
|
|
Register topaddr = scratch1;
|
|
|
|
mov(topaddr, Operand(new_space_allocation_top));
|
|
|
|
|
|
|
|
// This code stores a temporary value in ip. This is OK, as the code below
|
|
|
|
// does not need ip for implicit literal generation.
|
2009-09-07 09:44:29 +00:00
|
|
|
if ((flags & RESULT_CONTAINS_TOP) == 0) {
|
2010-12-06 09:59:08 +00:00
|
|
|
// Load allocation top into result and allocation limit into ip.
|
|
|
|
ldm(ia, topaddr, result.bit() | ip.bit());
|
|
|
|
} else {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Assert that result actually contains top on entry. ip is used
|
|
|
|
// immediately below so this use of ip does not cause difference with
|
|
|
|
// respect to register content between debug and release mode.
|
|
|
|
ldr(ip, MemOperand(topaddr));
|
|
|
|
cmp(result, ip);
|
|
|
|
Check(eq, "Unexpected allocation top");
|
|
|
|
}
|
|
|
|
// Load allocation limit into ip. Result already contains allocation top.
|
|
|
|
ldr(ip, MemOperand(topaddr, limit - top));
|
2009-09-07 09:44:29 +00:00
|
|
|
}
|
2009-09-02 11:13:44 +00:00
|
|
|
|
|
|
|
// Calculate new top and bail out if new space is exhausted. Use result
|
2010-12-06 09:59:08 +00:00
|
|
|
// to calculate the new top. Object size may be in words so a shift is
|
|
|
|
// required to get the number of bytes.
|
2010-05-07 14:06:55 +00:00
|
|
|
if ((flags & SIZE_IN_WORDS) != 0) {
|
2010-12-06 09:59:08 +00:00
|
|
|
add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2));
|
2010-05-07 14:06:55 +00:00
|
|
|
} else {
|
2010-12-06 09:59:08 +00:00
|
|
|
add(scratch2, result, Operand(object_size));
|
2010-05-07 14:06:55 +00:00
|
|
|
}
|
2010-12-06 09:59:08 +00:00
|
|
|
cmp(scratch2, Operand(ip));
|
2009-09-02 11:13:44 +00:00
|
|
|
b(hi, gc_required);
|
|
|
|
|
2009-12-04 10:22:41 +00:00
|
|
|
// Update allocation top. result temporarily holds the new top.
|
|
|
|
if (FLAG_debug_code) {
|
2010-12-06 09:59:08 +00:00
|
|
|
tst(scratch2, Operand(kObjectAlignmentMask));
|
2009-12-04 10:22:41 +00:00
|
|
|
Check(eq, "Unaligned allocation in new space");
|
|
|
|
}
|
2010-12-06 09:59:08 +00:00
|
|
|
str(scratch2, MemOperand(topaddr));
|
2009-09-07 09:44:29 +00:00
|
|
|
|
|
|
|
// Tag object if requested.
|
|
|
|
if ((flags & TAG_OBJECT) != 0) {
|
2009-09-02 11:13:44 +00:00
|
|
|
add(result, result, Operand(kHeapObjectTag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::UndoAllocationInNewSpace(Register object,
|
|
|
|
Register scratch) {
|
|
|
|
ExternalReference new_space_allocation_top =
|
|
|
|
ExternalReference::new_space_allocation_top_address();
|
|
|
|
|
|
|
|
// Make sure the object has no tag before resetting top.
|
|
|
|
and_(object, object, Operand(~kHeapObjectTagMask));
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that the object un-allocated is below the current top.
|
|
|
|
mov(scratch, Operand(new_space_allocation_top));
|
|
|
|
ldr(scratch, MemOperand(scratch));
|
|
|
|
cmp(object, scratch);
|
|
|
|
Check(lt, "Undo allocation of non allocated memory");
|
|
|
|
#endif
|
|
|
|
// Write the address of the object to un-allocate as the current top.
|
|
|
|
mov(scratch, Operand(new_space_allocation_top));
|
|
|
|
str(object, MemOperand(scratch));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 09:11:43 +00:00
|
|
|
void MacroAssembler::AllocateTwoByteString(Register result,
|
|
|
|
Register length,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Label* gc_required) {
|
|
|
|
// Calculate the number of bytes needed for the characters in the string while
|
|
|
|
// observing object alignment.
|
|
|
|
ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
|
|
|
|
mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars.
|
|
|
|
add(scratch1, scratch1,
|
|
|
|
Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize));
|
2010-05-07 14:06:55 +00:00
|
|
|
and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
|
2010-02-04 09:11:43 +00:00
|
|
|
|
|
|
|
// Allocate two-byte string in new space.
|
|
|
|
AllocateInNewSpace(scratch1,
|
|
|
|
result,
|
|
|
|
scratch2,
|
|
|
|
scratch3,
|
|
|
|
gc_required,
|
|
|
|
TAG_OBJECT);
|
|
|
|
|
|
|
|
// Set the map, length and hash field.
|
2010-05-04 14:49:50 +00:00
|
|
|
InitializeNewString(result,
|
|
|
|
length,
|
|
|
|
Heap::kStringMapRootIndex,
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
2010-02-04 09:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::AllocateAsciiString(Register result,
|
|
|
|
Register length,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Label* gc_required) {
|
|
|
|
// Calculate the number of bytes needed for the characters in the string while
|
|
|
|
// observing object alignment.
|
|
|
|
ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0);
|
|
|
|
ASSERT(kCharSize == 1);
|
|
|
|
add(scratch1, length,
|
|
|
|
Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize));
|
2010-05-07 14:06:55 +00:00
|
|
|
and_(scratch1, scratch1, Operand(~kObjectAlignmentMask));
|
2010-02-04 09:11:43 +00:00
|
|
|
|
|
|
|
// Allocate ASCII string in new space.
|
|
|
|
AllocateInNewSpace(scratch1,
|
|
|
|
result,
|
|
|
|
scratch2,
|
|
|
|
scratch3,
|
|
|
|
gc_required,
|
|
|
|
TAG_OBJECT);
|
|
|
|
|
|
|
|
// Set the map, length and hash field.
|
2010-05-04 14:49:50 +00:00
|
|
|
InitializeNewString(result,
|
|
|
|
length,
|
|
|
|
Heap::kAsciiStringMapRootIndex,
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
2010-02-04 09:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 12:00:42 +00:00
|
|
|
void MacroAssembler::AllocateTwoByteConsString(Register result,
|
|
|
|
Register length,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required) {
|
2010-05-07 14:06:55 +00:00
|
|
|
AllocateInNewSpace(ConsString::kSize,
|
2010-02-05 12:00:42 +00:00
|
|
|
result,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
gc_required,
|
|
|
|
TAG_OBJECT);
|
2010-05-04 14:49:50 +00:00
|
|
|
|
|
|
|
InitializeNewString(result,
|
|
|
|
length,
|
|
|
|
Heap::kConsStringMapRootIndex,
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
2010-02-05 12:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::AllocateAsciiConsString(Register result,
|
|
|
|
Register length,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* gc_required) {
|
2010-05-07 14:06:55 +00:00
|
|
|
AllocateInNewSpace(ConsString::kSize,
|
2010-02-05 12:00:42 +00:00
|
|
|
result,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
gc_required,
|
|
|
|
TAG_OBJECT);
|
2010-05-04 14:49:50 +00:00
|
|
|
|
|
|
|
InitializeNewString(result,
|
|
|
|
length,
|
|
|
|
Heap::kConsAsciiStringMapRootIndex,
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
2010-02-05 12:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
void MacroAssembler::CompareObjectType(Register object,
|
2009-06-10 11:42:13 +00:00
|
|
|
Register map,
|
|
|
|
Register type_reg,
|
|
|
|
InstanceType type) {
|
2010-04-28 11:14:31 +00:00
|
|
|
ldr(map, FieldMemOperand(object, HeapObject::kMapOffset));
|
2009-09-02 11:13:44 +00:00
|
|
|
CompareInstanceType(map, type_reg, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CompareInstanceType(Register map,
|
|
|
|
Register type_reg,
|
|
|
|
InstanceType type) {
|
2009-06-10 11:42:13 +00:00
|
|
|
ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
|
|
|
cmp(type_reg, Operand(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 13:57:18 +00:00
|
|
|
void MacroAssembler::CheckMap(Register obj,
|
|
|
|
Register scratch,
|
|
|
|
Handle<Map> map,
|
|
|
|
Label* fail,
|
|
|
|
bool is_heap_object) {
|
|
|
|
if (!is_heap_object) {
|
2011-01-26 07:44:45 +00:00
|
|
|
JumpIfSmi(obj, fail);
|
2010-02-05 13:57:18 +00:00
|
|
|
}
|
|
|
|
ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
|
|
|
|
mov(ip, Operand(map));
|
|
|
|
cmp(scratch, ip);
|
|
|
|
b(ne, fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-11 10:25:34 +00:00
|
|
|
void MacroAssembler::CheckMap(Register obj,
|
|
|
|
Register scratch,
|
|
|
|
Heap::RootListIndex index,
|
|
|
|
Label* fail,
|
|
|
|
bool is_heap_object) {
|
|
|
|
if (!is_heap_object) {
|
2011-01-26 07:44:45 +00:00
|
|
|
JumpIfSmi(obj, fail);
|
2010-06-11 10:25:34 +00:00
|
|
|
}
|
|
|
|
ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
|
|
|
|
LoadRoot(ip, index);
|
|
|
|
cmp(scratch, ip);
|
|
|
|
b(ne, fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-10 11:42:13 +00:00
|
|
|
void MacroAssembler::TryGetFunctionPrototype(Register function,
|
|
|
|
Register result,
|
|
|
|
Register scratch,
|
|
|
|
Label* miss) {
|
|
|
|
// Check that the receiver isn't a smi.
|
2011-01-26 07:44:45 +00:00
|
|
|
JumpIfSmi(function, miss);
|
2009-06-10 11:42:13 +00:00
|
|
|
|
|
|
|
// Check that the function really is a function. Load map into result reg.
|
|
|
|
CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE);
|
|
|
|
b(ne, miss);
|
|
|
|
|
|
|
|
// Make sure that the function has an instance prototype.
|
|
|
|
Label non_instance;
|
|
|
|
ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset));
|
|
|
|
tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
|
|
|
|
b(ne, &non_instance);
|
|
|
|
|
|
|
|
// Get the prototype or initial map from the function.
|
|
|
|
ldr(result,
|
|
|
|
FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
|
|
|
|
|
|
|
|
// If the prototype or initial map is the hole, don't return it and
|
|
|
|
// simply miss the cache instead. This will allow us to allocate a
|
|
|
|
// prototype object on-demand in the runtime system.
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
|
|
|
cmp(result, ip);
|
2009-06-10 11:42:13 +00:00
|
|
|
b(eq, miss);
|
|
|
|
|
|
|
|
// If the function does not have an initial map, we're done.
|
|
|
|
Label done;
|
|
|
|
CompareObjectType(result, scratch, scratch, MAP_TYPE);
|
|
|
|
b(ne, &done);
|
|
|
|
|
|
|
|
// Get the prototype from the initial map.
|
|
|
|
ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
|
|
|
|
jmp(&done);
|
|
|
|
|
|
|
|
// Non-instance prototype: Fetch prototype from constructor field
|
|
|
|
// in initial map.
|
|
|
|
bind(&non_instance);
|
|
|
|
ldr(result, FieldMemOperand(result, Map::kConstructorOffset));
|
|
|
|
|
|
|
|
// All done.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:27:32 +00:00
|
|
|
void MacroAssembler::CallStub(CodeStub* stub, Condition cond) {
|
2008-07-30 08:49:36 +00:00
|
|
|
ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs
|
2009-08-26 10:27:32 +00:00
|
|
|
Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 12:00:42 +00:00
|
|
|
void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) {
|
|
|
|
ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs
|
|
|
|
Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-06 06:41:10 +00:00
|
|
|
void MacroAssembler::IllegalOperation(int num_arguments) {
|
|
|
|
if (num_arguments > 0) {
|
|
|
|
add(sp, sp, Operand(num_arguments * kPointerSize));
|
|
|
|
}
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(r0, Heap::kUndefinedValueRootIndex);
|
2008-10-06 06:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-27 11:47:12 +00:00
|
|
|
void MacroAssembler::IndexFromHash(Register hash, Register index) {
|
|
|
|
// If the hash field contains an array index pick it out. The assert checks
|
|
|
|
// that the constants for the maximum number of digits for an array index
|
|
|
|
// cached in the hash field and the number of bits reserved for it does not
|
|
|
|
// conflict.
|
|
|
|
ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
|
|
|
|
(1 << String::kArrayIndexValueBits));
|
|
|
|
// We want the smi-tagged index in key. kArrayIndexValueMask has zeros in
|
|
|
|
// the low kHashShift bits.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits);
|
|
|
|
mov(index, Operand(hash, LSL, kSmiTagSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 13:55:21 +00:00
|
|
|
void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg,
|
|
|
|
Register outHighReg,
|
|
|
|
Register outLowReg) {
|
|
|
|
// ARMv7 VFP3 instructions to implement integer to double conversion.
|
|
|
|
mov(r7, Operand(inReg, ASR, kSmiTagSize));
|
2009-12-09 11:14:45 +00:00
|
|
|
vmov(s15, r7);
|
2010-03-23 13:38:04 +00:00
|
|
|
vcvt_f64_s32(d7, s15);
|
2009-12-09 11:14:45 +00:00
|
|
|
vmov(outLowReg, outHighReg, d7);
|
2009-11-12 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-29 09:40:36 +00:00
|
|
|
void MacroAssembler::ObjectToDoubleVFPRegister(Register object,
|
|
|
|
DwVfpRegister result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register heap_number_map,
|
|
|
|
SwVfpRegister scratch3,
|
|
|
|
Label* not_number,
|
|
|
|
ObjectToDoubleFlags flags) {
|
|
|
|
Label done;
|
|
|
|
if ((flags & OBJECT_NOT_SMI) == 0) {
|
|
|
|
Label not_smi;
|
2011-01-26 07:44:45 +00:00
|
|
|
JumpIfNotSmi(object, ¬_smi);
|
2010-06-29 09:40:36 +00:00
|
|
|
// Remove smi tag and convert to double.
|
|
|
|
mov(scratch1, Operand(object, ASR, kSmiTagSize));
|
|
|
|
vmov(scratch3, scratch1);
|
|
|
|
vcvt_f64_s32(result, scratch3);
|
|
|
|
b(&done);
|
|
|
|
bind(¬_smi);
|
|
|
|
}
|
|
|
|
// Check for heap number and load double value from it.
|
|
|
|
ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset));
|
|
|
|
sub(scratch2, object, Operand(kHeapObjectTag));
|
|
|
|
cmp(scratch1, heap_number_map);
|
|
|
|
b(ne, not_number);
|
|
|
|
if ((flags & AVOID_NANS_AND_INFINITIES) != 0) {
|
|
|
|
// If exponent is all ones the number is either a NaN or +/-Infinity.
|
|
|
|
ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset));
|
|
|
|
Sbfx(scratch1,
|
|
|
|
scratch1,
|
|
|
|
HeapNumber::kExponentShift,
|
|
|
|
HeapNumber::kExponentBits);
|
|
|
|
// All-one value sign extend to -1.
|
|
|
|
cmp(scratch1, Operand(-1));
|
|
|
|
b(eq, not_number);
|
|
|
|
}
|
|
|
|
vldr(result, scratch2, HeapNumber::kValueOffset);
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::SmiToDoubleVFPRegister(Register smi,
|
|
|
|
DwVfpRegister value,
|
|
|
|
Register scratch1,
|
|
|
|
SwVfpRegister scratch2) {
|
|
|
|
mov(scratch1, Operand(smi, ASR, kSmiTagSize));
|
|
|
|
vmov(scratch2, scratch1);
|
|
|
|
vcvt_f64_s32(value, scratch2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-02 08:30:52 +00:00
|
|
|
// Tries to get a signed int32 out of a double precision floating point heap
|
|
|
|
// number. Rounds towards 0. Branch to 'not_int32' if the double is out of the
|
|
|
|
// 32bits signed integer range.
|
|
|
|
void MacroAssembler::ConvertToInt32(Register source,
|
|
|
|
Register dest,
|
|
|
|
Register scratch,
|
|
|
|
Register scratch2,
|
|
|
|
Label *not_int32) {
|
|
|
|
if (CpuFeatures::IsSupported(VFP3)) {
|
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
sub(scratch, source, Operand(kHeapObjectTag));
|
|
|
|
vldr(d0, scratch, HeapNumber::kValueOffset);
|
|
|
|
vcvt_s32_f64(s0, d0);
|
|
|
|
vmov(dest, s0);
|
|
|
|
// Signed vcvt instruction will saturate to the minimum (0x80000000) or
|
|
|
|
// maximun (0x7fffffff) signed 32bits integer when the double is out of
|
|
|
|
// range. When substracting one, the minimum signed integer becomes the
|
|
|
|
// maximun signed integer.
|
|
|
|
sub(scratch, dest, Operand(1));
|
|
|
|
cmp(scratch, Operand(LONG_MAX - 1));
|
|
|
|
// If equal then dest was LONG_MAX, if greater dest was LONG_MIN.
|
|
|
|
b(ge, not_int32);
|
|
|
|
} else {
|
|
|
|
// This code is faster for doubles that are in the ranges -0x7fffffff to
|
|
|
|
// -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to
|
|
|
|
// the range of signed int32 values that are not Smis. Jumps to the label
|
|
|
|
// 'not_int32' if the double isn't in the range -0x80000000.0 to
|
|
|
|
// 0x80000000.0 (excluding the endpoints).
|
|
|
|
Label right_exponent, done;
|
|
|
|
// Get exponent word.
|
|
|
|
ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset));
|
|
|
|
// Get exponent alone in scratch2.
|
|
|
|
Ubfx(scratch2,
|
|
|
|
scratch,
|
|
|
|
HeapNumber::kExponentShift,
|
|
|
|
HeapNumber::kExponentBits);
|
|
|
|
// Load dest with zero. We use this either for the final shift or
|
|
|
|
// for the answer.
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(dest, Operand(0, RelocInfo::NONE));
|
2010-09-02 08:30:52 +00:00
|
|
|
// Check whether the exponent matches a 32 bit signed int that is not a Smi.
|
|
|
|
// A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is
|
|
|
|
// the exponent that we are fastest at and also the highest exponent we can
|
|
|
|
// handle here.
|
|
|
|
const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30;
|
|
|
|
// The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we
|
|
|
|
// split it up to avoid a constant pool entry. You can't do that in general
|
|
|
|
// for cmp because of the overflow flag, but we know the exponent is in the
|
|
|
|
// range 0-2047 so there is no overflow.
|
|
|
|
int fudge_factor = 0x400;
|
|
|
|
sub(scratch2, scratch2, Operand(fudge_factor));
|
|
|
|
cmp(scratch2, Operand(non_smi_exponent - fudge_factor));
|
|
|
|
// If we have a match of the int32-but-not-Smi exponent then skip some
|
|
|
|
// logic.
|
|
|
|
b(eq, &right_exponent);
|
|
|
|
// If the exponent is higher than that then go to slow case. This catches
|
|
|
|
// numbers that don't fit in a signed int32, infinities and NaNs.
|
|
|
|
b(gt, not_int32);
|
|
|
|
|
|
|
|
// We know the exponent is smaller than 30 (biased). If it is less than
|
|
|
|
// 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie
|
|
|
|
// it rounds to zero.
|
|
|
|
const uint32_t zero_exponent = HeapNumber::kExponentBias + 0;
|
|
|
|
sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC);
|
|
|
|
// Dest already has a Smi zero.
|
|
|
|
b(lt, &done);
|
|
|
|
|
|
|
|
// We have an exponent between 0 and 30 in scratch2. Subtract from 30 to
|
|
|
|
// get how much to shift down.
|
|
|
|
rsb(dest, scratch2, Operand(30));
|
|
|
|
|
|
|
|
bind(&right_exponent);
|
|
|
|
// Get the top bits of the mantissa.
|
|
|
|
and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask));
|
|
|
|
// Put back the implicit 1.
|
|
|
|
orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift));
|
|
|
|
// Shift up the mantissa bits to take up the space the exponent used to
|
|
|
|
// take. We just orred in the implicit bit so that took care of one and
|
|
|
|
// we want to leave the sign bit 0 so we subtract 2 bits from the shift
|
|
|
|
// distance.
|
|
|
|
const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2;
|
|
|
|
mov(scratch2, Operand(scratch2, LSL, shift_distance));
|
|
|
|
// Put sign in zero flag.
|
|
|
|
tst(scratch, Operand(HeapNumber::kSignMask));
|
|
|
|
// Get the second half of the double. For some exponents we don't
|
|
|
|
// actually need this because the bits get shifted out again, but
|
|
|
|
// it's probably slower to test than just to do it.
|
|
|
|
ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset));
|
|
|
|
// Shift down 22 bits to get the last 10 bits.
|
|
|
|
orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance));
|
|
|
|
// Move down according to the exponent.
|
|
|
|
mov(dest, Operand(scratch, LSR, dest));
|
|
|
|
// Fix sign if sign bit was set.
|
2010-09-07 11:09:45 +00:00
|
|
|
rsb(dest, dest, Operand(0, RelocInfo::NONE), LeaveCC, ne);
|
2010-09-02 08:30:52 +00:00
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 08:46:41 +00:00
|
|
|
void MacroAssembler::GetLeastBitsFromSmi(Register dst,
|
|
|
|
Register src,
|
|
|
|
int num_least_bits) {
|
|
|
|
if (CpuFeatures::IsSupported(ARMv7)) {
|
2010-05-27 13:46:18 +00:00
|
|
|
ubfx(dst, src, kSmiTagSize, num_least_bits);
|
2010-02-05 08:46:41 +00:00
|
|
|
} else {
|
|
|
|
mov(dst, Operand(src, ASR, kSmiTagSize));
|
|
|
|
and_(dst, dst, Operand((1 << num_least_bits) - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) {
|
2008-08-13 09:32:07 +00:00
|
|
|
// All parameters are on the stack. r0 has the return value after call.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-06 06:41:10 +00:00
|
|
|
// If the expected number of arguments of the runtime function is
|
|
|
|
// constant, we check that the actual number of arguments match the
|
|
|
|
// expectation.
|
|
|
|
if (f->nargs >= 0 && f->nargs != num_arguments) {
|
|
|
|
IllegalOperation(num_arguments);
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-01-29 12:41:11 +00:00
|
|
|
// TODO(1236192): Most runtime routines don't need the number of
|
|
|
|
// arguments passed in because it is constant. At some point we
|
|
|
|
// should remove this need and make the runtime routine entry code
|
|
|
|
// smarter.
|
|
|
|
mov(r0, Operand(num_arguments));
|
|
|
|
mov(r1, Operand(ExternalReference(f)));
|
|
|
|
CEntryStub stub(1);
|
2008-07-03 15:10:15 +00:00
|
|
|
CallStub(&stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) {
|
|
|
|
CallRuntime(Runtime::FunctionForId(fid), num_arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) {
|
|
|
|
Runtime::Function* function = Runtime::FunctionForId(id);
|
|
|
|
mov(r0, Operand(function->nargs));
|
|
|
|
mov(r1, Operand(ExternalReference(function)));
|
|
|
|
CEntryStub stub(1);
|
|
|
|
stub.SaveDoubles();
|
|
|
|
CallStub(&stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 12:32:27 +00:00
|
|
|
void MacroAssembler::CallExternalReference(const ExternalReference& ext,
|
|
|
|
int num_arguments) {
|
|
|
|
mov(r0, Operand(num_arguments));
|
|
|
|
mov(r1, Operand(ext));
|
|
|
|
|
|
|
|
CEntryStub stub(1);
|
|
|
|
CallStub(&stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-24 08:33:51 +00:00
|
|
|
void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
|
|
|
|
int num_arguments,
|
|
|
|
int result_size) {
|
2008-08-13 09:32:07 +00:00
|
|
|
// TODO(1236192): Most runtime routines don't need the number of
|
|
|
|
// arguments passed in because it is constant. At some point we
|
|
|
|
// should remove this need and make the runtime routine entry code
|
|
|
|
// smarter.
|
|
|
|
mov(r0, Operand(num_arguments));
|
2010-02-24 08:33:51 +00:00
|
|
|
JumpToExternalReference(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
|
|
|
|
int num_arguments,
|
|
|
|
int result_size) {
|
|
|
|
TailCallExternalReference(ExternalReference(fid), num_arguments, result_size);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-24 08:33:51 +00:00
|
|
|
void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#if defined(__thumb__)
|
|
|
|
// Thumb mode builtin.
|
|
|
|
ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1);
|
|
|
|
#endif
|
|
|
|
mov(r1, Operand(builtin));
|
2009-09-08 11:52:05 +00:00
|
|
|
CEntryStub stub(1);
|
2008-09-22 13:57:03 +00:00
|
|
|
Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 03:29:06 +00:00
|
|
|
void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
|
2011-01-10 12:24:19 +00:00
|
|
|
InvokeJSFlags flags,
|
|
|
|
PostCallGenerator* post_call_generator) {
|
2010-02-11 08:05:33 +00:00
|
|
|
GetBuiltinEntry(r2, id);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (flags == CALL_JS) {
|
2010-02-11 08:05:33 +00:00
|
|
|
Call(r2);
|
2011-01-10 12:24:19 +00:00
|
|
|
if (post_call_generator != NULL) post_call_generator->Generate();
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(flags == JUMP_JS);
|
2010-02-11 08:05:33 +00:00
|
|
|
Jump(r2);
|
2008-09-12 03:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 07:10:18 +00:00
|
|
|
void MacroAssembler::GetBuiltinFunction(Register target,
|
|
|
|
Builtins::JavaScript id) {
|
2010-04-14 20:16:19 +00:00
|
|
|
// Load the builtins object into target register.
|
|
|
|
ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
|
2010-02-11 08:05:33 +00:00
|
|
|
// Load the JavaScript builtin function from the builtins object.
|
2010-08-20 07:10:18 +00:00
|
|
|
ldr(target, FieldMemOperand(target,
|
2010-04-14 20:16:19 +00:00
|
|
|
JSBuiltinsObject::OffsetOfFunctionWithId(id)));
|
2010-08-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 20:16:19 +00:00
|
|
|
|
2010-08-20 07:10:18 +00:00
|
|
|
void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
|
|
|
|
ASSERT(!target.is(r1));
|
|
|
|
GetBuiltinFunction(r1, id);
|
2010-04-14 20:16:19 +00:00
|
|
|
// Load the code entry point from the builtins object.
|
2010-08-20 07:10:18 +00:00
|
|
|
ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-20 16:59:00 +00:00
|
|
|
void MacroAssembler::SetCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch1, Operand(value));
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
ASSERT(value > 0);
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
ldr(scratch1, MemOperand(scratch2));
|
|
|
|
add(scratch1, scratch1, Operand(value));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
ASSERT(value > 0);
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
ldr(scratch1, MemOperand(scratch2));
|
|
|
|
sub(scratch1, scratch1, Operand(value));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::Assert(Condition cc, const char* msg) {
|
|
|
|
if (FLAG_debug_code)
|
|
|
|
Check(cc, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 21:51:51 +00:00
|
|
|
void MacroAssembler::AssertRegisterIsRoot(Register reg,
|
|
|
|
Heap::RootListIndex index) {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
LoadRoot(ip, index);
|
|
|
|
cmp(reg, ip);
|
|
|
|
Check(eq, "Register did not match expected root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-16 16:06:46 +00:00
|
|
|
void MacroAssembler::AssertFastElements(Register elements) {
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
ASSERT(!elements.is(ip));
|
|
|
|
Label ok;
|
|
|
|
push(elements);
|
|
|
|
ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
|
|
|
|
LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
|
|
|
|
cmp(elements, ip);
|
|
|
|
b(eq, &ok);
|
|
|
|
LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex);
|
|
|
|
cmp(elements, ip);
|
|
|
|
b(eq, &ok);
|
|
|
|
Abort("JSObject with fast elements map has slow elements");
|
|
|
|
bind(&ok);
|
|
|
|
pop(elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::Check(Condition cc, const char* msg) {
|
|
|
|
Label L;
|
|
|
|
b(cc, &L);
|
|
|
|
Abort(msg);
|
|
|
|
// will not return here
|
|
|
|
bind(&L);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Abort(const char* msg) {
|
2010-06-24 13:56:35 +00:00
|
|
|
Label abort_start;
|
|
|
|
bind(&abort_start);
|
2008-07-03 15:10:15 +00:00
|
|
|
// We want to pass the msg string like a smi to avoid GC
|
|
|
|
// problems, however msg is not guaranteed to be aligned
|
|
|
|
// properly. Instead, we pass an aligned pointer that is
|
2009-01-15 19:08:34 +00:00
|
|
|
// a proper v8 smi, but also pass the alignment difference
|
2008-07-03 15:10:15 +00:00
|
|
|
// from the real pointer as a smi.
|
|
|
|
intptr_t p1 = reinterpret_cast<intptr_t>(msg);
|
|
|
|
intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag;
|
|
|
|
ASSERT(reinterpret_cast<Object*>(p0)->IsSmi());
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (msg != NULL) {
|
|
|
|
RecordComment("Abort message: ");
|
|
|
|
RecordComment(msg);
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-04 10:22:41 +00:00
|
|
|
// Disable stub call restrictions to always allow calls to abort.
|
2011-01-07 10:37:26 +00:00
|
|
|
AllowStubCallsScope allow_scope(this, true);
|
2009-12-04 10:22:41 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r0, Operand(p0));
|
|
|
|
push(r0);
|
|
|
|
mov(r0, Operand(Smi::FromInt(p1 - p0)));
|
2008-08-13 09:32:07 +00:00
|
|
|
push(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
CallRuntime(Runtime::kAbort, 2);
|
|
|
|
// will not return here
|
2010-06-24 13:56:35 +00:00
|
|
|
if (is_const_pool_blocked()) {
|
|
|
|
// If the calling code cares about the exact number of
|
|
|
|
// instructions generated, we insert padding here to keep the size
|
|
|
|
// of the Abort macro constant.
|
|
|
|
static const int kExpectedAbortInstructions = 10;
|
|
|
|
int abort_instructions = InstructionsGeneratedSince(&abort_start);
|
|
|
|
ASSERT(abort_instructions <= kExpectedAbortInstructions);
|
|
|
|
while (abort_instructions++ < kExpectedAbortInstructions) {
|
|
|
|
nop();
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 07:36:46 +00:00
|
|
|
|
2009-11-26 10:28:32 +00:00
|
|
|
void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
|
|
|
|
if (context_chain_length > 0) {
|
|
|
|
// Move up the chain of contexts to the context containing the slot.
|
|
|
|
ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX)));
|
|
|
|
// Load the function context (which is the incoming, outer context).
|
|
|
|
ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
|
|
|
|
for (int i = 1; i < context_chain_length; i++) {
|
|
|
|
ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX)));
|
|
|
|
ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
|
|
|
|
}
|
|
|
|
// The context may be an intermediate context, not a function context.
|
|
|
|
ldr(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX)));
|
|
|
|
} else { // Slot is in the current function context.
|
|
|
|
// The context may be an intermediate context, not a function context.
|
|
|
|
ldr(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-26 08:43:34 +00:00
|
|
|
void MacroAssembler::LoadGlobalFunction(int index, Register function) {
|
|
|
|
// Load the global or builtins object from the current context.
|
|
|
|
ldr(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
// Load the global context from the global or builtins object.
|
|
|
|
ldr(function, FieldMemOperand(function,
|
|
|
|
GlobalObject::kGlobalContextOffset));
|
|
|
|
// Load the function from the global context.
|
|
|
|
ldr(function, MemOperand(function, Context::SlotOffset(index)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
|
|
|
|
Register map,
|
|
|
|
Register scratch) {
|
|
|
|
// Load the initial map. The global functions all have initial maps.
|
|
|
|
ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
Label ok, fail;
|
|
|
|
CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, false);
|
|
|
|
b(&ok);
|
|
|
|
bind(&fail);
|
|
|
|
Abort("Global functions must have initial map");
|
|
|
|
bind(&ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-05 12:00:42 +00:00
|
|
|
void MacroAssembler::JumpIfNotBothSmi(Register reg1,
|
|
|
|
Register reg2,
|
|
|
|
Label* on_not_both_smi) {
|
2011-01-25 14:52:35 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-02-05 12:00:42 +00:00
|
|
|
tst(reg1, Operand(kSmiTagMask));
|
|
|
|
tst(reg2, Operand(kSmiTagMask), eq);
|
|
|
|
b(ne, on_not_both_smi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::JumpIfEitherSmi(Register reg1,
|
|
|
|
Register reg2,
|
|
|
|
Label* on_either_smi) {
|
2011-01-25 14:52:35 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-02-05 12:00:42 +00:00
|
|
|
tst(reg1, Operand(kSmiTagMask));
|
|
|
|
tst(reg2, Operand(kSmiTagMask), ne);
|
|
|
|
b(eq, on_either_smi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-12 13:43:08 +00:00
|
|
|
void MacroAssembler::AbortIfSmi(Register object) {
|
2011-01-25 14:52:35 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-08-12 13:43:08 +00:00
|
|
|
tst(object, Operand(kSmiTagMask));
|
|
|
|
Assert(ne, "Operand is a smi");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-20 14:20:54 +00:00
|
|
|
void MacroAssembler::AbortIfNotSmi(Register object) {
|
2011-01-25 14:52:35 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2011-01-20 14:20:54 +00:00
|
|
|
tst(object, Operand(kSmiTagMask));
|
|
|
|
Assert(eq, "Operand is not smi");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 14:52:35 +00:00
|
|
|
void MacroAssembler::JumpIfNotHeapNumber(Register object,
|
|
|
|
Register heap_number_map,
|
|
|
|
Register scratch,
|
|
|
|
Label* on_not_heap_number) {
|
|
|
|
ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
|
|
|
|
AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
cmp(scratch, heap_number_map);
|
|
|
|
b(ne, on_not_heap_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-21 12:10:56 +00:00
|
|
|
void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings(
|
|
|
|
Register first,
|
|
|
|
Register second,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* failure) {
|
|
|
|
// Test that both first and second are sequential ASCII strings.
|
|
|
|
// Assume that they are non-smis.
|
|
|
|
ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
|
|
|
|
ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
|
|
|
|
ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
|
|
|
|
ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
|
2010-03-08 11:58:33 +00:00
|
|
|
|
|
|
|
JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1,
|
|
|
|
scratch2,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
failure);
|
2010-01-21 12:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first,
|
|
|
|
Register second,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* failure) {
|
|
|
|
// Check that neither is a smi.
|
2011-01-25 14:52:35 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-01-21 12:10:56 +00:00
|
|
|
and_(scratch1, first, Operand(second));
|
|
|
|
tst(scratch1, Operand(kSmiTagMask));
|
|
|
|
b(eq, failure);
|
|
|
|
JumpIfNonSmisNotBothSequentialAsciiStrings(first,
|
|
|
|
second,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
failure);
|
|
|
|
}
|
|
|
|
|
2009-11-26 10:28:32 +00:00
|
|
|
|
2010-03-23 13:38:04 +00:00
|
|
|
// Allocates a heap number or jumps to the need_gc label if the young space
|
|
|
|
// is full and a scavenge is needed.
|
|
|
|
void MacroAssembler::AllocateHeapNumber(Register result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
2010-06-17 21:51:51 +00:00
|
|
|
Register heap_number_map,
|
2010-03-23 13:38:04 +00:00
|
|
|
Label* gc_required) {
|
|
|
|
// Allocate an object in the heap for the heap number and tag it as a heap
|
|
|
|
// object.
|
2010-05-07 14:06:55 +00:00
|
|
|
AllocateInNewSpace(HeapNumber::kSize,
|
2010-03-23 13:38:04 +00:00
|
|
|
result,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
gc_required,
|
|
|
|
TAG_OBJECT);
|
|
|
|
|
2010-06-17 21:51:51 +00:00
|
|
|
// Store heap number map in the allocated object.
|
|
|
|
AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
|
2010-03-23 13:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-29 09:40:36 +00:00
|
|
|
void MacroAssembler::AllocateHeapNumberWithValue(Register result,
|
|
|
|
DwVfpRegister value,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register heap_number_map,
|
|
|
|
Label* gc_required) {
|
|
|
|
AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required);
|
|
|
|
sub(scratch1, result, Operand(kHeapObjectTag));
|
|
|
|
vstr(value, scratch1, HeapNumber::kValueOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-06 13:04:27 +00:00
|
|
|
// Copies a fixed number of fields of heap objects from src to dst.
|
|
|
|
void MacroAssembler::CopyFields(Register dst,
|
|
|
|
Register src,
|
|
|
|
RegList temps,
|
|
|
|
int field_count) {
|
|
|
|
// At least one bit set in the first 15 registers.
|
|
|
|
ASSERT((temps & ((1 << 15) - 1)) != 0);
|
|
|
|
ASSERT((temps & dst.bit()) == 0);
|
|
|
|
ASSERT((temps & src.bit()) == 0);
|
|
|
|
// Primitive implementation using only one temporary register.
|
|
|
|
|
|
|
|
Register tmp = no_reg;
|
|
|
|
// Find a temp register in temps list.
|
|
|
|
for (int i = 0; i < 15; i++) {
|
|
|
|
if ((temps & (1 << i)) != 0) {
|
|
|
|
tmp.set_code(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(!tmp.is(no_reg));
|
|
|
|
|
|
|
|
for (int i = 0; i < field_count; i++) {
|
|
|
|
ldr(tmp, FieldMemOperand(src, i * kPointerSize));
|
|
|
|
str(tmp, FieldMemOperand(dst, i * kPointerSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 11:47:23 +00:00
|
|
|
void MacroAssembler::CountLeadingZeros(Register zeros, // Answer.
|
|
|
|
Register source, // Input.
|
|
|
|
Register scratch) {
|
|
|
|
ASSERT(!zeros.is(source) || !source.is(zeros));
|
|
|
|
ASSERT(!zeros.is(scratch));
|
|
|
|
ASSERT(!scratch.is(ip));
|
|
|
|
ASSERT(!source.is(ip));
|
|
|
|
ASSERT(!zeros.is(ip));
|
2010-03-23 13:38:04 +00:00
|
|
|
#ifdef CAN_USE_ARMV5_INSTRUCTIONS
|
|
|
|
clz(zeros, source); // This instruction is only supported after ARM5.
|
|
|
|
#else
|
2010-09-07 11:09:45 +00:00
|
|
|
mov(zeros, Operand(0, RelocInfo::NONE));
|
2010-06-28 11:47:23 +00:00
|
|
|
Move(scratch, source);
|
2010-03-23 13:38:04 +00:00
|
|
|
// Top 16.
|
|
|
|
tst(scratch, Operand(0xffff0000));
|
|
|
|
add(zeros, zeros, Operand(16), LeaveCC, eq);
|
|
|
|
mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq);
|
|
|
|
// Top 8.
|
|
|
|
tst(scratch, Operand(0xff000000));
|
|
|
|
add(zeros, zeros, Operand(8), LeaveCC, eq);
|
|
|
|
mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq);
|
|
|
|
// Top 4.
|
|
|
|
tst(scratch, Operand(0xf0000000));
|
|
|
|
add(zeros, zeros, Operand(4), LeaveCC, eq);
|
|
|
|
mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq);
|
|
|
|
// Top 2.
|
|
|
|
tst(scratch, Operand(0xc0000000));
|
|
|
|
add(zeros, zeros, Operand(2), LeaveCC, eq);
|
|
|
|
mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq);
|
|
|
|
// Top bit.
|
|
|
|
tst(scratch, Operand(0x80000000u));
|
|
|
|
add(zeros, zeros, Operand(1), LeaveCC, eq);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-08 11:58:33 +00:00
|
|
|
void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii(
|
|
|
|
Register first,
|
|
|
|
Register second,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Label* failure) {
|
|
|
|
int kFlatAsciiStringMask =
|
|
|
|
kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
|
|
|
|
int kFlatAsciiStringTag = ASCII_STRING_TYPE;
|
|
|
|
and_(scratch1, first, Operand(kFlatAsciiStringMask));
|
|
|
|
and_(scratch2, second, Operand(kFlatAsciiStringMask));
|
|
|
|
cmp(scratch1, Operand(kFlatAsciiStringTag));
|
|
|
|
// Ignore second test if first test failed.
|
|
|
|
cmp(scratch2, Operand(kFlatAsciiStringTag), eq);
|
|
|
|
b(ne, failure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type,
|
|
|
|
Register scratch,
|
|
|
|
Label* failure) {
|
|
|
|
int kFlatAsciiStringMask =
|
|
|
|
kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
|
|
|
|
int kFlatAsciiStringTag = ASCII_STRING_TYPE;
|
|
|
|
and_(scratch, type, Operand(kFlatAsciiStringMask));
|
|
|
|
cmp(scratch, Operand(kFlatAsciiStringTag));
|
|
|
|
b(ne, failure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-09 11:25:52 +00:00
|
|
|
void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
|
2010-04-15 09:34:47 +00:00
|
|
|
int frame_alignment = ActivationFrameAlignment();
|
2010-04-09 11:25:52 +00:00
|
|
|
// Up to four simple arguments are passed in registers r0..r3.
|
|
|
|
int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4;
|
2010-04-15 09:34:47 +00:00
|
|
|
if (frame_alignment > kPointerSize) {
|
2010-04-09 11:25:52 +00:00
|
|
|
// Make stack end at alignment and make room for num_arguments - 4 words
|
|
|
|
// and the original value of sp.
|
|
|
|
mov(scratch, sp);
|
|
|
|
sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
|
2010-04-15 09:34:47 +00:00
|
|
|
ASSERT(IsPowerOf2(frame_alignment));
|
|
|
|
and_(sp, sp, Operand(-frame_alignment));
|
2010-04-09 11:25:52 +00:00
|
|
|
str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
|
|
|
} else {
|
|
|
|
sub(sp, sp, Operand(stack_passed_arguments * kPointerSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CallCFunction(ExternalReference function,
|
|
|
|
int num_arguments) {
|
|
|
|
mov(ip, Operand(function));
|
|
|
|
CallCFunction(ip, num_arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CallCFunction(Register function, int num_arguments) {
|
2010-04-15 09:34:47 +00:00
|
|
|
// Make sure that the stack is aligned before calling a C function unless
|
|
|
|
// running in the simulator. The simulator has its own alignment check which
|
|
|
|
// provides more information.
|
|
|
|
#if defined(V8_HOST_ARCH_ARM)
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
int frame_alignment = OS::ActivationFrameAlignment();
|
|
|
|
int frame_alignment_mask = frame_alignment - 1;
|
|
|
|
if (frame_alignment > kPointerSize) {
|
|
|
|
ASSERT(IsPowerOf2(frame_alignment));
|
|
|
|
Label alignment_as_expected;
|
|
|
|
tst(sp, Operand(frame_alignment_mask));
|
|
|
|
b(eq, &alignment_as_expected);
|
|
|
|
// Don't use Check here, as it will call Runtime_Abort possibly
|
|
|
|
// re-entering here.
|
|
|
|
stop("Unexpected alignment");
|
|
|
|
bind(&alignment_as_expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-09 11:25:52 +00:00
|
|
|
// Just call directly. The function called cannot cause a GC, or
|
|
|
|
// allow preemption, so the return address in the link register
|
|
|
|
// stays correct.
|
|
|
|
Call(function);
|
|
|
|
int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4;
|
|
|
|
if (OS::ActivationFrameAlignment() > kPointerSize) {
|
|
|
|
ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
|
|
|
} else {
|
|
|
|
add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 14:53:38 +00:00
|
|
|
void MacroAssembler::GetRelocatedValueLocation(Register ldr_location,
|
|
|
|
Register result) {
|
|
|
|
const uint32_t kLdrOffsetMask = (1 << 12) - 1;
|
|
|
|
const int32_t kPCRegOffset = 2 * kPointerSize;
|
|
|
|
ldr(result, MemOperand(ldr_location));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Check that the instruction is a ldr reg, [pc + offset] .
|
|
|
|
and_(result, result, Operand(kLdrPCPattern));
|
|
|
|
cmp(result, Operand(kLdrPCPattern));
|
|
|
|
Check(eq, "The instruction to patch should be a load from pc.");
|
|
|
|
// Result was clobbered. Restore it.
|
|
|
|
ldr(result, MemOperand(ldr_location));
|
|
|
|
}
|
|
|
|
// Get the address of the constant.
|
|
|
|
and_(result, result, Operand(kLdrOffsetMask));
|
|
|
|
add(result, ldr_location, Operand(result));
|
|
|
|
add(result, result, Operand(kPCRegOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-14 06:57:24 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
CodePatcher::CodePatcher(byte* address, int instructions)
|
|
|
|
: address_(address),
|
|
|
|
instructions_(instructions),
|
|
|
|
size_(instructions * Assembler::kInstrSize),
|
|
|
|
masm_(address, size_ + Assembler::kGap) {
|
|
|
|
// Create a new macro assembler pointing to the address of the code to patch.
|
|
|
|
// The size is adjusted with kGap on order for the assembler to generate size
|
|
|
|
// bytes of instructions without failing with buffer size constraints.
|
|
|
|
ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodePatcher::~CodePatcher() {
|
|
|
|
// Indicate that code has changed.
|
|
|
|
CPU::FlushICache(address_, size_);
|
|
|
|
|
|
|
|
// Check that the code was patched as expected.
|
|
|
|
ASSERT(masm_.pc_ == address_ + size_);
|
|
|
|
ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodePatcher::Emit(Instr x) {
|
|
|
|
masm()->emit(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodePatcher::Emit(Address addr) {
|
|
|
|
masm()->emit(reinterpret_cast<Instr>(addr));
|
|
|
|
}
|
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
2010-05-17 15:41:35 +00:00
|
|
|
|
|
|
|
#endif // V8_TARGET_ARCH_ARM
|