Commit 20ebd21b authored by yangguo@chromium.org's avatar yangguo@chromium.org

Port r7868 (constant masking) to x64.

BUG=v8:1374
TEST=test-compiler/SplitConstantsInFullCompiler

Review URL: https://chromiumcodereview.appspot.com/10662045

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11932 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 69020284
......@@ -227,7 +227,7 @@ void FullCodeGenerator::Generate() {
__ lea(edx,
Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset));
__ push(edx);
__ SafePush(Immediate(Smi::FromInt(num_parameters)));
__ push(Immediate(Smi::FromInt(num_parameters)));
// Arguments to ArgumentsAccessStub:
// function, receiver address, parameter count.
// The stub will rewrite receiver and parameter count if the previous
......@@ -2491,7 +2491,7 @@ void FullCodeGenerator::VisitCallNew(CallNew* expr) {
SetSourcePosition(expr->position());
// Load function and argument count into edi and eax.
__ SafeSet(eax, Immediate(arg_count));
__ Set(eax, Immediate(arg_count));
__ mov(edi, Operand(esp, arg_count * kPointerSize));
// Record call targets in unoptimized code, but not in the snapshot.
......@@ -2849,7 +2849,7 @@ void FullCodeGenerator::EmitArguments(CallRuntime* expr) {
// parameter count in eax.
VisitForAccumulatorValue(args->at(0));
__ mov(edx, eax);
__ SafeSet(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters())));
__ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters())));
ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT);
__ CallStub(&stub);
context()->Plug(eax);
......@@ -2861,7 +2861,7 @@ void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) {
Label exit;
// Get the number of formal parameters.
__ SafeSet(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters())));
__ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters())));
// Check if the calling frame is an arguments adaptor frame.
__ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
......
......@@ -504,12 +504,20 @@ void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
void FullCodeGenerator::AccumulatorValueContext::Plug(
Handle<Object> lit) const {
__ Move(result_register(), lit);
if (lit->IsSmi()) {
__ SafeMove(result_register(), Smi::cast(*lit));
} else {
__ Move(result_register(), lit);
}
}
void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
__ Push(lit);
if (lit->IsSmi()) {
__ SafePush(Smi::cast(*lit));
} else {
__ Push(lit);
}
}
......
......@@ -892,6 +892,38 @@ void MacroAssembler::Set(const Operand& dst, int64_t x) {
}
}
bool MacroAssembler::IsUnsafeInt(const int x) {
static const int kMaxBits = 17;
return !is_intn(x, kMaxBits);
}
void MacroAssembler::SafeMove(Register dst, Smi* src) {
ASSERT(!dst.is(kScratchRegister));
ASSERT(kSmiValueSize == 32); // JIT cookie can be converted to Smi.
if (IsUnsafeInt(src->value()) && jit_cookie() != 0) {
Move(dst, Smi::FromInt(src->value() ^ jit_cookie()));
Move(kScratchRegister, Smi::FromInt(jit_cookie()));
xor_(dst, kScratchRegister);
} else {
Move(dst, src);
}
}
void MacroAssembler::SafePush(Smi* src) {
ASSERT(kSmiValueSize == 32); // JIT cookie can be converted to Smi.
if (IsUnsafeInt(src->value()) && jit_cookie() != 0) {
Push(Smi::FromInt(src->value() ^ jit_cookie()));
Move(kScratchRegister, Smi::FromInt(jit_cookie()));
xor_(Operand(rsp, 0), kScratchRegister);
} else {
Push(src);
}
}
// ----------------------------------------------------------------------------
// Smi tagging, untagging and tag detection.
......
......@@ -774,6 +774,11 @@ class MacroAssembler: public Assembler {
// Move if the registers are not identical.
void Move(Register target, Register source);
// Support for constant splitting.
bool IsUnsafeInt(const int x);
void SafeMove(Register dst, Smi* src);
void SafePush(Smi* src);
// Bit-field support.
void TestBit(const Operand& dst, int bit_index);
......
......@@ -406,15 +406,16 @@ static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) {
Address end = pc + decode_size;
v8::internal::EmbeddedVector<char, 128> decode_buffer;
v8::internal::EmbeddedVector<char, 128> smi_hex_buffer;
Smi* smi = Smi::FromInt(12345678);
OS::SNPrintF(smi_hex_buffer, "0x%lx", reinterpret_cast<intptr_t>(smi));
while (pc < end) {
int num_const = d.ConstantPoolSizeAt(pc);
if (num_const >= 0) {
pc += (num_const + 1) * kPointerSize;
} else {
pc += d.InstructionDecode(decode_buffer, pc);
CHECK(strstr(decode_buffer.start(), "mov eax,0x178c29c") == NULL);
CHECK(strstr(decode_buffer.start(), "push 0x178c29c") == NULL);
CHECK(strstr(decode_buffer.start(), "0x178c29c") == NULL);
CHECK(strstr(decode_buffer.start(), smi_hex_buffer.start()) == NULL);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment