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

Side by Side Diff: src/arm/code-stubs-arm.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: Properly bind label 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
« no previous file with comments | « no previous file | src/arm/stub-cache-arm.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 4178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4189 __ add(sp, sp, Operand(2 * kPointerSize)); 4189 __ add(sp, sp, Operand(2 * kPointerSize));
4190 GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5); 4190 GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5);
4191 4191
4192 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) 4192 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
4193 // tagged as a small integer. 4193 // tagged as a small integer.
4194 __ bind(&runtime); 4194 __ bind(&runtime);
4195 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); 4195 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
4196 } 4196 }
4197 4197
4198 4198
4199 void ArrayPushStub::Generate(MacroAssembler* masm) {
4200 Register receiver = r0;
4201 Register scratch = r1;
4202
4203 int argc = arguments_count();
4204
4205 if (argc == 0) {
4206 // Nothing to do, just return the length.
4207 __ ldr(r0, FieldMemOperand(receiver, JSArray::kLengthOffset));
4208 __ Drop(argc + 1);
4209 __ Ret();
4210 return;
4211 }
4212
4213 Isolate* isolate = masm->isolate();
4214
4215 if (argc != 1) {
4216 __ TailCallExternalReference(
4217 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4218 return;
4219 }
4220
4221 Label call_builtin, attempt_to_grow_elements, with_write_barrier;
4222
4223 Register elements = r6;
4224 Register end_elements = r5;
4225 // Get the elements array of the object.
4226 __ ldr(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
4227
4228 if (IsFastSmiOrObjectElementsKind(elements_kind())) {
4229 // Check that the elements are in fast mode and writable.
4230 __ CheckMap(elements,
4231 scratch,
4232 Heap::kFixedArrayMapRootIndex,
4233 &call_builtin,
4234 DONT_DO_SMI_CHECK);
4235 }
4236
4237 // Get the array's length into scratch and calculate new length.
4238 __ ldr(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4239 __ add(scratch, scratch, Operand(Smi::FromInt(argc)));
4240
4241 // Get the elements' length.
4242 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
4243
4244 // Check if we could survive without allocation.
4245 __ cmp(scratch, r4);
4246
4247 const int kEndElementsOffset =
4248 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
4249
4250 if (IsFastSmiOrObjectElementsKind(elements_kind())) {
4251 __ b(gt, &attempt_to_grow_elements);
4252
4253 // Check if value is a smi.
4254 __ ldr(r4, MemOperand(sp, (argc - 1) * kPointerSize));
4255 __ JumpIfNotSmi(r4, &with_write_barrier);
4256
4257 // Store the value.
4258 // We may need a register containing the address end_elements below, so
4259 // write back the value in end_elements.
4260 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
4261 __ str(r4, MemOperand(end_elements, kEndElementsOffset, PreIndex));
4262 } else {
4263 // Check if we could survive without allocation.
4264 __ cmp(scratch, r4);
4265 __ b(gt, &call_builtin);
4266
4267 __ ldr(r4, MemOperand(sp, (argc - 1) * kPointerSize));
4268 __ StoreNumberToDoubleElements(r4, scratch, elements, r5, d0,
4269 &call_builtin, argc * kDoubleSize);
4270 }
4271
4272 // Save new length.
4273 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4274 __ Drop(argc + 1);
4275 __ mov(r0, scratch);
4276 __ Ret();
4277
4278 if (IsFastDoubleElementsKind(elements_kind())) {
4279 __ bind(&call_builtin);
4280 __ TailCallExternalReference(
4281 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4282 return;
4283 }
4284
4285 __ bind(&with_write_barrier);
4286
4287 if (IsFastSmiElementsKind(elements_kind())) {
4288 if (FLAG_trace_elements_transitions) __ jmp(&call_builtin);
4289
4290 __ ldr(r9, FieldMemOperand(r4, HeapObject::kMapOffset));
4291 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
4292 __ cmp(r9, ip);
4293 __ b(eq, &call_builtin);
4294
4295 ElementsKind target_kind = IsHoleyElementsKind(elements_kind())
4296 ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS;
4297 __ ldr(r3, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
4298 __ ldr(r3, FieldMemOperand(r3, GlobalObject::kNativeContextOffset));
4299 __ ldr(r3, ContextOperand(r3, Context::JS_ARRAY_MAPS_INDEX));
4300 const int header_size = FixedArrayBase::kHeaderSize;
4301 // Verify that the object can be transitioned in place.
4302 const int origin_offset = header_size + elements_kind() * kPointerSize;
4303 __ ldr(r2, FieldMemOperand(receiver, origin_offset));
4304 __ ldr(ip, FieldMemOperand(r3, HeapObject::kMapOffset));
4305 __ cmp(r2, ip);
4306 __ b(ne, &call_builtin);
4307
4308 const int target_offset = header_size + target_kind * kPointerSize;
4309 __ ldr(r3, FieldMemOperand(r3, target_offset));
4310 __ mov(r2, receiver);
4311 ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
4312 masm, DONT_TRACK_ALLOCATION_SITE, NULL);
4313 }
4314
4315 // Save new length.
4316 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4317
4318 // Store the value.
4319 // We may need a register containing the address end_elements below, so write
4320 // back the value in end_elements.
4321 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
4322 __ str(r4, MemOperand(end_elements, kEndElementsOffset, PreIndex));
4323
4324 __ RecordWrite(elements,
4325 end_elements,
4326 r4,
4327 kLRHasNotBeenSaved,
4328 kDontSaveFPRegs,
4329 EMIT_REMEMBERED_SET,
4330 OMIT_SMI_CHECK);
4331 __ Drop(argc + 1);
4332 __ mov(r0, scratch);
4333 __ Ret();
4334
4335 __ bind(&attempt_to_grow_elements);
4336 // scratch: array's length + 1.
4337
4338 if (!FLAG_inline_new) {
4339 __ bind(&call_builtin);
4340 __ TailCallExternalReference(
4341 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4342 return;
4343 }
4344
4345 __ ldr(r2, MemOperand(sp, (argc - 1) * kPointerSize));
4346 // Growing elements that are SMI-only requires special handling in case the
4347 // new element is non-Smi. For now, delegate to the builtin.
4348 if (IsFastSmiElementsKind(elements_kind())) {
4349 __ JumpIfNotSmi(r2, &call_builtin);
4350 }
4351
4352 // We could be lucky and the elements array could be at the top of new-space.
4353 // In this case we can just grow it in place by moving the allocation pointer
4354 // up.
4355 ExternalReference new_space_allocation_top =
4356 ExternalReference::new_space_allocation_top_address(isolate);
4357 ExternalReference new_space_allocation_limit =
4358 ExternalReference::new_space_allocation_limit_address(isolate);
4359
4360 const int kAllocationDelta = 4;
4361 ASSERT(kAllocationDelta >= argc);
4362 // Load top and check if it is the end of elements.
4363 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
4364 __ add(end_elements, end_elements, Operand(kEndElementsOffset));
4365 __ mov(r4, Operand(new_space_allocation_top));
4366 __ ldr(r3, MemOperand(r4));
4367 __ cmp(end_elements, r3);
4368 __ b(ne, &call_builtin);
4369
4370 __ mov(r9, Operand(new_space_allocation_limit));
4371 __ ldr(r9, MemOperand(r9));
4372 __ add(r3, r3, Operand(kAllocationDelta * kPointerSize));
4373 __ cmp(r3, r9);
4374 __ b(hi, &call_builtin);
4375
4376 // We fit and could grow elements.
4377 // Update new_space_allocation_top.
4378 __ str(r3, MemOperand(r4));
4379 // Push the argument.
4380 __ str(r2, MemOperand(end_elements));
4381 // Fill the rest with holes.
4382 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
4383 for (int i = 1; i < kAllocationDelta; i++) {
4384 __ str(r3, MemOperand(end_elements, i * kPointerSize));
4385 }
4386
4387 // Update elements' and array's sizes.
4388 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4389 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
4390 __ add(r4, r4, Operand(Smi::FromInt(kAllocationDelta)));
4391 __ str(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
4392
4393 // Elements are in new space, so write barrier is not required.
4394 __ Drop(argc + 1);
4395 __ mov(r0, scratch);
4396 __ Ret();
4397
4398 __ bind(&call_builtin);
4399 __ TailCallExternalReference(
4400 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4401 }
4402
4403
4199 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { 4404 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4200 // ----------- S t a t e ------------- 4405 // ----------- S t a t e -------------
4201 // -- r1 : left 4406 // -- r1 : left
4202 // -- r0 : right 4407 // -- r0 : right
4203 // -- lr : return address 4408 // -- lr : return address
4204 // ----------------------------------- 4409 // -----------------------------------
4205 Isolate* isolate = masm->isolate(); 4410 Isolate* isolate = masm->isolate();
4206 4411
4207 // Load r2 with the allocation site. We stick an undefined dummy value here 4412 // Load r2 with the allocation site. We stick an undefined dummy value here
4208 // and replace it with the real allocation site later when we instantiate this 4413 // and replace it with the real allocation site later when we instantiate this
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after
5850 __ bind(&fast_elements_case); 6055 __ bind(&fast_elements_case);
5851 GenerateCase(masm, FAST_ELEMENTS); 6056 GenerateCase(masm, FAST_ELEMENTS);
5852 } 6057 }
5853 6058
5854 6059
5855 #undef __ 6060 #undef __
5856 6061
5857 } } // namespace v8::internal 6062 } } // namespace v8::internal
5858 6063
5859 #endif // V8_TARGET_ARCH_ARM 6064 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/arm/stub-cache-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698