Revision: 6527
Author: [email protected]
Date: Fri Jan 28 06:18:26 2011
Log: Introduce ToNumber stub and use it in non-optimized code for to-number
conversion.
This stub is used for increment/decrement operations and unary plus.
The resulting code is more compact and faster than calling a JS builtin.
Review URL: http://codereview.chromium.org/6350021
http://code.google.com/p/v8/source/detail?r=6527
Modified:
/branches/bleeding_edge/src/arm/code-stubs-arm.cc
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/code-stubs.h
/branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/x64/code-stubs-x64.cc
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Thu Jan 27 10:21:07
2011
+++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Fri Jan 28 06:18:26
2011
@@ -55,6 +55,28 @@
Register rhs);
+void ToNumberStub::Generate(MacroAssembler* masm) {
+ // The ToNumber stub takes one argument in eax.
+ Label check_heap_number, call_builtin;
+ __ tst(r0, Operand(kSmiTagMask));
+ __ b(ne, &check_heap_number);
+ __ Ret();
+
+ __ bind(&check_heap_number);
+ __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
+ __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
+ __ cmp(r1, ip);
+ __ b(ne, &call_builtin);
+ __ Ret();
+
+ __ bind(&call_builtin);
+ __ pop(r2); // Pop return address.
+ __ push(r0);
+ __ push(r2); // Push return address.
+ __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_JS);
+}
+
+
void FastNewClosureStub::Generate(MacroAssembler* masm) {
// Create a new closure from the given function info in new
// space. Set the context to the current context in cp.
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Jan 26 12:25:33
2011
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Fri Jan 28 06:18:26
2011
@@ -3057,8 +3057,8 @@
Label no_conversion;
__ tst(result_register(), Operand(kSmiTagMask));
__ b(eq, &no_conversion);
- __ push(r0);
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
context()->Plug(result_register());
break;
@@ -3177,8 +3177,8 @@
// Call ToNumber only if operand is not a smi.
Label no_conversion;
__ JumpIfSmi(r0, &no_conversion);
- __ push(r0);
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
// Save result for postfix expressions.
=======================================
--- /branches/bleeding_edge/src/code-stubs.h Tue Jan 25 05:01:45 2011
+++ /branches/bleeding_edge/src/code-stubs.h Fri Jan 28 06:18:26 2011
@@ -59,6 +59,7 @@
V(GenericUnaryOp) \
V(RevertToNumber) \
V(ToBoolean) \
+ V(ToNumber) \
V(CounterOp) \
V(ArgumentsAccess) \
V(RegExpExec) \
@@ -260,6 +261,19 @@
};
+class ToNumberStub: public CodeStub {
+ public:
+ ToNumberStub() { }
+
+ void Generate(MacroAssembler* masm);
+
+ private:
+ Major MajorKey() { return ToNumber; }
+ int MinorKey() { return 0; }
+ const char* GetName() { return "ToNumberStub"; }
+};
+
+
class FastNewClosureStub : public CodeStub {
public:
void Generate(MacroAssembler* masm);
=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Thu Jan 27 10:21:07
2011
+++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Fri Jan 28 06:18:26
2011
@@ -38,6 +38,28 @@
namespace internal {
#define __ ACCESS_MASM(masm)
+
+void ToNumberStub::Generate(MacroAssembler* masm) {
+ // The ToNumber stub takes one argument in eax.
+ NearLabel check_heap_number, call_builtin;
+ __ test(eax, Immediate(kSmiTagMask));
+ __ j(not_zero, &check_heap_number);
+ __ ret(0);
+
+ __ bind(&check_heap_number);
+ __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset));
+ __ cmp(Operand(ebx), Immediate(Factory::heap_number_map()));
+ __ j(not_equal, &call_builtin);
+ __ ret(0);
+
+ __ bind(&call_builtin);
+ __ pop(ecx); // Pop return address.
+ __ push(eax);
+ __ push(ecx); // Push return address.
+ __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}
+
+
void FastNewClosureStub::Generate(MacroAssembler* masm) {
// Create a new closure from the given function info in new
// space. Set the context to the current context in esi.
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Jan 26
07:28:17 2011
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Fri Jan 28
06:18:26 2011
@@ -3747,8 +3747,8 @@
Label no_conversion;
__ test(result_register(), Immediate(kSmiTagMask));
__ j(zero, &no_conversion);
- __ push(result_register());
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
context()->Plug(result_register());
break;
@@ -3868,8 +3868,8 @@
__ test(eax, Immediate(kSmiTagMask));
__ j(zero, &no_conversion);
}
- __ push(eax);
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
// Save result for postfix expressions.
=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Thu Jan 27 10:21:07
2011
+++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Fri Jan 28 06:18:26
2011
@@ -37,6 +37,28 @@
namespace internal {
#define __ ACCESS_MASM(masm)
+
+void ToNumberStub::Generate(MacroAssembler* masm) {
+ // The ToNumber stub takes one argument in eax.
+ NearLabel check_heap_number, call_builtin;
+ __ SmiTest(rax);
+ __ j(not_zero, &check_heap_number);
+ __ Ret();
+
+ __ bind(&check_heap_number);
+ __ Move(rbx, Factory::heap_number_map());
+ __ cmpq(rbx, FieldOperand(rax, HeapObject::kMapOffset));
+ __ j(not_equal, &call_builtin);
+ __ Ret();
+
+ __ bind(&call_builtin);
+ __ pop(rcx); // Pop return address.
+ __ push(rax);
+ __ push(rcx); // Push return address.
+ __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION);
+}
+
+
void FastNewClosureStub::Generate(MacroAssembler* masm) {
// Create a new closure from the given function info in new
// space. Set the context to the current context in rsi.
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Jan 26 07:28:17
2011
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Fri Jan 28 06:18:26
2011
@@ -3063,8 +3063,8 @@
Label no_conversion;
Condition is_smi = masm_->CheckSmi(result_register());
__ j(is_smi, &no_conversion);
- __ push(result_register());
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
context()->Plug(result_register());
break;
@@ -3180,8 +3180,8 @@
Condition is_smi;
is_smi = masm_->CheckSmi(rax);
__ j(is_smi, &no_conversion);
- __ push(rax);
- __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION);
+ ToNumberStub convert_stub;
+ __ CallStub(&convert_stub);
__ bind(&no_conversion);
// Save result for postfix expressions.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev