OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/assembler.h" | 5 #include "src/assembler.h" |
6 #include "src/codegen.h" | 6 #include "src/codegen.h" |
7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
8 #include "src/compiler/raw-machine-assembler.h" | 8 #include "src/compiler/raw-machine-assembler.h" |
9 #include "src/machine-type.h" | 9 #include "src/machine-type.h" |
10 #include "src/register-configuration.h" | 10 #include "src/register-configuration.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 int gp_offset; | 126 int gp_offset; |
127 int* gp_regs; | 127 int* gp_regs; |
128 | 128 |
129 int fp_count; | 129 int fp_count; |
130 int fp_offset; | 130 int fp_offset; |
131 int* fp_regs; | 131 int* fp_regs; |
132 | 132 |
133 int stack_offset; | 133 int stack_offset; |
134 | 134 |
135 LinkageLocation Next(MachineType type) { | 135 LinkageLocation Next(MachineType type) { |
136 if (IsFloatingPoint(type)) { | 136 if (IsFloatingPoint(type.representation())) { |
137 // Allocate a floating point register/stack location. | 137 // Allocate a floating point register/stack location. |
138 if (fp_offset < fp_count) { | 138 if (fp_offset < fp_count) { |
139 return LinkageLocation::ForRegister(fp_regs[fp_offset++]); | 139 return LinkageLocation::ForRegister(fp_regs[fp_offset++]); |
140 } else { | 140 } else { |
141 int offset = -1 - stack_offset; | 141 int offset = -1 - stack_offset; |
142 stack_offset += StackWords(type); | 142 stack_offset += StackWords(type); |
143 return LinkageLocation::ForCallerFrameSlot(offset); | 143 return LinkageLocation::ForCallerFrameSlot(offset); |
144 } | 144 } |
145 } else { | 145 } else { |
146 // Allocate a general purpose register/stack location. | 146 // Allocate a general purpose register/stack location. |
147 if (gp_offset < gp_count) { | 147 if (gp_offset < gp_count) { |
148 return LinkageLocation::ForRegister(gp_regs[gp_offset++]); | 148 return LinkageLocation::ForRegister(gp_regs[gp_offset++]); |
149 } else { | 149 } else { |
150 int offset = -1 - stack_offset; | 150 int offset = -1 - stack_offset; |
151 stack_offset += StackWords(type); | 151 stack_offset += StackWords(type); |
152 return LinkageLocation::ForCallerFrameSlot(offset); | 152 return LinkageLocation::ForCallerFrameSlot(offset); |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 bool IsFloatingPoint(MachineType type) { | |
157 return RepresentationOf(type) == kRepFloat32 || | |
158 RepresentationOf(type) == kRepFloat64; | |
159 } | |
160 int StackWords(MachineType type) { | 156 int StackWords(MachineType type) { |
161 // TODO(titzer): hack. float32 occupies 8 bytes on stack. | 157 // TODO(titzer): hack. float32 occupies 8 bytes on stack. |
162 int size = (RepresentationOf(type) == kRepFloat32 || | 158 int size = IsFloatingPoint(type.representation()) |
163 RepresentationOf(type) == kRepFloat64) | |
164 ? kDoubleSize | 159 ? kDoubleSize |
165 : ElementSizeOf(type); | 160 : (1 << ElementSizeLog2Of(type.representation())); |
166 return size <= kPointerSize ? 1 : size / kPointerSize; | 161 return size <= kPointerSize ? 1 : size / kPointerSize; |
167 } | 162 } |
168 void Reset() { | 163 void Reset() { |
169 fp_offset = 0; | 164 fp_offset = 0; |
170 gp_offset = 0; | 165 gp_offset = 0; |
171 stack_offset = 0; | 166 stack_offset = 0; |
172 } | 167 } |
173 }; | 168 }; |
174 | 169 |
175 | 170 |
(...skipping 15 matching lines...) Expand all Loading... |
191 | 186 |
192 // Add register and/or stack parameter(s). | 187 // Add register and/or stack parameter(s). |
193 const int parameter_count = static_cast<int>(msig->parameter_count()); | 188 const int parameter_count = static_cast<int>(msig->parameter_count()); |
194 for (int i = 0; i < parameter_count; i++) { | 189 for (int i = 0; i < parameter_count; i++) { |
195 locations.AddParam(params.Next(msig->GetParam(i))); | 190 locations.AddParam(params.Next(msig->GetParam(i))); |
196 } | 191 } |
197 | 192 |
198 const RegList kCalleeSaveRegisters = 0; | 193 const RegList kCalleeSaveRegisters = 0; |
199 const RegList kCalleeSaveFPRegisters = 0; | 194 const RegList kCalleeSaveFPRegisters = 0; |
200 | 195 |
201 MachineType target_type = kMachAnyTagged; | 196 MachineType target_type = MachineType::AnyTagged(); |
202 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); | 197 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); |
203 int stack_param_count = params.stack_offset; | 198 int stack_param_count = params.stack_offset; |
204 return new (zone) CallDescriptor( // -- | 199 return new (zone) CallDescriptor( // -- |
205 CallDescriptor::kCallCodeObject, // kind | 200 CallDescriptor::kCallCodeObject, // kind |
206 target_type, // target MachineType | 201 target_type, // target MachineType |
207 target_loc, // target location | 202 target_loc, // target location |
208 msig, // machine_sig | 203 msig, // machine_sig |
209 locations.Build(), // location_sig | 204 locations.Build(), // location_sig |
210 stack_param_count, // stack_parameter_count | 205 stack_param_count, // stack_parameter_count |
211 compiler::Operator::kNoProperties, // properties | 206 compiler::Operator::kNoProperties, // properties |
212 kCalleeSaveRegisters, // callee-saved registers | 207 kCalleeSaveRegisters, // callee-saved registers |
213 kCalleeSaveFPRegisters, // callee-saved fp regs | 208 kCalleeSaveFPRegisters, // callee-saved fp regs |
214 CallDescriptor::kUseNativeStack, // flags | 209 CallDescriptor::kUseNativeStack, // flags |
215 "c-call"); | 210 "c-call"); |
216 } | 211 } |
217 | 212 |
218 private: | 213 private: |
219 Allocator& params; | 214 Allocator& params; |
220 Allocator& rets; | 215 Allocator& rets; |
221 }; | 216 }; |
222 | 217 |
223 const int kMaxParamCount = 64; | 218 const int kMaxParamCount = 64; |
224 | 219 |
225 MachineType kIntTypes[kMaxParamCount + 1] = { | 220 MachineType kIntTypes[kMaxParamCount + 1] = { |
226 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 221 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
227 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 222 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
228 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 223 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
229 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 224 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
230 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 225 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
231 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 226 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
232 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 227 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
233 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 228 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
234 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 229 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
235 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32, | 230 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
236 kMachInt32, kMachInt32, kMachInt32, kMachInt32, kMachInt32}; | 231 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 232 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 233 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 234 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 235 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 236 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 237 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 238 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 239 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 240 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 241 MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), |
| 242 MachineType::Int32(), MachineType::Int32()}; |
237 | 243 |
238 | 244 |
239 // For making uniform int32 signatures shorter. | 245 // For making uniform int32 signatures shorter. |
240 class Int32Signature : public MachineSignature { | 246 class Int32Signature : public MachineSignature { |
241 public: | 247 public: |
242 explicit Int32Signature(int param_count) | 248 explicit Int32Signature(int param_count) |
243 : MachineSignature(1, param_count, kIntTypes) { | 249 : MachineSignature(1, param_count, kIntTypes) { |
244 CHECK(param_count <= kMaxParamCount); | 250 CHECK(param_count <= kMaxParamCount); |
245 } | 251 } |
246 }; | 252 }; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 HandleScope scope(isolate); | 562 HandleScope scope(isolate); |
557 Handle<Code> inner = Handle<Code>::null(); | 563 Handle<Code> inner = Handle<Code>::null(); |
558 { | 564 { |
559 // Writes all parameters into the output buffer. | 565 // Writes all parameters into the output buffer. |
560 Zone zone; | 566 Zone zone; |
561 Graph graph(&zone); | 567 Graph graph(&zone); |
562 RawMachineAssembler raw(isolate, &graph, desc); | 568 RawMachineAssembler raw(isolate, &graph, desc); |
563 Node* base = raw.PointerConstant(output); | 569 Node* base = raw.PointerConstant(output); |
564 for (int i = 0; i < kNumParams; i++) { | 570 for (int i = 0; i < kNumParams; i++) { |
565 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); | 571 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); |
566 raw.Store(kMachInt32, base, offset, raw.Parameter(i), kNoWriteBarrier); | 572 raw.Store(MachineType::Int32(), base, offset, raw.Parameter(i), |
| 573 kNoWriteBarrier); |
567 } | 574 } |
568 raw.Return(raw.Int32Constant(42)); | 575 raw.Return(raw.Int32Constant(42)); |
569 inner = CompileGraph("CopyTwentyInt32", desc, &graph, raw.Export()); | 576 inner = CompileGraph("CopyTwentyInt32", desc, &graph, raw.Export()); |
570 } | 577 } |
571 | 578 |
572 CSignature0<int32_t> csig; | 579 CSignature0<int32_t> csig; |
573 Handle<Code> wrapper = Handle<Code>::null(); | 580 Handle<Code> wrapper = Handle<Code>::null(); |
574 { | 581 { |
575 // Loads parameters from the input buffer and calls the above code. | 582 // Loads parameters from the input buffer and calls the above code. |
576 Zone zone; | 583 Zone zone; |
577 Graph graph(&zone); | 584 Graph graph(&zone); |
578 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 585 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
579 RawMachineAssembler raw(isolate, &graph, cdesc); | 586 RawMachineAssembler raw(isolate, &graph, cdesc); |
580 Node* base = raw.PointerConstant(input); | 587 Node* base = raw.PointerConstant(input); |
581 Node* target = raw.HeapConstant(inner); | 588 Node* target = raw.HeapConstant(inner); |
582 Node** args = zone.NewArray<Node*>(kNumParams); | 589 Node** args = zone.NewArray<Node*>(kNumParams); |
583 for (int i = 0; i < kNumParams; i++) { | 590 for (int i = 0; i < kNumParams; i++) { |
584 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); | 591 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); |
585 args[i] = raw.Load(kMachInt32, base, offset); | 592 args[i] = raw.Load(MachineType::Int32(), base, offset); |
586 } | 593 } |
587 | 594 |
588 Node* call = raw.CallN(desc, target, args); | 595 Node* call = raw.CallN(desc, target, args); |
589 raw.Return(call); | 596 raw.Return(call); |
590 wrapper = | 597 wrapper = |
591 CompileGraph("CopyTwentyInt32-wrapper", cdesc, &graph, raw.Export()); | 598 CompileGraph("CopyTwentyInt32-wrapper", cdesc, &graph, raw.Export()); |
592 } | 599 } |
593 | 600 |
594 CodeRunner<int32_t> runnable(isolate, wrapper, &csig); | 601 CodeRunner<int32_t> runnable(isolate, wrapper, &csig); |
595 | 602 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 1016 |
1010 | 1017 |
1011 void MixedParamTest(int start) { | 1018 void MixedParamTest(int start) { |
1012 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1019 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
1013 ->num_double_registers() < 2) | 1020 ->num_double_registers() < 2) |
1014 return; | 1021 return; |
1015 | 1022 |
1016 // TODO(titzer): mix in 64-bit types on all platforms when supported. | 1023 // TODO(titzer): mix in 64-bit types on all platforms when supported. |
1017 #if V8_TARGET_ARCH_32_BIT | 1024 #if V8_TARGET_ARCH_32_BIT |
1018 static MachineType types[] = { | 1025 static MachineType types[] = { |
1019 kMachInt32, kMachFloat32, kMachFloat64, kMachInt32, kMachFloat64, | 1026 MachineType::Int32(), MachineType::Float32(), MachineType::Float64(), |
1020 kMachFloat32, kMachFloat32, kMachFloat64, kMachInt32, kMachFloat32, | 1027 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), |
1021 kMachInt32, kMachFloat64, kMachFloat64, kMachFloat32, kMachInt32, | 1028 MachineType::Float32(), MachineType::Float64(), MachineType::Int32(), |
1022 kMachFloat64, kMachInt32, kMachFloat32}; | 1029 MachineType::Float32(), MachineType::Int32(), MachineType::Float64(), |
| 1030 MachineType::Float64(), MachineType::Float32(), MachineType::Int32(), |
| 1031 MachineType::Float64(), MachineType::Int32(), MachineType::Float32()}; |
1023 #else | 1032 #else |
1024 static MachineType types[] = { | 1033 static MachineType types[] = { |
1025 kMachInt32, kMachInt64, kMachFloat32, kMachFloat64, kMachInt32, | 1034 MachineType::Int32(), MachineType::Int64(), MachineType::Float32(), |
1026 kMachFloat64, kMachFloat32, kMachInt64, kMachInt64, kMachFloat32, | 1035 MachineType::Float64(), MachineType::Int32(), MachineType::Float64(), |
1027 kMachFloat32, kMachInt32, kMachFloat64, kMachFloat64, kMachInt64, | 1036 MachineType::Float32(), MachineType::Int64(), MachineType::Int64(), |
1028 kMachInt32, kMachFloat64, kMachInt32, kMachFloat32}; | 1037 MachineType::Float32(), MachineType::Float32(), MachineType::Int32(), |
| 1038 MachineType::Float64(), MachineType::Float64(), MachineType::Int64(), |
| 1039 MachineType::Int32(), MachineType::Float64(), MachineType::Int32(), |
| 1040 MachineType::Float32()}; |
1029 #endif | 1041 #endif |
1030 | 1042 |
1031 Isolate* isolate = CcTest::InitIsolateOnce(); | 1043 Isolate* isolate = CcTest::InitIsolateOnce(); |
1032 | 1044 |
1033 // Build machine signature | 1045 // Build machine signature |
1034 MachineType* params = &types[start]; | 1046 MachineType* params = &types[start]; |
1035 const int num_params = static_cast<int>(arraysize(types) - start); | 1047 const int num_params = static_cast<int>(arraysize(types) - start); |
1036 | 1048 |
1037 // Build call descriptor | 1049 // Build call descriptor |
1038 int parray_gp[] = { | 1050 int parray_gp[] = { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 Zone zone; | 1099 Zone zone; |
1088 Graph graph(&zone); | 1100 Graph graph(&zone); |
1089 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 1101 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
1090 RawMachineAssembler raw(isolate, &graph, cdesc); | 1102 RawMachineAssembler raw(isolate, &graph, cdesc); |
1091 Node* target = raw.HeapConstant(select); | 1103 Node* target = raw.HeapConstant(select); |
1092 Node** args = zone.NewArray<Node*>(num_params); | 1104 Node** args = zone.NewArray<Node*>(num_params); |
1093 int64_t constant = 0x0102030405060708; | 1105 int64_t constant = 0x0102030405060708; |
1094 for (int i = 0; i < num_params; i++) { | 1106 for (int i = 0; i < num_params; i++) { |
1095 MachineType param_type = sig->GetParam(i); | 1107 MachineType param_type = sig->GetParam(i); |
1096 Node* konst = nullptr; | 1108 Node* konst = nullptr; |
1097 if (param_type == kMachInt32) { | 1109 if (param_type == MachineType::Int32()) { |
1098 int32_t value[] = {static_cast<int32_t>(constant)}; | 1110 int32_t value[] = {static_cast<int32_t>(constant)}; |
1099 konst = raw.Int32Constant(value[0]); | 1111 konst = raw.Int32Constant(value[0]); |
1100 if (i == which) memcpy(bytes, value, expected_size = 4); | 1112 if (i == which) memcpy(bytes, value, expected_size = 4); |
1101 } | 1113 } |
1102 if (param_type == kMachInt64) { | 1114 if (param_type == MachineType::Int64()) { |
1103 int64_t value[] = {static_cast<int64_t>(constant)}; | 1115 int64_t value[] = {static_cast<int64_t>(constant)}; |
1104 konst = raw.Int64Constant(value[0]); | 1116 konst = raw.Int64Constant(value[0]); |
1105 if (i == which) memcpy(bytes, value, expected_size = 8); | 1117 if (i == which) memcpy(bytes, value, expected_size = 8); |
1106 } | 1118 } |
1107 if (param_type == kMachFloat32) { | 1119 if (param_type == MachineType::Float32()) { |
1108 float32 value[] = {static_cast<float32>(constant)}; | 1120 float32 value[] = {static_cast<float32>(constant)}; |
1109 konst = raw.Float32Constant(value[0]); | 1121 konst = raw.Float32Constant(value[0]); |
1110 if (i == which) memcpy(bytes, value, expected_size = 4); | 1122 if (i == which) memcpy(bytes, value, expected_size = 4); |
1111 } | 1123 } |
1112 if (param_type == kMachFloat64) { | 1124 if (param_type == MachineType::Float64()) { |
1113 float64 value[] = {static_cast<float64>(constant)}; | 1125 float64 value[] = {static_cast<float64>(constant)}; |
1114 konst = raw.Float64Constant(value[0]); | 1126 konst = raw.Float64Constant(value[0]); |
1115 if (i == which) memcpy(bytes, value, expected_size = 8); | 1127 if (i == which) memcpy(bytes, value, expected_size = 8); |
1116 } | 1128 } |
1117 CHECK_NOT_NULL(konst); | 1129 CHECK_NOT_NULL(konst); |
1118 | 1130 |
1119 args[i] = konst; | 1131 args[i] = konst; |
1120 constant += 0x1010101010101010; | 1132 constant += 0x1010101010101010; |
1121 } | 1133 } |
1122 | 1134 |
(...skipping 17 matching lines...) Expand all Loading... |
1140 | 1152 |
1141 | 1153 |
1142 TEST(MixedParams_0) { MixedParamTest(0); } | 1154 TEST(MixedParams_0) { MixedParamTest(0); } |
1143 TEST(MixedParams_1) { MixedParamTest(1); } | 1155 TEST(MixedParams_1) { MixedParamTest(1); } |
1144 TEST(MixedParams_2) { MixedParamTest(2); } | 1156 TEST(MixedParams_2) { MixedParamTest(2); } |
1145 TEST(MixedParams_3) { MixedParamTest(3); } | 1157 TEST(MixedParams_3) { MixedParamTest(3); } |
1146 | 1158 |
1147 } // namespace compiler | 1159 } // namespace compiler |
1148 } // namespace internal | 1160 } // namespace internal |
1149 } // namespace v8 | 1161 } // namespace v8 |
OLD | NEW |