OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 | 1055 |
1056 void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { | 1056 void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
1057 // ----------- S t a t e ------------- | 1057 // ----------- S t a t e ------------- |
1058 // -- rax : argument count (preserved for callee) | 1058 // -- rax : argument count (preserved for callee) |
1059 // -- rdx : new target (preserved for callee) | 1059 // -- rdx : new target (preserved for callee) |
1060 // -- rdi : target function (preserved for callee) | 1060 // -- rdi : target function (preserved for callee) |
1061 // ----------------------------------- | 1061 // ----------------------------------- |
1062 Label failed; | 1062 Label failed; |
1063 { | 1063 { |
1064 FrameScope scope(masm, StackFrame::INTERNAL); | 1064 FrameScope scope(masm, StackFrame::INTERNAL); |
| 1065 // Preserve argument count for later compare. |
| 1066 __ movp(kScratchRegister, rax); |
1065 // Push the number of arguments to the callee. | 1067 // Push the number of arguments to the callee. |
1066 __ Integer32ToSmi(rax, rax); | 1068 __ Integer32ToSmi(rax, rax); |
1067 __ Push(rax); | 1069 __ Push(rax); |
1068 // Push a copy of the target function and the new target. | 1070 // Push a copy of the target function and the new target. |
1069 __ Push(rdi); | 1071 __ Push(rdi); |
1070 __ Push(rdx); | 1072 __ Push(rdx); |
1071 | 1073 |
1072 // The function. | 1074 // The function. |
1073 __ Push(rdi); | 1075 __ Push(rdi); |
1074 // Copy arguments from caller (stdlib, foreign, heap). | 1076 // Copy arguments from caller (stdlib, foreign, heap). |
1075 for (int i = 2; i >= 0; --i) { | 1077 Label args_done; |
1076 __ Push(Operand( | 1078 for (int j = 0; j < 4; ++j) { |
1077 rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); | 1079 Label over; |
| 1080 if (j < 3) { |
| 1081 __ cmpp(kScratchRegister, Immediate(j)); |
| 1082 __ j(not_equal, &over, Label::kNear); |
| 1083 } |
| 1084 for (int i = j - 1; i >= 0; --i) { |
| 1085 __ Push(Operand( |
| 1086 rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); |
| 1087 } |
| 1088 for (int i = 0; i < 3 - j; ++i) { |
| 1089 __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 1090 } |
| 1091 if (j < 3) { |
| 1092 __ jmp(&args_done, Label::kNear); |
| 1093 __ bind(&over); |
| 1094 } |
1078 } | 1095 } |
| 1096 __ bind(&args_done); |
| 1097 |
1079 // Call runtime, on success unwind frame, and parent frame. | 1098 // Call runtime, on success unwind frame, and parent frame. |
1080 __ CallRuntime(Runtime::kInstantiateAsmJs, 4); | 1099 __ CallRuntime(Runtime::kInstantiateAsmJs, 4); |
1081 // A smi 0 is returned on failure, an object on success. | 1100 // A smi 0 is returned on failure, an object on success. |
1082 __ JumpIfSmi(rax, &failed, Label::kNear); | 1101 __ JumpIfSmi(rax, &failed, Label::kNear); |
| 1102 |
| 1103 __ Drop(2); |
| 1104 __ Pop(kScratchRegister); |
| 1105 __ SmiToInteger32(kScratchRegister, kScratchRegister); |
1083 scope.GenerateLeaveFrame(); | 1106 scope.GenerateLeaveFrame(); |
1084 __ ret(4 * kPointerSize); | 1107 |
| 1108 __ PopReturnAddressTo(rbx); |
| 1109 __ incp(kScratchRegister); |
| 1110 __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0)); |
| 1111 __ PushReturnAddressFrom(rbx); |
| 1112 __ ret(0); |
1085 | 1113 |
1086 __ bind(&failed); | 1114 __ bind(&failed); |
1087 // Restore target function and new target. | 1115 // Restore target function and new target. |
1088 __ Pop(rdx); | 1116 __ Pop(rdx); |
1089 __ Pop(rdi); | 1117 __ Pop(rdi); |
1090 __ Pop(rax); | 1118 __ Pop(rax); |
1091 __ SmiToInteger32(rax, rax); | 1119 __ SmiToInteger32(rax, rax); |
1092 } | 1120 } |
1093 // On failure, tail call back to regular js. | 1121 // On failure, tail call back to regular js. |
1094 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); | 1122 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); |
(...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3045 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3073 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3046 Generate_OnStackReplacementHelper(masm, true); | 3074 Generate_OnStackReplacementHelper(masm, true); |
3047 } | 3075 } |
3048 | 3076 |
3049 #undef __ | 3077 #undef __ |
3050 | 3078 |
3051 } // namespace internal | 3079 } // namespace internal |
3052 } // namespace v8 | 3080 } // namespace v8 |
3053 | 3081 |
3054 #endif // V8_TARGET_ARCH_X64 | 3082 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |