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

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

Issue 143213003: Turn ArrayPush into a stub specialized on the elements kind and argc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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
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 4239 matching lines...) Expand 10 before | Expand all | Expand 10 after
4250 __ PushReturnAddressFrom(rcx); 4250 __ PushReturnAddressFrom(rcx);
4251 GenerateCompareFlatAsciiStrings(masm, rdx, rax, rcx, rbx, rdi, r8); 4251 GenerateCompareFlatAsciiStrings(masm, rdx, rax, rcx, rbx, rdi, r8);
4252 4252
4253 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) 4253 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
4254 // tagged as a small integer. 4254 // tagged as a small integer.
4255 __ bind(&runtime); 4255 __ bind(&runtime);
4256 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); 4256 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4257 } 4257 }
4258 4258
4259 4259
4260 void ArrayPushStub::Generate(MacroAssembler* masm) {
4261 int argc = arguments_count();
4262
4263 StackArgumentsAccessor args(rsp, argc);
4264 if (argc == 0) {
4265 // Noop, return the length.
4266 __ movp(rax, FieldOperand(rdx, JSArray::kLengthOffset));
4267 __ ret((argc + 1) * kPointerSize);
4268 return;
4269 }
4270
4271 Isolate* isolate = masm->isolate();
4272
4273 if (argc != 1) {
4274 __ TailCallExternalReference(
4275 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4276 return;
4277 }
4278
4279 Label call_builtin, attempt_to_grow_elements, with_write_barrier;
4280
4281 // Get the elements array of the object.
4282 __ movp(rdi, FieldOperand(rdx, JSArray::kElementsOffset));
4283
4284 if (IsFastSmiOrObjectElementsKind(elements_kind())) {
4285 // Check that the elements are in fast mode and writable.
4286 __ Cmp(FieldOperand(rdi, HeapObject::kMapOffset),
4287 isolate->factory()->fixed_array_map());
4288 __ j(not_equal, &call_builtin);
4289 }
4290
4291 // Get the array's length into rax and calculate new length.
4292 __ SmiToInteger32(rax, FieldOperand(rdx, JSArray::kLengthOffset));
4293 STATIC_ASSERT(FixedArray::kMaxLength < Smi::kMaxValue);
4294 __ addl(rax, Immediate(argc));
4295
4296 // Get the elements' length into rcx.
4297 __ SmiToInteger32(rcx, FieldOperand(rdi, FixedArray::kLengthOffset));
4298
4299 // Check if we could survive without allocation.
4300 __ cmpl(rax, rcx);
4301
4302 if (IsFastSmiOrObjectElementsKind(elements_kind())) {
4303 __ j(greater, &attempt_to_grow_elements);
4304
4305 // Check if value is a smi.
4306 __ movp(rcx, args.GetArgumentOperand(1));
4307 __ JumpIfNotSmi(rcx, &with_write_barrier);
4308
4309 // Store the value.
4310 __ movp(FieldOperand(rdi,
4311 rax,
4312 times_pointer_size,
4313 FixedArray::kHeaderSize - argc * kPointerSize),
4314 rcx);
4315 } else {
4316 __ j(greater, &call_builtin);
4317
4318 __ movp(rcx, args.GetArgumentOperand(1));
4319 __ StoreNumberToDoubleElements(
4320 rcx, rdi, rax, xmm0, &call_builtin, argc * kDoubleSize);
4321 }
4322
4323 // Save new length.
4324 __ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax);
4325
4326 __ Integer32ToSmi(rax, rax); // Return new length as smi.
4327 __ ret((argc + 1) * kPointerSize);
4328
4329 if (IsFastDoubleElementsKind(elements_kind())) {
4330 __ bind(&call_builtin);
4331 __ TailCallExternalReference(
4332 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4333 return;
4334 }
4335
4336 __ bind(&with_write_barrier);
4337
4338 if (IsFastSmiElementsKind(elements_kind())) {
4339 if (FLAG_trace_elements_transitions) __ jmp(&call_builtin);
4340
4341 __ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
4342 isolate->factory()->heap_number_map());
4343 __ j(equal, &call_builtin);
4344
4345 ElementsKind target_kind = IsHoleyElementsKind(elements_kind())
4346 ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS;
4347 __ movp(rbx, ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX));
4348 __ movp(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset));
4349 __ movp(rbx, ContextOperand(rbx, Context::JS_ARRAY_MAPS_INDEX));
4350 int offset = FixedArrayBase::kHeaderSize + target_kind * kPointerSize;
4351 __ movp(rbx, FieldOperand(rbx, offset));
4352 ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
4353 masm, DONT_TRACK_ALLOCATION_SITE, NULL);
4354 __ movp(rdi, FieldOperand(rdx, JSArray::kElementsOffset));
4355 }
4356
4357 // Save new length.
4358 __ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax);
4359
4360 // Store the value.
4361 __ lea(rdx, FieldOperand(rdi,
4362 rax, times_pointer_size,
4363 FixedArray::kHeaderSize - argc * kPointerSize));
4364 __ movp(Operand(rdx, 0), rcx);
4365
4366 __ RecordWrite(rdi, rdx, rcx, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
4367 OMIT_SMI_CHECK);
4368
4369 __ Integer32ToSmi(rax, rax); // Return new length as smi.
4370 __ ret((argc + 1) * kPointerSize);
4371
4372 __ bind(&attempt_to_grow_elements);
4373 if (!FLAG_inline_new) {
4374 __ TailCallExternalReference(
4375 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4376 return;
4377 }
4378
4379 __ movp(rbx, args.GetArgumentOperand(1));
4380 // Growing elements that are SMI-only requires special handling in case the
4381 // new element is non-Smi. For now, delegate to the builtin.
4382 Label no_fast_elements_check;
4383 __ JumpIfSmi(rbx, &no_fast_elements_check);
4384 __ movp(rcx, FieldOperand(rdx, HeapObject::kMapOffset));
4385 __ CheckFastObjectElements(rcx, &call_builtin, Label::kFar);
4386 __ bind(&no_fast_elements_check);
4387
4388 ExternalReference new_space_allocation_top =
4389 ExternalReference::new_space_allocation_top_address(isolate);
4390 ExternalReference new_space_allocation_limit =
4391 ExternalReference::new_space_allocation_limit_address(isolate);
4392
4393 const int kAllocationDelta = 4;
4394 // Load top.
4395 __ Load(rcx, new_space_allocation_top);
4396
4397 // Check if it's the end of elements.
4398 __ lea(rdx, FieldOperand(rdi,
4399 rax, times_pointer_size,
4400 FixedArray::kHeaderSize - argc * kPointerSize));
4401 __ cmpq(rdx, rcx);
4402 __ j(not_equal, &call_builtin);
4403 __ addq(rcx, Immediate(kAllocationDelta * kPointerSize));
4404 Operand limit_operand = masm->ExternalOperand(new_space_allocation_limit);
4405 __ cmpq(rcx, limit_operand);
4406 __ j(above, &call_builtin);
4407
4408 // We fit and could grow elements.
4409 __ Store(new_space_allocation_top, rcx);
4410
4411 // Push the argument...
4412 __ movp(Operand(rdx, 0), rbx);
4413 // ... and fill the rest with holes.
4414 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
4415 for (int i = 1; i < kAllocationDelta; i++) {
4416 __ movp(Operand(rdx, i * kPointerSize), kScratchRegister);
4417 }
4418
4419 if (IsFastObjectElementsKind(elements_kind())) {
4420 // We know the elements array is in new space so we don't need the
4421 // remembered set, but we just pushed a value onto it so we may have to tell
4422 // the incremental marker to rescan the object that we just grew. We don't
4423 // need to worry about the holes because they are in old space and already
4424 // marked black.
4425 __ RecordWrite(rdi, rdx, rbx, kDontSaveFPRegs, OMIT_REMEMBERED_SET);
4426 }
4427
4428 // Restore receiver to rdx as finish sequence assumes it's here.
4429 __ movp(rdx, args.GetReceiverOperand());
4430
4431 // Increment element's and array's sizes.
4432 __ SmiAddConstant(FieldOperand(rdi, FixedArray::kLengthOffset),
4433 Smi::FromInt(kAllocationDelta));
4434
4435 // Make new length a smi before returning it.
4436 __ Integer32ToSmi(rax, rax);
4437 __ movp(FieldOperand(rdx, JSArray::kLengthOffset), rax);
4438
4439 __ ret((argc + 1) * kPointerSize);
4440
4441 __ bind(&call_builtin);
4442 __ TailCallExternalReference(
4443 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4444 }
4445
4446
4260 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { 4447 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4261 // ----------- S t a t e ------------- 4448 // ----------- S t a t e -------------
4262 // -- rdx : left 4449 // -- rdx : left
4263 // -- rax : right 4450 // -- rax : right
4264 // -- rsp[0] : return address 4451 // -- rsp[0] : return address
4265 // ----------------------------------- 4452 // -----------------------------------
4266 Isolate* isolate = masm->isolate(); 4453 Isolate* isolate = masm->isolate();
4267 4454
4268 // Load rcx with the allocation site. We stick an undefined dummy value here 4455 // Load rcx with the allocation site. We stick an undefined dummy value here
4269 // and replace it with the real allocation site later when we instantiate this 4456 // and replace it with the real allocation site later when we instantiate this
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
5528 __ bind(&fast_elements_case); 5715 __ bind(&fast_elements_case);
5529 GenerateCase(masm, FAST_ELEMENTS); 5716 GenerateCase(masm, FAST_ELEMENTS);
5530 } 5717 }
5531 5718
5532 5719
5533 #undef __ 5720 #undef __
5534 5721
5535 } } // namespace v8::internal 5722 } } // namespace v8::internal
5536 5723
5537 #endif // V8_TARGET_ARCH_X64 5724 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/ia32/code-stubs-ia32.cc ('K') | « src/stub-cache.cc ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698