Commit 0503ba76 authored by jyan's avatar jyan Committed by Commit bot

S390: [stubs] Split ToNumberStub into reusable subparts.

Port b7aa4c3a

Original commit message:
    Split ToNumberStub into the entry ToNumberStub, and two new stubs,
    StringToNumberStub and NonNumberToNumberStub, which can be used when we
    already know something about the input (i.e. in various branches of the
    code stubs, or in TurboFan graphs).

    Also introduce an appropriate StringToNumber simplified operator for
    TurboFan, that is pure and is lowered to an invocation of the newly
    added StringToNumberStub.

R=bmeurer@chromium.org, joransiu@ca.ibm.com, mbrandy@us.ibm.com, michael_dawson@ca.ibm.com
BUG=

Review URL: https://codereview.chromium.org/1825593003

Cr-Commit-Position: refs/heads/master@{#35004}
parent 716ab0d3
......@@ -2712,10 +2712,9 @@ void SubStringStub::Generate(MacroAssembler* masm) {
void ToNumberStub::Generate(MacroAssembler* masm) {
// The ToNumber stub takes one argument in r2.
Label not_smi;
__ JumpIfNotSmi(r2, &not_smi);
__ b(r14);
__ bind(&not_smi);
STATIC_ASSERT(kSmiTag == 0);
__ TestIfSmi(r2);
__ Ret(eq);
__ CompareObjectType(r2, r3, r3, HEAP_NUMBER_TYPE);
// r2: receiver
......@@ -2725,19 +2724,19 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
__ Ret();
__ bind(&not_heap_number);
Label not_string, slow_string;
__ CmpLogicalP(r3, Operand(FIRST_NONSTRING_TYPE));
__ bge(&not_string, Label::kNear);
// Check if string has a cached array index.
__ LoadlW(r4, FieldMemOperand(r2, String::kHashFieldOffset));
__ AndP(r0, r4, Operand(String::kContainsCachedArrayIndexMask));
__ bne(&slow_string, Label::kNear);
__ IndexFromHash(r4, r2);
__ b(r14);
__ bind(&slow_string);
__ push(r2); // Push argument.
__ TailCallRuntime(Runtime::kStringToNumber);
__ bind(&not_string);
NonNumberToNumberStub stub(masm->isolate());
__ TailCallStub(&stub);
}
void NonNumberToNumberStub::Generate(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in r2.
__ AssertNotNumber(r2);
__ CompareObjectType(r2, r3, r3, FIRST_NONSTRING_TYPE);
// r2: receiver
// r3: receiver instance type
StringToNumberStub stub(masm->isolate());
__ TailCallStub(&stub, lt);
Label not_oddball;
__ CmpP(r3, Operand(ODDBALL_TYPE));
......@@ -2750,6 +2749,23 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kToNumber);
}
void StringToNumberStub::Generate(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in r2.
__ AssertString(r2);
// Check if string has a cached array index.
Label runtime;
__ LoadlW(r4, FieldMemOperand(r2, String::kHashFieldOffset));
__ And(r0, r4, Operand(String::kContainsCachedArrayIndexMask));
__ bne(&runtime);
__ IndexFromHash(r4, r2);
__ Ret();
__ bind(&runtime);
__ push(r2); // Push argument.
__ TailCallRuntime(Runtime::kStringToNumber);
}
void ToLengthStub::Generate(MacroAssembler* masm) {
// The ToLength stub takes one argument in r2.
Label not_smi;
......
......@@ -2925,6 +2925,18 @@ void MacroAssembler::JumpIfEitherSmi(Register reg1, Register reg2,
JumpIfSmi(reg2, on_either_smi);
}
void MacroAssembler::AssertNotNumber(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object);
Check(ne, kOperandIsANumber, cr0);
push(object);
CompareObjectType(object, object, object, HEAP_NUMBER_TYPE);
pop(object);
Check(ne, kOperandIsANumber);
}
}
void MacroAssembler::AssertNotSmi(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
......
......@@ -1630,6 +1630,9 @@ class MacroAssembler : public Assembler {
// Jump if either of the registers contain a smi.
void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
// Abort execution if argument is a number, enabled via --debug-code.
void AssertNotNumber(Register object);
// Abort execution if argument is a smi, enabled via --debug-code.
void AssertNotSmi(Register object);
void AssertSmi(Register object);
......
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