Commit a1917883 authored by whesse@chromium.org's avatar whesse@chromium.org

Add binary operations with constants to the safe-int32 expression compiler.

Review URL: http://codereview.chromium.org/1089004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4230 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d1c0dd17
...@@ -7223,15 +7223,39 @@ void CodeGenerator::Int32BinaryOperation(BinaryOperation* node) { ...@@ -7223,15 +7223,39 @@ void CodeGenerator::Int32BinaryOperation(BinaryOperation* node) {
case Token::BIT_OR: case Token::BIT_OR:
case Token::BIT_XOR: case Token::BIT_XOR:
case Token::BIT_AND: case Token::BIT_AND:
left.ToRegister(); if (left.is_constant() || right.is_constant()) {
right.ToRegister(); int32_t value; // Put constant in value, non-constant in left.
if (op == Token::BIT_OR) { // Constants are known to be int32 values, from static analysis,
__ or_(left.reg(), Operand(right.reg())); // or else will be converted to int32 by implicit ECMA [[ToInt32]].
} else if (op == Token::BIT_XOR) { if (left.is_constant()) {
__ xor_(left.reg(), Operand(right.reg())); ASSERT(left.handle()->IsSmi() || left.handle()->IsHeapNumber());
value = NumberToInt32(*left.handle());
left = right;
} else {
ASSERT(right.handle()->IsSmi() || right.handle()->IsHeapNumber());
value = NumberToInt32(*right.handle());
}
left.ToRegister();
if (op == Token::BIT_OR) {
__ or_(Operand(left.reg()), Immediate(value));
} else if (op == Token::BIT_XOR) {
__ xor_(Operand(left.reg()), Immediate(value));
} else {
ASSERT(op == Token::BIT_AND);
__ and_(Operand(left.reg()), Immediate(value));
}
} else { } else {
ASSERT(op == Token::BIT_AND); ASSERT(left.is_register());
__ and_(left.reg(), Operand(right.reg())); ASSERT(right.is_register());
if (op == Token::BIT_OR) {
__ or_(left.reg(), Operand(right.reg()));
} else if (op == Token::BIT_XOR) {
__ xor_(left.reg(), Operand(right.reg()));
} else {
ASSERT(op == Token::BIT_AND);
__ and_(left.reg(), Operand(right.reg()));
}
} }
frame_->Push(&left); frame_->Push(&left);
right.Unuse(); right.Unuse();
...@@ -7290,16 +7314,39 @@ void CodeGenerator::Int32BinaryOperation(BinaryOperation* node) { ...@@ -7290,16 +7314,39 @@ void CodeGenerator::Int32BinaryOperation(BinaryOperation* node) {
case Token::ADD: case Token::ADD:
case Token::SUB: case Token::SUB:
case Token::MUL: case Token::MUL:
left.ToRegister(); if ((left.is_constant() && op != Token::SUB) || right.is_constant()) {
right.ToRegister(); int32_t value; // Put constant in value, non-constant in left.
if (op == Token::ADD) { if (right.is_constant()) {
__ add(left.reg(), Operand(right.reg())); ASSERT(right.handle()->IsSmi() || right.handle()->IsHeapNumber());
} else if (op == Token::SUB) { value = NumberToInt32(*right.handle());
__ sub(left.reg(), Operand(right.reg())); } else {
ASSERT(left.handle()->IsSmi() || left.handle()->IsHeapNumber());
value = NumberToInt32(*left.handle());
left = right;
}
left.ToRegister();
if (op == Token::ADD) {
__ add(Operand(left.reg()), Immediate(value));
} else if (op == Token::SUB) {
__ sub(Operand(left.reg()), Immediate(value));
} else {
ASSERT(op == Token::MUL);
__ imul(left.reg(), left.reg(), value);
}
} else { } else {
ASSERT(op == Token::MUL); left.ToRegister();
// We have statically verified that a negative zero can be ignored. ASSERT(left.is_register());
__ imul(left.reg(), Operand(right.reg())); ASSERT(right.is_register());
if (op == Token::ADD) {
__ add(left.reg(), Operand(right.reg()));
} else if (op == Token::SUB) {
__ sub(left.reg(), Operand(right.reg()));
} else {
ASSERT(op == Token::MUL);
// We have statically verified that a negative zero can be ignored.
__ imul(left.reg(), Operand(right.reg()));
}
} }
right.Unuse(); right.Unuse();
frame_->Push(&left); frame_->Push(&left);
......
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