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

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: 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') | src/ia32/code-stubs-ia32.cc » ('J')
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 int offset = FixedArrayBase::kHeaderSize + target_kind * kPointerSize;
4301 __ ldr(r3, FieldMemOperand(r3, offset));
4302 __ mov(r2, receiver);
4303 ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
4304 masm, DONT_TRACK_ALLOCATION_SITE, NULL);
4305 }
4306
4307 // Save new length.
4308 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4309
4310 // Store the value.
4311 // We may need a register containing the address end_elements below, so write
4312 // back the value in end_elements.
4313 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
4314 __ str(r4, MemOperand(end_elements, kEndElementsOffset, PreIndex));
4315
4316 __ RecordWrite(elements,
4317 end_elements,
4318 r4,
4319 kLRHasNotBeenSaved,
4320 kDontSaveFPRegs,
4321 EMIT_REMEMBERED_SET,
4322 OMIT_SMI_CHECK);
4323 __ Drop(argc + 1);
4324 __ mov(r0, scratch);
4325 __ Ret();
4326
4327 __ bind(&attempt_to_grow_elements);
4328 // scratch: array's length + 1.
4329
4330 if (!FLAG_inline_new) {
4331 __ TailCallExternalReference(
4332 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4333 return;
4334 }
4335
4336 __ ldr(r2, MemOperand(sp, (argc - 1) * kPointerSize));
4337 // Growing elements that are SMI-only requires special handling in case the
4338 // new element is non-Smi. For now, delegate to the builtin.
4339 if (IsFastSmiElementsKind(elements_kind())) {
4340 __ JumpIfNotSmi(r2, &call_builtin);
4341 }
4342
4343 // We could be lucky and the elements array could be at the top of new-space.
4344 // In this case we can just grow it in place by moving the allocation pointer
4345 // up.
4346 ExternalReference new_space_allocation_top =
4347 ExternalReference::new_space_allocation_top_address(isolate);
4348 ExternalReference new_space_allocation_limit =
4349 ExternalReference::new_space_allocation_limit_address(isolate);
4350
4351 const int kAllocationDelta = 4;
4352 // Load top and check if it is the end of elements.
4353 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
4354 __ add(end_elements, end_elements, Operand(kEndElementsOffset));
4355 __ mov(r4, Operand(new_space_allocation_top));
4356 __ ldr(r3, MemOperand(r4));
4357 __ cmp(end_elements, r3);
4358 __ b(ne, &call_builtin);
4359
4360 __ mov(r9, Operand(new_space_allocation_limit));
4361 __ ldr(r9, MemOperand(r9));
4362 __ add(r3, r3, Operand(kAllocationDelta * kPointerSize));
4363 __ cmp(r3, r9);
4364 __ b(hi, &call_builtin);
4365
4366 // We fit and could grow elements.
4367 // Update new_space_allocation_top.
4368 __ str(r3, MemOperand(r4));
4369 // Push the argument.
4370 __ str(r2, MemOperand(end_elements));
4371 // Fill the rest with holes.
4372 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
4373 for (int i = 1; i < kAllocationDelta; i++) {
4374 __ str(r3, MemOperand(end_elements, i * kPointerSize));
4375 }
4376
4377 // Update elements' and array's sizes.
4378 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
4379 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
4380 __ add(r4, r4, Operand(Smi::FromInt(kAllocationDelta)));
4381 __ str(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
4382
4383 // Elements are in new space, so write barrier is not required.
4384 __ Drop(argc + 1);
4385 __ mov(r0, scratch);
4386 __ Ret();
4387
4388 __ bind(&call_builtin);
4389 __ TailCallExternalReference(
4390 ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
4391 }
4392
4393
4199 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { 4394 void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
4200 // ----------- S t a t e ------------- 4395 // ----------- S t a t e -------------
4201 // -- r1 : left 4396 // -- r1 : left
4202 // -- r0 : right 4397 // -- r0 : right
4203 // -- lr : return address 4398 // -- lr : return address
4204 // ----------------------------------- 4399 // -----------------------------------
4205 Isolate* isolate = masm->isolate(); 4400 Isolate* isolate = masm->isolate();
4206 4401
4207 // Load r2 with the allocation site. We stick an undefined dummy value here 4402 // 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 4403 // 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); 6045 __ bind(&fast_elements_case);
5851 GenerateCase(masm, FAST_ELEMENTS); 6046 GenerateCase(masm, FAST_ELEMENTS);
5852 } 6047 }
5853 6048
5854 6049
5855 #undef __ 6050 #undef __
5856 6051
5857 } } // namespace v8::internal 6052 } } // namespace v8::internal
5858 6053
5859 #endif // V8_TARGET_ARCH_ARM 6054 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/arm/stub-cache-arm.cc » ('j') | src/ia32/code-stubs-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698