Commit 4ca7b509 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Compare IC: add STRINGS state.

BUG=1340

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7783 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 788db8ae
......@@ -5903,6 +5903,71 @@ void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) {
}
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::STRINGS);
Label miss;
// Registers containing left and right operands respectively.
Register left = r1;
Register right = r0;
Register tmp1 = r2;
Register tmp2 = r3;
Register tmp3 = r4;
Register tmp4 = r5;
// Check that both operands are heap objects.
__ JumpIfEitherSmi(left, right, &miss);
// Check that both operands are strings. This leaves the instance
// types loaded in tmp1 and tmp2.
__ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset));
__ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
__ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset));
__ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset));
STATIC_ASSERT(kNotStringTag != 0);
__ orr(tmp3, tmp1, tmp2);
__ tst(tmp3, Operand(kIsNotStringMask));
__ b(ne, &miss);
// Fast check for identical strings.
__ cmp(left, right);
STATIC_ASSERT(EQUAL == 0);
STATIC_ASSERT(kSmiTag == 0);
__ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq);
__ Ret(eq);
// Handle not identical strings.
// Check that both strings are symbols. If they are, we're done
// because we already know they are not identical.
ASSERT(GetCondition() == eq);
STATIC_ASSERT(kSymbolTag != 0);
__ and_(tmp3, tmp1, Operand(tmp2));
__ tst(tmp3, Operand(kIsSymbolMask));
// Make sure r0 is non-zero. At this point input operands are
// guaranteed to be non-zero.
ASSERT(right.is(r0));
__ Ret(ne);
// Check that both strings are sequential ASCII.
Label runtime;
__ JumpIfBothInstanceTypesAreNotSequentialAscii(tmp1, tmp2, tmp3, tmp4,
&runtime);
// Compare flat ASCII strings. Returns when done.
StringCompareStub::GenerateCompareFlatAsciiStrings(
masm, left, right, tmp1, tmp2, tmp3, tmp4);
// Handle more complex cases in runtime.
__ bind(&runtime);
__ Push(left, right);
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
__ bind(&miss);
GenerateMiss(masm);
}
void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::OBJECTS);
Label miss;
......
......@@ -197,6 +197,9 @@ void ICCompareStub::Generate(MacroAssembler* masm) {
case CompareIC::HEAP_NUMBERS:
GenerateHeapNumbers(masm);
break;
case CompareIC::STRINGS:
GenerateStrings(masm);
break;
case CompareIC::OBJECTS:
GenerateObjects(masm);
break;
......
......@@ -424,6 +424,7 @@ class ICCompareStub: public CodeStub {
void GenerateSmis(MacroAssembler* masm);
void GenerateHeapNumbers(MacroAssembler* masm);
void GenerateStrings(MacroAssembler* masm);
void GenerateObjects(MacroAssembler* masm);
void GenerateMiss(MacroAssembler* masm);
......
......@@ -5806,6 +5806,83 @@ void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) {
}
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::STRINGS);
Label miss;
// Registers containing left and right operands respectively.
Register left = edx;
Register right = eax;
Register tmp1 = ecx;
Register tmp2 = ebx;
Register tmp3 = edi;
// Check that both operands are heap objects.
__ mov(tmp1, Operand(left));
STATIC_ASSERT(kSmiTag == 0);
__ and_(tmp1, Operand(right));
__ test(tmp1, Immediate(kSmiTagMask));
__ j(zero, &miss);
// Check that both operands are strings. This leaves the instance
// types loaded in tmp1 and tmp2.
__ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset));
__ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset));
__ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
__ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
__ mov(tmp3, tmp1);
STATIC_ASSERT(kNotStringTag != 0);
__ or_(tmp3, Operand(tmp2));
__ test(tmp3, Immediate(kIsNotStringMask));
__ j(not_zero, &miss);
// Fast check for identical strings.
NearLabel not_same;
__ cmp(left, Operand(right));
__ j(not_equal, &not_same);
STATIC_ASSERT(EQUAL == 0);
STATIC_ASSERT(kSmiTag == 0);
__ Set(eax, Immediate(Smi::FromInt(EQUAL)));
__ ret(0);
// Handle not identical strings.
__ bind(&not_same);
// Check that both strings are symbols. If they are, we're done
// because we already know they are not identical.
NearLabel do_compare;
ASSERT(GetCondition() == equal);
STATIC_ASSERT(kSymbolTag != 0);
__ and_(tmp1, Operand(tmp2));
__ test(tmp1, Immediate(kIsSymbolMask));
__ j(zero, &do_compare);
// Make sure eax is non-zero. At this point input operands are
// guaranteed to be non-zero.
ASSERT(right.is(eax));
__ ret(0);
// Check that both strings are sequential ASCII.
Label runtime;
__ bind(&do_compare);
__ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime);
// Compare flat ASCII strings. Returns when done.
StringCompareStub::GenerateCompareFlatAsciiStrings(
masm, left, right, tmp1, tmp2, tmp3);
// Handle more complex cases in runtime.
__ bind(&runtime);
__ pop(tmp1); // Return address.
__ push(left);
__ push(right);
__ push(tmp1);
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
__ bind(&miss);
GenerateMiss(masm);
}
void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::OBJECTS);
NearLabel miss;
......
......@@ -2141,6 +2141,7 @@ const char* CompareIC::GetStateName(State state) {
case SMIS: return "SMIS";
case HEAP_NUMBERS: return "HEAP_NUMBERS";
case OBJECTS: return "OBJECTS";
case STRINGS: return "STRINGS";
case GENERIC: return "GENERIC";
default:
UNREACHABLE();
......@@ -2158,6 +2159,8 @@ CompareIC::State CompareIC::TargetState(State state,
if ((state == UNINITIALIZED || (state == SMIS && has_inlined_smi_code)) &&
x->IsNumber() && y->IsNumber()) return HEAP_NUMBERS;
if (op_ != Token::EQ && op_ != Token::EQ_STRICT) return GENERIC;
if (state == UNINITIALIZED &&
x->IsString() && y->IsString()) return STRINGS;
if (state == UNINITIALIZED &&
x->IsJSObject() && y->IsJSObject()) return OBJECTS;
return GENERIC;
......
......@@ -592,6 +592,7 @@ class CompareIC: public IC {
UNINITIALIZED,
SMIS,
HEAP_NUMBERS,
STRINGS,
OBJECTS,
GENERIC
};
......
......@@ -4685,6 +4685,81 @@ void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) {
}
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::STRINGS);
Label miss;
// Registers containing left and right operands respectively.
Register left = rdx;
Register right = rax;
Register tmp1 = rcx;
Register tmp2 = rbx;
Register tmp3 = rdi;
Register tmp4 = r8;
// Check that both operands are heap objects.
Condition cond = masm->CheckEitherSmi(left, right, tmp1);
__ j(cond, &miss);
// Check that both operands are strings. This leaves the instance
// types loaded in tmp1 and tmp2.
__ movq(tmp1, FieldOperand(left, HeapObject::kMapOffset));
__ movq(tmp2, FieldOperand(right, HeapObject::kMapOffset));
__ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
__ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
__ movq(tmp3, tmp1);
STATIC_ASSERT(kNotStringTag != 0);
__ or_(tmp3, tmp2);
__ testl(tmp3, Immediate(kIsNotStringMask));
__ j(not_zero, &miss);
// Fast check for identical strings.
NearLabel not_same;
__ cmpq(left, right);
__ j(not_equal, &not_same);
STATIC_ASSERT(EQUAL == 0);
STATIC_ASSERT(kSmiTag == 0);
__ Move(rax, Smi::FromInt(EQUAL));
__ ret(0);
// Handle not identical strings.
__ bind(&not_same);
// Check that both strings are symbols. If they are, we're done
// because we already know they are not identical.
NearLabel do_compare;
ASSERT(GetCondition() == equal);
STATIC_ASSERT(kSymbolTag != 0);
__ and_(tmp1, tmp2);
__ testl(tmp1, Immediate(kIsSymbolMask));
__ j(zero, &do_compare);
// Make sure rax is non-zero. At this point input operands are
// guaranteed to be non-zero.
ASSERT(right.is(rax));
__ ret(0);
// Check that both strings are sequential ASCII.
Label runtime;
__ bind(&do_compare);
__ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime);
// Compare flat ASCII strings. Returns when done.
StringCompareStub::GenerateCompareFlatAsciiStrings(
masm, left, right, tmp1, tmp2, tmp3, tmp4);
// Handle more complex cases in runtime.
__ bind(&runtime);
__ pop(tmp1); // Return address.
__ push(left);
__ push(right);
__ push(tmp1);
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
__ bind(&miss);
GenerateMiss(masm);
}
void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
ASSERT(state_ == CompareIC::OBJECTS);
NearLabel miss;
......
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