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

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: review feedback 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
« no previous file with comments | « src/code-stubs.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 int length,
237 FastCloneShallowArrayStub::Mode mode,
238 Label* fail) {
239 // Stack and register layout on entry:
236 // 240 //
237 // [esp + kPointerSize]: constant elements. 241 // [esp + kPointerSize]: constant elements.
238 // [esp + (2 * kPointerSize)]: literal index. 242 // [esp + (2 * kPointerSize)]: literal index.
239 // [esp + (3 * kPointerSize)]: literals array. 243 // [esp + (3 * kPointerSize)]: literals array.
244 // eax: literal index.
245 // ecx: literals array.
246 ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS);
240 247
241 // All sizes here are multiples of kPointerSize. 248 // All sizes here are multiples of kPointerSize.
242 int elements_size = 0; 249 int elements_size = 0;
243 if (length_ > 0) { 250 if (length > 0) {
244 elements_size = mode_ == CLONE_DOUBLE_ELEMENTS 251 elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS
245 ? FixedDoubleArray::SizeFor(length_) 252 ? FixedDoubleArray::SizeFor(length)
246 : FixedArray::SizeFor(length_); 253 : FixedArray::SizeFor(length);
247 } 254 }
248 int size = JSArray::kSize + elements_size; 255 int size = JSArray::kSize + elements_size;
249 256
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 257 // Allocate both the JS array and the elements array in one big
286 // allocation. This avoids multiple limit checks. 258 // allocation. This avoids multiple limit checks.
287 __ AllocateInNewSpace(size, eax, ebx, edx, &slow_case, TAG_OBJECT); 259 __ AllocateInNewSpace(size, eax, ebx, edx, fail, TAG_OBJECT);
288 260
289 // Copy the JS array part. 261 // Copy the JS array part.
290 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { 262 for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
291 if ((i != JSArray::kElementsOffset) || (length_ == 0)) { 263 if ((i != JSArray::kElementsOffset) || (length == 0)) {
292 __ mov(ebx, FieldOperand(ecx, i)); 264 __ mov(ebx, FieldOperand(ecx, i));
293 __ mov(FieldOperand(eax, i), ebx); 265 __ mov(FieldOperand(eax, i), ebx);
294 } 266 }
295 } 267 }
296 268
297 if (length_ > 0) { 269 if (length > 0) {
298 // Get hold of the elements array of the boilerplate and setup the 270 // Get hold of the elements array of the boilerplate and setup the
299 // elements pointer in the resulting object. 271 // elements pointer in the resulting object.
300 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); 272 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
301 __ lea(edx, Operand(eax, JSArray::kSize)); 273 __ lea(edx, Operand(eax, JSArray::kSize));
302 __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); 274 __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx);
303 275
304 // Copy the elements array. 276 // Copy the elements array.
305 if (mode_ == CLONE_ELEMENTS) { 277 if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) {
306 for (int i = 0; i < elements_size; i += kPointerSize) { 278 for (int i = 0; i < elements_size; i += kPointerSize) {
307 __ mov(ebx, FieldOperand(ecx, i)); 279 __ mov(ebx, FieldOperand(ecx, i));
308 __ mov(FieldOperand(edx, i), ebx); 280 __ mov(FieldOperand(edx, i), ebx);
309 } 281 }
310 } else { 282 } else {
311 ASSERT(mode_ == CLONE_DOUBLE_ELEMENTS); 283 ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS);
312 int i; 284 int i;
313 for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) { 285 for (i = 0; i < FixedDoubleArray::kHeaderSize; i += kPointerSize) {
314 __ mov(ebx, FieldOperand(ecx, i)); 286 __ mov(ebx, FieldOperand(ecx, i));
315 __ mov(FieldOperand(edx, i), ebx); 287 __ mov(FieldOperand(edx, i), ebx);
316 } 288 }
317 while (i < elements_size) { 289 while (i < elements_size) {
318 __ fld_d(FieldOperand(ecx, i)); 290 __ fld_d(FieldOperand(ecx, i));
319 __ fstp_d(FieldOperand(edx, i)); 291 __ fstp_d(FieldOperand(edx, i));
320 i += kDoubleSize; 292 i += kDoubleSize;
321 } 293 }
322 ASSERT(i == elements_size); 294 ASSERT(i == elements_size);
323 } 295 }
324 } 296 }
297 }
325 298
299
300 void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) {
301 // Stack layout on entry:
302 //
303 // [esp + kPointerSize]: constant elements.
304 // [esp + (2 * kPointerSize)]: literal index.
305 // [esp + (3 * kPointerSize)]: literals array.
306
307 // Load boilerplate object into ecx and check if we need to create a
308 // boilerplate.
309 __ mov(ecx, Operand(esp, 3 * kPointerSize));
310 __ mov(eax, Operand(esp, 2 * kPointerSize));
311 STATIC_ASSERT(kPointerSize == 4);
312 STATIC_ASSERT(kSmiTagSize == 1);
313 STATIC_ASSERT(kSmiTag == 0);
314 __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size,
315 FixedArray::kHeaderSize));
316 Factory* factory = masm->isolate()->factory();
317 __ cmp(ecx, factory->undefined_value());
318 Label slow_case;
319 __ j(equal, &slow_case);
320
321 FastCloneShallowArrayStub::Mode mode = mode_;
322 // ecx is boilerplate object.
323 if (mode == CLONE_ANY_ELEMENTS) {
324 Label double_elements, check_fast_elements;
325 __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset));
326 __ CheckMap(ebx, factory->fixed_cow_array_map(),
327 &check_fast_elements, DONT_DO_SMI_CHECK);
328 GenerateFastCloneShallowArrayCommon(masm, 0,
329 COPY_ON_WRITE_ELEMENTS, &slow_case);
330 __ ret(3 * kPointerSize);
331
332 __ bind(&check_fast_elements);
333 __ CheckMap(ebx, factory->fixed_array_map(),
334 &double_elements, DONT_DO_SMI_CHECK);
335 GenerateFastCloneShallowArrayCommon(masm, length_,
336 CLONE_ELEMENTS, &slow_case);
337 __ ret(3 * kPointerSize);
338
339 __ bind(&double_elements);
340 mode = CLONE_DOUBLE_ELEMENTS;
341 // Fall through to generate the code to handle double elements.
342 }
343
344 if (FLAG_debug_code) {
345 const char* message;
346 Handle<Map> expected_map;
347 if (mode == CLONE_ELEMENTS) {
348 message = "Expected (writable) fixed array";
349 expected_map = factory->fixed_array_map();
350 } else if (mode == CLONE_DOUBLE_ELEMENTS) {
351 message = "Expected (writable) fixed double array";
352 expected_map = factory->fixed_double_array_map();
353 } else {
354 ASSERT(mode == COPY_ON_WRITE_ELEMENTS);
355 message = "Expected copy-on-write fixed array";
356 expected_map = factory->fixed_cow_array_map();
357 }
358 __ push(ecx);
359 __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset));
360 __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map);
361 __ Assert(equal, message);
362 __ pop(ecx);
363 }
364
365 GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case);
326 // Return and remove the on-stack parameters. 366 // Return and remove the on-stack parameters.
327 __ ret(3 * kPointerSize); 367 __ ret(3 * kPointerSize);
328 368
329 __ bind(&slow_case); 369 __ bind(&slow_case);
330 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); 370 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1);
331 } 371 }
332 372
333 373
334 // The stub expects its argument on the stack and returns its result in tos_: 374 // 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. 375 // zero for false, and a non-zero value for true.
(...skipping 6768 matching lines...) Expand 10 before | Expand all | Expand 10 after
7104 false); 7144 false);
7105 __ pop(edx); 7145 __ pop(edx);
7106 __ ret(0); 7146 __ ret(0);
7107 } 7147 }
7108 7148
7109 #undef __ 7149 #undef __
7110 7150
7111 } } // namespace v8::internal 7151 } } // namespace v8::internal
7112 7152
7113 #endif // V8_TARGET_ARCH_IA32 7153 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/code-stubs.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698