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

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 8574053: Add ia32 FastCloneShallowArrayStub that copies all boilerplate kinds. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Return and remove the on-stack parameters. 224 // Return and remove the on-stack parameters.
225 __ mov(esi, eax); 225 __ mov(esi, eax);
226 __ ret(2 * kPointerSize); 226 __ ret(2 * kPointerSize);
227 227
228 // Need to collect. Call into runtime system. 228 // Need to collect. Call into runtime system.
229 __ bind(&gc); 229 __ bind(&gc);
230 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); 230 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1);
231 } 231 }
232 232
233 233
234 void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { 234 static void GenerateFastCloneShallowArrayCommon(
235 // Stack layout on entry: 235 MacroAssembler* masm,
236 // 236 int length,
237 // [esp + kPointerSize]: constant elements. 237 FastCloneShallowArrayStub::Mode mode,
Jakob Kummerow 2011/11/17 12:31:36 Just to be explicit, please add an ASSERT(mode !=
danno 2011/11/17 13:51:23 Done.
238 // [esp + (2 * kPointerSize)]: literal index. 238 Label* fail) {
239 // [esp + (3 * kPointerSize)]: literals array. 239 // eax: literal index.
240 // ecx: literals array.
240 241
241 // All sizes here are multiples of kPointerSize. 242 // All sizes here are multiples of kPointerSize.
242 int elements_size = 0; 243 int elements_size = 0;
243 if (length_ > 0) { 244 if (length > 0) {
244 elements_size = mode_ == CLONE_DOUBLE_ELEMENTS 245 elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
245 ? FixedDoubleArray::SizeFor(length_) 246 ? FixedDoubleArray::SizeFor(length)
246 : FixedArray::SizeFor(length_); 247 : FixedArray::SizeFor(length);
247 } 248 }
248 int size = JSArray::kSize + elements_size; 249 int size = JSArray::kSize + elements_size;
249 250
250 // Load boilerplate object into ecx and check if we need to create a
251 // boilerplate.
252 Label slow_case;
253 __ mov(ecx, Operand(esp, 3 * kPointerSize));
254 __ mov(eax, Operand(esp, 2 * kPointerSize));
255 STATIC_ASSERT(kPointerSize == 4);
256 STATIC_ASSERT(kSmiTagSize == 1);
257 STATIC_ASSERT(kSmiTag == 0);
258 __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size,
259 FixedArray::kHeaderSize));
260 Factory* factory = masm->isolate()->factory();
261 __ cmp(ecx, factory->undefined_value());
262 __ j(equal, &slow_case);
263
264 if (FLAG_debug_code) {
265 const char* message;
266 Handle<Map> expected_map;
267 if (mode_ == CLONE_ELEMENTS) {
268 message = "Expected (writable) fixed array";
269 expected_map = factory->fixed_array_map();
270 } else if (mode_ == CLONE_DOUBLE_ELEMENTS) {
271 message = "Expected (writable) fixed double array";
272 expected_map = factory->fixed_double_array_map();
273 } else {
274 ASSERT(mode_ == COPY_ON_WRITE_ELEMENTS);
275 message = "Expected copy-on-write fixed array";
276 expected_map = factory->fixed_cow_array_map();
277 }
278 __ push(ecx);
279 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
280 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map);
281 __ Assert(equal, message);
282 __ pop(ecx);
283 }
284
285 // Allocate both the JS array and the elements array in one big 251 // Allocate both the JS array and the elements array in one big
286 // allocation. This avoids multiple limit checks. 252 // allocation. This avoids multiple limit checks.
287 __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); 253 __ AllocateInNewSpace(size, eax, ebx, edx, fail, TAG_OBJECT);
288 254
289 // Copy the JS array part. 255 // Copy the JS array part.
290 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { 256 for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
291 if ((i != JSArray::kElementsOffset) || (length_ == 0)) { 257 if ((i != JSArray::kElementsOffset) || (length == 0)) {
292 __ mov(ebx, FieldOperand(ecx, i)); 258 __ mov(ebx, FieldOperand(ecx, i));
293 __ mov(FieldOperand(eax, i), ebx); 259 __ mov(FieldOperand(eax, i), ebx);
294 } 260 }
295 } 261 }
296 262
297 if (length_ > 0) { 263 if (length > 0) {
298 // Get hold of the elements array of the boilerplate and setup the 264 // Get hold of the elements array of the boilerplate and setup the
299 // elements pointer in the resulting object. 265 // elements pointer in the resulting object.
300 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); 266 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
301 __ lea(edx, Operand(eax, JSArray::kSize)); 267 __ lea(edx, Operand(eax, JSArray::kSize));
302 __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); 268 __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx);
303 269
304 // Copy the elements array. 270 // Copy the elements array.
305 if (mode_ == CLONE_ELEMENTS) { 271 if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) {
306 for (int i = 0; i < elements_size; i += kPointerSize) { 272 for (int i = 0; i < elements_size; i += kPointerSize) {
307 __ mov(ebx, FieldOperand(ecx, i)); 273 __ mov(ebx, FieldOperand(ecx, i));
308 __ mov(FieldOperand(edx, i), ebx); 274 __ mov(FieldOperand(edx, i), ebx);
309 } 275 }
310 } else { 276 } else {
311 ASSERT(mode_ == CLONE_DOUBLE_ELEMENTS); 277 ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS);
312 int i; 278 int i;
313 for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { 279 for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) {
314 __ mov(ebx, FieldOperand(ecx, i)); 280 __ mov(ebx, FieldOperand(ecx, i));
315 __ mov(FieldOperand(edx, i), ebx); 281 __ mov(FieldOperand(edx, i), ebx);
316 } 282 }
317 while (i < elements_size) { 283 while (i < elements_size) {
318 __ fld_d(FieldOperand(ecx, i)); 284 __ fld_d(FieldOperand(ecx, i));
319 __ fstp_d(FieldOperand(edx, i)); 285 __ fstp_d(FieldOperand(edx, i));
320 i += kDoubleSize; 286 i += kDoubleSize;
321 } 287 }
322 ASSERT(i == elements_size); 288 ASSERT(i == elements_size);
323 } 289 }
324 } 290 }
291 }
325 292
293
294 void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) {
295 // Stack layout on entry:
296 //
297 // [esp + kPointerSize]: constant elements.
298 // [esp + (2 * kPointerSize)]: literal index.
299 // [esp + (3 * kPointerSize)]: literals array.
300
301 // Load boilerplate object into ecx and check if we need to create a
302 // boilerplate.
303 __ mov(ecx, Operand(esp, 3 * kPointerSize));
304 __ mov(eax, Operand(esp, 2 * kPointerSize));
305 STATIC_ASSERT(kPointerSize == 4);
306 STATIC_ASSERT(kSmiTagSize == 1);
307 STATIC_ASSERT(kSmiTag == 0);
308 __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size,
309 FixedArray::kHeaderSize));
310 Factory* factory = masm->isolate()->factory();
311 __ cmp(ecx, factory->undefined_value());
312 Label slow_case;
313 __ j(equal, &slow_case);
314
315 FastCloneShallowArrayStub::Mode mode = mode_;
316 // ecx is boilerplate object.
317 if (mode == CLONE_ANY_ELEMENTS) {
318 Label double_elements, check_fast_elements;
319 __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset));
320 __ CheckMap(ebx, factory->fixed_cow_array_map(),
321 &check_fast_elements, DONT_DO_SMI_CHECK);
322 GenerateFastCloneShallowArrayCommon(masm, 0,
323 COPY_ON_WRITE_ELEMENTS, &slow_case);
324 __ ret(3 * kPointerSize);
325
326 __ bind(&check_fast_elements);
327 __ CheckMap(ebx, factory->fixed_array_map(),
328 &double_elements, DONT_DO_SMI_CHECK);
329 GenerateFastCloneShallowArrayCommon(masm, length_,
330 CLONE_ELEMENTS, &slow_case);
331 __ ret(3 * kPointerSize);
332
333 __ bind(&double_elements);
334 mode = CLONE_DOUBLE_ELEMENTS;
335 // Fall through to generate the code to handle double elements.
336 }
337
338 if (FLAG_debug_code) {
339 const char* message;
340 Handle<Map> expected_map;
341 if (mode == CLONE_ELEMENTS) {
342 message = "Expected (writable) fixed array";
343 expected_map = factory->fixed_array_map();
344 } else if (mode == CLONE_DOUBLE_ELEMENTS) {
345 message = "Expected (writable) fixed double array";
346 expected_map = factory->fixed_double_array_map();
347 } else {
348 ASSERT(mode == COPY_ON_WRITE_ELEMENTS);
349 message = "Expected copy-on-write fixed array";
350 expected_map = factory->fixed_cow_array_map();
351 }
352 __ push(ecx);
353 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
354 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map);
355 __ Assert(equal, message);
356 __ pop(ecx);
357 }
358
359 GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case);
326 // Return and remove the on-stack parameters. 360 // Return and remove the on-stack parameters.
327 __ ret(3 * kPointerSize); 361 __ ret(3 * kPointerSize);
328 362
329 __ bind(&slow_case); 363 __ bind(&slow_case);
330 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); 364 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1);
331 } 365 }
332 366
333 367
334 // The stub expects its argument on the stack and returns its result in tos_: 368 // The stub expects its argument on the stack and returns its result in tos_:
335 // zero for false, and a non-zero value for true. 369 // zero for false, and a non-zero value for true.
(...skipping 6771 matching lines...) Expand 10 before | Expand all | Expand 10 after
7107 false); 7141 false);
7108 __ pop(edx); 7142 __ pop(edx);
7109 __ ret(0); 7143 __ ret(0);
7110 } 7144 }
7111 7145
7112 #undef __ 7146 #undef __
7113 7147
7114 } } // namespace v8::internal 7148 } } // namespace v8::internal
7115 7149
7116 #endif // V8_TARGET_ARCH_IA32 7150 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/code-stubs.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | src/ia32/full-codegen-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698