From 8016547c8e6fde00fff0a1791f3c83b444d8af25 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Fri, 18 Sep 2015 01:30:22 -0700 Subject: [PATCH] [stubs] Refactor StringCompareStub and use it for HStringCompareAndBranch. The StringCompareStub used to take its parameters on the (JavaScript) stack, which made it impossible to use in TurboFan. Actually StringCompareStub was currently completely unused. This changes the calling convention to something TurboFan compatible and introduces a CallInterfaceDescriptor for StringCompareStub. It also changes HStringCompareAndBranch to use the StringCompareStub instead of using the full blown CompareICStub for a stupid string comparison. R=jarin@chromium.org Review URL: https://codereview.chromium.org/1347913003 Cr-Commit-Position: refs/heads/master@{#30818} --- src/arm/code-stubs-arm.cc | 29 +++++++------ src/arm/interface-descriptors-arm.cc | 4 ++ src/arm/lithium-codegen-arm.cc | 18 +++------ src/arm64/code-stubs-arm64.cc | 47 +++++++++------------- src/arm64/interface-descriptors-arm64.cc | 4 ++ src/arm64/lithium-codegen-arm64.cc | 18 +++------ src/code-factory.cc | 7 ++++ src/code-factory.h | 1 + src/code-stubs.h | 6 ++- src/hydrogen-instructions.h | 24 +++++------ src/ia32/code-stubs-ia32.cc | 30 +++++++------- src/ia32/interface-descriptors-ia32.cc | 4 ++ src/ia32/lithium-codegen-ia32.cc | 20 ++++----- src/ia32/lithium-ia32.h | 2 +- src/interface-descriptors.cc | 7 ++++ src/interface-descriptors.h | 11 +++++ src/mips/code-stubs-mips.cc | 31 +++++++------- src/mips/interface-descriptors-mips.cc | 4 ++ src/mips/lithium-codegen-mips.cc | 18 +++------ src/mips64/code-stubs-mips64.cc | 35 ++++++++-------- src/mips64/interface-descriptors-mips64.cc | 4 ++ src/mips64/lithium-codegen-mips64.cc | 18 +++------ src/x64/code-stubs-x64.cc | 33 +++++++-------- src/x64/interface-descriptors-x64.cc | 4 ++ src/x64/lithium-codegen-x64.cc | 17 +++----- 25 files changed, 194 insertions(+), 202 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 7996779a1..cb7d15fce 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -3319,38 +3319,37 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - Counters* counters = isolate()->counters(); - - // Stack frame on entry. - // sp[0]: right string - // sp[4]: left string - __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1. + // ----------- S t a t e ------------- + // -- r1 : left + // -- r0 : right + // -- lr : return address + // ----------------------------------- + __ AssertString(r1); + __ AssertString(r0); Label not_same; __ cmp(r0, r1); __ b(ne, ¬_same); - STATIC_ASSERT(EQUAL == 0); - STATIC_ASSERT(kSmiTag == 0); __ mov(r0, Operand(Smi::FromInt(EQUAL))); - __ IncrementCounter(counters->string_compare_native(), 1, r1, r2); - __ add(sp, sp, Operand(2 * kPointerSize)); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r1, + r2); __ Ret(); __ bind(¬_same); // Check that both objects are sequential one-byte strings. + Label runtime; __ JumpIfNotBothSequentialOneByteStrings(r1, r0, r2, r3, &runtime); - // Compare flat one-byte strings natively. Remove arguments from stack first. - __ IncrementCounter(counters->string_compare_native(), 1, r2, r3); - __ add(sp, sp, Operand(2 * kPointerSize)); + // Compare flat one-byte strings natively. + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, r2, + r3); StringHelper::GenerateCompareFlatOneByteStrings(masm, r1, r0, r2, r3, r4, r5); // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) // tagged as a small integer. __ bind(&runtime); + __ Push(r1, r0); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/arm/interface-descriptors-arm.cc b/src/arm/interface-descriptors-arm.cc index 09fdd5bad..52084fd3d 100644 --- a/src/arm/interface-descriptors-arm.cc +++ b/src/arm/interface-descriptors-arm.cc @@ -52,6 +52,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return r1; } const Register InstanceOfDescriptor::RightRegister() { return r0; } +const Register StringCompareDescriptor::LeftRegister() { return r1; } +const Register StringCompareDescriptor::RightRegister() { return r0; } + + const Register ArgumentsAccessReadDescriptor::index() { return r1; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return r0; } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 3049ddbce..b16306145 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -1065,11 +1065,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -2534,17 +2529,14 @@ static Condition ComputeCompareCondition(Token::Value op) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); - Token::Value op = instr->op(); + DCHECK(ToRegister(instr->left()).is(r1)); + DCHECK(ToRegister(instr->right()).is(r0)); - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); - // This instruction also signals no smi code inlined. + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); __ cmp(r0, Operand::Zero()); - Condition condition = ComputeCompareCondition(op); - - EmitBranch(instr, condition); + EmitBranch(instr, ComputeCompareCondition(instr->op())); } diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index 7173bdbf2..e93fe44e7 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -4042,45 +4042,38 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - Counters* counters = isolate()->counters(); - - // Stack frame on entry. - // sp[0]: right string - // sp[8]: left string - Register right = x10; - Register left = x11; - Register result = x0; - __ Pop(right, left); + // ----------- S t a t e ------------- + // -- x1 : left + // -- x0 : right + // -- lr : return address + // ----------------------------------- + __ AssertString(x1); + __ AssertString(x0); Label not_same; - __ Subs(result, right, left); + __ Cmp(x0, x1); __ B(ne, ¬_same); - STATIC_ASSERT(EQUAL == 0); - __ IncrementCounter(counters->string_compare_native(), 1, x3, x4); + __ Mov(x0, Smi::FromInt(EQUAL)); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3, + x4); __ Ret(); __ Bind(¬_same); // Check that both objects are sequential one-byte strings. - __ JumpIfEitherIsNotSequentialOneByteStrings(left, right, x12, x13, &runtime); - - // Compare flat one-byte strings natively. Remove arguments from stack first, - // as this function will generate a return. - __ IncrementCounter(counters->string_compare_native(), 1, x3, x4); - StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, x12, x13, - x14, x15); - - __ Bind(&runtime); + Label runtime; + __ JumpIfEitherIsNotSequentialOneByteStrings(x1, x0, x12, x13, &runtime); - // Push arguments back on to the stack. - // sp[0] = right string - // sp[8] = left string. - __ Push(left, right); + // Compare flat one-byte strings natively. + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, x3, + x4); + StringHelper::GenerateCompareFlatOneByteStrings(masm, x1, x0, x12, x13, x14, + x15); // Call the runtime. // Returns -1 (less), 0 (equal), or 1 (greater) tagged as a small integer. + __ Bind(&runtime); + __ Push(x1, x0); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/arm64/interface-descriptors-arm64.cc b/src/arm64/interface-descriptors-arm64.cc index 76bcca3e5..5c117025c 100644 --- a/src/arm64/interface-descriptors-arm64.cc +++ b/src/arm64/interface-descriptors-arm64.cc @@ -52,6 +52,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return x1; } const Register InstanceOfDescriptor::RightRegister() { return x0; } +const Register StringCompareDescriptor::LeftRegister() { return x1; } +const Register StringCompareDescriptor::RightRegister() { return x0; } + + const Register ArgumentsAccessReadDescriptor::index() { return x1; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return x0; } diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index e256ed0b0..488e14f82 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -2098,11 +2098,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -5503,16 +5498,13 @@ void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); - Token::Value op = instr->op(); - - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); - InlineSmiCheckInfo::EmitNotInlined(masm()); + DCHECK(ToRegister(instr->left()).is(x1)); + DCHECK(ToRegister(instr->right()).is(x0)); - Condition condition = TokenToCondition(op, false); + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); - EmitCompareAndBranch(instr, condition, x0, 0); + EmitCompareAndBranch(instr, TokenToCondition(instr->op(), false), x0, 0); } diff --git a/src/code-factory.cc b/src/code-factory.cc index 63dba9d42..0d6b36b9d 100644 --- a/src/code-factory.cc +++ b/src/code-factory.cc @@ -197,6 +197,13 @@ Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags, } +// static +Callable CodeFactory::StringCompare(Isolate* isolate) { + StringCompareStub stub(isolate); + return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); +} + + // static Callable CodeFactory::Typeof(Isolate* isolate) { TypeofStub stub(isolate); diff --git a/src/code-factory.h b/src/code-factory.h index 89507d1a1..a67b5b81e 100644 --- a/src/code-factory.h +++ b/src/code-factory.h @@ -78,6 +78,7 @@ class CodeFactory final { static Callable StringAdd(Isolate* isolate, StringAddFlags flags, PretenureFlag pretenure_flag); + static Callable StringCompare(Isolate* isolate); static Callable Typeof(Isolate* isolate); diff --git a/src/code-stubs.h b/src/code-stubs.h index f793e6e5d..20da57f02 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -3064,7 +3064,7 @@ class StringCompareStub : public PlatformCodeStub { public: explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {} - DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly); + DEFINE_CALL_INTERFACE_DESCRIPTOR(StringCompare); DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub); }; @@ -3077,6 +3077,8 @@ class StringCompareStub : public PlatformCodeStub { #undef DEFINE_CODE_STUB_BASE extern Representation RepresentationFromType(Type* type); -} } // namespace v8::internal + +} // namespace internal +} // namespace v8 #endif // V8_CODE_STUBS_H_ diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index f81d8771a..f39cbf70b 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -4526,34 +4526,28 @@ class HIsUndetectableAndBranch final : public HUnaryControlInstruction { }; -class HStringCompareAndBranch : public HTemplateControlInstruction<2, 3> { +class HStringCompareAndBranch final : public HTemplateControlInstruction<2, 3> { public: DECLARE_INSTRUCTION_WITH_CONTEXT_FACTORY_P3(HStringCompareAndBranch, HValue*, HValue*, Token::Value); - HValue* context() { return OperandAt(0); } - HValue* left() { return OperandAt(1); } - HValue* right() { return OperandAt(2); } + HValue* context() const { return OperandAt(0); } + HValue* left() const { return OperandAt(1); } + HValue* right() const { return OperandAt(2); } Token::Value token() const { return token_; } - std::ostream& PrintDataTo(std::ostream& os) const override; // NOLINT - - Representation RequiredInputRepresentation(int index) override { - return Representation::Tagged(); - } + std::ostream& PrintDataTo(std::ostream& os) const final; // NOLINT - Representation GetInputRepresentation() const { + Representation RequiredInputRepresentation(int index) final { return Representation::Tagged(); } DECLARE_CONCRETE_INSTRUCTION(StringCompareAndBranch) private: - HStringCompareAndBranch(HValue* context, - HValue* left, - HValue* right, + HStringCompareAndBranch(HValue* context, HValue* left, HValue* right, Token::Value token) : token_(token) { DCHECK(Token::IsCompareOp(token)); @@ -4562,9 +4556,11 @@ class HStringCompareAndBranch : public HTemplateControlInstruction<2, 3> { SetOperandAt(2, right); set_representation(Representation::Tagged()); SetChangesFlag(kNewSpacePromotion); + SetDependsOnFlag(kStringChars); + SetDependsOnFlag(kStringLengths); } - Token::Value token_; + Token::Value const token_; }; diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index e698c658f..3cb99eb07 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -3362,41 +3362,39 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - // Stack frame on entry. - // esp[0]: return address - // esp[4]: right string - // esp[8]: left string - - __ mov(edx, Operand(esp, 2 * kPointerSize)); // left - __ mov(eax, Operand(esp, 1 * kPointerSize)); // right + // ----------- S t a t e ------------- + // -- edx : left string + // -- eax : right string + // -- esp[0] : return address + // ----------------------------------- + __ AssertString(edx); + __ AssertString(eax); Label not_same; __ cmp(edx, eax); __ j(not_equal, ¬_same, Label::kNear); - STATIC_ASSERT(EQUAL == 0); - STATIC_ASSERT(kSmiTag == 0); __ Move(eax, Immediate(Smi::FromInt(EQUAL))); __ IncrementCounter(isolate()->counters()->string_compare_native(), 1); - __ ret(2 * kPointerSize); + __ Ret(); __ bind(¬_same); // Check that both objects are sequential one-byte strings. + Label runtime; __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx, &runtime); // Compare flat one-byte strings. - // Drop arguments from the stack. - __ pop(ecx); - __ add(esp, Immediate(2 * kPointerSize)); - __ push(ecx); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1); StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx, edi); // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) // tagged as a small integer. __ bind(&runtime); + __ PopReturnAddressTo(ecx); + __ Push(edx); + __ Push(eax); + __ PushReturnAddressFrom(ecx); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/ia32/interface-descriptors-ia32.cc b/src/ia32/interface-descriptors-ia32.cc index 0fea67b76..9ced41000 100644 --- a/src/ia32/interface-descriptors-ia32.cc +++ b/src/ia32/interface-descriptors-ia32.cc @@ -57,6 +57,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return edx; } const Register InstanceOfDescriptor::RightRegister() { return eax; } +const Register StringCompareDescriptor::LeftRegister() { return edx; } +const Register StringCompareDescriptor::RightRegister() { return eax; } + + const Register ArgumentsAccessReadDescriptor::index() { return edx; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return eax; } diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 16fe6694a..99c0938b6 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -1071,11 +1071,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -2441,16 +2436,15 @@ static Condition ComputeCompareCondition(Token::Value op) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { - Token::Value op = instr->op(); - - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); + DCHECK(ToRegister(instr->context()).is(esi)); + DCHECK(ToRegister(instr->left()).is(edx)); + DCHECK(ToRegister(instr->right()).is(eax)); - Condition condition = ComputeCompareCondition(op); - __ test(eax, Operand(eax)); + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); + __ test(eax, eax); - EmitBranch(instr, condition); + EmitBranch(instr, ComputeCompareCondition(instr->op())); } diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index 41468fdb8..9e4b885c4 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -1055,7 +1055,7 @@ class LStringCompareAndBranch final : public LControlInstruction<3, 0> { inputs_[2] = right; } - LOperand* context() { return inputs_[1]; } + LOperand* context() { return inputs_[0]; } LOperand* left() { return inputs_[1]; } LOperand* right() { return inputs_[2]; } diff --git a/src/interface-descriptors.cc b/src/interface-descriptors.cc index b66f67c1d..b446d6396 100644 --- a/src/interface-descriptors.cc +++ b/src/interface-descriptors.cc @@ -167,6 +167,13 @@ void InstanceOfDescriptor::InitializePlatformSpecific( } +void StringCompareDescriptor::InitializePlatformSpecific( + CallInterfaceDescriptorData* data) { + Register registers[] = {LeftRegister(), RightRegister()}; + data->InitializePlatformSpecific(arraysize(registers), registers); +} + + void ToStringDescriptor::InitializePlatformSpecific( CallInterfaceDescriptorData* data) { Register registers[] = {ReceiverRegister()}; diff --git a/src/interface-descriptors.h b/src/interface-descriptors.h index 06e586e87..6866a97d1 100644 --- a/src/interface-descriptors.h +++ b/src/interface-descriptors.h @@ -52,6 +52,7 @@ class PlatformInterfaceDescriptor; V(BinaryOp) \ V(BinaryOpWithAllocationSite) \ V(StringAdd) \ + V(StringCompare) \ V(Keyed) \ V(Named) \ V(CallHandler) \ @@ -570,6 +571,16 @@ class StringAddDescriptor : public CallInterfaceDescriptor { }; +class StringCompareDescriptor : public CallInterfaceDescriptor { + public: + DECLARE_DESCRIPTOR(StringCompareDescriptor, CallInterfaceDescriptor) + + enum ParameterIndices { kLeftIndex, kRightIndex, kParameterCount }; + static const Register LeftRegister(); + static const Register RightRegister(); +}; + + class KeyedDescriptor : public CallInterfaceDescriptor { public: DECLARE_DESCRIPTOR(KeyedDescriptor, CallInterfaceDescriptor) diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index ae038075b..78c24cf9b 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -3482,35 +3482,34 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - Counters* counters = isolate()->counters(); - - // Stack frame on entry. - // sp[0]: right string - // sp[4]: left string - __ lw(a1, MemOperand(sp, 1 * kPointerSize)); // Left. - __ lw(a0, MemOperand(sp, 0 * kPointerSize)); // Right. + // ----------- S t a t e ------------- + // -- a1 : left + // -- a0 : right + // -- ra : return address + // ----------------------------------- + __ AssertString(a1); + __ AssertString(a0); Label not_same; __ Branch(¬_same, ne, a0, Operand(a1)); - STATIC_ASSERT(EQUAL == 0); - STATIC_ASSERT(kSmiTag == 0); __ li(v0, Operand(Smi::FromInt(EQUAL))); - __ IncrementCounter(counters->string_compare_native(), 1, a1, a2); - __ DropAndRet(2); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1, + a2); + __ Ret(); __ bind(¬_same); // Check that both objects are sequential one-byte strings. + Label runtime; __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime); - // Compare flat ASCII strings natively. Remove arguments from stack first. - __ IncrementCounter(counters->string_compare_native(), 1, a2, a3); - __ Addu(sp, sp, Operand(2 * kPointerSize)); + // Compare flat ASCII strings natively. + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, + a3); StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1); __ bind(&runtime); + __ Push(a1, a0); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/mips/interface-descriptors-mips.cc b/src/mips/interface-descriptors-mips.cc index 3e566293a..06bf028c6 100644 --- a/src/mips/interface-descriptors-mips.cc +++ b/src/mips/interface-descriptors-mips.cc @@ -50,6 +50,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return a1; } const Register InstanceOfDescriptor::RightRegister() { return a0; } +const Register StringCompareDescriptor::LeftRegister() { return a1; } +const Register StringCompareDescriptor::RightRegister() { return a0; } + + const Register ArgumentsAccessReadDescriptor::index() { return a1; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return a0; } diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index 9d914838f..9e45868f8 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -1032,11 +1032,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -2459,15 +2454,14 @@ static Condition ComputeCompareCondition(Token::Value op) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); - Token::Value op = instr->op(); - - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); + DCHECK(ToRegister(instr->left()).is(a1)); + DCHECK(ToRegister(instr->right()).is(a0)); - Condition condition = ComputeCompareCondition(op); + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); - EmitBranch(instr, condition, v0, Operand(zero_reg)); + EmitBranch(instr, ComputeCompareCondition(instr->op()), v0, + Operand(zero_reg)); } diff --git a/src/mips64/code-stubs-mips64.cc b/src/mips64/code-stubs-mips64.cc index 98ca8521c..9df14e387 100644 --- a/src/mips64/code-stubs-mips64.cc +++ b/src/mips64/code-stubs-mips64.cc @@ -3514,35 +3514,34 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - Counters* counters = isolate()->counters(); - - // Stack frame on entry. - // sp[0]: right string - // sp[4]: left string - __ ld(a1, MemOperand(sp, 1 * kPointerSize)); // Left. - __ ld(a0, MemOperand(sp, 0 * kPointerSize)); // Right. + // ----------- S t a t e ------------- + // -- a1 : left + // -- a0 : right + // -- ra : return address + // ----------------------------------- + __ AssertString(a1); + __ AssertString(a0); Label not_same; __ Branch(¬_same, ne, a0, Operand(a1)); - STATIC_ASSERT(EQUAL == 0); - STATIC_ASSERT(kSmiTag == 0); __ li(v0, Operand(Smi::FromInt(EQUAL))); - __ IncrementCounter(counters->string_compare_native(), 1, a1, a2); - __ DropAndRet(2); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a1, + a2); + __ Ret(); __ bind(¬_same); - // Check that both objects are sequential one_byte strings. + // Check that both objects are sequential one-byte strings. + Label runtime; __ JumpIfNotBothSequentialOneByteStrings(a1, a0, a2, a3, &runtime); - // Compare flat one_byte strings natively. Remove arguments from stack first. - __ IncrementCounter(counters->string_compare_native(), 1, a2, a3); - __ Daddu(sp, sp, Operand(2 * kPointerSize)); - StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, a4, a5); + // Compare flat ASCII strings natively. + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1, a2, + a3); + StringHelper::GenerateCompareFlatOneByteStrings(masm, a1, a0, a2, a3, t0, t1); __ bind(&runtime); + __ Push(a1, a0); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/mips64/interface-descriptors-mips64.cc b/src/mips64/interface-descriptors-mips64.cc index 42513e086..98a2821f8 100644 --- a/src/mips64/interface-descriptors-mips64.cc +++ b/src/mips64/interface-descriptors-mips64.cc @@ -50,6 +50,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return a1; } const Register InstanceOfDescriptor::RightRegister() { return a0; } +const Register StringCompareDescriptor::LeftRegister() { return a1; } +const Register StringCompareDescriptor::RightRegister() { return a0; } + + const Register ArgumentsAccessReadDescriptor::index() { return a1; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return a0; } diff --git a/src/mips64/lithium-codegen-mips64.cc b/src/mips64/lithium-codegen-mips64.cc index 810414dd7..4c7655113 100644 --- a/src/mips64/lithium-codegen-mips64.cc +++ b/src/mips64/lithium-codegen-mips64.cc @@ -1021,11 +1021,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -2563,15 +2558,14 @@ static Condition ComputeCompareCondition(Token::Value op) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(cp)); - Token::Value op = instr->op(); - - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); + DCHECK(ToRegister(instr->left()).is(a1)); + DCHECK(ToRegister(instr->right()).is(a0)); - Condition condition = ComputeCompareCondition(op); + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); - EmitBranch(instr, condition, v0, Operand(zero_reg)); + EmitBranch(instr, ComputeCompareCondition(instr->op()), v0, + Operand(zero_reg)); } diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index dde834f8e..86cca8979 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -3316,43 +3316,40 @@ void StringHelper::GenerateOneByteCharsCompareLoop( void StringCompareStub::Generate(MacroAssembler* masm) { - Label runtime; - - // Stack frame on entry. - // rsp[0] : return address - // rsp[8] : right string - // rsp[16] : left string - - StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER); - __ movp(rdx, args.GetArgumentOperand(0)); // left - __ movp(rax, args.GetArgumentOperand(1)); // right + // ----------- S t a t e ------------- + // -- rdx : left string + // -- rax : right string + // -- rsp[0] : return address + // ----------------------------------- + __ AssertString(rdx); + __ AssertString(rax); // Check for identity. Label not_same; __ cmpp(rdx, rax); __ j(not_equal, ¬_same, Label::kNear); __ Move(rax, Smi::FromInt(EQUAL)); - Counters* counters = isolate()->counters(); - __ IncrementCounter(counters->string_compare_native(), 1); - __ ret(2 * kPointerSize); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1); + __ Ret(); __ bind(¬_same); // Check that both are sequential one-byte strings. + Label runtime; __ JumpIfNotBothSequentialOneByteStrings(rdx, rax, rcx, rbx, &runtime); // Inline comparison of one-byte strings. - __ IncrementCounter(counters->string_compare_native(), 1); - // Drop arguments from the stack - __ PopReturnAddressTo(rcx); - __ addp(rsp, Immediate(2 * kPointerSize)); - __ PushReturnAddressFrom(rcx); + __ IncrementCounter(isolate()->counters()->string_compare_native(), 1); StringHelper::GenerateCompareFlatOneByteStrings(masm, rdx, rax, rcx, rbx, rdi, r8); // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) // tagged as a small integer. __ bind(&runtime); + __ PopReturnAddressTo(rcx); + __ Push(rdx); + __ Push(rax); + __ PushReturnAddressFrom(rcx); __ TailCallRuntime(Runtime::kStringCompare, 2, 1); } diff --git a/src/x64/interface-descriptors-x64.cc b/src/x64/interface-descriptors-x64.cc index 146d9a89a..ada386ffc 100644 --- a/src/x64/interface-descriptors-x64.cc +++ b/src/x64/interface-descriptors-x64.cc @@ -50,6 +50,10 @@ const Register InstanceOfDescriptor::LeftRegister() { return rdx; } const Register InstanceOfDescriptor::RightRegister() { return rax; } +const Register StringCompareDescriptor::LeftRegister() { return rdx; } +const Register StringCompareDescriptor::RightRegister() { return rax; } + + const Register ArgumentsAccessReadDescriptor::index() { return rdx; } const Register ArgumentsAccessReadDescriptor::parameter_count() { return rax; } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 7ef838ab1..81d275f7a 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -999,11 +999,6 @@ void LCodeGen::DoCallStub(LCallStub* instr) { CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); break; } - case CodeStub::StringCompare: { - StringCompareStub stub(isolate()); - CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); - break; - } default: UNREACHABLE(); } @@ -2491,16 +2486,14 @@ void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { DCHECK(ToRegister(instr->context()).is(rsi)); - Token::Value op = instr->op(); - - Handle ic = - CodeFactory::CompareIC(isolate(), op, Strength::WEAK).code(); - CallCode(ic, RelocInfo::CODE_TARGET, instr); + DCHECK(ToRegister(instr->left()).is(rdx)); + DCHECK(ToRegister(instr->right()).is(rax)); - Condition condition = TokenToCondition(op, false); + Handle code = CodeFactory::StringCompare(isolate()).code(); + CallCode(code, RelocInfo::CODE_TARGET, instr); __ testp(rax, rax); - EmitBranch(instr, condition); + EmitBranch(instr, TokenToCondition(instr->op(), false)); } -- 2.34.1