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

Side by Side Diff: src/arm/builtins-arm.cc

Issue 5322009: Implement string constructor stub on ARM. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years 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/macro-assembler-arm.h » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // Jump to the generic construct code in case the specialized code cannot 475 // Jump to the generic construct code in case the specialized code cannot
476 // handle the construction. 476 // handle the construction.
477 __ bind(&generic_constructor); 477 __ bind(&generic_constructor);
478 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); 478 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric);
479 Handle<Code> generic_construct_stub(code); 479 Handle<Code> generic_construct_stub(code);
480 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); 480 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
481 } 481 }
482 482
483 483
484 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { 484 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
485 // TODO(849): implement custom construct stub. 485 // ----------- S t a t e -------------
486 // Generate a copy of the generic stub for now. 486 // -- r0 : number of arguments
487 Generate_JSConstructStubGeneric(masm); 487 // -- r1 : constructor function
488 // -- lr : return address
489 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
490 // -- sp[argc * 4] : receiver
491 // -----------------------------------
492 __ IncrementCounter(&Counters::string_ctor_calls, 1, r2, r3);
493
494 Register function = r1;
495 if (FLAG_debug_code) {
496 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, r2);
497 __ cmp(function, Operand(r2));
498 __ Assert(eq, "Unexpected String function");
499 }
500
501 // Load the first arguments in r0 and get rid of the rest.
502 Label no_arguments;
503 __ cmp(r0, Operand(0));
504 __ b(eq, &no_arguments);
505 // First args = sp[(argc - 1) * 4].
506 __ sub(r0, r0, Operand(1));
507 __ ldr(r0, MemOperand(sp, r0, LSL, kPointerSizeLog2, PreIndex));
508 // sp now point to args[0], drop args[0] + receiver.
509 __ Drop(2);
510
511 Register argument = r2;
512 Label not_cached, argument_is_string;
513 NumberToStringStub::GenerateLookupNumberStringCache(
514 masm,
515 r0, // Input.
516 argument, // Result.
517 r3, // Scratch.
518 r4, // Scratch.
519 r5, // Scratch.
520 false, // Is it a Smi?
521 &not_cached);
522 __ IncrementCounter(&Counters::string_ctor_cached_number, 1, r3, r4);
523 __ bind(&argument_is_string);
524
525 // ----------- S t a t e -------------
526 // -- r2 : argument converted to string
527 // -- r1 : constructor function
528 // -- lr : return address
529 // -----------------------------------
530
531 Label gc_required;
532 __ AllocateInNewSpace(JSValue::kSize,
533 r0, // Result.
534 r3, // Scratch.
535 r4, // Scratch.
536 &gc_required,
537 TAG_OBJECT);
538
539 // Initialising the String Object.
540 Register map = r3;
541 __ LoadGlobalFunctionInitialMap(function, map, r4);
542 if (FLAG_debug_code) {
543 __ ldrb(r4, FieldMemOperand(map, Map::kInstanceSizeOffset));
544 __ cmp(r4, Operand(JSValue::kSize >> kPointerSizeLog2));
545 __ Assert(eq, "Unexpected string wrapper instance size");
546 __ ldrb(r4, FieldMemOperand(map, Map::kUnusedPropertyFieldsOffset));
547 __ cmp(r4, Operand(0));
548 __ Assert(eq, "Unexpected unused properties of string wrapper");
549 }
550 __ str(map, FieldMemOperand(r0, HeapObject::kMapOffset));
551
552 __ LoadRoot(r3, Heap::kEmptyFixedArrayRootIndex);
553 __ str(r3, FieldMemOperand(r0, JSObject::kPropertiesOffset));
554 __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset));
555
556 __ str(argument, FieldMemOperand(r0, JSValue::kValueOffset));
557
558 // Ensure the object is fully initialized.
559 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
560
561 __ Ret();
562
563 // The argument was not found in the number to string cache. Check
564 // if it's a string already before calling the conversion builtin.
565 Label convert_argument;
566 __ bind(&not_cached);
567 __ BranchOnSmi(r0, &convert_argument);
568
569 // Is it a String?
570 __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
571 __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceTypeOffset));
572 ASSERT(kNotStringTag != 0);
573 __ tst(r3, Operand(kIsNotStringMask));
574 __ b(ne, &convert_argument);
575 __ mov(argument, r0);
576 __ IncrementCounter(&Counters::string_ctor_conversions, 1, r3, r4);
577 __ b(&argument_is_string);
578
579 // Invoke the conversion builtin and put the result into r2.
580 __ bind(&convert_argument);
581 __ push(function); // Preserve the function.
582 __ IncrementCounter(&Counters::string_ctor_conversions, 1, r3, r4);
583 __ EnterInternalFrame();
584 __ push(r0);
585 __ InvokeBuiltin(Builtins::TO_STRING, CALL_JS);
586 __ LeaveInternalFrame();
587 __ pop(function);
588 __ mov(argument, r0);
589 __ b(&argument_is_string);
590
591 // Load the empty string into r2, remove the receiver from the
592 // stack, and jump back to the case where the argument is a string.
593 __ bind(&no_arguments);
594 __ LoadRoot(argument, Heap::kEmptyStringRootIndex);
595 __ Drop(1);
596 __ b(&argument_is_string);
597
598 // At this point the argument is already a string. Call runtime to
599 // create a string wrapper.
600 __ bind(&gc_required);
601 __ IncrementCounter(&Counters::string_ctor_gc_required, 1, r3, r4);
602 __ EnterInternalFrame();
603 __ push(argument);
604 __ CallRuntime(Runtime::kNewStringWrapper, 1);
605 __ LeaveInternalFrame();
606 __ Ret();
488 } 607 }
489 608
490 609
491 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { 610 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) {
492 // ----------- S t a t e ------------- 611 // ----------- S t a t e -------------
493 // -- r0 : number of arguments 612 // -- r0 : number of arguments
494 // -- r1 : constructor function 613 // -- r1 : constructor function
495 // -- lr : return address 614 // -- lr : return address
496 // -- sp[...]: constructor arguments 615 // -- sp[...]: constructor arguments
497 // ----------------------------------- 616 // -----------------------------------
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 __ bind(&dont_adapt_arguments); 1489 __ bind(&dont_adapt_arguments);
1371 __ Jump(r3); 1490 __ Jump(r3);
1372 } 1491 }
1373 1492
1374 1493
1375 #undef __ 1494 #undef __
1376 1495
1377 } } // namespace v8::internal 1496 } } // namespace v8::internal
1378 1497
1379 #endif // V8_TARGET_ARCH_ARM 1498 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/arm/macro-assembler-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698