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 };
48 // -------------------------------------------------------------------------
51 // A reference is a C++ stack-allocated object that puts a
52 // reference on the virtual frame. The reference may be consumed
53 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
54 // When the lifetime (scope) of a valid reference ends, it must have
55 // been consumed, and be in state UNLOADED.
56 class Reference BASE_EMBEDDED {
58 // The values of the types is important, see size().
59 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
60 Reference(CodeGenerator* cgen,
61 Expression* expression,
62 bool persist_after_get = false);
65 Expression* expression() const { return expression_; }
66 Type type() const { return type_; }
67 void set_type(Type value) {
68 ASSERT_EQ(ILLEGAL, type_);
73 ASSERT_NE(ILLEGAL, type_);
74 ASSERT_NE(UNLOADED, type_);
77 // The size the reference takes up on the stack.
79 return (type_ < SLOT) ? 0 : type_;
82 bool is_illegal() const { return type_ == ILLEGAL; }
83 bool is_slot() const { return type_ == SLOT; }
84 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
85 bool is_unloaded() const { return type_ == UNLOADED; }
87 // Return the name. Only valid for named property references.
88 Handle<String> GetName();
90 // Generate code to push the value of the reference on top of the
91 // expression stack. The reference is expected to be already on top of
92 // the expression stack, and it is consumed by the call unless the
93 // reference is for a compound assignment.
94 // If the reference is not consumed, it is left in place under its value.
97 // Generate code to store the value on top of the expression stack in the
98 // reference. The reference is expected to be immediately below the value
99 // on the expression stack. The value is stored in the location specified
100 // by the reference, and is left on top of the stack, after the reference
101 // is popped from beneath it (unloaded).
102 void SetValue(InitState init_state);
104 // This is in preparation for something that uses the reference on the stack.
105 // If we need this reference afterwards get then dup it now. Otherwise mark
107 inline void DupIfPersist();
110 CodeGenerator* cgen_;
111 Expression* expression_;
113 // Keep the reference on the stack after get, so it can be used by set later.
114 bool persist_after_get_;
118 // -------------------------------------------------------------------------
119 // Code generation state
121 // The state is passed down the AST by the code generator (and back up, in
122 // the form of the state of the label pair). It is threaded through the
123 // call stack. Constructing a state implicitly pushes it on the owning code
124 // generator's stack of states, and destroying one implicitly pops it.
126 class CodeGenState BASE_EMBEDDED {
128 // Create an initial code generator state. Destroying the initial state
129 // leaves the code generator with a NULL state.
130 explicit CodeGenState(CodeGenerator* owner);
132 // Create a code generator state based on a code generator's current
133 // state. The new state has its own pair of branch labels.
134 CodeGenState(CodeGenerator* owner,
135 JumpTarget* true_target,
136 JumpTarget* false_target);
138 // Destroy a code generator state and restore the owning code generator's
142 JumpTarget* true_target() const { return true_target_; }
143 JumpTarget* false_target() const { return false_target_; }
146 CodeGenerator* owner_;
147 JumpTarget* true_target_;
148 JumpTarget* false_target_;
149 CodeGenState* previous_;
153 // -------------------------------------------------------------------------
154 // Arguments allocation mode
156 enum ArgumentsAllocationMode {
157 NO_ARGUMENTS_ALLOCATION,
158 EAGER_ARGUMENTS_ALLOCATION,
159 LAZY_ARGUMENTS_ALLOCATION
163 // Different nop operations are used by the code generator to detect certain
164 // states of the generated code.
165 enum NopMarkerTypes {
167 PROPERTY_ACCESS_INLINED
171 // -------------------------------------------------------------------------
174 class CodeGenerator: public AstVisitor {
176 // Takes a function literal, generates code for it. This function should only
177 // be called by compiler.cc.
178 static Handle<Code> MakeCode(CompilationInfo* info);
180 // Printing of AST, etc. as requested by flags.
181 static void MakeCodePrologue(CompilationInfo* info);
183 // Allocate and install the code.
184 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
186 CompilationInfo* info);
188 #ifdef ENABLE_LOGGING_AND_PROFILING
189 static bool ShouldGenerateLog(Expression* type);
192 static void SetFunctionInfo(Handle<JSFunction> fun,
193 FunctionLiteral* lit,
195 Handle<Script> script);
197 static void RecordPositions(MacroAssembler* masm, int pos);
200 MacroAssembler* masm() { return masm_; }
201 VirtualFrame* frame() const { return frame_; }
202 inline Handle<Script> script();
204 bool has_valid_frame() const { return frame_ != NULL; }
206 // Set the virtual frame to be new_frame, with non-frame register
207 // reference counts given by non_frame_registers. The non-frame
208 // register reference counts of the old frame are returned in
209 // non_frame_registers.
210 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
214 RegisterAllocator* allocator() const { return allocator_; }
216 CodeGenState* state() { return state_; }
217 void set_state(CodeGenState* state) { state_ = state; }
219 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
221 static const int kUnknownIntValue = -1;
223 // If the name is an inline runtime function call return the number of
224 // expected arguments. Otherwise return -1.
225 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
227 // Constants related to patching of inlined load/store.
228 static const int kInlinedKeyedLoadInstructionsAfterPatch = 19;
229 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
232 // Construction/Destruction
233 explicit CodeGenerator(MacroAssembler* masm);
236 inline bool is_eval();
237 inline Scope* scope();
239 // Generating deferred code.
240 void ProcessDeferred();
243 bool has_cc() const { return cc_reg_ != al; }
244 JumpTarget* true_target() const { return state_->true_target(); }
245 JumpTarget* false_target() const { return state_->false_target(); }
247 // Track loop nesting level.
248 int loop_nesting() const { return loop_nesting_; }
249 void IncrementLoopNesting() { loop_nesting_++; }
250 void DecrementLoopNesting() { loop_nesting_--; }
253 void VisitStatements(ZoneList<Statement*>* statements);
255 #define DEF_VISIT(type) \
256 void Visit##type(type* node);
257 AST_NODE_LIST(DEF_VISIT)
260 // Main code generation function
261 void Generate(CompilationInfo* info);
263 // Returns the arguments allocation mode.
264 ArgumentsAllocationMode ArgumentsMode();
266 // Store the arguments object and allocate it if necessary.
267 void StoreArgumentsObject(bool initial);
269 // The following are used by class Reference.
270 void LoadReference(Reference* ref);
271 void UnloadReference(Reference* ref);
273 static MemOperand ContextOperand(Register context, int index) {
274 return MemOperand(context, Context::SlotOffset(index));
277 MemOperand SlotOperand(Slot* slot, Register tmp);
279 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
285 static MemOperand GlobalObject() {
286 return ContextOperand(cp, Context::GLOBAL_INDEX);
289 void LoadCondition(Expression* x,
290 JumpTarget* true_target,
291 JumpTarget* false_target,
293 void Load(Expression* expr);
295 void LoadGlobalReceiver(Register scratch);
297 // Read a value from a slot and leave it on top of the expression stack.
298 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
299 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
301 // Store the value on top of the stack to a slot.
302 void StoreToSlot(Slot* slot, InitState init_state);
304 // Support for compiling assignment expressions.
305 void EmitSlotAssignment(Assignment* node);
306 void EmitNamedPropertyAssignment(Assignment* node);
307 void EmitKeyedPropertyAssignment(Assignment* node);
309 // Load a named property, returning it in r0. The receiver is passed on the
310 // stack, and remains there.
311 void EmitNamedLoad(Handle<String> name, bool is_contextual);
313 // Store to a named property. If the store is contextual, value is passed on
314 // the frame and consumed. Otherwise, receiver and value are passed on the
315 // frame and consumed. The result is returned in r0.
316 void EmitNamedStore(Handle<String> name, bool is_contextual);
318 // Load a keyed property, leaving it in r0. The receiver and key are
319 // passed on the stack, and remain there.
320 void EmitKeyedLoad();
322 // Store a keyed property. Key and receiver are on the stack and the value is
323 // in r0. Result is returned in r0.
324 void EmitKeyedStore(StaticType* key_type);
326 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
327 TypeofState typeof_state,
330 // Support for loading from local/global variables and arguments
331 // whose location is known unless they are shadowed by
332 // eval-introduced bindings. Generates no code for unsupported slot
333 // types and therefore expects to fall through to the slow jump target.
334 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
335 TypeofState typeof_state,
339 // Special code for typeof expressions: Unfortunately, we must
340 // be careful when loading the expression in 'typeof'
341 // expressions. We are not allowed to throw reference errors for
342 // non-existing properties of the global object, so we must make it
343 // look like an explicit property access, instead of an access
344 // through the context chain.
345 void LoadTypeofExpression(Expression* x);
347 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
349 // Generate code that computes a shortcutting logical operation.
350 void GenerateLogicalBooleanOperation(BinaryOperation* node);
352 void GenericBinaryOperation(Token::Value op,
353 OverwriteMode overwrite_mode,
354 int known_rhs = kUnknownIntValue);
355 void VirtualFrameBinaryOperation(Token::Value op,
356 OverwriteMode overwrite_mode,
357 int known_rhs = kUnknownIntValue);
358 void Comparison(Condition cc,
361 bool strict = false);
363 void SmiOperation(Token::Value op,
364 Handle<Object> value,
368 void CallWithArguments(ZoneList<Expression*>* arguments,
369 CallFunctionFlags flags,
372 // An optimized implementation of expressions of the form
373 // x.apply(y, arguments). We call x the applicand and y the receiver.
374 // The optimization avoids allocating an arguments object if possible.
375 void CallApplyLazy(Expression* applicand,
376 Expression* receiver,
377 VariableProxy* arguments,
381 void Branch(bool if_true, JumpTarget* target);
384 struct InlineRuntimeLUT {
385 void (CodeGenerator::*method)(ZoneList<Expression*>*);
390 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
391 bool CheckForInlineRuntimeCall(CallRuntime* node);
392 static bool PatchInlineRuntimeEntry(Handle<String> name,
393 const InlineRuntimeLUT& new_entry,
394 InlineRuntimeLUT* old_entry);
396 static Handle<Code> ComputeLazyCompile(int argc);
397 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
399 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
401 // Declare global variables and functions in the given array of
403 void DeclareGlobals(Handle<FixedArray> pairs);
405 // Instantiate the function based on the shared function info.
406 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
408 // Support for type checks.
409 void GenerateIsSmi(ZoneList<Expression*>* args);
410 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
411 void GenerateIsArray(ZoneList<Expression*>* args);
412 void GenerateIsRegExp(ZoneList<Expression*>* args);
413 void GenerateIsObject(ZoneList<Expression*>* args);
414 void GenerateIsFunction(ZoneList<Expression*>* args);
415 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
417 // Support for construct call checks.
418 void GenerateIsConstructCall(ZoneList<Expression*>* args);
420 // Support for arguments.length and arguments[?].
421 void GenerateArgumentsLength(ZoneList<Expression*>* args);
422 void GenerateArguments(ZoneList<Expression*>* args);
424 // Support for accessing the class and value fields of an object.
425 void GenerateClassOf(ZoneList<Expression*>* args);
426 void GenerateValueOf(ZoneList<Expression*>* args);
427 void GenerateSetValueOf(ZoneList<Expression*>* args);
429 // Fast support for charCodeAt(n).
430 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
432 // Fast support for string.charAt(n) and string[n].
433 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
435 // Fast support for string.charAt(n) and string[n].
436 void GenerateStringCharAt(ZoneList<Expression*>* args);
438 // Fast support for object equality testing.
439 void GenerateObjectEquals(ZoneList<Expression*>* args);
441 void GenerateLog(ZoneList<Expression*>* args);
443 // Fast support for Math.random().
444 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
446 // Fast support for StringAdd.
447 void GenerateStringAdd(ZoneList<Expression*>* args);
449 // Fast support for SubString.
450 void GenerateSubString(ZoneList<Expression*>* args);
452 // Fast support for StringCompare.
453 void GenerateStringCompare(ZoneList<Expression*>* args);
455 // Support for direct calls from JavaScript to native RegExp code.
456 void GenerateRegExpExec(ZoneList<Expression*>* args);
458 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
460 // Support for fast native caches.
461 void GenerateGetFromCache(ZoneList<Expression*>* args);
463 // Fast support for number to string.
464 void GenerateNumberToString(ZoneList<Expression*>* args);
466 // Fast swapping of elements.
467 void GenerateSwapElements(ZoneList<Expression*>* args);
469 // Fast call for custom callbacks.
470 void GenerateCallFunction(ZoneList<Expression*>* args);
472 // Fast call to math functions.
473 void GenerateMathPow(ZoneList<Expression*>* args);
474 void GenerateMathSin(ZoneList<Expression*>* args);
475 void GenerateMathCos(ZoneList<Expression*>* args);
476 void GenerateMathSqrt(ZoneList<Expression*>* args);
478 // Simple condition analysis.
479 enum ConditionAnalysis {
484 ConditionAnalysis AnalyzeCondition(Expression* cond);
486 // Methods used to indicate which source code is generated for. Source
487 // positions are collected by the assembler and emitted with the relocation
489 void CodeForFunctionPosition(FunctionLiteral* fun);
490 void CodeForReturnPosition(FunctionLiteral* fun);
491 void CodeForStatementPosition(Statement* node);
492 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
493 void CodeForSourcePosition(int pos);
496 // True if the registers are valid for entry to a block.
497 bool HasValidEntryRegisters();
500 List<DeferredCode*> deferred_;
503 MacroAssembler* masm_; // to generate code
505 CompilationInfo* info_;
507 // Code generation state
508 VirtualFrame* frame_;
509 RegisterAllocator* allocator_;
511 CodeGenState* state_;
515 BreakTarget function_return_;
517 // True if the function return is shadowed (ie, jumping to the target
518 // function_return_ does not jump to the true function return, but rather
519 // to some unlinking code).
520 bool function_return_is_shadowed_;
522 static InlineRuntimeLUT kInlineRuntimeLUT[];
524 friend class VirtualFrame;
525 friend class JumpTarget;
526 friend class Reference;
527 friend class FastCodeGenerator;
528 friend class FullCodeGenerator;
529 friend class FullCodeGenSyntaxChecker;
531 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
535 class GenericBinaryOpStub : public CodeStub {
537 GenericBinaryOpStub(Token::Value op,
541 int constant_rhs = CodeGenerator::kUnknownIntValue)
546 constant_rhs_(constant_rhs),
547 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
548 runtime_operands_type_(BinaryOpIC::DEFAULT),
551 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
552 : op_(OpBits::decode(key)),
553 mode_(ModeBits::decode(key)),
554 lhs_(LhsRegister(RegisterBits::decode(key))),
555 rhs_(RhsRegister(RegisterBits::decode(key))),
556 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
557 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
558 runtime_operands_type_(type_info),
567 bool specialized_on_rhs_;
568 BinaryOpIC::TypeInfo runtime_operands_type_;
571 static const int kMaxKnownRhs = 0x40000000;
572 static const int kKnownRhsKeyBits = 6;
574 // Minor key encoding in 17 bits.
575 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
576 class OpBits: public BitField<Token::Value, 2, 6> {};
577 class TypeInfoBits: public BitField<int, 8, 2> {};
578 class RegisterBits: public BitField<bool, 10, 1> {};
579 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
581 Major MajorKey() { return GenericBinaryOp; }
583 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
584 (lhs_.is(r1) && rhs_.is(r0)));
585 // Encode the parameters in a unique 18 bit value.
586 return OpBits::encode(op_)
587 | ModeBits::encode(mode_)
588 | KnownIntBits::encode(MinorKeyForKnownInt())
589 | TypeInfoBits::encode(runtime_operands_type_)
590 | RegisterBits::encode(lhs_.is(r0));
593 void Generate(MacroAssembler* masm);
594 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
595 void HandleBinaryOpSlowCases(MacroAssembler* masm,
599 const Builtins::JavaScript& builtin);
600 void GenerateTypeTransition(MacroAssembler* masm);
602 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
603 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
604 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
605 if (op == Token::MOD) {
606 if (constant_rhs <= 1) return false;
607 if (constant_rhs <= 10) return true;
608 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
614 int MinorKeyForKnownInt() {
615 if (!specialized_on_rhs_) return 0;
616 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
617 ASSERT(IsPowerOf2(constant_rhs_));
619 int d = constant_rhs_;
620 while ((d & 1) == 0) {
624 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
628 int KnownBitsForMinorKey(int key) {
630 if (key <= 11) return key - 1;
639 Register LhsRegister(bool lhs_is_r0) {
640 return lhs_is_r0 ? r0 : r1;
643 Register RhsRegister(bool lhs_is_r0) {
644 return lhs_is_r0 ? r1 : r0;
647 bool ShouldGenerateSmiCode() {
648 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
649 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
650 runtime_operands_type_ != BinaryOpIC::STRINGS;
653 bool ShouldGenerateFPCode() {
654 return runtime_operands_type_ != BinaryOpIC::STRINGS;
657 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
659 virtual InlineCacheState GetICState() {
660 return BinaryOpIC::ToState(runtime_operands_type_);
663 const char* GetName();
667 if (!specialized_on_rhs_) {
668 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
670 PrintF("GenericBinaryOpStub (%s by %d)\n",
679 class StringHelper : public AllStatic {
681 // Generate code for copying characters using a simple loop. This should only
682 // be used in places where the number of characters is small and the
683 // additional setup and checking in GenerateCopyCharactersLong adds too much
684 // overhead. Copying of overlapping regions is not supported.
685 // Dest register ends at the position after the last character written.
686 static void GenerateCopyCharacters(MacroAssembler* masm,
693 // Generate code for copying a large number of characters. This function
694 // is allowed to spend extra time setting up conditions to make copying
695 // faster. Copying of overlapping regions is not supported.
696 // Dest register ends at the position after the last character written.
697 static void GenerateCopyCharactersLong(MacroAssembler* masm,
709 // Probe the symbol table for a two character string. If the string is
710 // not found by probing a jump to the label not_found is performed. This jump
711 // does not guarantee that the string is not in the symbol table. If the
712 // string is found the code falls through with the string in register r0.
713 // Contents of both c1 and c2 registers are modified. At the exit c1 is
714 // guaranteed to contain halfword with low and high bytes equal to
715 // initial contents of c1 and c2 respectively.
716 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
726 // Generate string hash.
727 static void GenerateHashInit(MacroAssembler* masm,
731 static void GenerateHashAddCharacter(MacroAssembler* masm,
735 static void GenerateHashGetHash(MacroAssembler* masm,
739 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
743 // Flag that indicates how to generate code for the stub StringAddStub.
744 enum StringAddFlags {
745 NO_STRING_ADD_FLAGS = 0,
746 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
750 class StringAddStub: public CodeStub {
752 explicit StringAddStub(StringAddFlags flags) {
753 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
757 Major MajorKey() { return StringAdd; }
758 int MinorKey() { return string_check_ ? 0 : 1; }
760 void Generate(MacroAssembler* masm);
762 // Should the stub check whether arguments are strings?
767 class SubStringStub: public CodeStub {
772 Major MajorKey() { return SubString; }
773 int MinorKey() { return 0; }
775 void Generate(MacroAssembler* masm);
780 class StringCompareStub: public CodeStub {
782 StringCompareStub() { }
784 // Compare two flat ASCII strings and returns result in r0.
785 // Does not use the stack.
786 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
795 Major MajorKey() { return StringCompare; }
796 int MinorKey() { return 0; }
798 void Generate(MacroAssembler* masm);
802 // This stub can convert a signed int32 to a heap number (double). It does
803 // not work for int32s that are in Smi range! No GC occurs during this stub
804 // so you don't have to set up the frame.
805 class WriteInt32ToHeapNumberStub : public CodeStub {
807 WriteInt32ToHeapNumberStub(Register the_int,
808 Register the_heap_number,
811 the_heap_number_(the_heap_number),
812 scratch_(scratch) { }
816 Register the_heap_number_;
819 // Minor key encoding in 16 bits.
820 class IntRegisterBits: public BitField<int, 0, 4> {};
821 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
822 class ScratchRegisterBits: public BitField<int, 8, 4> {};
824 Major MajorKey() { return WriteInt32ToHeapNumber; }
826 // Encode the parameters in a unique 16 bit value.
827 return IntRegisterBits::encode(the_int_.code())
828 | HeapNumberRegisterBits::encode(the_heap_number_.code())
829 | ScratchRegisterBits::encode(scratch_.code());
832 void Generate(MacroAssembler* masm);
834 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
837 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
842 class NumberToStringStub: public CodeStub {
844 NumberToStringStub() { }
846 // Generate code to do a lookup in the number string cache. If the number in
847 // the register object is found in the cache the generated code falls through
848 // with the result in the result register. The object and the result register
849 // can be the same. If the number is not found in the cache the code jumps to
850 // the label not_found with only the content of register object unchanged.
851 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
861 Major MajorKey() { return NumberToString; }
862 int MinorKey() { return 0; }
864 void Generate(MacroAssembler* masm);
866 const char* GetName() { return "NumberToStringStub"; }
870 PrintF("NumberToStringStub\n");
876 class RecordWriteStub : public CodeStub {
878 RecordWriteStub(Register object, Register offset, Register scratch)
879 : object_(object), offset_(offset), scratch_(scratch) { }
881 void Generate(MacroAssembler* masm);
890 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
891 " (scratch reg %d)\n",
892 object_.code(), offset_.code(), scratch_.code());
896 // Minor key encoding in 12 bits. 4 bits for each of the three
897 // registers (object, offset and scratch) OOOOAAAASSSS.
898 class ScratchBits: public BitField<uint32_t, 0, 4> {};
899 class OffsetBits: public BitField<uint32_t, 4, 4> {};
900 class ObjectBits: public BitField<uint32_t, 8, 4> {};
902 Major MajorKey() { return RecordWrite; }
905 // Encode the registers.
906 return ObjectBits::encode(object_.code()) |
907 OffsetBits::encode(offset_.code()) |
908 ScratchBits::encode(scratch_.code());
913 } } // namespace v8::internal
915 #endif // V8_ARM_CODEGEN_ARM_H_