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 // Declare global variables and functions in the given array of
454 void DeclareGlobals(Handle<FixedArray> pairs);
456 // Instantiate the function based on the shared function info.
457 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
459 // Support for type checks.
460 void GenerateIsSmi(ZoneList<Expression*>* args);
461 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
462 void GenerateIsArray(ZoneList<Expression*>* args);
463 void GenerateIsRegExp(ZoneList<Expression*>* args);
464 void GenerateIsObject(ZoneList<Expression*>* args);
465 void GenerateIsFunction(ZoneList<Expression*>* args);
466 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
468 // Support for construct call checks.
469 void GenerateIsConstructCall(ZoneList<Expression*>* args);
471 // Support for arguments.length and arguments[?].
472 void GenerateArgumentsLength(ZoneList<Expression*>* args);
473 void GenerateArguments(ZoneList<Expression*>* args);
475 // Support for accessing the class and value fields of an object.
476 void GenerateClassOf(ZoneList<Expression*>* args);
477 void GenerateValueOf(ZoneList<Expression*>* args);
478 void GenerateSetValueOf(ZoneList<Expression*>* args);
480 // Fast support for charCodeAt(n).
481 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
483 // Fast support for string.charAt(n) and string[n].
484 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
486 // Fast support for string.charAt(n) and string[n].
487 void GenerateStringCharAt(ZoneList<Expression*>* args);
489 // Fast support for object equality testing.
490 void GenerateObjectEquals(ZoneList<Expression*>* args);
492 void GenerateLog(ZoneList<Expression*>* args);
494 // Fast support for Math.random().
495 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
497 // Fast support for StringAdd.
498 void GenerateStringAdd(ZoneList<Expression*>* args);
500 // Fast support for SubString.
501 void GenerateSubString(ZoneList<Expression*>* args);
503 // Fast support for StringCompare.
504 void GenerateStringCompare(ZoneList<Expression*>* args);
506 // Support for direct calls from JavaScript to native RegExp code.
507 void GenerateRegExpExec(ZoneList<Expression*>* args);
509 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
511 // Support for fast native caches.
512 void GenerateGetFromCache(ZoneList<Expression*>* args);
514 // Fast support for number to string.
515 void GenerateNumberToString(ZoneList<Expression*>* args);
517 // Fast swapping of elements.
518 void GenerateSwapElements(ZoneList<Expression*>* args);
520 // Fast call for custom callbacks.
521 void GenerateCallFunction(ZoneList<Expression*>* args);
523 // Fast call to math functions.
524 void GenerateMathPow(ZoneList<Expression*>* args);
525 void GenerateMathSin(ZoneList<Expression*>* args);
526 void GenerateMathCos(ZoneList<Expression*>* args);
527 void GenerateMathSqrt(ZoneList<Expression*>* args);
529 // Simple condition analysis.
530 enum ConditionAnalysis {
535 ConditionAnalysis AnalyzeCondition(Expression* cond);
537 // Methods used to indicate which source code is generated for. Source
538 // positions are collected by the assembler and emitted with the relocation
540 void CodeForFunctionPosition(FunctionLiteral* fun);
541 void CodeForReturnPosition(FunctionLiteral* fun);
542 void CodeForStatementPosition(Statement* node);
543 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
544 void CodeForSourcePosition(int pos);
547 // True if the registers are valid for entry to a block.
548 bool HasValidEntryRegisters();
551 List<DeferredCode*> deferred_;
554 MacroAssembler* masm_; // to generate code
556 CompilationInfo* info_;
558 // Code generation state
559 VirtualFrame* frame_;
560 RegisterAllocator* allocator_;
562 CodeGenState* state_;
565 Vector<TypeInfo>* type_info_;
568 BreakTarget function_return_;
570 // True if the function return is shadowed (ie, jumping to the target
571 // function_return_ does not jump to the true function return, but rather
572 // to some unlinking code).
573 bool function_return_is_shadowed_;
575 static InlineRuntimeLUT kInlineRuntimeLUT[];
577 friend class VirtualFrame;
578 friend class JumpTarget;
579 friend class Reference;
580 friend class FastCodeGenerator;
581 friend class FullCodeGenerator;
582 friend class FullCodeGenSyntaxChecker;
584 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
588 class GenericBinaryOpStub : public CodeStub {
590 GenericBinaryOpStub(Token::Value op,
594 int constant_rhs = CodeGenerator::kUnknownIntValue)
599 constant_rhs_(constant_rhs),
600 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
601 runtime_operands_type_(BinaryOpIC::DEFAULT),
604 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
605 : op_(OpBits::decode(key)),
606 mode_(ModeBits::decode(key)),
607 lhs_(LhsRegister(RegisterBits::decode(key))),
608 rhs_(RhsRegister(RegisterBits::decode(key))),
609 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
610 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
611 runtime_operands_type_(type_info),
620 bool specialized_on_rhs_;
621 BinaryOpIC::TypeInfo runtime_operands_type_;
624 static const int kMaxKnownRhs = 0x40000000;
625 static const int kKnownRhsKeyBits = 6;
627 // Minor key encoding in 17 bits.
628 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
629 class OpBits: public BitField<Token::Value, 2, 6> {};
630 class TypeInfoBits: public BitField<int, 8, 2> {};
631 class RegisterBits: public BitField<bool, 10, 1> {};
632 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
634 Major MajorKey() { return GenericBinaryOp; }
636 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
637 (lhs_.is(r1) && rhs_.is(r0)));
638 // Encode the parameters in a unique 18 bit value.
639 return OpBits::encode(op_)
640 | ModeBits::encode(mode_)
641 | KnownIntBits::encode(MinorKeyForKnownInt())
642 | TypeInfoBits::encode(runtime_operands_type_)
643 | RegisterBits::encode(lhs_.is(r0));
646 void Generate(MacroAssembler* masm);
647 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
648 void HandleBinaryOpSlowCases(MacroAssembler* masm,
652 const Builtins::JavaScript& builtin);
653 void GenerateTypeTransition(MacroAssembler* masm);
655 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
656 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
657 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
658 if (op == Token::MOD) {
659 if (constant_rhs <= 1) return false;
660 if (constant_rhs <= 10) return true;
661 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
667 int MinorKeyForKnownInt() {
668 if (!specialized_on_rhs_) return 0;
669 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
670 ASSERT(IsPowerOf2(constant_rhs_));
672 int d = constant_rhs_;
673 while ((d & 1) == 0) {
677 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
681 int KnownBitsForMinorKey(int key) {
683 if (key <= 11) return key - 1;
692 Register LhsRegister(bool lhs_is_r0) {
693 return lhs_is_r0 ? r0 : r1;
696 Register RhsRegister(bool lhs_is_r0) {
697 return lhs_is_r0 ? r1 : r0;
700 bool ShouldGenerateSmiCode() {
701 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
702 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
703 runtime_operands_type_ != BinaryOpIC::STRINGS;
706 bool ShouldGenerateFPCode() {
707 return runtime_operands_type_ != BinaryOpIC::STRINGS;
710 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
712 virtual InlineCacheState GetICState() {
713 return BinaryOpIC::ToState(runtime_operands_type_);
716 const char* GetName();
720 if (!specialized_on_rhs_) {
721 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
723 PrintF("GenericBinaryOpStub (%s by %d)\n",
732 class StringHelper : public AllStatic {
734 // Generate code for copying characters using a simple loop. This should only
735 // be used in places where the number of characters is small and the
736 // additional setup and checking in GenerateCopyCharactersLong adds too much
737 // overhead. Copying of overlapping regions is not supported.
738 // Dest register ends at the position after the last character written.
739 static void GenerateCopyCharacters(MacroAssembler* masm,
746 // Generate code for copying a large number of characters. This function
747 // is allowed to spend extra time setting up conditions to make copying
748 // faster. Copying of overlapping regions is not supported.
749 // Dest register ends at the position after the last character written.
750 static void GenerateCopyCharactersLong(MacroAssembler* masm,
762 // Probe the symbol table for a two character string. If the string is
763 // not found by probing a jump to the label not_found is performed. This jump
764 // does not guarantee that the string is not in the symbol table. If the
765 // string is found the code falls through with the string in register r0.
766 // Contents of both c1 and c2 registers are modified. At the exit c1 is
767 // guaranteed to contain halfword with low and high bytes equal to
768 // initial contents of c1 and c2 respectively.
769 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
779 // Generate string hash.
780 static void GenerateHashInit(MacroAssembler* masm,
784 static void GenerateHashAddCharacter(MacroAssembler* masm,
788 static void GenerateHashGetHash(MacroAssembler* masm,
792 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
796 // Flag that indicates how to generate code for the stub StringAddStub.
797 enum StringAddFlags {
798 NO_STRING_ADD_FLAGS = 0,
799 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
803 class StringAddStub: public CodeStub {
805 explicit StringAddStub(StringAddFlags flags) {
806 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
810 Major MajorKey() { return StringAdd; }
811 int MinorKey() { return string_check_ ? 0 : 1; }
813 void Generate(MacroAssembler* masm);
815 // Should the stub check whether arguments are strings?
820 class SubStringStub: public CodeStub {
825 Major MajorKey() { return SubString; }
826 int MinorKey() { return 0; }
828 void Generate(MacroAssembler* masm);
833 class StringCompareStub: public CodeStub {
835 StringCompareStub() { }
837 // Compare two flat ASCII strings and returns result in r0.
838 // Does not use the stack.
839 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
848 Major MajorKey() { return StringCompare; }
849 int MinorKey() { return 0; }
851 void Generate(MacroAssembler* masm);
855 // This stub can convert a signed int32 to a heap number (double). It does
856 // not work for int32s that are in Smi range! No GC occurs during this stub
857 // so you don't have to set up the frame.
858 class WriteInt32ToHeapNumberStub : public CodeStub {
860 WriteInt32ToHeapNumberStub(Register the_int,
861 Register the_heap_number,
864 the_heap_number_(the_heap_number),
865 scratch_(scratch) { }
869 Register the_heap_number_;
872 // Minor key encoding in 16 bits.
873 class IntRegisterBits: public BitField<int, 0, 4> {};
874 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
875 class ScratchRegisterBits: public BitField<int, 8, 4> {};
877 Major MajorKey() { return WriteInt32ToHeapNumber; }
879 // Encode the parameters in a unique 16 bit value.
880 return IntRegisterBits::encode(the_int_.code())
881 | HeapNumberRegisterBits::encode(the_heap_number_.code())
882 | ScratchRegisterBits::encode(scratch_.code());
885 void Generate(MacroAssembler* masm);
887 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
890 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
895 class NumberToStringStub: public CodeStub {
897 NumberToStringStub() { }
899 // Generate code to do a lookup in the number string cache. If the number in
900 // the register object is found in the cache the generated code falls through
901 // with the result in the result register. The object and the result register
902 // can be the same. If the number is not found in the cache the code jumps to
903 // the label not_found with only the content of register object unchanged.
904 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
914 Major MajorKey() { return NumberToString; }
915 int MinorKey() { return 0; }
917 void Generate(MacroAssembler* masm);
919 const char* GetName() { return "NumberToStringStub"; }
923 PrintF("NumberToStringStub\n");
929 class RecordWriteStub : public CodeStub {
931 RecordWriteStub(Register object, Register offset, Register scratch)
932 : object_(object), offset_(offset), scratch_(scratch) { }
934 void Generate(MacroAssembler* masm);
943 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
944 " (scratch reg %d)\n",
945 object_.code(), offset_.code(), scratch_.code());
949 // Minor key encoding in 12 bits. 4 bits for each of the three
950 // registers (object, offset and scratch) OOOOAAAASSSS.
951 class ScratchBits: public BitField<uint32_t, 0, 4> {};
952 class OffsetBits: public BitField<uint32_t, 4, 4> {};
953 class ObjectBits: public BitField<uint32_t, 8, 4> {};
955 Major MajorKey() { return RecordWrite; }
958 // Encode the registers.
959 return ObjectBits::encode(object_.code()) |
960 OffsetBits::encode(offset_.code()) |
961 ScratchBits::encode(scratch_.code());
966 } } // namespace v8::internal
968 #endif // V8_ARM_CODEGEN_ARM_H_