Upstream version 9.38.207.0
[platform/framework/web/crosswalk.git] / src / v8 / src / arm / macro-assembler-arm.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_
6 #define V8_ARM_MACRO_ASSEMBLER_ARM_H_
7
8 #include "src/assembler.h"
9 #include "src/frames.h"
10 #include "src/globals.h"
11
12 namespace v8 {
13 namespace internal {
14
15 // ----------------------------------------------------------------------------
16 // Static helper functions
17
18 // Generate a MemOperand for loading a field from an object.
19 inline MemOperand FieldMemOperand(Register object, int offset) {
20   return MemOperand(object, offset - kHeapObjectTag);
21 }
22
23
24 // Give alias names to registers
25 const Register cp = { kRegister_r7_Code };  // JavaScript context pointer.
26 const Register pp = { kRegister_r8_Code };  // Constant pool pointer.
27 const Register kRootRegister = { kRegister_r10_Code };  // Roots array pointer.
28
29 // Flags used for AllocateHeapNumber
30 enum TaggingMode {
31   // Tag the result.
32   TAG_RESULT,
33   // Don't tag
34   DONT_TAG_RESULT
35 };
36
37
38 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
39 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
40 enum PointersToHereCheck {
41   kPointersToHereMaybeInteresting,
42   kPointersToHereAreAlwaysInteresting
43 };
44 enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
45
46
47 Register GetRegisterThatIsNotOneOf(Register reg1,
48                                    Register reg2 = no_reg,
49                                    Register reg3 = no_reg,
50                                    Register reg4 = no_reg,
51                                    Register reg5 = no_reg,
52                                    Register reg6 = no_reg);
53
54
55 #ifdef DEBUG
56 bool AreAliased(Register reg1,
57                 Register reg2,
58                 Register reg3 = no_reg,
59                 Register reg4 = no_reg,
60                 Register reg5 = no_reg,
61                 Register reg6 = no_reg,
62                 Register reg7 = no_reg,
63                 Register reg8 = no_reg);
64 #endif
65
66
67 enum TargetAddressStorageMode {
68   CAN_INLINE_TARGET_ADDRESS,
69   NEVER_INLINE_TARGET_ADDRESS
70 };
71
72 // MacroAssembler implements a collection of frequently used macros.
73 class MacroAssembler: public Assembler {
74  public:
75   // The isolate parameter can be NULL if the macro assembler should
76   // not use isolate-dependent functionality. In this case, it's the
77   // responsibility of the caller to never invoke such function on the
78   // macro assembler.
79   MacroAssembler(Isolate* isolate, void* buffer, int size);
80
81
82   // Returns the size of a call in instructions. Note, the value returned is
83   // only valid as long as no entries are added to the constant pool between
84   // checking the call size and emitting the actual call.
85   static int CallSize(Register target, Condition cond = al);
86   int CallSize(Address target, RelocInfo::Mode rmode, Condition cond = al);
87   int CallStubSize(CodeStub* stub,
88                    TypeFeedbackId ast_id = TypeFeedbackId::None(),
89                    Condition cond = al);
90   static int CallSizeNotPredictableCodeSize(Isolate* isolate,
91                                             Address target,
92                                             RelocInfo::Mode rmode,
93                                             Condition cond = al);
94
95   // Jump, Call, and Ret pseudo instructions implementing inter-working.
96   void Jump(Register target, Condition cond = al);
97   void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
98   void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
99   void Call(Register target, Condition cond = al);
100   void Call(Address target, RelocInfo::Mode rmode,
101             Condition cond = al,
102             TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
103   int CallSize(Handle<Code> code,
104                RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
105                TypeFeedbackId ast_id = TypeFeedbackId::None(),
106                Condition cond = al);
107   void Call(Handle<Code> code,
108             RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
109             TypeFeedbackId ast_id = TypeFeedbackId::None(),
110             Condition cond = al,
111             TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
112   void Ret(Condition cond = al);
113
114   // Emit code to discard a non-negative number of pointer-sized elements
115   // from the stack, clobbering only the sp register.
116   void Drop(int count, Condition cond = al);
117
118   void Ret(int drop, Condition cond = al);
119
120   // Swap two registers.  If the scratch register is omitted then a slightly
121   // less efficient form using xor instead of mov is emitted.
122   void Swap(Register reg1,
123             Register reg2,
124             Register scratch = no_reg,
125             Condition cond = al);
126
127   void Mls(Register dst, Register src1, Register src2, Register srcA,
128            Condition cond = al);
129   void And(Register dst, Register src1, const Operand& src2,
130            Condition cond = al);
131   void Ubfx(Register dst, Register src, int lsb, int width,
132             Condition cond = al);
133   void Sbfx(Register dst, Register src, int lsb, int width,
134             Condition cond = al);
135   // The scratch register is not used for ARMv7.
136   // scratch can be the same register as src (in which case it is trashed), but
137   // not the same as dst.
138   void Bfi(Register dst,
139            Register src,
140            Register scratch,
141            int lsb,
142            int width,
143            Condition cond = al);
144   void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al);
145   void Usat(Register dst, int satpos, const Operand& src,
146             Condition cond = al);
147
148   void Call(Label* target);
149   void Push(Register src) { push(src); }
150   void Pop(Register dst) { pop(dst); }
151
152   // Register move. May do nothing if the registers are identical.
153   void Move(Register dst, Handle<Object> value);
154   void Move(Register dst, Register src, Condition cond = al);
155   void Move(Register dst, const Operand& src, Condition cond = al) {
156     if (!src.is_reg() || !src.rm().is(dst)) mov(dst, src, LeaveCC, cond);
157   }
158   void Move(DwVfpRegister dst, DwVfpRegister src);
159
160   void Load(Register dst, const MemOperand& src, Representation r);
161   void Store(Register src, const MemOperand& dst, Representation r);
162
163   // Load an object from the root table.
164   void LoadRoot(Register destination,
165                 Heap::RootListIndex index,
166                 Condition cond = al);
167   // Store an object to the root table.
168   void StoreRoot(Register source,
169                  Heap::RootListIndex index,
170                  Condition cond = al);
171
172   // ---------------------------------------------------------------------------
173   // GC Support
174
175   void IncrementalMarkingRecordWriteHelper(Register object,
176                                            Register value,
177                                            Register address);
178
179   enum RememberedSetFinalAction {
180     kReturnAtEnd,
181     kFallThroughAtEnd
182   };
183
184   // Record in the remembered set the fact that we have a pointer to new space
185   // at the address pointed to by the addr register.  Only works if addr is not
186   // in new space.
187   void RememberedSetHelper(Register object,  // Used for debug code.
188                            Register addr,
189                            Register scratch,
190                            SaveFPRegsMode save_fp,
191                            RememberedSetFinalAction and_then);
192
193   void CheckPageFlag(Register object,
194                      Register scratch,
195                      int mask,
196                      Condition cc,
197                      Label* condition_met);
198
199   void CheckMapDeprecated(Handle<Map> map,
200                           Register scratch,
201                           Label* if_deprecated);
202
203   // Check if object is in new space.  Jumps if the object is not in new space.
204   // The register scratch can be object itself, but scratch will be clobbered.
205   void JumpIfNotInNewSpace(Register object,
206                            Register scratch,
207                            Label* branch) {
208     InNewSpace(object, scratch, ne, branch);
209   }
210
211   // Check if object is in new space.  Jumps if the object is in new space.
212   // The register scratch can be object itself, but it will be clobbered.
213   void JumpIfInNewSpace(Register object,
214                         Register scratch,
215                         Label* branch) {
216     InNewSpace(object, scratch, eq, branch);
217   }
218
219   // Check if an object has a given incremental marking color.
220   void HasColor(Register object,
221                 Register scratch0,
222                 Register scratch1,
223                 Label* has_color,
224                 int first_bit,
225                 int second_bit);
226
227   void JumpIfBlack(Register object,
228                    Register scratch0,
229                    Register scratch1,
230                    Label* on_black);
231
232   // Checks the color of an object.  If the object is already grey or black
233   // then we just fall through, since it is already live.  If it is white and
234   // we can determine that it doesn't need to be scanned, then we just mark it
235   // black and fall through.  For the rest we jump to the label so the
236   // incremental marker can fix its assumptions.
237   void EnsureNotWhite(Register object,
238                       Register scratch1,
239                       Register scratch2,
240                       Register scratch3,
241                       Label* object_is_white_and_not_data);
242
243   // Detects conservatively whether an object is data-only, i.e. it does need to
244   // be scanned by the garbage collector.
245   void JumpIfDataObject(Register value,
246                         Register scratch,
247                         Label* not_data_object);
248
249   // Notify the garbage collector that we wrote a pointer into an object.
250   // |object| is the object being stored into, |value| is the object being
251   // stored.  value and scratch registers are clobbered by the operation.
252   // The offset is the offset from the start of the object, not the offset from
253   // the tagged HeapObject pointer.  For use with FieldOperand(reg, off).
254   void RecordWriteField(
255       Register object,
256       int offset,
257       Register value,
258       Register scratch,
259       LinkRegisterStatus lr_status,
260       SaveFPRegsMode save_fp,
261       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
262       SmiCheck smi_check = INLINE_SMI_CHECK,
263       PointersToHereCheck pointers_to_here_check_for_value =
264           kPointersToHereMaybeInteresting);
265
266   // As above, but the offset has the tag presubtracted.  For use with
267   // MemOperand(reg, off).
268   inline void RecordWriteContextSlot(
269       Register context,
270       int offset,
271       Register value,
272       Register scratch,
273       LinkRegisterStatus lr_status,
274       SaveFPRegsMode save_fp,
275       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
276       SmiCheck smi_check = INLINE_SMI_CHECK,
277       PointersToHereCheck pointers_to_here_check_for_value =
278           kPointersToHereMaybeInteresting) {
279     RecordWriteField(context,
280                      offset + kHeapObjectTag,
281                      value,
282                      scratch,
283                      lr_status,
284                      save_fp,
285                      remembered_set_action,
286                      smi_check,
287                      pointers_to_here_check_for_value);
288   }
289
290   void RecordWriteForMap(
291       Register object,
292       Register map,
293       Register dst,
294       LinkRegisterStatus lr_status,
295       SaveFPRegsMode save_fp);
296
297   // For a given |object| notify the garbage collector that the slot |address|
298   // has been written.  |value| is the object being stored. The value and
299   // address registers are clobbered by the operation.
300   void RecordWrite(
301       Register object,
302       Register address,
303       Register value,
304       LinkRegisterStatus lr_status,
305       SaveFPRegsMode save_fp,
306       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
307       SmiCheck smi_check = INLINE_SMI_CHECK,
308       PointersToHereCheck pointers_to_here_check_for_value =
309           kPointersToHereMaybeInteresting);
310
311   // Push a handle.
312   void Push(Handle<Object> handle);
313   void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
314
315   // Push two registers.  Pushes leftmost register first (to highest address).
316   void Push(Register src1, Register src2, Condition cond = al) {
317     DCHECK(!src1.is(src2));
318     if (src1.code() > src2.code()) {
319       stm(db_w, sp, src1.bit() | src2.bit(), cond);
320     } else {
321       str(src1, MemOperand(sp, 4, NegPreIndex), cond);
322       str(src2, MemOperand(sp, 4, NegPreIndex), cond);
323     }
324   }
325
326   // Push three registers.  Pushes leftmost register first (to highest address).
327   void Push(Register src1, Register src2, Register src3, Condition cond = al) {
328     DCHECK(!src1.is(src2));
329     DCHECK(!src2.is(src3));
330     DCHECK(!src1.is(src3));
331     if (src1.code() > src2.code()) {
332       if (src2.code() > src3.code()) {
333         stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
334       } else {
335         stm(db_w, sp, src1.bit() | src2.bit(), cond);
336         str(src3, MemOperand(sp, 4, NegPreIndex), cond);
337       }
338     } else {
339       str(src1, MemOperand(sp, 4, NegPreIndex), cond);
340       Push(src2, src3, cond);
341     }
342   }
343
344   // Push four registers.  Pushes leftmost register first (to highest address).
345   void Push(Register src1,
346             Register src2,
347             Register src3,
348             Register src4,
349             Condition cond = al) {
350     DCHECK(!src1.is(src2));
351     DCHECK(!src2.is(src3));
352     DCHECK(!src1.is(src3));
353     DCHECK(!src1.is(src4));
354     DCHECK(!src2.is(src4));
355     DCHECK(!src3.is(src4));
356     if (src1.code() > src2.code()) {
357       if (src2.code() > src3.code()) {
358         if (src3.code() > src4.code()) {
359           stm(db_w,
360               sp,
361               src1.bit() | src2.bit() | src3.bit() | src4.bit(),
362               cond);
363         } else {
364           stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
365           str(src4, MemOperand(sp, 4, NegPreIndex), cond);
366         }
367       } else {
368         stm(db_w, sp, src1.bit() | src2.bit(), cond);
369         Push(src3, src4, cond);
370       }
371     } else {
372       str(src1, MemOperand(sp, 4, NegPreIndex), cond);
373       Push(src2, src3, src4, cond);
374     }
375   }
376
377   // Pop two registers. Pops rightmost register first (from lower address).
378   void Pop(Register src1, Register src2, Condition cond = al) {
379     DCHECK(!src1.is(src2));
380     if (src1.code() > src2.code()) {
381       ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
382     } else {
383       ldr(src2, MemOperand(sp, 4, PostIndex), cond);
384       ldr(src1, MemOperand(sp, 4, PostIndex), cond);
385     }
386   }
387
388   // Pop three registers.  Pops rightmost register first (from lower address).
389   void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
390     DCHECK(!src1.is(src2));
391     DCHECK(!src2.is(src3));
392     DCHECK(!src1.is(src3));
393     if (src1.code() > src2.code()) {
394       if (src2.code() > src3.code()) {
395         ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
396       } else {
397         ldr(src3, MemOperand(sp, 4, PostIndex), cond);
398         ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
399       }
400     } else {
401       Pop(src2, src3, cond);
402       ldr(src1, MemOperand(sp, 4, PostIndex), cond);
403     }
404   }
405
406   // Pop four registers.  Pops rightmost register first (from lower address).
407   void Pop(Register src1,
408            Register src2,
409            Register src3,
410            Register src4,
411            Condition cond = al) {
412     DCHECK(!src1.is(src2));
413     DCHECK(!src2.is(src3));
414     DCHECK(!src1.is(src3));
415     DCHECK(!src1.is(src4));
416     DCHECK(!src2.is(src4));
417     DCHECK(!src3.is(src4));
418     if (src1.code() > src2.code()) {
419       if (src2.code() > src3.code()) {
420         if (src3.code() > src4.code()) {
421           ldm(ia_w,
422               sp,
423               src1.bit() | src2.bit() | src3.bit() | src4.bit(),
424               cond);
425         } else {
426           ldr(src4, MemOperand(sp, 4, PostIndex), cond);
427           ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
428         }
429       } else {
430         Pop(src3, src4, cond);
431         ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
432       }
433     } else {
434       Pop(src2, src3, src4, cond);
435       ldr(src1, MemOperand(sp, 4, PostIndex), cond);
436     }
437   }
438
439   // Push a fixed frame, consisting of lr, fp, constant pool (if
440   // FLAG_enable_ool_constant_pool), context and JS function / marker id if
441   // marker_reg is a valid register.
442   void PushFixedFrame(Register marker_reg = no_reg);
443   void PopFixedFrame(Register marker_reg = no_reg);
444
445   // Push and pop the registers that can hold pointers, as defined by the
446   // RegList constant kSafepointSavedRegisters.
447   void PushSafepointRegisters();
448   void PopSafepointRegisters();
449   // Store value in register src in the safepoint stack slot for
450   // register dst.
451   void StoreToSafepointRegisterSlot(Register src, Register dst);
452   // Load the value of the src register from its safepoint stack slot
453   // into register dst.
454   void LoadFromSafepointRegisterSlot(Register dst, Register src);
455
456   // Load two consecutive registers with two consecutive memory locations.
457   void Ldrd(Register dst1,
458             Register dst2,
459             const MemOperand& src,
460             Condition cond = al);
461
462   // Store two consecutive registers to two consecutive memory locations.
463   void Strd(Register src1,
464             Register src2,
465             const MemOperand& dst,
466             Condition cond = al);
467
468   // Ensure that FPSCR contains values needed by JavaScript.
469   // We need the NaNModeControlBit to be sure that operations like
470   // vadd and vsub generate the Canonical NaN (if a NaN must be generated).
471   // In VFP3 it will be always the Canonical NaN.
472   // In VFP2 it will be either the Canonical NaN or the negative version
473   // of the Canonical NaN. It doesn't matter if we have two values. The aim
474   // is to be sure to never generate the hole NaN.
475   void VFPEnsureFPSCRState(Register scratch);
476
477   // If the value is a NaN, canonicalize the value else, do nothing.
478   void VFPCanonicalizeNaN(const DwVfpRegister dst,
479                           const DwVfpRegister src,
480                           const Condition cond = al);
481   void VFPCanonicalizeNaN(const DwVfpRegister value,
482                           const Condition cond = al) {
483     VFPCanonicalizeNaN(value, value, cond);
484   }
485
486   // Compare double values and move the result to the normal condition flags.
487   void VFPCompareAndSetFlags(const DwVfpRegister src1,
488                              const DwVfpRegister src2,
489                              const Condition cond = al);
490   void VFPCompareAndSetFlags(const DwVfpRegister src1,
491                              const double src2,
492                              const Condition cond = al);
493
494   // Compare double values and then load the fpscr flags to a register.
495   void VFPCompareAndLoadFlags(const DwVfpRegister src1,
496                               const DwVfpRegister src2,
497                               const Register fpscr_flags,
498                               const Condition cond = al);
499   void VFPCompareAndLoadFlags(const DwVfpRegister src1,
500                               const double src2,
501                               const Register fpscr_flags,
502                               const Condition cond = al);
503
504   void Vmov(const DwVfpRegister dst,
505             const double imm,
506             const Register scratch = no_reg);
507
508   void VmovHigh(Register dst, DwVfpRegister src);
509   void VmovHigh(DwVfpRegister dst, Register src);
510   void VmovLow(Register dst, DwVfpRegister src);
511   void VmovLow(DwVfpRegister dst, Register src);
512
513   // Loads the number from object into dst register.
514   // If |object| is neither smi nor heap number, |not_number| is jumped to
515   // with |object| still intact.
516   void LoadNumber(Register object,
517                   LowDwVfpRegister dst,
518                   Register heap_number_map,
519                   Register scratch,
520                   Label* not_number);
521
522   // Loads the number from object into double_dst in the double format.
523   // Control will jump to not_int32 if the value cannot be exactly represented
524   // by a 32-bit integer.
525   // Floating point value in the 32-bit integer range that are not exact integer
526   // won't be loaded.
527   void LoadNumberAsInt32Double(Register object,
528                                DwVfpRegister double_dst,
529                                Register heap_number_map,
530                                Register scratch,
531                                LowDwVfpRegister double_scratch,
532                                Label* not_int32);
533
534   // Loads the number from object into dst as a 32-bit integer.
535   // Control will jump to not_int32 if the object cannot be exactly represented
536   // by a 32-bit integer.
537   // Floating point value in the 32-bit integer range that are not exact integer
538   // won't be converted.
539   void LoadNumberAsInt32(Register object,
540                          Register dst,
541                          Register heap_number_map,
542                          Register scratch,
543                          DwVfpRegister double_scratch0,
544                          LowDwVfpRegister double_scratch1,
545                          Label* not_int32);
546
547   // Generates function and stub prologue code.
548   void StubPrologue();
549   void Prologue(bool code_pre_aging);
550
551   // Enter exit frame.
552   // stack_space - extra stack space, used for alignment before call to C.
553   void EnterExitFrame(bool save_doubles, int stack_space = 0);
554
555   // Leave the current exit frame. Expects the return value in r0.
556   // Expect the number of values, pushed prior to the exit frame, to
557   // remove in a register (or no_reg, if there is nothing to remove).
558   void LeaveExitFrame(bool save_doubles,
559                       Register argument_count,
560                       bool restore_context);
561
562   // Get the actual activation frame alignment for target environment.
563   static int ActivationFrameAlignment();
564
565   void LoadContext(Register dst, int context_chain_length);
566
567   // Conditionally load the cached Array transitioned map of type
568   // transitioned_kind from the native context if the map in register
569   // map_in_out is the cached Array map in the native context of
570   // expected_kind.
571   void LoadTransitionedArrayMapConditional(
572       ElementsKind expected_kind,
573       ElementsKind transitioned_kind,
574       Register map_in_out,
575       Register scratch,
576       Label* no_map_match);
577
578   void LoadGlobalFunction(int index, Register function);
579
580   // Load the initial map from the global function. The registers
581   // function and map can be the same, function is then overwritten.
582   void LoadGlobalFunctionInitialMap(Register function,
583                                     Register map,
584                                     Register scratch);
585
586   void InitializeRootRegister() {
587     ExternalReference roots_array_start =
588         ExternalReference::roots_array_start(isolate());
589     mov(kRootRegister, Operand(roots_array_start));
590   }
591
592   // ---------------------------------------------------------------------------
593   // JavaScript invokes
594
595   // Invoke the JavaScript function code by either calling or jumping.
596   void InvokeCode(Register code,
597                   const ParameterCount& expected,
598                   const ParameterCount& actual,
599                   InvokeFlag flag,
600                   const CallWrapper& call_wrapper);
601
602   // Invoke the JavaScript function in the given register. Changes the
603   // current context to the context in the function before invoking.
604   void InvokeFunction(Register function,
605                       const ParameterCount& actual,
606                       InvokeFlag flag,
607                       const CallWrapper& call_wrapper);
608
609   void InvokeFunction(Register function,
610                       const ParameterCount& expected,
611                       const ParameterCount& actual,
612                       InvokeFlag flag,
613                       const CallWrapper& call_wrapper);
614
615   void InvokeFunction(Handle<JSFunction> function,
616                       const ParameterCount& expected,
617                       const ParameterCount& actual,
618                       InvokeFlag flag,
619                       const CallWrapper& call_wrapper);
620
621   void IsObjectJSObjectType(Register heap_object,
622                             Register map,
623                             Register scratch,
624                             Label* fail);
625
626   void IsInstanceJSObjectType(Register map,
627                               Register scratch,
628                               Label* fail);
629
630   void IsObjectJSStringType(Register object,
631                             Register scratch,
632                             Label* fail);
633
634   void IsObjectNameType(Register object,
635                         Register scratch,
636                         Label* fail);
637
638   // ---------------------------------------------------------------------------
639   // Debugger Support
640
641   void DebugBreak();
642
643   // ---------------------------------------------------------------------------
644   // Exception handling
645
646   // Push a new try handler and link into try handler chain.
647   void PushTryHandler(StackHandler::Kind kind, int handler_index);
648
649   // Unlink the stack handler on top of the stack from the try handler chain.
650   // Must preserve the result register.
651   void PopTryHandler();
652
653   // Passes thrown value to the handler of top of the try handler chain.
654   void Throw(Register value);
655
656   // Propagates an uncatchable exception to the top of the current JS stack's
657   // handler chain.
658   void ThrowUncatchable(Register value);
659
660   // ---------------------------------------------------------------------------
661   // Inline caching support
662
663   // Generate code for checking access rights - used for security checks
664   // on access to global objects across environments. The holder register
665   // is left untouched, whereas both scratch registers are clobbered.
666   void CheckAccessGlobalProxy(Register holder_reg,
667                               Register scratch,
668                               Label* miss);
669
670   void GetNumberHash(Register t0, Register scratch);
671
672   void LoadFromNumberDictionary(Label* miss,
673                                 Register elements,
674                                 Register key,
675                                 Register result,
676                                 Register t0,
677                                 Register t1,
678                                 Register t2);
679
680
681   inline void MarkCode(NopMarkerTypes type) {
682     nop(type);
683   }
684
685   // Check if the given instruction is a 'type' marker.
686   // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
687   // These instructions are generated to mark special location in the code,
688   // like some special IC code.
689   static inline bool IsMarkedCode(Instr instr, int type) {
690     DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
691     return IsNop(instr, type);
692   }
693
694
695   static inline int GetCodeMarker(Instr instr) {
696     int dst_reg_offset = 12;
697     int dst_mask = 0xf << dst_reg_offset;
698     int src_mask = 0xf;
699     int dst_reg = (instr & dst_mask) >> dst_reg_offset;
700     int src_reg = instr & src_mask;
701     uint32_t non_register_mask = ~(dst_mask | src_mask);
702     uint32_t mov_mask = al | 13 << 21;
703
704     // Return <n> if we have a mov rn rn, else return -1.
705     int type = ((instr & non_register_mask) == mov_mask) &&
706                (dst_reg == src_reg) &&
707                (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
708                    ? src_reg
709                    : -1;
710     DCHECK((type == -1) ||
711            ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
712     return type;
713   }
714
715
716   // ---------------------------------------------------------------------------
717   // Allocation support
718
719   // Allocate an object in new space or old pointer space. The object_size is
720   // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
721   // is passed. If the space is exhausted control continues at the gc_required
722   // label. The allocated object is returned in result. If the flag
723   // tag_allocated_object is true the result is tagged as as a heap object.
724   // All registers are clobbered also when control continues at the gc_required
725   // label.
726   void Allocate(int object_size,
727                 Register result,
728                 Register scratch1,
729                 Register scratch2,
730                 Label* gc_required,
731                 AllocationFlags flags);
732
733   void Allocate(Register object_size,
734                 Register result,
735                 Register scratch1,
736                 Register scratch2,
737                 Label* gc_required,
738                 AllocationFlags flags);
739
740   // Undo allocation in new space. The object passed and objects allocated after
741   // it will no longer be allocated. The caller must make sure that no pointers
742   // are left to the object(s) no longer allocated as they would be invalid when
743   // allocation is undone.
744   void UndoAllocationInNewSpace(Register object, Register scratch);
745
746
747   void AllocateTwoByteString(Register result,
748                              Register length,
749                              Register scratch1,
750                              Register scratch2,
751                              Register scratch3,
752                              Label* gc_required);
753   void AllocateAsciiString(Register result,
754                            Register length,
755                            Register scratch1,
756                            Register scratch2,
757                            Register scratch3,
758                            Label* gc_required);
759   void AllocateTwoByteConsString(Register result,
760                                  Register length,
761                                  Register scratch1,
762                                  Register scratch2,
763                                  Label* gc_required);
764   void AllocateAsciiConsString(Register result,
765                                Register length,
766                                Register scratch1,
767                                Register scratch2,
768                                Label* gc_required);
769   void AllocateTwoByteSlicedString(Register result,
770                                    Register length,
771                                    Register scratch1,
772                                    Register scratch2,
773                                    Label* gc_required);
774   void AllocateAsciiSlicedString(Register result,
775                                  Register length,
776                                  Register scratch1,
777                                  Register scratch2,
778                                  Label* gc_required);
779
780   // Allocates a heap number or jumps to the gc_required label if the young
781   // space is full and a scavenge is needed. All registers are clobbered also
782   // when control continues at the gc_required label.
783   void AllocateHeapNumber(Register result,
784                           Register scratch1,
785                           Register scratch2,
786                           Register heap_number_map,
787                           Label* gc_required,
788                           TaggingMode tagging_mode = TAG_RESULT,
789                           MutableMode mode = IMMUTABLE);
790   void AllocateHeapNumberWithValue(Register result,
791                                    DwVfpRegister value,
792                                    Register scratch1,
793                                    Register scratch2,
794                                    Register heap_number_map,
795                                    Label* gc_required);
796   void AllocateSIMDHeapObject(int size,
797                               Register result,
798                               Register scratch1,
799                               Register scratch2,
800                               Register map,
801                               Label* gc_required,
802                               TaggingMode tagging_mode = TAG_RESULT);
803
804   // Copies a fixed number of fields of heap objects from src to dst.
805   void CopyFields(Register dst,
806                   Register src,
807                   LowDwVfpRegister double_scratch,
808                   int field_count);
809
810   // Copies a number of bytes from src to dst. All registers are clobbered. On
811   // exit src and dst will point to the place just after where the last byte was
812   // read or written and length will be zero.
813   void CopyBytes(Register src,
814                  Register dst,
815                  Register length,
816                  Register scratch);
817
818   // Initialize fields with filler values.  Fields starting at |start_offset|
819   // not including end_offset are overwritten with the value in |filler|.  At
820   // the end the loop, |start_offset| takes the value of |end_offset|.
821   void InitializeFieldsWithFiller(Register start_offset,
822                                   Register end_offset,
823                                   Register filler);
824
825   // ---------------------------------------------------------------------------
826   // Support functions.
827
828   // Try to get function prototype of a function and puts the value in
829   // the result register. Checks that the function really is a
830   // function and jumps to the miss label if the fast checks fail. The
831   // function register will be untouched; the other registers may be
832   // clobbered.
833   void TryGetFunctionPrototype(Register function,
834                                Register result,
835                                Register scratch,
836                                Label* miss,
837                                bool miss_on_bound_function = false);
838
839   // Compare object type for heap object.  heap_object contains a non-Smi
840   // whose object type should be compared with the given type.  This both
841   // sets the flags and leaves the object type in the type_reg register.
842   // It leaves the map in the map register (unless the type_reg and map register
843   // are the same register).  It leaves the heap object in the heap_object
844   // register unless the heap_object register is the same register as one of the
845   // other registers.
846   // Type_reg can be no_reg. In that case ip is used.
847   void CompareObjectType(Register heap_object,
848                          Register map,
849                          Register type_reg,
850                          InstanceType type);
851
852   // Compare object type for heap object. Branch to false_label if type
853   // is lower than min_type or greater than max_type.
854   // Load map into the register map.
855   void CheckObjectTypeRange(Register heap_object,
856                             Register map,
857                             InstanceType min_type,
858                             InstanceType max_type,
859                             Label* false_label);
860
861   // Compare instance type in a map.  map contains a valid map object whose
862   // object type should be compared with the given type.  This both
863   // sets the flags and leaves the object type in the type_reg register.
864   void CompareInstanceType(Register map,
865                            Register type_reg,
866                            InstanceType type);
867
868
869   // Check if a map for a JSObject indicates that the object has fast elements.
870   // Jump to the specified label if it does not.
871   void CheckFastElements(Register map,
872                          Register scratch,
873                          Label* fail);
874
875   // Check if a map for a JSObject indicates that the object can have both smi
876   // and HeapObject elements.  Jump to the specified label if it does not.
877   void CheckFastObjectElements(Register map,
878                                Register scratch,
879                                Label* fail);
880
881   // Check if a map for a JSObject indicates that the object has fast smi only
882   // elements.  Jump to the specified label if it does not.
883   void CheckFastSmiElements(Register map,
884                             Register scratch,
885                             Label* fail);
886
887   // Check to see if maybe_number can be stored as a double in
888   // FastDoubleElements. If it can, store it at the index specified by key in
889   // the FastDoubleElements array elements. Otherwise jump to fail.
890   void StoreNumberToDoubleElements(Register value_reg,
891                                    Register key_reg,
892                                    Register elements_reg,
893                                    Register scratch1,
894                                    LowDwVfpRegister double_scratch,
895                                    Label* fail,
896                                    int elements_offset = 0);
897
898   // Compare an object's map with the specified map and its transitioned
899   // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
900   // set with result of map compare. If multiple map compares are required, the
901   // compare sequences branches to early_success.
902   void CompareMap(Register obj,
903                   Register scratch,
904                   Handle<Map> map,
905                   Label* early_success);
906
907   // As above, but the map of the object is already loaded into the register
908   // which is preserved by the code generated.
909   void CompareMap(Register obj_map,
910                   Handle<Map> map,
911                   Label* early_success);
912
913   // Check if the map of an object is equal to a specified map and branch to
914   // label if not. Skip the smi check if not required (object is known to be a
915   // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
916   // against maps that are ElementsKind transition maps of the specified map.
917   void CheckMap(Register obj,
918                 Register scratch,
919                 Handle<Map> map,
920                 Label* fail,
921                 SmiCheckType smi_check_type);
922
923
924   void CheckMap(Register obj,
925                 Register scratch,
926                 Heap::RootListIndex index,
927                 Label* fail,
928                 SmiCheckType smi_check_type);
929
930
931   // Check if the map of an object is equal to a specified map and branch to a
932   // specified target if equal. Skip the smi check if not required (object is
933   // known to be a heap object)
934   void DispatchMap(Register obj,
935                    Register scratch,
936                    Handle<Map> map,
937                    Handle<Code> success,
938                    SmiCheckType smi_check_type);
939
940
941   // Compare the object in a register to a value from the root list.
942   // Uses the ip register as scratch.
943   void CompareRoot(Register obj, Heap::RootListIndex index);
944
945
946   // Load and check the instance type of an object for being a string.
947   // Loads the type into the second argument register.
948   // Returns a condition that will be enabled if the object was a string
949   // and the passed-in condition passed. If the passed-in condition failed
950   // then flags remain unchanged.
951   Condition IsObjectStringType(Register obj,
952                                Register type,
953                                Condition cond = al) {
954     ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond);
955     ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond);
956     tst(type, Operand(kIsNotStringMask), cond);
957     DCHECK_EQ(0, kStringTag);
958     return eq;
959   }
960
961
962   // Picks out an array index from the hash field.
963   // Register use:
964   //   hash - holds the index's hash. Clobbered.
965   //   index - holds the overwritten index on exit.
966   void IndexFromHash(Register hash, Register index);
967
968   // Get the number of least significant bits from a register
969   void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
970   void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
971
972   // Load the value of a smi object into a double register.
973   // The register value must be between d0 and d15.
974   void SmiToDouble(LowDwVfpRegister value, Register smi);
975
976   // Check if a double can be exactly represented as a signed 32-bit integer.
977   // Z flag set to one if true.
978   void TestDoubleIsInt32(DwVfpRegister double_input,
979                          LowDwVfpRegister double_scratch);
980
981   // Try to convert a double to a signed 32-bit integer.
982   // Z flag set to one and result assigned if the conversion is exact.
983   void TryDoubleToInt32Exact(Register result,
984                              DwVfpRegister double_input,
985                              LowDwVfpRegister double_scratch);
986
987   // Floor a double and writes the value to the result register.
988   // Go to exact if the conversion is exact (to be able to test -0),
989   // fall through calling code if an overflow occurred, else go to done.
990   // In return, input_high is loaded with high bits of input.
991   void TryInt32Floor(Register result,
992                      DwVfpRegister double_input,
993                      Register input_high,
994                      LowDwVfpRegister double_scratch,
995                      Label* done,
996                      Label* exact);
997
998   // Performs a truncating conversion of a floating point number as used by
999   // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
1000   // succeeds, otherwise falls through if result is saturated. On return
1001   // 'result' either holds answer, or is clobbered on fall through.
1002   //
1003   // Only public for the test code in test-code-stubs-arm.cc.
1004   void TryInlineTruncateDoubleToI(Register result,
1005                                   DwVfpRegister input,
1006                                   Label* done);
1007
1008   // Performs a truncating conversion of a floating point number as used by
1009   // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
1010   // Exits with 'result' holding the answer.
1011   void TruncateDoubleToI(Register result, DwVfpRegister double_input);
1012
1013   // Performs a truncating conversion of a heap number as used by
1014   // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1015   // must be different registers.  Exits with 'result' holding the answer.
1016   void TruncateHeapNumberToI(Register result, Register object);
1017
1018   // Converts the smi or heap number in object to an int32 using the rules
1019   // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1020   // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1021   // different registers.
1022   void TruncateNumberToI(Register object,
1023                          Register result,
1024                          Register heap_number_map,
1025                          Register scratch1,
1026                          Label* not_int32);
1027
1028   // Check whether d16-d31 are available on the CPU. The result is given by the
1029   // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
1030   void CheckFor32DRegs(Register scratch);
1031
1032   // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
1033   // values to location, saving [d0..(d15|d31)].
1034   void SaveFPRegs(Register location, Register scratch);
1035
1036   // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
1037   // values to location, restoring [d0..(d15|d31)].
1038   void RestoreFPRegs(Register location, Register scratch);
1039
1040   // ---------------------------------------------------------------------------
1041   // Runtime calls
1042
1043   // Call a code stub.
1044   void CallStub(CodeStub* stub,
1045                 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1046                 Condition cond = al);
1047
1048   // Call a code stub.
1049   void TailCallStub(CodeStub* stub, Condition cond = al);
1050
1051   // Call a runtime routine.
1052   void CallRuntime(const Runtime::Function* f,
1053                    int num_arguments,
1054                    SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1055   void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1056     const Runtime::Function* function = Runtime::FunctionForId(id);
1057     CallRuntime(function, function->nargs, kSaveFPRegs);
1058   }
1059
1060   // Convenience function: Same as above, but takes the fid instead.
1061   void CallRuntime(Runtime::FunctionId id,
1062                    int num_arguments,
1063                    SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1064     CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1065   }
1066
1067   // Convenience function: call an external reference.
1068   void CallExternalReference(const ExternalReference& ext,
1069                              int num_arguments);
1070
1071   // Tail call of a runtime routine (jump).
1072   // Like JumpToExternalReference, but also takes care of passing the number
1073   // of parameters.
1074   void TailCallExternalReference(const ExternalReference& ext,
1075                                  int num_arguments,
1076                                  int result_size);
1077
1078   // Convenience function: tail call a runtime routine (jump).
1079   void TailCallRuntime(Runtime::FunctionId fid,
1080                        int num_arguments,
1081                        int result_size);
1082
1083   int CalculateStackPassedWords(int num_reg_arguments,
1084                                 int num_double_arguments);
1085
1086   // Before calling a C-function from generated code, align arguments on stack.
1087   // After aligning the frame, non-register arguments must be stored in
1088   // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
1089   // are word sized. If double arguments are used, this function assumes that
1090   // all double arguments are stored before core registers; otherwise the
1091   // correct alignment of the double values is not guaranteed.
1092   // Some compilers/platforms require the stack to be aligned when calling
1093   // C++ code.
1094   // Needs a scratch register to do some arithmetic. This register will be
1095   // trashed.
1096   void PrepareCallCFunction(int num_reg_arguments,
1097                             int num_double_registers,
1098                             Register scratch);
1099   void PrepareCallCFunction(int num_reg_arguments,
1100                             Register scratch);
1101
1102   // There are two ways of passing double arguments on ARM, depending on
1103   // whether soft or hard floating point ABI is used. These functions
1104   // abstract parameter passing for the three different ways we call
1105   // C functions from generated code.
1106   void MovToFloatParameter(DwVfpRegister src);
1107   void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
1108   void MovToFloatResult(DwVfpRegister src);
1109
1110   // Calls a C function and cleans up the space for arguments allocated
1111   // by PrepareCallCFunction. The called function is not allowed to trigger a
1112   // garbage collection, since that might move the code and invalidate the
1113   // return address (unless this is somehow accounted for by the called
1114   // function).
1115   void CallCFunction(ExternalReference function, int num_arguments);
1116   void CallCFunction(Register function, int num_arguments);
1117   void CallCFunction(ExternalReference function,
1118                      int num_reg_arguments,
1119                      int num_double_arguments);
1120   void CallCFunction(Register function,
1121                      int num_reg_arguments,
1122                      int num_double_arguments);
1123
1124   void MovFromFloatParameter(DwVfpRegister dst);
1125   void MovFromFloatResult(DwVfpRegister dst);
1126
1127   // Calls an API function.  Allocates HandleScope, extracts returned value
1128   // from handle and propagates exceptions.  Restores context.  stack_space
1129   // - space to be unwound on exit (includes the call JS arguments space and
1130   // the additional space allocated for the fast call).
1131   void CallApiFunctionAndReturn(Register function_address,
1132                                 ExternalReference thunk_ref,
1133                                 int stack_space,
1134                                 MemOperand return_value_operand,
1135                                 MemOperand* context_restore_operand);
1136
1137   // Jump to a runtime routine.
1138   void JumpToExternalReference(const ExternalReference& builtin);
1139
1140   // Invoke specified builtin JavaScript function. Adds an entry to
1141   // the unresolved list if the name does not resolve.
1142   void InvokeBuiltin(Builtins::JavaScript id,
1143                      InvokeFlag flag,
1144                      const CallWrapper& call_wrapper = NullCallWrapper());
1145
1146   // Store the code object for the given builtin in the target register and
1147   // setup the function in r1.
1148   void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1149
1150   // Store the function for the given builtin in the target register.
1151   void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1152
1153   Handle<Object> CodeObject() {
1154     DCHECK(!code_object_.is_null());
1155     return code_object_;
1156   }
1157
1158
1159   // Emit code for a truncating division by a constant. The dividend register is
1160   // unchanged and ip gets clobbered. Dividend and result must be different.
1161   void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1162
1163   // ---------------------------------------------------------------------------
1164   // StatsCounter support
1165
1166   void SetCounter(StatsCounter* counter, int value,
1167                   Register scratch1, Register scratch2);
1168   void IncrementCounter(StatsCounter* counter, int value,
1169                         Register scratch1, Register scratch2);
1170   void DecrementCounter(StatsCounter* counter, int value,
1171                         Register scratch1, Register scratch2);
1172
1173
1174   // ---------------------------------------------------------------------------
1175   // Debugging
1176
1177   // Calls Abort(msg) if the condition cond is not satisfied.
1178   // Use --debug_code to enable.
1179   void Assert(Condition cond, BailoutReason reason);
1180   void AssertFastElements(Register elements);
1181
1182   // Like Assert(), but always enabled.
1183   void Check(Condition cond, BailoutReason reason);
1184
1185   // Print a message to stdout and abort execution.
1186   void Abort(BailoutReason msg);
1187
1188   // Verify restrictions about code generated in stubs.
1189   void set_generating_stub(bool value) { generating_stub_ = value; }
1190   bool generating_stub() { return generating_stub_; }
1191   void set_has_frame(bool value) { has_frame_ = value; }
1192   bool has_frame() { return has_frame_; }
1193   inline bool AllowThisStubCall(CodeStub* stub);
1194
1195   // EABI variant for double arguments in use.
1196   bool use_eabi_hardfloat() {
1197 #ifdef __arm__
1198     return base::OS::ArmUsingHardFloat();
1199 #elif USE_EABI_HARDFLOAT
1200     return true;
1201 #else
1202     return false;
1203 #endif
1204   }
1205
1206   // ---------------------------------------------------------------------------
1207   // Number utilities
1208
1209   // Check whether the value of reg is a power of two and not zero. If not
1210   // control continues at the label not_power_of_two. If reg is a power of two
1211   // the register scratch contains the value of (reg - 1) when control falls
1212   // through.
1213   void JumpIfNotPowerOfTwoOrZero(Register reg,
1214                                  Register scratch,
1215                                  Label* not_power_of_two_or_zero);
1216   // Check whether the value of reg is a power of two and not zero.
1217   // Control falls through if it is, with scratch containing the mask
1218   // value (reg - 1).
1219   // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1220   // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1221   // strictly positive but not a power of two.
1222   void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1223                                        Register scratch,
1224                                        Label* zero_and_neg,
1225                                        Label* not_power_of_two);
1226
1227   // ---------------------------------------------------------------------------
1228   // Smi utilities
1229
1230   void SmiTag(Register reg, SBit s = LeaveCC) {
1231     add(reg, reg, Operand(reg), s);
1232   }
1233   void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1234     add(dst, src, Operand(src), s);
1235   }
1236
1237   // Try to convert int32 to smi. If the value is to large, preserve
1238   // the original value and jump to not_a_smi. Destroys scratch and
1239   // sets flags.
1240   void TrySmiTag(Register reg, Label* not_a_smi) {
1241     TrySmiTag(reg, reg, not_a_smi);
1242   }
1243   void TrySmiTag(Register reg, Register src, Label* not_a_smi) {
1244     SmiTag(ip, src, SetCC);
1245     b(vs, not_a_smi);
1246     mov(reg, ip);
1247   }
1248
1249
1250   void SmiUntag(Register reg, SBit s = LeaveCC) {
1251     mov(reg, Operand::SmiUntag(reg), s);
1252   }
1253   void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
1254     mov(dst, Operand::SmiUntag(src), s);
1255   }
1256
1257   // Untag the source value into destination and jump if source is a smi.
1258   // Souce and destination can be the same register.
1259   void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1260
1261   // Untag the source value into destination and jump if source is not a smi.
1262   // Souce and destination can be the same register.
1263   void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1264
1265   // Test if the register contains a smi (Z == 0 (eq) if true).
1266   inline void SmiTst(Register value) {
1267     tst(value, Operand(kSmiTagMask));
1268   }
1269   inline void NonNegativeSmiTst(Register value) {
1270     tst(value, Operand(kSmiTagMask | kSmiSignMask));
1271   }
1272   // Jump if the register contains a smi.
1273   inline void JumpIfSmi(Register value, Label* smi_label) {
1274     tst(value, Operand(kSmiTagMask));
1275     b(eq, smi_label);
1276   }
1277   // Jump if either of the registers contain a non-smi.
1278   inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1279     tst(value, Operand(kSmiTagMask));
1280     b(ne, not_smi_label);
1281   }
1282   // Jump if either of the registers contain a non-smi.
1283   void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1284   // Jump if either of the registers contain a smi.
1285   void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1286
1287   // Abort execution if argument is a smi, enabled via --debug-code.
1288   void AssertNotSmi(Register object);
1289   void AssertSmi(Register object);
1290
1291   // Abort execution if argument is not a string, enabled via --debug-code.
1292   void AssertString(Register object);
1293
1294   // Abort execution if argument is not a name, enabled via --debug-code.
1295   void AssertName(Register object);
1296
1297   // Abort execution if argument is not undefined or an AllocationSite, enabled
1298   // via --debug-code.
1299   void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1300
1301   // Abort execution if reg is not the root value with the given index,
1302   // enabled via --debug-code.
1303   void AssertIsRoot(Register reg, Heap::RootListIndex index);
1304
1305   // ---------------------------------------------------------------------------
1306   // HeapNumber utilities
1307
1308   void JumpIfNotHeapNumber(Register object,
1309                            Register heap_number_map,
1310                            Register scratch,
1311                            Label* on_not_heap_number);
1312
1313   // ---------------------------------------------------------------------------
1314   // String utilities
1315
1316   // Generate code to do a lookup in the number string cache. If the number in
1317   // the register object is found in the cache the generated code falls through
1318   // with the result in the result register. The object and the result register
1319   // can be the same. If the number is not found in the cache the code jumps to
1320   // the label not_found with only the content of register object unchanged.
1321   void LookupNumberStringCache(Register object,
1322                                Register result,
1323                                Register scratch1,
1324                                Register scratch2,
1325                                Register scratch3,
1326                                Label* not_found);
1327
1328   // Checks if both objects are sequential ASCII strings and jumps to label
1329   // if either is not. Assumes that neither object is a smi.
1330   void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
1331                                                   Register object2,
1332                                                   Register scratch1,
1333                                                   Register scratch2,
1334                                                   Label* failure);
1335
1336   // Checks if both objects are sequential ASCII strings and jumps to label
1337   // if either is not.
1338   void JumpIfNotBothSequentialAsciiStrings(Register first,
1339                                            Register second,
1340                                            Register scratch1,
1341                                            Register scratch2,
1342                                            Label* not_flat_ascii_strings);
1343
1344   // Checks if both instance types are sequential ASCII strings and jumps to
1345   // label if either is not.
1346   void JumpIfBothInstanceTypesAreNotSequentialAscii(
1347       Register first_object_instance_type,
1348       Register second_object_instance_type,
1349       Register scratch1,
1350       Register scratch2,
1351       Label* failure);
1352
1353   // Check if instance type is sequential ASCII string and jump to label if
1354   // it is not.
1355   void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1356                                               Register scratch,
1357                                               Label* failure);
1358
1359   void JumpIfNotUniqueName(Register reg, Label* not_unique_name);
1360
1361   void EmitSeqStringSetCharCheck(Register string,
1362                                  Register index,
1363                                  Register value,
1364                                  uint32_t encoding_mask);
1365
1366   // ---------------------------------------------------------------------------
1367   // Patching helpers.
1368
1369   // Get the location of a relocated constant (its address in the constant pool)
1370   // from its load site.
1371   void GetRelocatedValueLocation(Register ldr_location, Register result,
1372                                  Register scratch);
1373
1374
1375   void ClampUint8(Register output_reg, Register input_reg);
1376
1377   void ClampDoubleToUint8(Register result_reg,
1378                           DwVfpRegister input_reg,
1379                           LowDwVfpRegister double_scratch);
1380
1381
1382   void LoadInstanceDescriptors(Register map, Register descriptors);
1383   void EnumLength(Register dst, Register map);
1384   void NumberOfOwnDescriptors(Register dst, Register map);
1385
1386   template<typename Field>
1387   void DecodeField(Register dst, Register src) {
1388     Ubfx(dst, src, Field::kShift, Field::kSize);
1389   }
1390
1391   template<typename Field>
1392   void DecodeField(Register reg) {
1393     DecodeField<Field>(reg, reg);
1394   }
1395
1396   template<typename Field>
1397   void DecodeFieldToSmi(Register dst, Register src) {
1398     static const int shift = Field::kShift;
1399     static const int mask = Field::kMask >> shift << kSmiTagSize;
1400     STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1401     STATIC_ASSERT(kSmiTag == 0);
1402     if (shift < kSmiTagSize) {
1403       mov(dst, Operand(src, LSL, kSmiTagSize - shift));
1404       and_(dst, dst, Operand(mask));
1405     } else if (shift > kSmiTagSize) {
1406       mov(dst, Operand(src, LSR, shift - kSmiTagSize));
1407       and_(dst, dst, Operand(mask));
1408     } else {
1409       and_(dst, src, Operand(mask));
1410     }
1411   }
1412
1413   template<typename Field>
1414   void DecodeFieldToSmi(Register reg) {
1415     DecodeField<Field>(reg, reg);
1416   }
1417
1418   // Activation support.
1419   void EnterFrame(StackFrame::Type type, bool load_constant_pool = false);
1420   // Returns the pc offset at which the frame ends.
1421   int LeaveFrame(StackFrame::Type type);
1422
1423   // Expects object in r0 and returns map with validated enum cache
1424   // in r0.  Assumes that any other register can be used as a scratch.
1425   void CheckEnumCache(Register null_value, Label* call_runtime);
1426
1427   // AllocationMemento support. Arrays may have an associated
1428   // AllocationMemento object that can be checked for in order to pretransition
1429   // to another type.
1430   // On entry, receiver_reg should point to the array object.
1431   // scratch_reg gets clobbered.
1432   // If allocation info is present, condition flags are set to eq.
1433   void TestJSArrayForAllocationMemento(Register receiver_reg,
1434                                        Register scratch_reg,
1435                                        Label* no_memento_found);
1436
1437   void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1438                                          Register scratch_reg,
1439                                          Label* memento_found) {
1440     Label no_memento_found;
1441     TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1442                                     &no_memento_found);
1443     b(eq, memento_found);
1444     bind(&no_memento_found);
1445   }
1446
1447   // Jumps to found label if a prototype map has dictionary elements.
1448   void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1449                                         Register scratch1, Label* found);
1450
1451  private:
1452   void CallCFunctionHelper(Register function,
1453                            int num_reg_arguments,
1454                            int num_double_arguments);
1455
1456   void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
1457
1458   // Helper functions for generating invokes.
1459   void InvokePrologue(const ParameterCount& expected,
1460                       const ParameterCount& actual,
1461                       Handle<Code> code_constant,
1462                       Register code_reg,
1463                       Label* done,
1464                       bool* definitely_mismatches,
1465                       InvokeFlag flag,
1466                       const CallWrapper& call_wrapper);
1467
1468   void InitializeNewString(Register string,
1469                            Register length,
1470                            Heap::RootListIndex map_index,
1471                            Register scratch1,
1472                            Register scratch2);
1473
1474   // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1475   void InNewSpace(Register object,
1476                   Register scratch,
1477                   Condition cond,  // eq for new space, ne otherwise.
1478                   Label* branch);
1479
1480   // Helper for finding the mark bits for an address.  Afterwards, the
1481   // bitmap register points at the word with the mark bits and the mask
1482   // the position of the first bit.  Leaves addr_reg unchanged.
1483   inline void GetMarkBits(Register addr_reg,
1484                           Register bitmap_reg,
1485                           Register mask_reg);
1486
1487   // Helper for throwing exceptions.  Compute a handler address and jump to
1488   // it.  See the implementation for register usage.
1489   void JumpToHandlerEntry();
1490
1491   // Compute memory operands for safepoint stack slots.
1492   static int SafepointRegisterStackIndex(int reg_code);
1493   MemOperand SafepointRegisterSlot(Register reg);
1494   MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1495
1496   // Loads the constant pool pointer (pp) register.
1497   void LoadConstantPoolPointerRegister();
1498
1499   bool generating_stub_;
1500   bool has_frame_;
1501   // This handle will be patched with the code object on installation.
1502   Handle<Object> code_object_;
1503
1504   // Needs access to SafepointRegisterStackIndex for compiled frame
1505   // traversal.
1506   friend class StandardFrame;
1507 };
1508
1509
1510 // The code patcher is used to patch (typically) small parts of code e.g. for
1511 // debugging and other types of instrumentation. When using the code patcher
1512 // the exact number of bytes specified must be emitted. It is not legal to emit
1513 // relocation information. If any of these constraints are violated it causes
1514 // an assertion to fail.
1515 class CodePatcher {
1516  public:
1517   enum FlushICache {
1518     FLUSH,
1519     DONT_FLUSH
1520   };
1521
1522   CodePatcher(byte* address,
1523               int instructions,
1524               FlushICache flush_cache = FLUSH);
1525   virtual ~CodePatcher();
1526
1527   // Macro assembler to emit code.
1528   MacroAssembler* masm() { return &masm_; }
1529
1530   // Emit an instruction directly.
1531   void Emit(Instr instr);
1532
1533   // Emit an address directly.
1534   void Emit(Address addr);
1535
1536   // Emit the condition part of an instruction leaving the rest of the current
1537   // instruction unchanged.
1538   void EmitCondition(Condition cond);
1539
1540  private:
1541   byte* address_;  // The address of the code being patched.
1542   int size_;  // Number of bytes of the expected patch size.
1543   MacroAssembler masm_;  // Macro assembler used to generate the code.
1544   FlushICache flush_cache_;  // Whether to flush the I cache after patching.
1545 };
1546
1547
1548 class FrameAndConstantPoolScope {
1549  public:
1550   FrameAndConstantPoolScope(MacroAssembler* masm, StackFrame::Type type)
1551       : masm_(masm),
1552         type_(type),
1553         old_has_frame_(masm->has_frame()),
1554         old_constant_pool_available_(masm->is_constant_pool_available())  {
1555     // We only want to enable constant pool access for non-manual frame scopes
1556     // to ensure the constant pool pointer is valid throughout the scope.
1557     DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
1558     masm->set_has_frame(true);
1559     masm->set_constant_pool_available(true);
1560     masm->EnterFrame(type, !old_constant_pool_available_);
1561   }
1562
1563   ~FrameAndConstantPoolScope() {
1564     masm_->LeaveFrame(type_);
1565     masm_->set_has_frame(old_has_frame_);
1566     masm_->set_constant_pool_available(old_constant_pool_available_);
1567   }
1568
1569   // Normally we generate the leave-frame code when this object goes
1570   // out of scope.  Sometimes we may need to generate the code somewhere else
1571   // in addition.  Calling this will achieve that, but the object stays in
1572   // scope, the MacroAssembler is still marked as being in a frame scope, and
1573   // the code will be generated again when it goes out of scope.
1574   void GenerateLeaveFrame() {
1575     DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
1576     masm_->LeaveFrame(type_);
1577   }
1578
1579  private:
1580   MacroAssembler* masm_;
1581   StackFrame::Type type_;
1582   bool old_has_frame_;
1583   bool old_constant_pool_available_;
1584
1585   DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope);
1586 };
1587
1588
1589 // Class for scoping the the unavailability of constant pool access.
1590 class ConstantPoolUnavailableScope {
1591  public:
1592   explicit ConstantPoolUnavailableScope(MacroAssembler* masm)
1593      : masm_(masm),
1594        old_constant_pool_available_(masm->is_constant_pool_available()) {
1595     if (FLAG_enable_ool_constant_pool) {
1596       masm_->set_constant_pool_available(false);
1597     }
1598   }
1599   ~ConstantPoolUnavailableScope() {
1600     if (FLAG_enable_ool_constant_pool) {
1601      masm_->set_constant_pool_available(old_constant_pool_available_);
1602     }
1603   }
1604
1605  private:
1606   MacroAssembler* masm_;
1607   int old_constant_pool_available_;
1608
1609   DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope);
1610 };
1611
1612
1613 // -----------------------------------------------------------------------------
1614 // Static helper functions.
1615
1616 inline MemOperand ContextOperand(Register context, int index) {
1617   return MemOperand(context, Context::SlotOffset(index));
1618 }
1619
1620
1621 inline MemOperand GlobalObjectOperand()  {
1622   return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
1623 }
1624
1625
1626 #ifdef GENERATED_CODE_COVERAGE
1627 #define CODE_COVERAGE_STRINGIFY(x) #x
1628 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1629 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1630 #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1631 #else
1632 #define ACCESS_MASM(masm) masm->
1633 #endif
1634
1635
1636 } }  // namespace v8::internal
1637
1638 #endif  // V8_ARM_MACRO_ASSEMBLER_ARM_H_