1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef V8_ARM_CODEGEN_ARM_H_
29 #define V8_ARM_CODEGEN_ARM_H_
37 // Forward declarations
38 class CompilationInfo;
41 class RegisterAllocator;
44 enum InitState { CONST_INIT, NOT_CONST_INIT };
45 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
46 enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI };
49 // -------------------------------------------------------------------------
52 // A reference is a C++ stack-allocated object that puts a
53 // reference on the virtual frame. The reference may be consumed
54 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
55 // When the lifetime (scope) of a valid reference ends, it must have
56 // been consumed, and be in state UNLOADED.
57 class Reference BASE_EMBEDDED {
59 // The values of the types is important, see size().
60 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
61 Reference(CodeGenerator* cgen,
62 Expression* expression,
63 bool persist_after_get = false);
66 Expression* expression() const { return expression_; }
67 Type type() const { return type_; }
68 void set_type(Type value) {
69 ASSERT_EQ(ILLEGAL, type_);
74 ASSERT_NE(ILLEGAL, type_);
75 ASSERT_NE(UNLOADED, type_);
78 // The size the reference takes up on the stack.
80 return (type_ < SLOT) ? 0 : type_;
83 bool is_illegal() const { return type_ == ILLEGAL; }
84 bool is_slot() const { return type_ == SLOT; }
85 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
86 bool is_unloaded() const { return type_ == UNLOADED; }
88 // Return the name. Only valid for named property references.
89 Handle<String> GetName();
91 // Generate code to push the value of the reference on top of the
92 // expression stack. The reference is expected to be already on top of
93 // the expression stack, and it is consumed by the call unless the
94 // reference is for a compound assignment.
95 // If the reference is not consumed, it is left in place under its value.
98 // Generate code to store the value on top of the expression stack in the
99 // reference. The reference is expected to be immediately below the value
100 // on the expression stack. The value is stored in the location specified
101 // by the reference, and is left on top of the stack, after the reference
102 // is popped from beneath it (unloaded).
103 void SetValue(InitState init_state);
105 // This is in preparation for something that uses the reference on the stack.
106 // If we need this reference afterwards get then dup it now. Otherwise mark
108 inline void DupIfPersist();
111 CodeGenerator* cgen_;
112 Expression* expression_;
114 // Keep the reference on the stack after get, so it can be used by set later.
115 bool persist_after_get_;
119 // -------------------------------------------------------------------------
120 // Code generation state
122 // The state is passed down the AST by the code generator (and back up, in
123 // the form of the state of the label pair). It is threaded through the
124 // call stack. Constructing a state implicitly pushes it on the owning code
125 // generator's stack of states, and destroying one implicitly pops it.
127 class CodeGenState BASE_EMBEDDED {
129 // Create an initial code generator state. Destroying the initial state
130 // leaves the code generator with a NULL state.
131 explicit CodeGenState(CodeGenerator* owner);
133 // Destroy a code generator state and restore the owning code generator's
135 virtual ~CodeGenState();
137 virtual JumpTarget* true_target() const { return NULL; }
138 virtual JumpTarget* false_target() const { return NULL; }
141 inline CodeGenerator* owner() { return owner_; }
142 inline CodeGenState* previous() const { return previous_; }
145 CodeGenerator* owner_;
146 CodeGenState* previous_;
150 class ConditionCodeGenState : public CodeGenState {
152 // Create a code generator state based on a code generator's current
153 // state. The new state has its own pair of branch labels.
154 ConditionCodeGenState(CodeGenerator* owner,
155 JumpTarget* true_target,
156 JumpTarget* false_target);
158 virtual JumpTarget* true_target() const { return true_target_; }
159 virtual JumpTarget* false_target() const { return false_target_; }
162 JumpTarget* true_target_;
163 JumpTarget* false_target_;
167 class TypeInfoCodeGenState : public CodeGenState {
169 TypeInfoCodeGenState(CodeGenerator* owner,
172 ~TypeInfoCodeGenState();
174 virtual JumpTarget* true_target() const { return previous()->true_target(); }
175 virtual JumpTarget* false_target() const {
176 return previous()->false_target();
181 TypeInfo old_type_info_;
185 // -------------------------------------------------------------------------
186 // Arguments allocation mode
188 enum ArgumentsAllocationMode {
189 NO_ARGUMENTS_ALLOCATION,
190 EAGER_ARGUMENTS_ALLOCATION,
191 LAZY_ARGUMENTS_ALLOCATION
195 // Different nop operations are used by the code generator to detect certain
196 // states of the generated code.
197 enum NopMarkerTypes {
199 PROPERTY_ACCESS_INLINED
203 // -------------------------------------------------------------------------
206 class CodeGenerator: public AstVisitor {
208 // Takes a function literal, generates code for it. This function should only
209 // be called by compiler.cc.
210 static Handle<Code> MakeCode(CompilationInfo* info);
212 // Printing of AST, etc. as requested by flags.
213 static void MakeCodePrologue(CompilationInfo* info);
215 // Allocate and install the code.
216 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
218 CompilationInfo* info);
220 #ifdef ENABLE_LOGGING_AND_PROFILING
221 static bool ShouldGenerateLog(Expression* type);
224 static void SetFunctionInfo(Handle<JSFunction> fun,
225 FunctionLiteral* lit,
227 Handle<Script> script);
229 static void RecordPositions(MacroAssembler* masm, int pos);
232 MacroAssembler* masm() { return masm_; }
233 VirtualFrame* frame() const { return frame_; }
234 inline Handle<Script> script();
236 bool has_valid_frame() const { return frame_ != NULL; }
238 // Set the virtual frame to be new_frame, with non-frame register
239 // reference counts given by non_frame_registers. The non-frame
240 // register reference counts of the old frame are returned in
241 // non_frame_registers.
242 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
246 RegisterAllocator* allocator() const { return allocator_; }
248 CodeGenState* state() { return state_; }
249 void set_state(CodeGenState* state) { state_ = state; }
251 TypeInfo type_info(Slot* slot) {
252 int index = NumberOfSlot(slot);
253 if (index == kInvalidSlotNumber) return TypeInfo::Unknown();
254 return (*type_info_)[index];
257 TypeInfo set_type_info(Slot* slot, TypeInfo info) {
258 int index = NumberOfSlot(slot);
259 ASSERT(index >= kInvalidSlotNumber);
260 if (index != kInvalidSlotNumber) {
261 TypeInfo previous_value = (*type_info_)[index];
262 (*type_info_)[index] = info;
263 return previous_value;
265 return TypeInfo::Unknown();
268 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
270 static const int kUnknownIntValue = -1;
272 // If the name is an inline runtime function call return the number of
273 // expected arguments. Otherwise return -1.
274 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
276 // Constants related to patching of inlined load/store.
277 static const int kInlinedKeyedLoadInstructionsAfterPatch = 17;
278 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
281 // Construction/Destruction
282 explicit CodeGenerator(MacroAssembler* masm);
285 inline bool is_eval();
286 inline Scope* scope();
288 // Generating deferred code.
289 void ProcessDeferred();
291 static const int kInvalidSlotNumber = -1;
293 int NumberOfSlot(Slot* slot);
296 bool has_cc() const { return cc_reg_ != al; }
297 JumpTarget* true_target() const { return state_->true_target(); }
298 JumpTarget* false_target() const { return state_->false_target(); }
300 // Track loop nesting level.
301 int loop_nesting() const { return loop_nesting_; }
302 void IncrementLoopNesting() { loop_nesting_++; }
303 void DecrementLoopNesting() { loop_nesting_--; }
306 void VisitStatements(ZoneList<Statement*>* statements);
308 #define DEF_VISIT(type) \
309 void Visit##type(type* node);
310 AST_NODE_LIST(DEF_VISIT)
313 // Main code generation function
314 void Generate(CompilationInfo* info);
316 // Returns the arguments allocation mode.
317 ArgumentsAllocationMode ArgumentsMode();
319 // Store the arguments object and allocate it if necessary.
320 void StoreArgumentsObject(bool initial);
322 // The following are used by class Reference.
323 void LoadReference(Reference* ref);
324 void UnloadReference(Reference* ref);
326 static MemOperand ContextOperand(Register context, int index) {
327 return MemOperand(context, Context::SlotOffset(index));
330 MemOperand SlotOperand(Slot* slot, Register tmp);
332 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
338 static MemOperand GlobalObject() {
339 return ContextOperand(cp, Context::GLOBAL_INDEX);
342 void LoadCondition(Expression* x,
343 JumpTarget* true_target,
344 JumpTarget* false_target,
346 void Load(Expression* expr);
348 void LoadGlobalReceiver(Register scratch);
350 // Read a value from a slot and leave it on top of the expression stack.
351 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
352 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
354 // Store the value on top of the stack to a slot.
355 void StoreToSlot(Slot* slot, InitState init_state);
357 // Support for compiling assignment expressions.
358 void EmitSlotAssignment(Assignment* node);
359 void EmitNamedPropertyAssignment(Assignment* node);
360 void EmitKeyedPropertyAssignment(Assignment* node);
362 // Load a named property, returning it in r0. The receiver is passed on the
363 // stack, and remains there.
364 void EmitNamedLoad(Handle<String> name, bool is_contextual);
366 // Store to a named property. If the store is contextual, value is passed on
367 // the frame and consumed. Otherwise, receiver and value are passed on the
368 // frame and consumed. The result is returned in r0.
369 void EmitNamedStore(Handle<String> name, bool is_contextual);
371 // Load a keyed property, leaving it in r0. The receiver and key are
372 // passed on the stack, and remain there.
373 void EmitKeyedLoad();
375 // Store a keyed property. Key and receiver are on the stack and the value is
376 // in r0. Result is returned in r0.
377 void EmitKeyedStore(StaticType* key_type);
379 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
380 TypeofState typeof_state,
383 // Support for loading from local/global variables and arguments
384 // whose location is known unless they are shadowed by
385 // eval-introduced bindings. Generates no code for unsupported slot
386 // types and therefore expects to fall through to the slow jump target.
387 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
388 TypeofState typeof_state,
392 // Special code for typeof expressions: Unfortunately, we must
393 // be careful when loading the expression in 'typeof'
394 // expressions. We are not allowed to throw reference errors for
395 // non-existing properties of the global object, so we must make it
396 // look like an explicit property access, instead of an access
397 // through the context chain.
398 void LoadTypeofExpression(Expression* x);
400 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
402 // Generate code that computes a shortcutting logical operation.
403 void GenerateLogicalBooleanOperation(BinaryOperation* node);
405 void GenericBinaryOperation(Token::Value op,
406 OverwriteMode overwrite_mode,
407 GenerateInlineSmi inline_smi,
408 int known_rhs = kUnknownIntValue);
409 void Comparison(Condition cc,
412 bool strict = false);
414 void SmiOperation(Token::Value op,
415 Handle<Object> value,
419 void CallWithArguments(ZoneList<Expression*>* arguments,
420 CallFunctionFlags flags,
423 // An optimized implementation of expressions of the form
424 // x.apply(y, arguments). We call x the applicand and y the receiver.
425 // The optimization avoids allocating an arguments object if possible.
426 void CallApplyLazy(Expression* applicand,
427 Expression* receiver,
428 VariableProxy* arguments,
432 void Branch(bool if_true, JumpTarget* target);
435 struct InlineRuntimeLUT {
436 void (CodeGenerator::*method)(ZoneList<Expression*>*);
441 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
442 bool CheckForInlineRuntimeCall(CallRuntime* node);
443 static bool PatchInlineRuntimeEntry(Handle<String> name,
444 const InlineRuntimeLUT& new_entry,
445 InlineRuntimeLUT* old_entry);
447 static Handle<Code> ComputeLazyCompile(int argc);
448 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
450 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
452 static Handle<Code> ComputeKeyedCallInitialize(int argc, InLoopFlag in_loop);
454 // Declare global variables and functions in the given array of
456 void DeclareGlobals(Handle<FixedArray> pairs);
458 // Instantiate the function based on the shared function info.
459 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
461 // Support for type checks.
462 void GenerateIsSmi(ZoneList<Expression*>* args);
463 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
464 void GenerateIsArray(ZoneList<Expression*>* args);
465 void GenerateIsRegExp(ZoneList<Expression*>* args);
466 void GenerateIsObject(ZoneList<Expression*>* args);
467 void GenerateIsFunction(ZoneList<Expression*>* args);
468 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
470 // Support for construct call checks.
471 void GenerateIsConstructCall(ZoneList<Expression*>* args);
473 // Support for arguments.length and arguments[?].
474 void GenerateArgumentsLength(ZoneList<Expression*>* args);
475 void GenerateArguments(ZoneList<Expression*>* args);
477 // Support for accessing the class and value fields of an object.
478 void GenerateClassOf(ZoneList<Expression*>* args);
479 void GenerateValueOf(ZoneList<Expression*>* args);
480 void GenerateSetValueOf(ZoneList<Expression*>* args);
482 // Fast support for charCodeAt(n).
483 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
485 // Fast support for string.charAt(n) and string[n].
486 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
488 // Fast support for string.charAt(n) and string[n].
489 void GenerateStringCharAt(ZoneList<Expression*>* args);
491 // Fast support for object equality testing.
492 void GenerateObjectEquals(ZoneList<Expression*>* args);
494 void GenerateLog(ZoneList<Expression*>* args);
496 // Fast support for Math.random().
497 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
499 // Fast support for StringAdd.
500 void GenerateStringAdd(ZoneList<Expression*>* args);
502 // Fast support for SubString.
503 void GenerateSubString(ZoneList<Expression*>* args);
505 // Fast support for StringCompare.
506 void GenerateStringCompare(ZoneList<Expression*>* args);
508 // Support for direct calls from JavaScript to native RegExp code.
509 void GenerateRegExpExec(ZoneList<Expression*>* args);
511 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
513 // Support for fast native caches.
514 void GenerateGetFromCache(ZoneList<Expression*>* args);
516 // Fast support for number to string.
517 void GenerateNumberToString(ZoneList<Expression*>* args);
519 // Fast swapping of elements.
520 void GenerateSwapElements(ZoneList<Expression*>* args);
522 // Fast call for custom callbacks.
523 void GenerateCallFunction(ZoneList<Expression*>* args);
525 // Fast call to math functions.
526 void GenerateMathPow(ZoneList<Expression*>* args);
527 void GenerateMathSin(ZoneList<Expression*>* args);
528 void GenerateMathCos(ZoneList<Expression*>* args);
529 void GenerateMathSqrt(ZoneList<Expression*>* args);
531 // Simple condition analysis.
532 enum ConditionAnalysis {
537 ConditionAnalysis AnalyzeCondition(Expression* cond);
539 // Methods used to indicate which source code is generated for. Source
540 // positions are collected by the assembler and emitted with the relocation
542 void CodeForFunctionPosition(FunctionLiteral* fun);
543 void CodeForReturnPosition(FunctionLiteral* fun);
544 void CodeForStatementPosition(Statement* node);
545 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
546 void CodeForSourcePosition(int pos);
549 // True if the registers are valid for entry to a block.
550 bool HasValidEntryRegisters();
553 List<DeferredCode*> deferred_;
556 MacroAssembler* masm_; // to generate code
558 CompilationInfo* info_;
560 // Code generation state
561 VirtualFrame* frame_;
562 RegisterAllocator* allocator_;
564 CodeGenState* state_;
567 Vector<TypeInfo>* type_info_;
570 BreakTarget function_return_;
572 // True if the function return is shadowed (ie, jumping to the target
573 // function_return_ does not jump to the true function return, but rather
574 // to some unlinking code).
575 bool function_return_is_shadowed_;
577 static InlineRuntimeLUT kInlineRuntimeLUT[];
579 friend class VirtualFrame;
580 friend class JumpTarget;
581 friend class Reference;
582 friend class FastCodeGenerator;
583 friend class FullCodeGenerator;
584 friend class FullCodeGenSyntaxChecker;
586 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
590 class GenericBinaryOpStub : public CodeStub {
592 GenericBinaryOpStub(Token::Value op,
596 int constant_rhs = CodeGenerator::kUnknownIntValue)
601 constant_rhs_(constant_rhs),
602 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
603 runtime_operands_type_(BinaryOpIC::DEFAULT),
606 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
607 : op_(OpBits::decode(key)),
608 mode_(ModeBits::decode(key)),
609 lhs_(LhsRegister(RegisterBits::decode(key))),
610 rhs_(RhsRegister(RegisterBits::decode(key))),
611 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
612 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
613 runtime_operands_type_(type_info),
622 bool specialized_on_rhs_;
623 BinaryOpIC::TypeInfo runtime_operands_type_;
626 static const int kMaxKnownRhs = 0x40000000;
627 static const int kKnownRhsKeyBits = 6;
629 // Minor key encoding in 17 bits.
630 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
631 class OpBits: public BitField<Token::Value, 2, 6> {};
632 class TypeInfoBits: public BitField<int, 8, 2> {};
633 class RegisterBits: public BitField<bool, 10, 1> {};
634 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
636 Major MajorKey() { return GenericBinaryOp; }
638 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
639 (lhs_.is(r1) && rhs_.is(r0)));
640 // Encode the parameters in a unique 18 bit value.
641 return OpBits::encode(op_)
642 | ModeBits::encode(mode_)
643 | KnownIntBits::encode(MinorKeyForKnownInt())
644 | TypeInfoBits::encode(runtime_operands_type_)
645 | RegisterBits::encode(lhs_.is(r0));
648 void Generate(MacroAssembler* masm);
649 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
650 void HandleBinaryOpSlowCases(MacroAssembler* masm,
654 const Builtins::JavaScript& builtin);
655 void GenerateTypeTransition(MacroAssembler* masm);
657 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
658 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
659 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
660 if (op == Token::MOD) {
661 if (constant_rhs <= 1) return false;
662 if (constant_rhs <= 10) return true;
663 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
669 int MinorKeyForKnownInt() {
670 if (!specialized_on_rhs_) return 0;
671 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
672 ASSERT(IsPowerOf2(constant_rhs_));
674 int d = constant_rhs_;
675 while ((d & 1) == 0) {
679 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
683 int KnownBitsForMinorKey(int key) {
685 if (key <= 11) return key - 1;
694 Register LhsRegister(bool lhs_is_r0) {
695 return lhs_is_r0 ? r0 : r1;
698 Register RhsRegister(bool lhs_is_r0) {
699 return lhs_is_r0 ? r1 : r0;
702 bool ShouldGenerateSmiCode() {
703 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
704 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
705 runtime_operands_type_ != BinaryOpIC::STRINGS;
708 bool ShouldGenerateFPCode() {
709 return runtime_operands_type_ != BinaryOpIC::STRINGS;
712 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
714 virtual InlineCacheState GetICState() {
715 return BinaryOpIC::ToState(runtime_operands_type_);
718 const char* GetName();
722 if (!specialized_on_rhs_) {
723 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
725 PrintF("GenericBinaryOpStub (%s by %d)\n",
734 class StringHelper : public AllStatic {
736 // Generate code for copying characters using a simple loop. This should only
737 // be used in places where the number of characters is small and the
738 // additional setup and checking in GenerateCopyCharactersLong adds too much
739 // overhead. Copying of overlapping regions is not supported.
740 // Dest register ends at the position after the last character written.
741 static void GenerateCopyCharacters(MacroAssembler* masm,
748 // Generate code for copying a large number of characters. This function
749 // is allowed to spend extra time setting up conditions to make copying
750 // faster. Copying of overlapping regions is not supported.
751 // Dest register ends at the position after the last character written.
752 static void GenerateCopyCharactersLong(MacroAssembler* masm,
764 // Probe the symbol table for a two character string. If the string is
765 // not found by probing a jump to the label not_found is performed. This jump
766 // does not guarantee that the string is not in the symbol table. If the
767 // string is found the code falls through with the string in register r0.
768 // Contents of both c1 and c2 registers are modified. At the exit c1 is
769 // guaranteed to contain halfword with low and high bytes equal to
770 // initial contents of c1 and c2 respectively.
771 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
781 // Generate string hash.
782 static void GenerateHashInit(MacroAssembler* masm,
786 static void GenerateHashAddCharacter(MacroAssembler* masm,
790 static void GenerateHashGetHash(MacroAssembler* masm,
794 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
798 // Flag that indicates how to generate code for the stub StringAddStub.
799 enum StringAddFlags {
800 NO_STRING_ADD_FLAGS = 0,
801 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
805 class StringAddStub: public CodeStub {
807 explicit StringAddStub(StringAddFlags flags) {
808 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
812 Major MajorKey() { return StringAdd; }
813 int MinorKey() { return string_check_ ? 0 : 1; }
815 void Generate(MacroAssembler* masm);
817 // Should the stub check whether arguments are strings?
822 class SubStringStub: public CodeStub {
827 Major MajorKey() { return SubString; }
828 int MinorKey() { return 0; }
830 void Generate(MacroAssembler* masm);
835 class StringCompareStub: public CodeStub {
837 StringCompareStub() { }
839 // Compare two flat ASCII strings and returns result in r0.
840 // Does not use the stack.
841 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
850 Major MajorKey() { return StringCompare; }
851 int MinorKey() { return 0; }
853 void Generate(MacroAssembler* masm);
857 // This stub can convert a signed int32 to a heap number (double). It does
858 // not work for int32s that are in Smi range! No GC occurs during this stub
859 // so you don't have to set up the frame.
860 class WriteInt32ToHeapNumberStub : public CodeStub {
862 WriteInt32ToHeapNumberStub(Register the_int,
863 Register the_heap_number,
866 the_heap_number_(the_heap_number),
867 scratch_(scratch) { }
871 Register the_heap_number_;
874 // Minor key encoding in 16 bits.
875 class IntRegisterBits: public BitField<int, 0, 4> {};
876 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
877 class ScratchRegisterBits: public BitField<int, 8, 4> {};
879 Major MajorKey() { return WriteInt32ToHeapNumber; }
881 // Encode the parameters in a unique 16 bit value.
882 return IntRegisterBits::encode(the_int_.code())
883 | HeapNumberRegisterBits::encode(the_heap_number_.code())
884 | ScratchRegisterBits::encode(scratch_.code());
887 void Generate(MacroAssembler* masm);
889 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
892 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
897 class NumberToStringStub: public CodeStub {
899 NumberToStringStub() { }
901 // Generate code to do a lookup in the number string cache. If the number in
902 // the register object is found in the cache the generated code falls through
903 // with the result in the result register. The object and the result register
904 // can be the same. If the number is not found in the cache the code jumps to
905 // the label not_found with only the content of register object unchanged.
906 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
916 Major MajorKey() { return NumberToString; }
917 int MinorKey() { return 0; }
919 void Generate(MacroAssembler* masm);
921 const char* GetName() { return "NumberToStringStub"; }
925 PrintF("NumberToStringStub\n");
931 class RecordWriteStub : public CodeStub {
933 RecordWriteStub(Register object, Register offset, Register scratch)
934 : object_(object), offset_(offset), scratch_(scratch) { }
936 void Generate(MacroAssembler* masm);
945 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
946 " (scratch reg %d)\n",
947 object_.code(), offset_.code(), scratch_.code());
951 // Minor key encoding in 12 bits. 4 bits for each of the three
952 // registers (object, offset and scratch) OOOOAAAASSSS.
953 class ScratchBits: public BitField<uint32_t, 0, 4> {};
954 class OffsetBits: public BitField<uint32_t, 4, 4> {};
955 class ObjectBits: public BitField<uint32_t, 8, 4> {};
957 Major MajorKey() { return RecordWrite; }
960 // Encode the registers.
961 return ObjectBits::encode(object_.code()) |
962 OffsetBits::encode(offset_.code()) |
963 ScratchBits::encode(scratch_.code());
968 } } // namespace v8::internal
970 #endif // V8_ARM_CODEGEN_ARM_H_