Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: src/a64/builtins-a64.cc

Issue 166833002: A64: Cleaning of Builtins::Generate_FunctionCall. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 } 988 }
989 __ Jump(masm->isolate()->builtins()->OnStackReplacement(), 989 __ Jump(masm->isolate()->builtins()->OnStackReplacement(),
990 RelocInfo::CODE_TARGET); 990 RelocInfo::CODE_TARGET);
991 991
992 __ Bind(&ok); 992 __ Bind(&ok);
993 __ Ret(); 993 __ Ret();
994 } 994 }
995 995
996 996
997 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { 997 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
998 enum {
999 call_type_JS_func = 0,
1000 call_type_func_proxy = 1,
1001 call_type_non_func = 2
1002 };
1003 Register argc = x0;
1004 Register function = x1;
1005 Register call_type = x4;
1006 Register scratch1 = x10;
1007 Register scratch2 = x11;
998 Register receiver_type = x13; 1008 Register receiver_type = x13;
999 1009
1000 ASM_LOCATION("Builtins::Generate_FunctionCall"); 1010 ASM_LOCATION("Builtins::Generate_FunctionCall");
1001 // TODO(all/rames): Optimize and use named registers.
1002 // 1. Make sure we have at least one argument. 1011 // 1. Make sure we have at least one argument.
1003 // x0: actual number of arguments
1004 { Label done; 1012 { Label done;
1005 __ Cbnz(x0, &done); 1013 __ Cbnz(argc, &done);
1006 __ LoadRoot(x10, Heap::kUndefinedValueRootIndex); 1014 __ LoadRoot(scratch1, Heap::kUndefinedValueRootIndex);
1007 __ Push(x10); 1015 __ Push(scratch1);
1008 __ Mov(x0, 1); 1016 __ Mov(argc, 1);
1009 __ Bind(&done); 1017 __ Bind(&done);
1010 } 1018 }
1011 1019
1012 // 2. Get the function to call (passed as receiver) from the stack, check 1020 // 2. Get the function to call (passed as receiver) from the stack, check
1013 // if it is a function. 1021 // if it is a function.
1014 // x0: actual number of arguments
1015 Label slow, non_function; 1022 Label slow, non_function;
1016 // TODO(jbramley): Consider giving Peek a unit_size parameter, like Claim and 1023 __ Peek(function, Operand(argc, LSL, kXRegSizeInBytesLog2));
1017 // Drop. This usage pattern is very common. 1024 __ JumpIfSmi(function, &non_function);
1018 __ Peek(x1, Operand(x0, LSL, kXRegSizeInBytesLog2)); 1025 __ JumpIfNotObjectType(function, scratch1, receiver_type,
1019 __ JumpIfSmi(x1, &non_function); 1026 JS_FUNCTION_TYPE, &slow);
1020 __ JumpIfNotObjectType(x1, x10, receiver_type, JS_FUNCTION_TYPE, &slow);
1021 1027
1022 // 3a. Patch the first argument if necessary when calling a function. 1028 // 3a. Patch the first argument if necessary when calling a function.
1023 // x0: actual number of arguments
1024 // x1: function
1025 Label shift_arguments; 1029 Label shift_arguments;
1026 __ Mov(x4, 0); // Indicates a regular JS_FUNCTION. 1030 __ Mov(call_type, call_type_JS_func);
1027 { Label convert_to_object, use_global_receiver, patch_receiver; 1031 { Label convert_to_object, use_global_receiver, patch_receiver;
1028 // Change context eagerly in case we need the global receiver. 1032 // Change context eagerly in case we need the global receiver.
1029 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset)); 1033 __ Ldr(cp, FieldMemOperand(function, JSFunction::kContextOffset));
1030 1034
1031 // Do not transform the receiver for strict mode functions. 1035 // Do not transform the receiver for strict mode functions.
1032 __ Ldr(x10, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset)); 1036 // Also do not transform the receiver for native (Compilerhints already in
1033 __ Ldr(w11, FieldMemOperand(x10, SharedFunctionInfo::kCompilerHintsOffset)); 1037 // x3).
1034 __ Tbnz(x11, SharedFunctionInfo::kStrictModeFunction, &shift_arguments); 1038 __ Ldr(scratch1,
1035 1039 FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1036 // TODO(all): Shoudld we insert space to avoid BTAC collisions? 1040 __ Ldr(scratch2.W(),
1037 // Do not transform the receiver for native (Compilerhints already in x3). 1041 FieldMemOperand(scratch1, SharedFunctionInfo::kCompilerHintsOffset));
1038 __ Tbnz(x11, SharedFunctionInfo::kNative, &shift_arguments); 1042 __ TestAndBranchIfAnySet(
1043 scratch2.W(),
1044 (1 << SharedFunctionInfo::kStrictModeFunction) |
1045 (1 << SharedFunctionInfo::kNative),
1046 &shift_arguments);
1039 1047
1040 // Compute the receiver in non-strict mode. 1048 // Compute the receiver in non-strict mode.
1041 __ Sub(x10, x0, 1); 1049 Register receiver = x2;
1042 __ Peek(x2, Operand(x10, LSL, kXRegSizeInBytesLog2)); 1050 __ Sub(scratch1, argc, 1);
1043 // x0: actual number of arguments 1051 __ Peek(receiver, Operand(scratch1, LSL, kXRegSizeInBytesLog2));
1044 // x1: function 1052 __ JumpIfSmi(receiver, &convert_to_object);
1045 // x2: first argument
1046 __ JumpIfSmi(x2, &convert_to_object);
1047 1053
1048 // TODO(all): We could potentially work to optimize loads of root values. 1054 __ JumpIfRoot(receiver, Heap::kUndefinedValueRootIndex,
1049 // TODO(all): If the indexes are successive we can use 'ldp'. 1055 &use_global_receiver);
1050 __ JumpIfRoot(x2, Heap::kUndefinedValueRootIndex, &use_global_receiver); 1056 __ JumpIfRoot(receiver, Heap::kNullValueRootIndex, &use_global_receiver);
1051 __ JumpIfRoot(x2, Heap::kNullValueRootIndex, &use_global_receiver);
1052 1057
1053 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); 1058 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE);
1054 __ JumpIfObjectType(x2, x10, x11, FIRST_SPEC_OBJECT_TYPE, &shift_arguments, 1059 __ JumpIfObjectType(receiver, scratch1, scratch2,
1055 ge); 1060 FIRST_SPEC_OBJECT_TYPE, &shift_arguments, ge);
1056 1061
1057 __ Bind(&convert_to_object); 1062 __ Bind(&convert_to_object);
1058 1063
1059 { 1064 {
1060 // Enter an internal frame in order to preserve argument count. 1065 // Enter an internal frame in order to preserve argument count.
1061 FrameScope scope(masm, StackFrame::INTERNAL); 1066 FrameScope scope(masm, StackFrame::INTERNAL);
1062 __ SmiTag(x0); 1067 __ SmiTag(argc);
1063 1068
1064 __ Push(x0, x2); 1069 __ Push(argc, receiver);
1065 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 1070 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
1066 __ Mov(x2, x0); 1071 __ Mov(receiver, x0);
1067 1072
1068 __ Pop(x0); 1073 __ Pop(argc);
1069 __ SmiUntag(x0); 1074 __ SmiUntag(argc);
1070 1075
1071 // Exit the internal frame. 1076 // Exit the internal frame.
1072 } 1077 }
1073 1078
1074 // Restore the function to x1, and the flag to x4. 1079 // Restore the function and flag in the registers.
1075 __ Peek(x1, Operand(x0, LSL, kXRegSizeInBytesLog2)); 1080 __ Peek(function, Operand(argc, LSL, kXRegSizeInBytesLog2));
1076 __ Mov(x4, 0); 1081 __ Mov(call_type, call_type_JS_func);
1077 __ B(&patch_receiver); 1082 __ B(&patch_receiver);
1078 1083
1079 __ Bind(&use_global_receiver); 1084 __ Bind(&use_global_receiver);
1080 __ Ldr(x2, GlobalObjectMemOperand()); 1085 __ Ldr(receiver, GlobalObjectMemOperand());
1081 __ Ldr(x2, FieldMemOperand(x2, GlobalObject::kGlobalReceiverOffset)); 1086 __ Ldr(receiver,
1087 FieldMemOperand(receiver, GlobalObject::kGlobalReceiverOffset));
1088
1082 1089
1083 __ Bind(&patch_receiver); 1090 __ Bind(&patch_receiver);
1084 __ Sub(x10, x0, 1); 1091 __ Sub(scratch1, argc, 1);
1085 __ Poke(x2, Operand(x10, LSL, kXRegSizeInBytesLog2)); 1092 __ Poke(receiver, Operand(scratch1, LSL, kXRegSizeInBytesLog2));
1086 1093
1087 __ B(&shift_arguments); 1094 __ B(&shift_arguments);
1088 } 1095 }
1089 1096
1090 // 3b. Check for function proxy. 1097 // 3b. Check for function proxy.
1091 __ Bind(&slow); 1098 __ Bind(&slow);
1092 __ Mov(x4, 1); // Indicate function proxy. 1099 __ Mov(call_type, call_type_func_proxy);
1093 __ Cmp(receiver_type, JS_FUNCTION_PROXY_TYPE); 1100 __ Cmp(receiver_type, JS_FUNCTION_PROXY_TYPE);
1094 __ B(eq, &shift_arguments); 1101 __ B(eq, &shift_arguments);
1095 __ Bind(&non_function); 1102 __ Bind(&non_function);
1096 __ Mov(x4, 2); // Indicate non-function. 1103 __ Mov(call_type, call_type_non_func);
1097 1104
1098 // 3c. Patch the first argument when calling a non-function. The 1105 // 3c. Patch the first argument when calling a non-function. The
1099 // CALL_NON_FUNCTION builtin expects the non-function callee as 1106 // CALL_NON_FUNCTION builtin expects the non-function callee as
1100 // receiver, so overwrite the first argument which will ultimately 1107 // receiver, so overwrite the first argument which will ultimately
1101 // become the receiver. 1108 // become the receiver.
1102 // x0: actual number of arguments 1109 // call type (0: JS function, 1: function proxy, 2: non-function)
1103 // x1: function 1110 __ Sub(scratch1, argc, 1);
1104 // x4: call type (0: JS function, 1: function proxy, 2: non-function) 1111 __ Poke(function, Operand(scratch1, LSL, kXRegSizeInBytesLog2));
1105 __ Sub(x10, x0, 1);
1106 __ Poke(x1, Operand(x10, LSL, kXRegSizeInBytesLog2));
1107 1112
1108 // 4. Shift arguments and return address one slot down on the stack 1113 // 4. Shift arguments and return address one slot down on the stack
1109 // (overwriting the original receiver). Adjust argument count to make 1114 // (overwriting the original receiver). Adjust argument count to make
1110 // the original first argument the new receiver. 1115 // the original first argument the new receiver.
1111 // x0: actual number of arguments 1116 // call type (0: JS function, 1: function proxy, 2: non-function)
1112 // x1: function
1113 // x4: call type (0: JS function, 1: function proxy, 2: non-function)
1114 __ Bind(&shift_arguments); 1117 __ Bind(&shift_arguments);
1115 { Label loop; 1118 { Label loop;
1116 // Calculate the copy start address (destination). Copy end address is jssp. 1119 // Calculate the copy start address (destination). Copy end address is jssp.
1117 __ Add(x11, jssp, Operand(x0, LSL, kPointerSizeLog2)); 1120 __ Add(scratch2, jssp, Operand(argc, LSL, kPointerSizeLog2));
1118 __ Sub(x10, x11, kPointerSize); 1121 __ Sub(scratch1, scratch2, kPointerSize);
1119 1122
1120 // TODO(all): Optimize to copy values 2 by 2?
1121 __ Bind(&loop); 1123 __ Bind(&loop);
1122 __ Ldr(x12, MemOperand(x10, -kPointerSize, PostIndex)); 1124 __ Ldr(x12, MemOperand(scratch1, -kPointerSize, PostIndex));
1123 __ Str(x12, MemOperand(x11, -kPointerSize, PostIndex)); 1125 __ Str(x12, MemOperand(scratch2, -kPointerSize, PostIndex));
1124 __ Cmp(x10, jssp); 1126 __ Cmp(scratch1, jssp);
1125 __ B(ge, &loop); 1127 __ B(ge, &loop);
1126 // Adjust the actual number of arguments and remove the top element 1128 // Adjust the actual number of arguments and remove the top element
1127 // (which is a copy of the last argument). 1129 // (which is a copy of the last argument).
1128 __ Sub(x0, x0, 1); 1130 __ Sub(argc, argc, 1);
1129 __ Drop(1); 1131 __ Drop(1);
1130 } 1132 }
1131 1133
1132 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin, 1134 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin,
1133 // or a function proxy via CALL_FUNCTION_PROXY. 1135 // or a function proxy via CALL_FUNCTION_PROXY.
1134 // x0: actual number of arguments 1136 // call type (0: JS function, 1: function proxy, 2: non-function)
1135 // x1: function 1137 { Label js_function, non_proxy;
1136 // x4: call type (0: JS function, 1: function proxy, 2: non-function) 1138 __ Cbz(call_type, &js_function);
1137 { Label function, non_proxy;
1138 __ Cbz(x4, &function);
1139 // Expected number of arguments is 0 for CALL_NON_FUNCTION. 1139 // Expected number of arguments is 0 for CALL_NON_FUNCTION.
1140 __ Mov(x2, 0); 1140 __ Mov(x2, 0);
1141 __ Cmp(x4, 1); 1141 __ Cmp(call_type, call_type_func_proxy);
1142 __ B(ne, &non_proxy); 1142 __ B(ne, &non_proxy);
1143 1143
1144 __ Push(x1); // Re-add proxy object as additional argument. 1144 __ Push(function); // Re-add proxy object as additional argument.
1145 __ Add(x0, x0, 1); 1145 __ Add(argc, argc, 1);
1146 __ GetBuiltinFunction(x1, Builtins::CALL_FUNCTION_PROXY); 1146 __ GetBuiltinFunction(function, Builtins::CALL_FUNCTION_PROXY);
1147 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), 1147 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
1148 RelocInfo::CODE_TARGET); 1148 RelocInfo::CODE_TARGET);
1149 1149
1150 __ Bind(&non_proxy); 1150 __ Bind(&non_proxy);
1151 __ GetBuiltinFunction(x1, Builtins::CALL_NON_FUNCTION); 1151 __ GetBuiltinFunction(function, Builtins::CALL_NON_FUNCTION);
1152 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), 1152 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
1153 RelocInfo::CODE_TARGET); 1153 RelocInfo::CODE_TARGET);
1154 __ Bind(&function); 1154 __ Bind(&js_function);
1155 } 1155 }
1156 1156
1157 // 5b. Get the code to call from the function and check that the number of 1157 // 5b. Get the code to call from the function and check that the number of
1158 // expected arguments matches what we're providing. If so, jump 1158 // expected arguments matches what we're providing. If so, jump
1159 // (tail-call) to the code in register edx without checking arguments. 1159 // (tail-call) to the code in register edx without checking arguments.
1160 // x0: actual number of arguments 1160 __ Ldr(x3, FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset));
1161 // x1: function
1162 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
1163 __ Ldrsw(x2, 1161 __ Ldrsw(x2,
1164 FieldMemOperand(x3, 1162 FieldMemOperand(x3,
1165 SharedFunctionInfo::kFormalParameterCountOffset)); 1163 SharedFunctionInfo::kFormalParameterCountOffset));
1166 Label dont_adapt_args; 1164 Label dont_adapt_args;
1167 __ Cmp(x2, x0); // Check formal and actual parameter counts. 1165 __ Cmp(x2, argc); // Check formal and actual parameter counts.
1168 __ B(eq, &dont_adapt_args); 1166 __ B(eq, &dont_adapt_args);
1169 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), 1167 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
1170 RelocInfo::CODE_TARGET); 1168 RelocInfo::CODE_TARGET);
1171 __ Bind(&dont_adapt_args); 1169 __ Bind(&dont_adapt_args);
1172 1170
1173 __ Ldr(x3, FieldMemOperand(x1, JSFunction::kCodeEntryOffset)); 1171 __ Ldr(x3, FieldMemOperand(function, JSFunction::kCodeEntryOffset));
1174 ParameterCount expected(0); 1172 ParameterCount expected(0);
1175 __ InvokeCode(x3, expected, expected, JUMP_FUNCTION, NullCallWrapper()); 1173 __ InvokeCode(x3, expected, expected, JUMP_FUNCTION, NullCallWrapper());
1176 } 1174 }
1177 1175
1178 1176
1179 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { 1177 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
1180 ASM_LOCATION("Builtins::Generate_FunctionApply"); 1178 ASM_LOCATION("Builtins::Generate_FunctionApply");
1181 const int kIndexOffset = 1179 const int kIndexOffset =
1182 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize); 1180 StandardFrameConstants::kExpressionsOffset - (2 * kPointerSize);
1183 const int kLimitOffset = 1181 const int kLimitOffset =
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 __ Bind(&dont_adapt_arguments); 1470 __ Bind(&dont_adapt_arguments);
1473 __ Jump(x3); 1471 __ Jump(x3);
1474 } 1472 }
1475 1473
1476 1474
1477 #undef __ 1475 #undef __
1478 1476
1479 } } // namespace v8::internal 1477 } } // namespace v8::internal
1480 1478
1481 #endif // V8_TARGET_ARCH_ARM 1479 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698