Commit 236d7005 authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: [stubs] Split ToNumberStub into reusable subparts.

  port b7aa4c3a (r34922)

  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.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#34971}
parent dcee82d6
......@@ -2328,23 +2328,21 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
__ Ret();
__ bind(&not_heap_number);
Label not_string, slow_string;
NonNumberToNumberStub stub(masm->isolate());
__ TailCallStub(&stub);
}
void NonNumberToNumberStub::Generate(MacroAssembler* masm) {
// The NonNumberToNumber stub takes one argument in eax.
__ AssertNotNumber(eax);
Label not_string;
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
// eax: object
// edi: object map
__ j(above_equal, &not_string, Label::kNear);
// Check if string has a cached array index.
__ test(FieldOperand(eax, String::kHashFieldOffset),
Immediate(String::kContainsCachedArrayIndexMask));
__ j(not_zero, &slow_string, Label::kNear);
__ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
__ IndexFromHash(eax, eax);
__ Ret();
__ bind(&slow_string);
__ pop(ecx); // Pop return address.
__ push(eax); // Push argument.
__ push(ecx); // Push return address.
__ TailCallRuntime(Runtime::kStringToNumber);
StringToNumberStub stub(masm->isolate());
__ TailCallStub(&stub);
__ bind(&not_string);
Label not_oddball;
......@@ -2360,6 +2358,25 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kToNumber);
}
void StringToNumberStub::Generate(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in eax.
__ AssertString(eax);
// Check if string has a cached array index.
Label runtime;
__ test(FieldOperand(eax, String::kHashFieldOffset),
Immediate(String::kContainsCachedArrayIndexMask));
__ j(not_zero, &runtime, Label::kNear);
__ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
__ IndexFromHash(eax, eax);
__ Ret();
__ bind(&runtime);
__ PopReturnAddressTo(ecx); // Pop return address.
__ Push(eax); // Push argument.
__ PushReturnAddressFrom(ecx); // Push return address.
__ TailCallRuntime(Runtime::kStringToNumber);
}
void ToLengthStub::Generate(MacroAssembler* masm) {
// The ToLength stub takes on argument in eax.
......
......@@ -907,6 +907,15 @@ void MacroAssembler::AssertNumber(Register object) {
}
}
void MacroAssembler::AssertNotNumber(Register object) {
if (emit_debug_code()) {
test(object, Immediate(kSmiTagMask));
Check(not_equal, kOperandIsANumber);
cmp(FieldOperand(object, HeapObject::kMapOffset),
isolate()->factory()->heap_number_map());
Check(not_equal, kOperandIsANumber);
}
}
void MacroAssembler::AssertSmi(Register object) {
if (emit_debug_code()) {
......
......@@ -531,6 +531,7 @@ class MacroAssembler: public Assembler {
// Abort execution if argument is not a number, enabled via --debug-code.
void AssertNumber(Register object);
void AssertNotNumber(Register object);
// Abort execution if argument is not a smi, enabled via --debug-code.
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