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 __ cmpp(kScratchRegister, Immediate(0)); |
1077 rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); | 1079 __ j(equal, &args_done, Label::kNear); |
1078 } | 1080 |
1081 Label args2; | |
1082 __ cmpp(kScratchRegister, Immediate(1)); | |
1083 __ j(not_equal, &args2, Label::kNear); | |
1084 __ Push(Operand( | |
1085 rbp, StandardFrameConstants::kCallerSPOffset + 0 * kPointerSize)); | |
1086 __ jmp(&args_done, Label::kNear); | |
1087 | |
1088 __ bind(&args2); | |
1089 Label args3; | |
1090 __ cmpp(kScratchRegister, Immediate(2)); | |
1091 __ j(not_equal, &args3, Label::kNear); | |
1092 __ Push(Operand( | |
1093 rbp, StandardFrameConstants::kCallerSPOffset + 1 * kPointerSize)); | |
1094 __ Push(Operand( | |
1095 rbp, StandardFrameConstants::kCallerSPOffset + 0 * kPointerSize)); | |
1096 __ jmp(&args_done, Label::kNear); | |
1097 | |
1098 __ bind(&args3); | |
1099 __ Push(Operand( | |
1100 rbp, StandardFrameConstants::kCallerSPOffset + 2 * kPointerSize)); | |
1101 __ Push(Operand( | |
1102 rbp, StandardFrameConstants::kCallerSPOffset + 1 * kPointerSize)); | |
1103 __ Push(Operand( | |
1104 rbp, StandardFrameConstants::kCallerSPOffset + 0 * kPointerSize)); | |
1105 __ bind(&args_done); | |
1106 | |
1107 // Increment and restore argument count to call runtime method | |
1108 // with function as extra argument. | |
1109 __ incp(kScratchRegister); | |
1110 __ movp(rax, kScratchRegister); | |
1079 // Call runtime, on success unwind frame, and parent frame. | 1111 // Call runtime, on success unwind frame, and parent frame. |
1080 __ CallRuntime(Runtime::kInstantiateAsmJs, 4); | 1112 __ CallRuntime(Runtime::kInstantiateAsmJs, -1); |
Michael Starzinger
2016/08/09 15:48:08
For the call-site to not pass the arguments count
bradn
2016/08/11 09:19:33
Ah, great idea!
I like that much better.
Done.
| |
1081 // A smi 0 is returned on failure, an object on success. | 1113 // A smi 0 is returned on failure, an object on success. |
1082 __ JumpIfSmi(rax, &failed, Label::kNear); | 1114 __ JumpIfSmi(rax, &failed, Label::kNear); |
1115 | |
1116 __ Pop(kScratchRegister); | |
1117 __ Pop(kScratchRegister); | |
1118 __ Pop(kScratchRegister); | |
1119 __ SmiToInteger32(kScratchRegister, kScratchRegister); | |
1083 scope.GenerateLeaveFrame(); | 1120 scope.GenerateLeaveFrame(); |
1084 __ ret(4 * kPointerSize); | 1121 |
1122 __ Pop(rbx); | |
1123 __ incp(kScratchRegister); | |
1124 __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0)); | |
1125 __ Push(rbx); | |
1126 __ ret(0); | |
1085 | 1127 |
1086 __ bind(&failed); | 1128 __ bind(&failed); |
1087 // Restore target function and new target. | 1129 // Restore target function and new target. |
1088 __ Pop(rdx); | 1130 __ Pop(rdx); |
1089 __ Pop(rdi); | 1131 __ Pop(rdi); |
1090 __ Pop(rax); | 1132 __ Pop(rax); |
1091 __ SmiToInteger32(rax, rax); | 1133 __ SmiToInteger32(rax, rax); |
1092 } | 1134 } |
1093 // On failure, tail call back to regular js. | 1135 // On failure, tail call back to regular js. |
1094 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); | 1136 GenerateTailCallToReturnedCode(masm, Runtime::kCompileBaseline); |
1095 } | 1137 } |
1096 | 1138 |
1097 static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { | 1139 static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { |
1098 // For now, we are relying on the fact that make_code_young doesn't do any | 1140 // For now, we are relying on the fact that make_code_young doesn't do any |
1099 // garbage collection which allows us to save/restore the registers without | 1141 // garbage collection which allows us to save/restore the registers without |
1100 // worrying about which of them contain pointers. We also don't build an | 1142 // worrying about which of them contain pointers. We also don't build an |
1101 // internal frame to make the code faster, since we shouldn't have to do stack | 1143 // internal frame to make the code faster, since we shouldn't have to do stack |
1102 // crawls in MakeCodeYoung. This seems a bit fragile. | 1144 // crawls in MakeCodeYoung. This seems a bit fragile. |
1103 | 1145 |
1104 // Re-execute the code that was patched back to the young age when | 1146 // Re-execute the code that was patched back to the young age when |
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3068 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3110 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3069 Generate_OnStackReplacementHelper(masm, true); | 3111 Generate_OnStackReplacementHelper(masm, true); |
3070 } | 3112 } |
3071 | 3113 |
3072 #undef __ | 3114 #undef __ |
3073 | 3115 |
3074 } // namespace internal | 3116 } // namespace internal |
3075 } // namespace v8 | 3117 } // namespace v8 |
3076 | 3118 |
3077 #endif // V8_TARGET_ARCH_X64 | 3119 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |