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