Index: src/arm64/code-stubs-arm64.cc |
diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc |
index 6392640741ba3513f025927b0365e5abd0d50bfe..e773b531a1e2784ca34a05626728621c5fd4adc2 100644 |
--- a/src/arm64/code-stubs-arm64.cc |
+++ b/src/arm64/code-stubs-arm64.cc |
@@ -3887,16 +3887,43 @@ void SubStringStub::Generate(MacroAssembler* masm) { |
void ToNumberStub::Generate(MacroAssembler* masm) { |
// The ToNumber stub takes one argument in x0. |
- Label check_heap_number, call_builtin; |
- __ JumpIfNotSmi(x0, &check_heap_number); |
+ Label not_smi; |
+ __ JumpIfNotSmi(x0, ¬_smi); |
__ Ret(); |
- |
- __ bind(&check_heap_number); |
- __ JumpIfNotHeapNumber(x0, &call_builtin); |
+ __ Bind(¬_smi); |
+ |
+ Label not_heap_number; |
+ __ Ldr(x1, FieldMemOperand(x0, HeapObject::kMapOffset)); |
+ __ Ldrb(x1, FieldMemOperand(x1, Map::kInstanceTypeOffset)); |
+ // x0: object |
+ // x1: instance type |
+ __ Cmp(x1, HEAP_NUMBER_TYPE); |
+ __ B(ne, ¬_heap_number); |
+ __ Ret(); |
+ __ Bind(¬_heap_number); |
+ |
+ Label not_string, slow_string; |
+ __ Cmp(x1, FIRST_NONSTRING_TYPE); |
+ __ B(hs, ¬_string); |
+ // Check if string has a cached array index. |
+ __ Ldr(x2, FieldMemOperand(x0, String::kHashFieldOffset)); |
+ __ Tst(x2, Operand(String::kContainsCachedArrayIndexMask)); |
+ __ B(ne, &slow_string); |
+ __ IndexFromHash(x2, x0); |
+ __ Ret(); |
+ __ Bind(&slow_string); |
+ __ Push(x0); // Push argument. |
+ __ TailCallRuntime(Runtime::kStringToNumber, 1, 1); |
+ __ Bind(¬_string); |
+ |
+ Label not_oddball; |
+ __ Cmp(x1, ODDBALL_TYPE); |
+ __ B(ne, ¬_oddball); |
+ __ Ldr(x0, FieldMemOperand(x0, Oddball::kToNumberOffset)); |
__ Ret(); |
+ __ Bind(¬_oddball); |
- __ bind(&call_builtin); |
- __ push(x0); |
+ __ Push(x0); // Push argument. |
__ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
} |