Commit befbeba8 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Small changes to improve test coverage in codegen-ia32.cc.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1769 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b39f4383
...@@ -1274,12 +1274,9 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op, ...@@ -1274,12 +1274,9 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op,
smi_value, smi_value,
overwrite_mode); overwrite_mode);
__ Set(answer.reg(), Immediate(value)); __ Set(answer.reg(), Immediate(value));
if (operand->is_register()) { // We are in the reversed case so they can't both be Smi constants.
__ sub(answer.reg(), Operand(operand->reg())); ASSERT(operand->is_register());
} else { __ sub(answer.reg(), Operand(operand->reg()));
ASSERT(operand->is_constant());
__ sub(Operand(answer.reg()), Immediate(operand->handle()));
}
} else { } else {
operand->ToRegister(); operand->ToRegister();
frame_->Spill(operand->reg()); frame_->Spill(operand->reg());
...@@ -1374,23 +1371,28 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op, ...@@ -1374,23 +1371,28 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op,
operand->ToRegister(); operand->ToRegister();
__ test(operand->reg(), Immediate(kSmiTagMask)); __ test(operand->reg(), Immediate(kSmiTagMask));
deferred->enter()->Branch(not_zero, operand, not_taken); deferred->enter()->Branch(not_zero, operand, not_taken);
Result answer = allocator()->Allocate(); if (shift_value != 0) {
ASSERT(answer.is_valid()); Result answer = allocator()->Allocate();
__ mov(answer.reg(), operand->reg()); ASSERT(answer.is_valid());
ASSERT(kSmiTag == 0); // adjust code if not the case __ mov(answer.reg(), operand->reg());
// We do no shifts, only the Smi conversion, if shift_value is 1. ASSERT(kSmiTag == 0); // adjust code if not the case
if (shift_value == 0) { // We do no shifts, only the Smi conversion, if shift_value is 1.
__ sar(answer.reg(), kSmiTagSize); if (shift_value == 0) {
} else if (shift_value > 1) { __ sar(answer.reg(), kSmiTagSize);
__ shl(answer.reg(), shift_value - 1); } else if (shift_value > 1) {
__ shl(answer.reg(), shift_value - 1);
}
// Convert int result to Smi, checking that it is in int range.
ASSERT(kSmiTagSize == times_2); // adjust code if not the case
__ add(answer.reg(), Operand(answer.reg()));
deferred->enter()->Branch(overflow, operand, not_taken);
operand->Unuse();
deferred->BindExit(&answer);
frame_->Push(&answer);
} else {
deferred->BindExit(operand);
frame_->Push(operand);
} }
// Convert int result to Smi, checking that it is in int range.
ASSERT(kSmiTagSize == times_2); // adjust code if not the case
__ add(answer.reg(), Operand(answer.reg()));
deferred->enter()->Branch(overflow, operand, not_taken);
operand->Unuse();
deferred->BindExit(&answer);
frame_->Push(&answer);
} }
break; break;
} }
...@@ -1411,11 +1413,7 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op, ...@@ -1411,11 +1413,7 @@ void CodeGenerator::ConstantSmiBinaryOperation(Token::Value op,
deferred->enter()->Branch(not_zero, operand, not_taken); deferred->enter()->Branch(not_zero, operand, not_taken);
frame_->Spill(operand->reg()); frame_->Spill(operand->reg());
if (op == Token::BIT_AND) { if (op == Token::BIT_AND) {
if (int_value == 0) { __ and_(Operand(operand->reg()), Immediate(value));
__ xor_(Operand(operand->reg()), operand->reg());
} else {
__ and_(Operand(operand->reg()), Immediate(value));
}
} else if (op == Token::BIT_XOR) { } else if (op == Token::BIT_XOR) {
if (int_value != 0) { if (int_value != 0) {
__ xor_(Operand(operand->reg()), Immediate(value)); __ xor_(Operand(operand->reg()), Immediate(value));
...@@ -5278,9 +5276,9 @@ void DeferredReferenceGetKeyedValue::Generate() { ...@@ -5278,9 +5276,9 @@ void DeferredReferenceGetKeyedValue::Generate() {
ASSERT(value.is_register() && value.reg().is(eax)); ASSERT(value.is_register() && value.reg().is(eax));
// The delta from the start of the map-compare instruction to the // The delta from the start of the map-compare instruction to the
// test eax instruction. We use masm_ directly here instead of the // test eax instruction. We use masm_ directly here instead of the
// __ macro because the __ macro sometimes uses macro expansion to turn // double underscore macro because the macro sometimes uses macro
// into something that can't return a value. This is encountered when // expansion to turn into something that can't return a value. This
// doing generated code coverage tests. // is encountered when doing generated code coverage tests.
int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(patch_site()); int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(patch_site());
__ test(value.reg(), Immediate(-delta_to_patch_site)); __ test(value.reg(), Immediate(-delta_to_patch_site));
__ IncrementCounter(&Counters::keyed_load_inline_miss, 1); __ IncrementCounter(&Counters::keyed_load_inline_miss, 1);
...@@ -5381,7 +5379,9 @@ void Reference::GetValue(TypeofState typeof_state) { ...@@ -5381,7 +5379,9 @@ void Reference::GetValue(TypeofState typeof_state) {
// Initially, use an invalid map. The map is patched in the IC // Initially, use an invalid map. The map is patched in the IC
// initialization code. // initialization code.
__ bind(deferred->patch_site()); __ bind(deferred->patch_site());
__ cmp(FieldOperand(receiver.reg(), HeapObject::kMapOffset), // Use masm-> here instead of the double underscore macro since extra
// coverage code can interfere with the patching.
masm->cmp(FieldOperand(receiver.reg(), HeapObject::kMapOffset),
Immediate(Factory::null_value())); Immediate(Factory::null_value()));
deferred->enter()->Branch(not_equal, &receiver, &key, not_taken); deferred->enter()->Branch(not_equal, &receiver, &key, not_taken);
......
...@@ -192,5 +192,41 @@ function BoolTest() { ...@@ -192,5 +192,41 @@ function BoolTest() {
} }
// Some tests of shifts that get into the corners in terms of coverage.
// We generate different code for the case where the operand is a constant.
function ShiftTest() {
var x = 123;
assertEquals(x, x >> 0);
assertEquals(x, x << 0);
assertEquals(x, x >>> 0);
assertEquals(61, x >> 1);
assertEquals(246, x << 1);
assertEquals(61, x >>> 1);
x = -123;
assertEquals(x, x >> 0);
assertEquals(x, x << 0);
assertEquals(0x10000 * 0x10000 + x, x >>> 0);
assertEquals(-62, x >> 1);
assertEquals(-246, x << 1);
assertEquals(0x10000 * 0x8000 - 62, x >>> 1);
// Answer is non-Smi so the subtraction is not folded in the code
// generator.
assertEquals(-0x40000001, -0x3fffffff - 2);
x = 123;
assertEquals(0, x & 0);
// Answer is non-smi and lhs of << is a temporary heap number that we can
// overwrite.
x = 123.0001;
assertEquals(1073741824, (x * x) << 30);
x = 123;
// Answer is non-smi and lhs of << is a temporary heap number that we think
// we can overwrite (but we can't because it's a Smi).
assertEquals(1073741824, (x * x) << 30);
}
test(); test();
BoolTest(); BoolTest();
ShiftTest();
...@@ -144,6 +144,35 @@ runTest = function() { ...@@ -144,6 +144,35 @@ runTest = function() {
runTest(); runTest();
// ----------------------------------------------------------------------
// Indexed access.
// ----------------------------------------------------------------------
runTest = function() {
var o = [ 42, 43 ];
var initial_X = 0;
var X = initial_X;
var Y = 1;
function fieldTest(change_index) {
for (var i = 0; i < 10; i++) {
var property = o[X];
if (i <= change_index) {
assertEquals(42, property);
} else {
assertEquals(43, property);
}
if (i == change_index) X = Y;
}
X = initial_X;
};
for (var i = 0; i < 10; i++) fieldTest(i);
}
runTest();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Constant function access. // Constant function access.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
......
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