Commit ab32e67f authored by Alexander.Gilday2's avatar Alexander.Gilday2 Committed by Commit bot

[builtins] Migrate StringToNumber to TurboFan builtin.

Migrate the platform StringToNumber builtin to TurboFan.

BUG=v8:5049

Review-Url: https://codereview.chromium.org/2235983003
Cr-Commit-Position: refs/heads/master@{#38573}
parent 7c3be989
......@@ -2759,31 +2759,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in r0.
__ AssertString(r0);
// Check if string has a cached array index.
Label runtime;
__ ldr(r2, FieldMemOperand(r0, String::kHashFieldOffset));
__ tst(r2, Operand(String::kContainsCachedArrayIndexMask));
__ b(ne, &runtime);
__ IndexFromHash(r2, r0);
__ Ret();
__ bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(r0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in r0.
STATIC_ASSERT(kSmiTag == 0);
......
......@@ -2846,31 +2846,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in x0.
__ AssertString(x0);
// Check if string has a cached array index.
Label runtime;
__ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset));
__ Tst(x2, Operand(String::kContainsCachedArrayIndexMask));
__ B(ne, &runtime);
__ IndexFromHash(x2, x0);
__ Ret();
__ Bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(x0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in x0.
......
......@@ -109,6 +109,38 @@ void Builtins::Generate_NonPrimitiveToPrimitive_String(
Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kString);
}
void Builtins::Generate_StringToNumber(CodeStubAssembler* assembler) {
typedef CodeStubAssembler::Label Label;
typedef compiler::Node Node;
typedef TypeConversionDescriptor Descriptor;
Node* input = assembler->Parameter(Descriptor::kArgument);
Node* context = assembler->Parameter(Descriptor::kContext);
Label runtime(assembler);
// Check if string has a cached array index.
Node* hash = assembler->LoadNameHashField(input);
Node* bit = assembler->Word32And(
hash, assembler->Int32Constant(String::kContainsCachedArrayIndexMask));
assembler->GotoIf(assembler->Word32NotEqual(bit, assembler->Int32Constant(0)),
&runtime);
assembler->Return(assembler->SmiTag(
assembler->BitFieldDecode<String::ArrayIndexValueBits>(hash)));
assembler->Bind(&runtime);
{
// Note: We cannot tail call to the runtime here, as js-to-wasm
// trampolines also use this code currently, and they declare all
// outgoing parameters as untagged, while we would push a tagged
// object here.
Node* result =
assembler->CallRuntime(Runtime::kStringToNumber, context, input);
assembler->Return(result);
}
}
// ES6 section 7.1.3 ToNumber ( argument )
void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) {
typedef CodeStubAssembler::Label Label;
......
......@@ -178,7 +178,7 @@ namespace internal {
TypeConversion) \
TFS(NonPrimitiveToPrimitive_String, BUILTIN, kNoExtraICState, \
TypeConversion) \
ASM(StringToNumber) \
TFS(StringToNumber, BUILTIN, kNoExtraICState, TypeConversion) \
TFS(NonNumberToNumber, BUILTIN, kNoExtraICState, TypeConversion) \
ASM(ToNumber) \
\
......
......@@ -2713,32 +2713,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(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);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(eax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in eax.
......
......@@ -2827,31 +2827,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes on argument in a0.
__ AssertString(a0);
// Check if string has a cached array index.
Label runtime;
__ lw(a2, FieldMemOperand(a0, String::kHashFieldOffset));
__ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
__ Branch(&runtime, ne, at, Operand(zero_reg));
__ IndexFromHash(a2, v0);
__ Ret();
__ bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(a0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in a0.
......
......@@ -2821,31 +2821,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes on argument in a0.
__ AssertString(a0);
// Check if string has a cached array index.
Label runtime;
__ lwu(a2, FieldMemOperand(a0, String::kHashFieldOffset));
__ And(at, a2, Operand(String::kContainsCachedArrayIndexMask));
__ Branch(&runtime, ne, at, Operand(zero_reg));
__ IndexFromHash(a2, v0);
__ Ret();
__ bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(a0);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in a0.
......
......@@ -2833,31 +2833,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in r3.
__ AssertString(r3);
// Check if string has a cached array index.
Label runtime;
__ lwz(r5, FieldMemOperand(r3, String::kHashFieldOffset));
__ And(r0, r5, Operand(String::kContainsCachedArrayIndexMask), SetRC);
__ bne(&runtime, cr0);
__ IndexFromHash(r5, r3);
__ blr();
__ bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(r3);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in r3.
......
......@@ -2849,31 +2849,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(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);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(r2);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in r2.
......
......@@ -2128,31 +2128,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
void Builtins::Generate_StringToNumber(MacroAssembler* masm) {
// The StringToNumber stub takes one argument in rax.
__ AssertString(rax);
// Check if string has a cached array index.
Label runtime;
__ testl(FieldOperand(rax, String::kHashFieldOffset),
Immediate(String::kContainsCachedArrayIndexMask));
__ j(not_zero, &runtime, Label::kNear);
__ movl(rax, FieldOperand(rax, String::kHashFieldOffset));
__ IndexFromHash(rax, rax);
__ Ret();
__ bind(&runtime);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ Push(rax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in rax.
......
......@@ -2737,32 +2737,6 @@ void Builtins::Generate_Abort(MacroAssembler* masm) {
__ TailCallRuntime(Runtime::kAbort);
}
// static
void Builtins::Generate_StringToNumber(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);
{
FrameScope frame(masm, StackFrame::INTERNAL);
// Push argument.
__ push(eax);
// We cannot use a tail call here because this builtin can also be called
// from wasm.
__ CallRuntime(Runtime::kStringToNumber);
}
__ Ret();
}
// static
void Builtins::Generate_ToNumber(MacroAssembler* masm) {
// The ToNumber stub takes one argument in eax.
......
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