• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_X64_MACRO_ASSEMBLER_X64_H_
6 #define V8_X64_MACRO_ASSEMBLER_X64_H_
7 
8 #include "src/assembler.h"
9 #include "src/bailout-reason.h"
10 #include "src/base/flags.h"
11 #include "src/frames.h"
12 #include "src/globals.h"
13 #include "src/x64/frames-x64.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // Give alias names to registers for calling conventions.
19 const Register kReturnRegister0 = {Register::kCode_rax};
20 const Register kReturnRegister1 = {Register::kCode_rdx};
21 const Register kReturnRegister2 = {Register::kCode_r8};
22 const Register kJSFunctionRegister = {Register::kCode_rdi};
23 const Register kContextRegister = {Register::kCode_rsi};
24 const Register kAllocateSizeRegister = {Register::kCode_rdx};
25 const Register kInterpreterAccumulatorRegister = {Register::kCode_rax};
26 const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r12};
27 const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r14};
28 const Register kInterpreterDispatchTableRegister = {Register::kCode_r15};
29 const Register kJavaScriptCallArgCountRegister = {Register::kCode_rax};
30 const Register kJavaScriptCallNewTargetRegister = {Register::kCode_rdx};
31 const Register kRuntimeCallFunctionRegister = {Register::kCode_rbx};
32 const Register kRuntimeCallArgCountRegister = {Register::kCode_rax};
33 
34 // Default scratch register used by MacroAssembler (and other code that needs
35 // a spare register). The register isn't callee save, and not used by the
36 // function calling convention.
37 const Register kScratchRegister = {10};      // r10.
38 const XMMRegister kScratchDoubleReg = {15};  // xmm15.
39 const Register kRootRegister = {13};         // r13 (callee save).
40 // Actual value of root register is offset from the root array's start
41 // to take advantage of negitive 8-bit displacement values.
42 const int kRootRegisterBias = 128;
43 
44 // Convenience for platform-independent signatures.
45 typedef Operand MemOperand;
46 
47 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
48 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
49 enum PointersToHereCheck {
50   kPointersToHereMaybeInteresting,
51   kPointersToHereAreAlwaysInteresting
52 };
53 
54 enum class SmiOperationConstraint {
55   kPreserveSourceRegister = 1 << 0,
56   kBailoutOnNoOverflow = 1 << 1,
57   kBailoutOnOverflow = 1 << 2
58 };
59 
60 enum class ReturnAddressState { kOnStack, kNotOnStack };
61 
62 typedef base::Flags<SmiOperationConstraint> SmiOperationConstraints;
63 
64 DEFINE_OPERATORS_FOR_FLAGS(SmiOperationConstraints)
65 
66 #ifdef DEBUG
67 bool AreAliased(Register reg1,
68                 Register reg2,
69                 Register reg3 = no_reg,
70                 Register reg4 = no_reg,
71                 Register reg5 = no_reg,
72                 Register reg6 = no_reg,
73                 Register reg7 = no_reg,
74                 Register reg8 = no_reg);
75 #endif
76 
77 // Forward declaration.
78 class JumpTarget;
79 
80 struct SmiIndex {
SmiIndexSmiIndex81   SmiIndex(Register index_register, ScaleFactor scale)
82       : reg(index_register),
83         scale(scale) {}
84   Register reg;
85   ScaleFactor scale;
86 };
87 
88 
89 // MacroAssembler implements a collection of frequently used macros.
90 class MacroAssembler: public Assembler {
91  public:
92   MacroAssembler(Isolate* isolate, void* buffer, int size,
93                  CodeObjectRequired create_code_object);
94 
95   // Prevent the use of the RootArray during the lifetime of this
96   // scope object.
97   class NoRootArrayScope BASE_EMBEDDED {
98    public:
NoRootArrayScope(MacroAssembler * assembler)99     explicit NoRootArrayScope(MacroAssembler* assembler)
100         : variable_(&assembler->root_array_available_),
101           old_value_(assembler->root_array_available_) {
102       assembler->root_array_available_ = false;
103     }
~NoRootArrayScope()104     ~NoRootArrayScope() {
105       *variable_ = old_value_;
106     }
107    private:
108     bool* variable_;
109     bool old_value_;
110   };
111 
112   // Operand pointing to an external reference.
113   // May emit code to set up the scratch register. The operand is
114   // only guaranteed to be correct as long as the scratch register
115   // isn't changed.
116   // If the operand is used more than once, use a scratch register
117   // that is guaranteed not to be clobbered.
118   Operand ExternalOperand(ExternalReference reference,
119                           Register scratch = kScratchRegister);
120   // Loads and stores the value of an external reference.
121   // Special case code for load and store to take advantage of
122   // load_rax/store_rax if possible/necessary.
123   // For other operations, just use:
124   //   Operand operand = ExternalOperand(extref);
125   //   operation(operand, ..);
126   void Load(Register destination, ExternalReference source);
127   void Store(ExternalReference destination, Register source);
128   // Loads the address of the external reference into the destination
129   // register.
130   void LoadAddress(Register destination, ExternalReference source);
131   // Returns the size of the code generated by LoadAddress.
132   // Used by CallSize(ExternalReference) to find the size of a call.
133   int LoadAddressSize(ExternalReference source);
134   // Pushes the address of the external reference onto the stack.
135   void PushAddress(ExternalReference source);
136 
137   // Operations on roots in the root-array.
138   void LoadRoot(Register destination, Heap::RootListIndex index);
LoadRoot(const Operand & destination,Heap::RootListIndex index)139   void LoadRoot(const Operand& destination, Heap::RootListIndex index) {
140     LoadRoot(kScratchRegister, index);
141     movp(destination, kScratchRegister);
142   }
143   void StoreRoot(Register source, Heap::RootListIndex index);
144   // Load a root value where the index (or part of it) is variable.
145   // The variable_offset register is added to the fixed_offset value
146   // to get the index into the root-array.
147   void LoadRootIndexed(Register destination,
148                        Register variable_offset,
149                        int fixed_offset);
150   void CompareRoot(Register with, Heap::RootListIndex index);
151   void CompareRoot(const Operand& with, Heap::RootListIndex index);
152   void PushRoot(Heap::RootListIndex index);
153 
154   // Compare the object in a register to a value and jump if they are equal.
155   void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal,
156                   Label::Distance if_equal_distance = Label::kFar) {
157     CompareRoot(with, index);
158     j(equal, if_equal, if_equal_distance);
159   }
160   void JumpIfRoot(const Operand& with, Heap::RootListIndex index,
161                   Label* if_equal,
162                   Label::Distance if_equal_distance = Label::kFar) {
163     CompareRoot(with, index);
164     j(equal, if_equal, if_equal_distance);
165   }
166 
167   // Compare the object in a register to a value and jump if they are not equal.
168   void JumpIfNotRoot(Register with, Heap::RootListIndex index,
169                      Label* if_not_equal,
170                      Label::Distance if_not_equal_distance = Label::kFar) {
171     CompareRoot(with, index);
172     j(not_equal, if_not_equal, if_not_equal_distance);
173   }
174   void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index,
175                      Label* if_not_equal,
176                      Label::Distance if_not_equal_distance = Label::kFar) {
177     CompareRoot(with, index);
178     j(not_equal, if_not_equal, if_not_equal_distance);
179   }
180 
181   // These functions do not arrange the registers in any particular order so
182   // they are not useful for calls that can cause a GC.  The caller can
183   // exclude up to 3 registers that do not need to be saved and restored.
184   void PushCallerSaved(SaveFPRegsMode fp_mode,
185                        Register exclusion1 = no_reg,
186                        Register exclusion2 = no_reg,
187                        Register exclusion3 = no_reg);
188   void PopCallerSaved(SaveFPRegsMode fp_mode,
189                       Register exclusion1 = no_reg,
190                       Register exclusion2 = no_reg,
191                       Register exclusion3 = no_reg);
192 
193 // ---------------------------------------------------------------------------
194 // GC Support
195 
196 
197   enum RememberedSetFinalAction {
198     kReturnAtEnd,
199     kFallThroughAtEnd
200   };
201 
202   // Record in the remembered set the fact that we have a pointer to new space
203   // at the address pointed to by the addr register.  Only works if addr is not
204   // in new space.
205   void RememberedSetHelper(Register object,  // Used for debug code.
206                            Register addr,
207                            Register scratch,
208                            SaveFPRegsMode save_fp,
209                            RememberedSetFinalAction and_then);
210 
211   void CheckPageFlag(Register object,
212                      Register scratch,
213                      int mask,
214                      Condition cc,
215                      Label* condition_met,
216                      Label::Distance condition_met_distance = Label::kFar);
217 
218   // Check if object is in new space.  Jumps if the object is not in new space.
219   // The register scratch can be object itself, but scratch will be clobbered.
220   void JumpIfNotInNewSpace(Register object,
221                            Register scratch,
222                            Label* branch,
223                            Label::Distance distance = Label::kFar) {
224     InNewSpace(object, scratch, zero, branch, distance);
225   }
226 
227   // Check if object is in new space.  Jumps if the object is in new space.
228   // The register scratch can be object itself, but it will be clobbered.
229   void JumpIfInNewSpace(Register object,
230                         Register scratch,
231                         Label* branch,
232                         Label::Distance distance = Label::kFar) {
233     InNewSpace(object, scratch, not_zero, branch, distance);
234   }
235 
236   // Check if an object has the black incremental marking color.  Also uses rcx!
237   void JumpIfBlack(Register object, Register bitmap_scratch,
238                    Register mask_scratch, Label* on_black,
239                    Label::Distance on_black_distance);
240 
241   // Checks the color of an object.  If the object is white we jump to the
242   // incremental marker.
243   void JumpIfWhite(Register value, Register scratch1, Register scratch2,
244                    Label* value_is_white, Label::Distance distance);
245 
246   // Notify the garbage collector that we wrote a pointer into an object.
247   // |object| is the object being stored into, |value| is the object being
248   // stored.  value and scratch registers are clobbered by the operation.
249   // The offset is the offset from the start of the object, not the offset from
250   // the tagged HeapObject pointer.  For use with FieldOperand(reg, off).
251   void RecordWriteField(
252       Register object,
253       int offset,
254       Register value,
255       Register scratch,
256       SaveFPRegsMode save_fp,
257       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
258       SmiCheck smi_check = INLINE_SMI_CHECK,
259       PointersToHereCheck pointers_to_here_check_for_value =
260           kPointersToHereMaybeInteresting);
261 
262   // As above, but the offset has the tag presubtracted.  For use with
263   // Operand(reg, off).
264   void RecordWriteContextSlot(
265       Register context,
266       int offset,
267       Register value,
268       Register scratch,
269       SaveFPRegsMode save_fp,
270       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
271       SmiCheck smi_check = INLINE_SMI_CHECK,
272       PointersToHereCheck pointers_to_here_check_for_value =
273           kPointersToHereMaybeInteresting) {
274     RecordWriteField(context,
275                      offset + kHeapObjectTag,
276                      value,
277                      scratch,
278                      save_fp,
279                      remembered_set_action,
280                      smi_check,
281                      pointers_to_here_check_for_value);
282   }
283 
284   // Notify the garbage collector that we wrote a pointer into a fixed array.
285   // |array| is the array being stored into, |value| is the
286   // object being stored.  |index| is the array index represented as a non-smi.
287   // All registers are clobbered by the operation RecordWriteArray
288   // filters out smis so it does not update the write barrier if the
289   // value is a smi.
290   void RecordWriteArray(
291       Register array,
292       Register value,
293       Register index,
294       SaveFPRegsMode save_fp,
295       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
296       SmiCheck smi_check = INLINE_SMI_CHECK,
297       PointersToHereCheck pointers_to_here_check_for_value =
298           kPointersToHereMaybeInteresting);
299 
300   // Notify the garbage collector that we wrote a code entry into a
301   // JSFunction. Only scratch is clobbered by the operation.
302   void RecordWriteCodeEntryField(Register js_function, Register code_entry,
303                                  Register scratch);
304 
305   void RecordWriteForMap(
306       Register object,
307       Register map,
308       Register dst,
309       SaveFPRegsMode save_fp);
310 
311   // For page containing |object| mark region covering |address|
312   // dirty. |object| is the object being stored into, |value| is the
313   // object being stored. The address and value registers are clobbered by the
314   // operation.  RecordWrite filters out smis so it does not update
315   // the write barrier if the value is a smi.
316   void RecordWrite(
317       Register object,
318       Register address,
319       Register value,
320       SaveFPRegsMode save_fp,
321       RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
322       SmiCheck smi_check = INLINE_SMI_CHECK,
323       PointersToHereCheck pointers_to_here_check_for_value =
324           kPointersToHereMaybeInteresting);
325 
326   // ---------------------------------------------------------------------------
327   // Debugger Support
328 
329   void DebugBreak();
330 
331   // Generates function and stub prologue code.
332   void StubPrologue(StackFrame::Type type);
333   void Prologue(bool code_pre_aging);
334 
335   // Enter specific kind of exit frame; either in normal or
336   // debug mode. Expects the number of arguments in register rax and
337   // sets up the number of arguments in register rdi and the pointer
338   // to the first argument in register rsi.
339   //
340   // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
341   // accessible via StackSpaceOperand.
342   void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false,
343                       StackFrame::Type frame_type = StackFrame::EXIT);
344 
345   // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
346   // memory (not GCed) on the stack accessible via StackSpaceOperand.
347   void EnterApiExitFrame(int arg_stack_space);
348 
349   // Leave the current exit frame. Expects/provides the return value in
350   // register rax:rdx (untouched) and the pointer to the first
351   // argument in register rsi (if pop_arguments == true).
352   void LeaveExitFrame(bool save_doubles = false, bool pop_arguments = true);
353 
354   // Leave the current exit frame. Expects/provides the return value in
355   // register rax (untouched).
356   void LeaveApiExitFrame(bool restore_context);
357 
358   // Push and pop the registers that can hold pointers.
PushSafepointRegisters()359   void PushSafepointRegisters() { Pushad(); }
PopSafepointRegisters()360   void PopSafepointRegisters() { Popad(); }
361   // Store the value in register src in the safepoint register stack
362   // slot for register dst.
363   void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
364   void StoreToSafepointRegisterSlot(Register dst, Register src);
365   void LoadFromSafepointRegisterSlot(Register dst, Register src);
366 
InitializeRootRegister()367   void InitializeRootRegister() {
368     ExternalReference roots_array_start =
369         ExternalReference::roots_array_start(isolate());
370     Move(kRootRegister, roots_array_start);
371     addp(kRootRegister, Immediate(kRootRegisterBias));
372   }
373 
374   // ---------------------------------------------------------------------------
375   // JavaScript invokes
376 
377   // Removes current frame and its arguments from the stack preserving
378   // the arguments and a return address pushed to the stack for the next call.
379   // |ra_state| defines whether return address is already pushed to stack or
380   // not. Both |callee_args_count| and |caller_args_count_reg| do not include
381   // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
382   // is trashed.
383   void PrepareForTailCall(const ParameterCount& callee_args_count,
384                           Register caller_args_count_reg, Register scratch0,
385                           Register scratch1, ReturnAddressState ra_state);
386 
387   // Invoke the JavaScript function code by either calling or jumping.
388   void InvokeFunctionCode(Register function, Register new_target,
389                           const ParameterCount& expected,
390                           const ParameterCount& actual, InvokeFlag flag,
391                           const CallWrapper& call_wrapper);
392 
393   void FloodFunctionIfStepping(Register fun, Register new_target,
394                                const ParameterCount& expected,
395                                const ParameterCount& actual);
396 
397   // Invoke the JavaScript function in the given register. Changes the
398   // current context to the context in the function before invoking.
399   void InvokeFunction(Register function,
400                       Register new_target,
401                       const ParameterCount& actual,
402                       InvokeFlag flag,
403                       const CallWrapper& call_wrapper);
404 
405   void InvokeFunction(Register function,
406                       Register new_target,
407                       const ParameterCount& expected,
408                       const ParameterCount& actual,
409                       InvokeFlag flag,
410                       const CallWrapper& call_wrapper);
411 
412   void InvokeFunction(Handle<JSFunction> function,
413                       const ParameterCount& expected,
414                       const ParameterCount& actual,
415                       InvokeFlag flag,
416                       const CallWrapper& call_wrapper);
417 
418   // ---------------------------------------------------------------------------
419   // Smi tagging, untagging and operations on tagged smis.
420 
421   // Support for constant splitting.
422   bool IsUnsafeInt(const int32_t x);
423   void SafeMove(Register dst, Smi* src);
424   void SafePush(Smi* src);
425 
426   // Conversions between tagged smi values and non-tagged integer values.
427 
428   // Tag an integer value. The result must be known to be a valid smi value.
429   // Only uses the low 32 bits of the src register. Sets the N and Z flags
430   // based on the value of the resulting smi.
431   void Integer32ToSmi(Register dst, Register src);
432 
433   // Stores an integer32 value into a memory field that already holds a smi.
434   void Integer32ToSmiField(const Operand& dst, Register src);
435 
436   // Adds constant to src and tags the result as a smi.
437   // Result must be a valid smi.
438   void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
439 
440   // Convert smi to 32-bit integer. I.e., not sign extended into
441   // high 32 bits of destination.
442   void SmiToInteger32(Register dst, Register src);
443   void SmiToInteger32(Register dst, const Operand& src);
444 
445   // Convert smi to 64-bit integer (sign extended if necessary).
446   void SmiToInteger64(Register dst, Register src);
447   void SmiToInteger64(Register dst, const Operand& src);
448 
449   // Convert smi to double.
SmiToDouble(XMMRegister dst,Register src)450   void SmiToDouble(XMMRegister dst, Register src) {
451     SmiToInteger32(kScratchRegister, src);
452     Cvtlsi2sd(dst, kScratchRegister);
453   }
454 
455   // Multiply a positive smi's integer value by a power of two.
456   // Provides result as 64-bit integer value.
457   void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
458                                              Register src,
459                                              int power);
460 
461   // Divide a positive smi's integer value by a power of two.
462   // Provides result as 32-bit integer value.
463   void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
464                                            Register src,
465                                            int power);
466 
467   // Perform the logical or of two smi values and return a smi value.
468   // If either argument is not a smi, jump to on_not_smis and retain
469   // the original values of source registers. The destination register
470   // may be changed if it's not one of the source registers.
471   void SmiOrIfSmis(Register dst,
472                    Register src1,
473                    Register src2,
474                    Label* on_not_smis,
475                    Label::Distance near_jump = Label::kFar);
476 
477 
478   // Simple comparison of smis.  Both sides must be known smis to use these,
479   // otherwise use Cmp.
480   void SmiCompare(Register smi1, Register smi2);
481   void SmiCompare(Register dst, Smi* src);
482   void SmiCompare(Register dst, const Operand& src);
483   void SmiCompare(const Operand& dst, Register src);
484   void SmiCompare(const Operand& dst, Smi* src);
485   // Compare the int32 in src register to the value of the smi stored at dst.
486   void SmiCompareInteger32(const Operand& dst, Register src);
487   // Sets sign and zero flags depending on value of smi in register.
488   void SmiTest(Register src);
489 
490   // Functions performing a check on a known or potential smi. Returns
491   // a condition that is satisfied if the check is successful.
492 
493   // Is the value a tagged smi.
494   Condition CheckSmi(Register src);
495   Condition CheckSmi(const Operand& src);
496 
497   // Is the value a non-negative tagged smi.
498   Condition CheckNonNegativeSmi(Register src);
499 
500   // Are both values tagged smis.
501   Condition CheckBothSmi(Register first, Register second);
502 
503   // Are both values non-negative tagged smis.
504   Condition CheckBothNonNegativeSmi(Register first, Register second);
505 
506   // Are either value a tagged smi.
507   Condition CheckEitherSmi(Register first,
508                            Register second,
509                            Register scratch = kScratchRegister);
510 
511   // Checks whether an 32-bit integer value is a valid for conversion
512   // to a smi.
513   Condition CheckInteger32ValidSmiValue(Register src);
514 
515   // Checks whether an 32-bit unsigned integer value is a valid for
516   // conversion to a smi.
517   Condition CheckUInteger32ValidSmiValue(Register src);
518 
519   // Check whether src is a Smi, and set dst to zero if it is a smi,
520   // and to one if it isn't.
521   void CheckSmiToIndicator(Register dst, Register src);
522   void CheckSmiToIndicator(Register dst, const Operand& src);
523 
524   // Test-and-jump functions. Typically combines a check function
525   // above with a conditional jump.
526 
527   // Jump if the value can be represented by a smi.
528   void JumpIfValidSmiValue(Register src, Label* on_valid,
529                            Label::Distance near_jump = Label::kFar);
530 
531   // Jump if the value cannot be represented by a smi.
532   void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
533                               Label::Distance near_jump = Label::kFar);
534 
535   // Jump if the unsigned integer value can be represented by a smi.
536   void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
537                                Label::Distance near_jump = Label::kFar);
538 
539   // Jump if the unsigned integer value cannot be represented by a smi.
540   void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
541                                   Label::Distance near_jump = Label::kFar);
542 
543   // Jump to label if the value is a tagged smi.
544   void JumpIfSmi(Register src,
545                  Label* on_smi,
546                  Label::Distance near_jump = Label::kFar);
547 
548   // Jump to label if the value is not a tagged smi.
549   void JumpIfNotSmi(Register src,
550                     Label* on_not_smi,
551                     Label::Distance near_jump = Label::kFar);
552 
553   // Jump to label if the value is not a non-negative tagged smi.
554   void JumpUnlessNonNegativeSmi(Register src,
555                                 Label* on_not_smi,
556                                 Label::Distance near_jump = Label::kFar);
557 
558   // Jump to label if the value, which must be a tagged smi, has value equal
559   // to the constant.
560   void JumpIfSmiEqualsConstant(Register src,
561                                Smi* constant,
562                                Label* on_equals,
563                                Label::Distance near_jump = Label::kFar);
564 
565   // Jump if either or both register are not smi values.
566   void JumpIfNotBothSmi(Register src1,
567                         Register src2,
568                         Label* on_not_both_smi,
569                         Label::Distance near_jump = Label::kFar);
570 
571   // Jump if either or both register are not non-negative smi values.
572   void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
573                                     Label* on_not_both_smi,
574                                     Label::Distance near_jump = Label::kFar);
575 
576   // Operations on tagged smi values.
577 
578   // Smis represent a subset of integers. The subset is always equivalent to
579   // a two's complement interpretation of a fixed number of bits.
580 
581   // Add an integer constant to a tagged smi, giving a tagged smi as result.
582   // No overflow testing on the result is done.
583   void SmiAddConstant(Register dst, Register src, Smi* constant);
584 
585   // Add an integer constant to a tagged smi, giving a tagged smi as result.
586   // No overflow testing on the result is done.
587   void SmiAddConstant(const Operand& dst, Smi* constant);
588 
589   // Add an integer constant to a tagged smi, giving a tagged smi as result,
590   // or jumping to a label if the result cannot be represented by a smi.
591   void SmiAddConstant(Register dst, Register src, Smi* constant,
592                       SmiOperationConstraints constraints, Label* bailout_label,
593                       Label::Distance near_jump = Label::kFar);
594 
595   // Subtract an integer constant from a tagged smi, giving a tagged smi as
596   // result. No testing on the result is done. Sets the N and Z flags
597   // based on the value of the resulting integer.
598   void SmiSubConstant(Register dst, Register src, Smi* constant);
599 
600   // Subtract an integer constant from a tagged smi, giving a tagged smi as
601   // result, or jumping to a label if the result cannot be represented by a smi.
602   void SmiSubConstant(Register dst, Register src, Smi* constant,
603                       SmiOperationConstraints constraints, Label* bailout_label,
604                       Label::Distance near_jump = Label::kFar);
605 
606   // Negating a smi can give a negative zero or too large positive value.
607   // NOTICE: This operation jumps on success, not failure!
608   void SmiNeg(Register dst,
609               Register src,
610               Label* on_smi_result,
611               Label::Distance near_jump = Label::kFar);
612 
613   // Adds smi values and return the result as a smi.
614   // If dst is src1, then src1 will be destroyed if the operation is
615   // successful, otherwise kept intact.
616   void SmiAdd(Register dst,
617               Register src1,
618               Register src2,
619               Label* on_not_smi_result,
620               Label::Distance near_jump = Label::kFar);
621   void SmiAdd(Register dst,
622               Register src1,
623               const Operand& src2,
624               Label* on_not_smi_result,
625               Label::Distance near_jump = Label::kFar);
626 
627   void SmiAdd(Register dst,
628               Register src1,
629               Register src2);
630 
631   // Subtracts smi values and return the result as a smi.
632   // If dst is src1, then src1 will be destroyed if the operation is
633   // successful, otherwise kept intact.
634   void SmiSub(Register dst,
635               Register src1,
636               Register src2,
637               Label* on_not_smi_result,
638               Label::Distance near_jump = Label::kFar);
639   void SmiSub(Register dst,
640               Register src1,
641               const Operand& src2,
642               Label* on_not_smi_result,
643               Label::Distance near_jump = Label::kFar);
644 
645   void SmiSub(Register dst,
646               Register src1,
647               Register src2);
648 
649   void SmiSub(Register dst,
650               Register src1,
651               const Operand& src2);
652 
653   // Multiplies smi values and return the result as a smi,
654   // if possible.
655   // If dst is src1, then src1 will be destroyed, even if
656   // the operation is unsuccessful.
657   void SmiMul(Register dst,
658               Register src1,
659               Register src2,
660               Label* on_not_smi_result,
661               Label::Distance near_jump = Label::kFar);
662 
663   // Divides one smi by another and returns the quotient.
664   // Clobbers rax and rdx registers.
665   void SmiDiv(Register dst,
666               Register src1,
667               Register src2,
668               Label* on_not_smi_result,
669               Label::Distance near_jump = Label::kFar);
670 
671   // Divides one smi by another and returns the remainder.
672   // Clobbers rax and rdx registers.
673   void SmiMod(Register dst,
674               Register src1,
675               Register src2,
676               Label* on_not_smi_result,
677               Label::Distance near_jump = Label::kFar);
678 
679   // Bitwise operations.
680   void SmiNot(Register dst, Register src);
681   void SmiAnd(Register dst, Register src1, Register src2);
682   void SmiOr(Register dst, Register src1, Register src2);
683   void SmiXor(Register dst, Register src1, Register src2);
684   void SmiAndConstant(Register dst, Register src1, Smi* constant);
685   void SmiOrConstant(Register dst, Register src1, Smi* constant);
686   void SmiXorConstant(Register dst, Register src1, Smi* constant);
687 
688   void SmiShiftLeftConstant(Register dst,
689                             Register src,
690                             int shift_value,
691                             Label* on_not_smi_result = NULL,
692                             Label::Distance near_jump = Label::kFar);
693   void SmiShiftLogicalRightConstant(Register dst,
694                                     Register src,
695                                     int shift_value,
696                                     Label* on_not_smi_result,
697                                     Label::Distance near_jump = Label::kFar);
698   void SmiShiftArithmeticRightConstant(Register dst,
699                                        Register src,
700                                        int shift_value);
701 
702   // Shifts a smi value to the left, and returns the result if that is a smi.
703   // Uses and clobbers rcx, so dst may not be rcx.
704   void SmiShiftLeft(Register dst,
705                     Register src1,
706                     Register src2,
707                     Label* on_not_smi_result = NULL,
708                     Label::Distance near_jump = Label::kFar);
709   // Shifts a smi value to the right, shifting in zero bits at the top, and
710   // returns the unsigned intepretation of the result if that is a smi.
711   // Uses and clobbers rcx, so dst may not be rcx.
712   void SmiShiftLogicalRight(Register dst,
713                             Register src1,
714                             Register src2,
715                             Label* on_not_smi_result,
716                             Label::Distance near_jump = Label::kFar);
717   // Shifts a smi value to the right, sign extending the top, and
718   // returns the signed intepretation of the result. That will always
719   // be a valid smi value, since it's numerically smaller than the
720   // original.
721   // Uses and clobbers rcx, so dst may not be rcx.
722   void SmiShiftArithmeticRight(Register dst,
723                                Register src1,
724                                Register src2);
725 
726   // Specialized operations
727 
728   // Select the non-smi register of two registers where exactly one is a
729   // smi. If neither are smis, jump to the failure label.
730   void SelectNonSmi(Register dst,
731                     Register src1,
732                     Register src2,
733                     Label* on_not_smis,
734                     Label::Distance near_jump = Label::kFar);
735 
736   // Converts, if necessary, a smi to a combination of number and
737   // multiplier to be used as a scaled index.
738   // The src register contains a *positive* smi value. The shift is the
739   // power of two to multiply the index value by (e.g.
740   // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
741   // The returned index register may be either src or dst, depending
742   // on what is most efficient. If src and dst are different registers,
743   // src is always unchanged.
744   SmiIndex SmiToIndex(Register dst, Register src, int shift);
745 
746   // Converts a positive smi to a negative index.
747   SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
748 
749   // Add the value of a smi in memory to an int32 register.
750   // Sets flags as a normal add.
751   void AddSmiField(Register dst, const Operand& src);
752 
753   // Basic Smi operations.
Move(Register dst,Smi * source)754   void Move(Register dst, Smi* source) {
755     LoadSmiConstant(dst, source);
756   }
757 
Move(const Operand & dst,Smi * source)758   void Move(const Operand& dst, Smi* source) {
759     Register constant = GetSmiConstant(source);
760     movp(dst, constant);
761   }
762 
763   void Push(Smi* smi);
764 
765   // Save away a raw integer with pointer size on the stack as two integers
766   // masquerading as smis so that the garbage collector skips visiting them.
767   void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
768   // Reconstruct a raw integer with pointer size from two integers masquerading
769   // as smis on the top of stack.
770   void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
771 
772   void Test(const Operand& dst, Smi* source);
773 
774 
775   // ---------------------------------------------------------------------------
776   // String macros.
777 
778   // If object is a string, its map is loaded into object_map.
779   void JumpIfNotString(Register object,
780                        Register object_map,
781                        Label* not_string,
782                        Label::Distance near_jump = Label::kFar);
783 
784 
785   void JumpIfNotBothSequentialOneByteStrings(
786       Register first_object, Register second_object, Register scratch1,
787       Register scratch2, Label* on_not_both_flat_one_byte,
788       Label::Distance near_jump = Label::kFar);
789 
790   // Check whether the instance type represents a flat one-byte string. Jump
791   // to the label if not. If the instance type can be scratched specify same
792   // register for both instance type and scratch.
793   void JumpIfInstanceTypeIsNotSequentialOneByte(
794       Register instance_type, Register scratch,
795       Label* on_not_flat_one_byte_string,
796       Label::Distance near_jump = Label::kFar);
797 
798   void JumpIfBothInstanceTypesAreNotSequentialOneByte(
799       Register first_object_instance_type, Register second_object_instance_type,
800       Register scratch1, Register scratch2, Label* on_fail,
801       Label::Distance near_jump = Label::kFar);
802 
803   void EmitSeqStringSetCharCheck(Register string,
804                                  Register index,
805                                  Register value,
806                                  uint32_t encoding_mask);
807 
808   // Checks if the given register or operand is a unique name
809   void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
810                                        Label::Distance distance = Label::kFar);
811   void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
812                                        Label::Distance distance = Label::kFar);
813 
814   // ---------------------------------------------------------------------------
815   // Macro instructions.
816 
817   // Load/store with specific representation.
818   void Load(Register dst, const Operand& src, Representation r);
819   void Store(const Operand& dst, Register src, Representation r);
820 
821   // Load a register with a long value as efficiently as possible.
822   void Set(Register dst, int64_t x);
823   void Set(const Operand& dst, intptr_t x);
824 
825   void Cvtss2sd(XMMRegister dst, XMMRegister src);
826   void Cvtss2sd(XMMRegister dst, const Operand& src);
827   void Cvtsd2ss(XMMRegister dst, XMMRegister src);
828   void Cvtsd2ss(XMMRegister dst, const Operand& src);
829 
830   // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
831   // hinders register renaming and makes dependence chains longer. So we use
832   // xorpd to clear the dst register before cvtsi2sd to solve this issue.
833   void Cvtlsi2sd(XMMRegister dst, Register src);
834   void Cvtlsi2sd(XMMRegister dst, const Operand& src);
835 
836   void Cvtlsi2ss(XMMRegister dst, Register src);
837   void Cvtlsi2ss(XMMRegister dst, const Operand& src);
838   void Cvtqsi2ss(XMMRegister dst, Register src);
839   void Cvtqsi2ss(XMMRegister dst, const Operand& src);
840 
841   void Cvtqsi2sd(XMMRegister dst, Register src);
842   void Cvtqsi2sd(XMMRegister dst, const Operand& src);
843 
844   void Cvtqui2ss(XMMRegister dst, Register src, Register tmp);
845   void Cvtqui2sd(XMMRegister dst, Register src, Register tmp);
846 
847   void Cvtsd2si(Register dst, XMMRegister src);
848 
849   void Cvttss2si(Register dst, XMMRegister src);
850   void Cvttss2si(Register dst, const Operand& src);
851   void Cvttsd2si(Register dst, XMMRegister src);
852   void Cvttsd2si(Register dst, const Operand& src);
853   void Cvttss2siq(Register dst, XMMRegister src);
854   void Cvttss2siq(Register dst, const Operand& src);
855   void Cvttsd2siq(Register dst, XMMRegister src);
856   void Cvttsd2siq(Register dst, const Operand& src);
857 
858   // Move if the registers are not identical.
859   void Move(Register target, Register source);
860 
861   // TestBit and Load SharedFunctionInfo special field.
862   void TestBitSharedFunctionInfoSpecialField(Register base,
863                                              int offset,
864                                              int bit_index);
865   void LoadSharedFunctionInfoSpecialField(Register dst,
866                                           Register base,
867                                           int offset);
868 
869   // Handle support
870   void Move(Register dst, Handle<Object> source);
871   void Move(const Operand& dst, Handle<Object> source);
872   void Cmp(Register dst, Handle<Object> source);
873   void Cmp(const Operand& dst, Handle<Object> source);
874   void Cmp(Register dst, Smi* src);
875   void Cmp(const Operand& dst, Smi* src);
876   void Push(Handle<Object> source);
877 
878   // Load a heap object and handle the case of new-space objects by
879   // indirecting via a global cell.
880   void MoveHeapObject(Register result, Handle<Object> object);
881 
882   // Load a global cell into a register.
883   void LoadGlobalCell(Register dst, Handle<Cell> cell);
884 
885   // Compare the given value and the value of weak cell.
886   void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
887 
888   void GetWeakValue(Register value, Handle<WeakCell> cell);
889 
890   // Load the value of the weak cell in the value register. Branch to the given
891   // miss label if the weak cell was cleared.
892   void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
893 
894   // Emit code that loads |parameter_index|'th parameter from the stack to
895   // the register according to the CallInterfaceDescriptor definition.
896   // |sp_to_caller_sp_offset_in_words| specifies the number of words pushed
897   // below the caller's sp (on x64 it's at least return address).
898   template <class Descriptor>
899   void LoadParameterFromStack(
900       Register reg, typename Descriptor::ParameterIndices parameter_index,
901       int sp_to_ra_offset_in_words = 1) {
902     DCHECK(Descriptor::kPassLastArgsOnStack);
903     UNIMPLEMENTED();
904   }
905 
906   // Emit code to discard a non-negative number of pointer-sized elements
907   // from the stack, clobbering only the rsp register.
908   void Drop(int stack_elements);
909   // Emit code to discard a positive number of pointer-sized elements
910   // from the stack under the return address which remains on the top,
911   // clobbering the rsp register.
912   void DropUnderReturnAddress(int stack_elements,
913                               Register scratch = kScratchRegister);
914 
Call(Label * target)915   void Call(Label* target) { call(target); }
916   void Push(Register src);
917   void Push(const Operand& src);
918   void PushQuad(const Operand& src);
919   void Push(Immediate value);
920   void PushImm32(int32_t imm32);
921   void Pop(Register dst);
922   void Pop(const Operand& dst);
923   void PopQuad(const Operand& dst);
PushReturnAddressFrom(Register src)924   void PushReturnAddressFrom(Register src) { pushq(src); }
PopReturnAddressTo(Register dst)925   void PopReturnAddressTo(Register dst) { popq(dst); }
Move(Register dst,ExternalReference ext)926   void Move(Register dst, ExternalReference ext) {
927     movp(dst, reinterpret_cast<void*>(ext.address()),
928          RelocInfo::EXTERNAL_REFERENCE);
929   }
930 
931   // Loads a pointer into a register with a relocation mode.
Move(Register dst,void * ptr,RelocInfo::Mode rmode)932   void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
933     // This method must not be used with heap object references. The stored
934     // address is not GC safe. Use the handle version instead.
935     DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
936     movp(dst, ptr, rmode);
937   }
938 
Move(Register dst,Handle<Object> value,RelocInfo::Mode rmode)939   void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
940     AllowDeferredHandleDereference using_raw_address;
941     DCHECK(!RelocInfo::IsNone(rmode));
942     DCHECK(value->IsHeapObject());
943     movp(dst, reinterpret_cast<void*>(value.location()), rmode);
944   }
945 
946   void Move(XMMRegister dst, uint32_t src);
947   void Move(XMMRegister dst, uint64_t src);
Move(XMMRegister dst,float src)948   void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
Move(XMMRegister dst,double src)949   void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
950 
951 #define AVX_OP2_WITH_TYPE(macro_name, name, src_type) \
952   void macro_name(XMMRegister dst, src_type src) {    \
953     if (CpuFeatures::IsSupported(AVX)) {              \
954       CpuFeatureScope scope(this, AVX);               \
955       v##name(dst, dst, src);                         \
956     } else {                                          \
957       name(dst, src);                                 \
958     }                                                 \
959   }
960 #define AVX_OP2_X(macro_name, name) \
961   AVX_OP2_WITH_TYPE(macro_name, name, XMMRegister)
962 #define AVX_OP2_O(macro_name, name) \
963   AVX_OP2_WITH_TYPE(macro_name, name, const Operand&)
964 #define AVX_OP2_XO(macro_name, name) \
965   AVX_OP2_X(macro_name, name)        \
966   AVX_OP2_O(macro_name, name)
967 
968   AVX_OP2_XO(Addsd, addsd)
969   AVX_OP2_XO(Subsd, subsd)
970   AVX_OP2_XO(Mulsd, mulsd)
971   AVX_OP2_XO(Divss, divss)
972   AVX_OP2_XO(Divsd, divsd)
973   AVX_OP2_XO(Andps, andps)
974   AVX_OP2_XO(Andpd, andpd)
975   AVX_OP2_XO(Orpd, orpd)
976   AVX_OP2_XO(Xorpd, xorpd)
977   AVX_OP2_XO(Cmpeqps, cmpeqps)
978   AVX_OP2_XO(Cmpltps, cmpltps)
979   AVX_OP2_XO(Cmpleps, cmpleps)
980   AVX_OP2_XO(Cmpneqps, cmpneqps)
981   AVX_OP2_XO(Cmpnltps, cmpnltps)
982   AVX_OP2_XO(Cmpnleps, cmpnleps)
983   AVX_OP2_XO(Cmpeqpd, cmpeqpd)
984   AVX_OP2_XO(Cmpltpd, cmpltpd)
985   AVX_OP2_XO(Cmplepd, cmplepd)
986   AVX_OP2_XO(Cmpneqpd, cmpneqpd)
987   AVX_OP2_XO(Cmpnltpd, cmpnltpd)
988   AVX_OP2_XO(Cmpnlepd, cmpnlepd)
989   AVX_OP2_X(Pcmpeqd, pcmpeqd)
990   AVX_OP2_WITH_TYPE(Psllq, psllq, byte)
991   AVX_OP2_WITH_TYPE(Psrlq, psrlq, byte)
992 
993 #undef AVX_OP2_O
994 #undef AVX_OP2_X
995 #undef AVX_OP2_XO
996 #undef AVX_OP2_WITH_TYPE
997 
998   void Movsd(XMMRegister dst, XMMRegister src);
999   void Movsd(XMMRegister dst, const Operand& src);
1000   void Movsd(const Operand& dst, XMMRegister src);
1001   void Movss(XMMRegister dst, XMMRegister src);
1002   void Movss(XMMRegister dst, const Operand& src);
1003   void Movss(const Operand& dst, XMMRegister src);
1004 
1005   void Movd(XMMRegister dst, Register src);
1006   void Movd(XMMRegister dst, const Operand& src);
1007   void Movd(Register dst, XMMRegister src);
1008   void Movq(XMMRegister dst, Register src);
1009   void Movq(Register dst, XMMRegister src);
1010 
1011   void Movaps(XMMRegister dst, XMMRegister src);
1012   void Movups(XMMRegister dst, XMMRegister src);
1013   void Movups(XMMRegister dst, const Operand& src);
1014   void Movups(const Operand& dst, XMMRegister src);
1015   void Movmskps(Register dst, XMMRegister src);
1016   void Movapd(XMMRegister dst, XMMRegister src);
1017   void Movupd(XMMRegister dst, const Operand& src);
1018   void Movupd(const Operand& dst, XMMRegister src);
1019   void Movmskpd(Register dst, XMMRegister src);
1020 
1021   void Xorps(XMMRegister dst, XMMRegister src);
1022   void Xorps(XMMRegister dst, const Operand& src);
1023 
1024   void Roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
1025   void Roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
1026   void Sqrtsd(XMMRegister dst, XMMRegister src);
1027   void Sqrtsd(XMMRegister dst, const Operand& src);
1028 
1029   void Ucomiss(XMMRegister src1, XMMRegister src2);
1030   void Ucomiss(XMMRegister src1, const Operand& src2);
1031   void Ucomisd(XMMRegister src1, XMMRegister src2);
1032   void Ucomisd(XMMRegister src1, const Operand& src2);
1033 
1034   // ---------------------------------------------------------------------------
1035   // SIMD macros.
1036   void Absps(XMMRegister dst);
1037   void Negps(XMMRegister dst);
1038   void Abspd(XMMRegister dst);
1039   void Negpd(XMMRegister dst);
1040 
1041   // Control Flow
1042   void Jump(Address destination, RelocInfo::Mode rmode);
1043   void Jump(ExternalReference ext);
1044   void Jump(const Operand& op);
1045   void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
1046 
1047   void Call(Address destination, RelocInfo::Mode rmode);
1048   void Call(ExternalReference ext);
1049   void Call(const Operand& op);
1050   void Call(Handle<Code> code_object,
1051             RelocInfo::Mode rmode,
1052             TypeFeedbackId ast_id = TypeFeedbackId::None());
1053 
1054   // The size of the code generated for different call instructions.
CallSize(Address destination)1055   int CallSize(Address destination) {
1056     return kCallSequenceLength;
1057   }
1058   int CallSize(ExternalReference ext);
CallSize(Handle<Code> code_object)1059   int CallSize(Handle<Code> code_object) {
1060     // Code calls use 32-bit relative addressing.
1061     return kShortCallInstructionLength;
1062   }
CallSize(Register target)1063   int CallSize(Register target) {
1064     // Opcode: REX_opt FF /2 m64
1065     return (target.high_bit() != 0) ? 3 : 2;
1066   }
CallSize(const Operand & target)1067   int CallSize(const Operand& target) {
1068     // Opcode: REX_opt FF /2 m64
1069     return (target.requires_rex() ? 2 : 1) + target.operand_size();
1070   }
1071 
1072   // Non-SSE2 instructions.
1073   void Pextrd(Register dst, XMMRegister src, int8_t imm8);
1074   void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
1075   void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
1076 
1077   void Lzcntq(Register dst, Register src);
1078   void Lzcntq(Register dst, const Operand& src);
1079 
1080   void Lzcntl(Register dst, Register src);
1081   void Lzcntl(Register dst, const Operand& src);
1082 
1083   void Tzcntq(Register dst, Register src);
1084   void Tzcntq(Register dst, const Operand& src);
1085 
1086   void Tzcntl(Register dst, Register src);
1087   void Tzcntl(Register dst, const Operand& src);
1088 
1089   void Popcntl(Register dst, Register src);
1090   void Popcntl(Register dst, const Operand& src);
1091 
1092   void Popcntq(Register dst, Register src);
1093   void Popcntq(Register dst, const Operand& src);
1094 
1095   // Non-x64 instructions.
1096   // Push/pop all general purpose registers.
1097   // Does not push rsp/rbp nor any of the assembler's special purpose registers
1098   // (kScratchRegister, kRootRegister).
1099   void Pushad();
1100   void Popad();
1101   // Sets the stack as after performing Popad, without actually loading the
1102   // registers.
1103   void Dropad();
1104 
1105   // Compare object type for heap object.
1106   // Always use unsigned comparisons: above and below, not less and greater.
1107   // Incoming register is heap_object and outgoing register is map.
1108   // They may be the same register, and may be kScratchRegister.
1109   void CmpObjectType(Register heap_object, InstanceType type, Register map);
1110 
1111   // Compare instance type for map.
1112   // Always use unsigned comparisons: above and below, not less and greater.
1113   void CmpInstanceType(Register map, InstanceType type);
1114 
1115   // Check if a map for a JSObject indicates that the object can have both smi
1116   // and HeapObject elements.  Jump to the specified label if it does not.
1117   void CheckFastObjectElements(Register map,
1118                                Label* fail,
1119                                Label::Distance distance = Label::kFar);
1120 
1121   // Check if a map for a JSObject indicates that the object has fast smi only
1122   // elements.  Jump to the specified label if it does not.
1123   void CheckFastSmiElements(Register map,
1124                             Label* fail,
1125                             Label::Distance distance = Label::kFar);
1126 
1127   // Check to see if maybe_number can be stored as a double in
1128   // FastDoubleElements. If it can, store it at the index specified by index in
1129   // the FastDoubleElements array elements, otherwise jump to fail.  Note that
1130   // index must not be smi-tagged.
1131   void StoreNumberToDoubleElements(Register maybe_number,
1132                                    Register elements,
1133                                    Register index,
1134                                    XMMRegister xmm_scratch,
1135                                    Label* fail,
1136                                    int elements_offset = 0);
1137 
1138   // Compare an object's map with the specified map.
1139   void CompareMap(Register obj, Handle<Map> map);
1140 
1141   // Check if the map of an object is equal to a specified map and branch to
1142   // label if not. Skip the smi check if not required (object is known to be a
1143   // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1144   // against maps that are ElementsKind transition maps of the specified map.
1145   void CheckMap(Register obj,
1146                 Handle<Map> map,
1147                 Label* fail,
1148                 SmiCheckType smi_check_type);
1149 
1150   // Check if the map of an object is equal to a specified weak map and branch
1151   // to a specified target if equal. Skip the smi check if not required
1152   // (object is known to be a heap object)
1153   void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1154                        Handle<WeakCell> cell, Handle<Code> success,
1155                        SmiCheckType smi_check_type);
1156 
1157   // Check if the object in register heap_object is a string. Afterwards the
1158   // register map contains the object map and the register instance_type
1159   // contains the instance_type. The registers map and instance_type can be the
1160   // same in which case it contains the instance type afterwards. Either of the
1161   // registers map and instance_type can be the same as heap_object.
1162   Condition IsObjectStringType(Register heap_object,
1163                                Register map,
1164                                Register instance_type);
1165 
1166   // Check if the object in register heap_object is a name. Afterwards the
1167   // register map contains the object map and the register instance_type
1168   // contains the instance_type. The registers map and instance_type can be the
1169   // same in which case it contains the instance type afterwards. Either of the
1170   // registers map and instance_type can be the same as heap_object.
1171   Condition IsObjectNameType(Register heap_object,
1172                              Register map,
1173                              Register instance_type);
1174 
1175   // FCmp compares and pops the two values on top of the FPU stack.
1176   // The flag results are similar to integer cmp, but requires unsigned
1177   // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1178   void FCmp();
1179 
1180   void ClampUint8(Register reg);
1181 
1182   void ClampDoubleToUint8(XMMRegister input_reg,
1183                           XMMRegister temp_xmm_reg,
1184                           Register result_reg);
1185 
1186   void SlowTruncateToI(Register result_reg, Register input_reg,
1187       int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1188 
1189   void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1190   void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1191 
1192   void DoubleToI(Register result_reg, XMMRegister input_reg,
1193                  XMMRegister scratch, MinusZeroMode minus_zero_mode,
1194                  Label* lost_precision, Label* is_nan, Label* minus_zero,
1195                  Label::Distance dst = Label::kFar);
1196 
1197   void LoadUint32(XMMRegister dst, Register src);
1198 
1199   void LoadInstanceDescriptors(Register map, Register descriptors);
1200   void EnumLength(Register dst, Register map);
1201   void NumberOfOwnDescriptors(Register dst, Register map);
1202   void LoadAccessor(Register dst, Register holder, int accessor_index,
1203                     AccessorComponent accessor);
1204 
1205   template<typename Field>
DecodeField(Register reg)1206   void DecodeField(Register reg) {
1207     static const int shift = Field::kShift;
1208     static const int mask = Field::kMask >> Field::kShift;
1209     if (shift != 0) {
1210       shrp(reg, Immediate(shift));
1211     }
1212     andp(reg, Immediate(mask));
1213   }
1214 
1215   template<typename Field>
DecodeFieldToSmi(Register reg)1216   void DecodeFieldToSmi(Register reg) {
1217     if (SmiValuesAre32Bits()) {
1218       andp(reg, Immediate(Field::kMask));
1219       shlp(reg, Immediate(kSmiShift - Field::kShift));
1220     } else {
1221       static const int shift = Field::kShift;
1222       static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1223       DCHECK(SmiValuesAre31Bits());
1224       DCHECK(kSmiShift == kSmiTagSize);
1225       DCHECK((mask & 0x80000000u) == 0);
1226       if (shift < kSmiShift) {
1227         shlp(reg, Immediate(kSmiShift - shift));
1228       } else if (shift > kSmiShift) {
1229         sarp(reg, Immediate(shift - kSmiShift));
1230       }
1231       andp(reg, Immediate(mask));
1232     }
1233   }
1234 
1235   // Abort execution if argument is not a number, enabled via --debug-code.
1236   void AssertNumber(Register object);
1237   void AssertNotNumber(Register object);
1238 
1239   // Abort execution if argument is a smi, enabled via --debug-code.
1240   void AssertNotSmi(Register object);
1241 
1242   // Abort execution if argument is not a smi, enabled via --debug-code.
1243   void AssertSmi(Register object);
1244   void AssertSmi(const Operand& object);
1245 
1246   // Abort execution if a 64 bit register containing a 32 bit payload does not
1247   // have zeros in the top 32 bits, enabled via --debug-code.
1248   void AssertZeroExtended(Register reg);
1249 
1250   // Abort execution if argument is not a string, enabled via --debug-code.
1251   void AssertString(Register object);
1252 
1253   // Abort execution if argument is not a name, enabled via --debug-code.
1254   void AssertName(Register object);
1255 
1256   // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1257   void AssertFunction(Register object);
1258 
1259   // Abort execution if argument is not a JSBoundFunction,
1260   // enabled via --debug-code.
1261   void AssertBoundFunction(Register object);
1262 
1263   // Abort execution if argument is not a JSGeneratorObject,
1264   // enabled via --debug-code.
1265   void AssertGeneratorObject(Register object);
1266 
1267   // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1268   void AssertReceiver(Register object);
1269 
1270   // Abort execution if argument is not undefined or an AllocationSite, enabled
1271   // via --debug-code.
1272   void AssertUndefinedOrAllocationSite(Register object);
1273 
1274   // Abort execution if argument is not the root value with the given index,
1275   // enabled via --debug-code.
1276   void AssertRootValue(Register src,
1277                        Heap::RootListIndex root_value_index,
1278                        BailoutReason reason);
1279 
1280   // ---------------------------------------------------------------------------
1281   // Exception handling
1282 
1283   // Push a new stack handler and link it into stack handler chain.
1284   void PushStackHandler();
1285 
1286   // Unlink the stack handler on top of the stack from the stack handler chain.
1287   void PopStackHandler();
1288 
1289   // ---------------------------------------------------------------------------
1290   // Inline caching support
1291 
1292   void GetNumberHash(Register r0, Register scratch);
1293 
1294   // ---------------------------------------------------------------------------
1295   // Allocation support
1296 
1297   // Allocate an object in new space or old space. If the given space
1298   // is exhausted control continues at the gc_required label. The allocated
1299   // object is returned in result and end of the new object is returned in
1300   // result_end. The register scratch can be passed as no_reg in which case
1301   // an additional object reference will be added to the reloc info. The
1302   // returned pointers in result and result_end have not yet been tagged as
1303   // heap objects. If result_contains_top_on_entry is true the content of
1304   // result is known to be the allocation top on entry (could be result_end
1305   // from a previous call). If result_contains_top_on_entry is true scratch
1306   // should be no_reg as it is never used.
1307   void Allocate(int object_size,
1308                 Register result,
1309                 Register result_end,
1310                 Register scratch,
1311                 Label* gc_required,
1312                 AllocationFlags flags);
1313 
1314   void Allocate(int header_size,
1315                 ScaleFactor element_size,
1316                 Register element_count,
1317                 Register result,
1318                 Register result_end,
1319                 Register scratch,
1320                 Label* gc_required,
1321                 AllocationFlags flags);
1322 
1323   void Allocate(Register object_size,
1324                 Register result,
1325                 Register result_end,
1326                 Register scratch,
1327                 Label* gc_required,
1328                 AllocationFlags flags);
1329 
1330   // FastAllocate is right now only used for folded allocations. It just
1331   // increments the top pointer without checking against limit. This can only
1332   // be done if it was proved earlier that the allocation will succeed.
1333   void FastAllocate(int object_size, Register result, Register result_end,
1334                     AllocationFlags flags);
1335 
1336   void FastAllocate(Register object_size, Register result, Register result_end,
1337                     AllocationFlags flags);
1338 
1339   // Allocate a heap number in new space with undefined value. Returns
1340   // tagged pointer in result register, or jumps to gc_required if new
1341   // space is full.
1342   void AllocateHeapNumber(Register result,
1343                           Register scratch,
1344                           Label* gc_required,
1345                           MutableMode mode = IMMUTABLE);
1346 
1347   // Allocate a sequential string. All the header fields of the string object
1348   // are initialized.
1349   void AllocateTwoByteString(Register result,
1350                              Register length,
1351                              Register scratch1,
1352                              Register scratch2,
1353                              Register scratch3,
1354                              Label* gc_required);
1355   void AllocateOneByteString(Register result, Register length,
1356                              Register scratch1, Register scratch2,
1357                              Register scratch3, Label* gc_required);
1358 
1359   // Allocate a raw cons string object. Only the map field of the result is
1360   // initialized.
1361   void AllocateTwoByteConsString(Register result,
1362                           Register scratch1,
1363                           Register scratch2,
1364                           Label* gc_required);
1365   void AllocateOneByteConsString(Register result, Register scratch1,
1366                                  Register scratch2, Label* gc_required);
1367 
1368   // Allocate a raw sliced string object. Only the map field of the result is
1369   // initialized.
1370   void AllocateTwoByteSlicedString(Register result,
1371                             Register scratch1,
1372                             Register scratch2,
1373                             Label* gc_required);
1374   void AllocateOneByteSlicedString(Register result, Register scratch1,
1375                                    Register scratch2, Label* gc_required);
1376 
1377   // Allocate and initialize a JSValue wrapper with the specified {constructor}
1378   // and {value}.
1379   void AllocateJSValue(Register result, Register constructor, Register value,
1380                        Register scratch, Label* gc_required);
1381 
1382   // ---------------------------------------------------------------------------
1383   // Support functions.
1384 
1385   // Check if result is zero and op is negative.
1386   void NegativeZeroTest(Register result, Register op, Label* then_label);
1387 
1388   // Check if result is zero and op is negative in code using jump targets.
1389   void NegativeZeroTest(CodeGenerator* cgen,
1390                         Register result,
1391                         Register op,
1392                         JumpTarget* then_target);
1393 
1394   // Check if result is zero and any of op1 and op2 are negative.
1395   // Register scratch is destroyed, and it must be different from op2.
1396   void NegativeZeroTest(Register result, Register op1, Register op2,
1397                         Register scratch, Label* then_label);
1398 
1399   // Machine code version of Map::GetConstructor().
1400   // |temp| holds |result|'s map when done.
1401   void GetMapConstructor(Register result, Register map, Register temp);
1402 
1403   // Try to get function prototype of a function and puts the value in
1404   // the result register. Checks that the function really is a
1405   // function and jumps to the miss label if the fast checks fail. The
1406   // function register will be untouched; the other register may be
1407   // clobbered.
1408   void TryGetFunctionPrototype(Register function, Register result, Label* miss);
1409 
1410   // Find the function context up the context chain.
1411   void LoadContext(Register dst, int context_chain_length);
1412 
1413   // Load the global object from the current context.
LoadGlobalObject(Register dst)1414   void LoadGlobalObject(Register dst) {
1415     LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
1416   }
1417 
1418   // Load the global proxy from the current context.
LoadGlobalProxy(Register dst)1419   void LoadGlobalProxy(Register dst) {
1420     LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
1421   }
1422 
1423   // Conditionally load the cached Array transitioned map of type
1424   // transitioned_kind from the native context if the map in register
1425   // map_in_out is the cached Array map in the native context of
1426   // expected_kind.
1427   void LoadTransitionedArrayMapConditional(
1428       ElementsKind expected_kind,
1429       ElementsKind transitioned_kind,
1430       Register map_in_out,
1431       Register scratch,
1432       Label* no_map_match);
1433 
1434   // Load the native context slot with the current index.
1435   void LoadNativeContextSlot(int index, Register dst);
1436 
1437   // Load the initial map from the global function. The registers
1438   // function and map can be the same.
1439   void LoadGlobalFunctionInitialMap(Register function, Register map);
1440 
1441   // ---------------------------------------------------------------------------
1442   // Runtime calls
1443 
1444   // Call a code stub.
1445   void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1446 
1447   // Tail call a code stub (jump).
1448   void TailCallStub(CodeStub* stub);
1449 
1450   // Return from a code stub after popping its arguments.
1451   void StubReturn(int argc);
1452 
1453   // Call a runtime routine.
1454   void CallRuntime(const Runtime::Function* f,
1455                    int num_arguments,
1456                    SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1457 
1458   // Call a runtime function and save the value of XMM registers.
CallRuntimeSaveDoubles(Runtime::FunctionId fid)1459   void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1460     const Runtime::Function* function = Runtime::FunctionForId(fid);
1461     CallRuntime(function, function->nargs, kSaveFPRegs);
1462   }
1463 
1464   // Convenience function: Same as above, but takes the fid instead.
1465   void CallRuntime(Runtime::FunctionId fid,
1466                    SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1467     const Runtime::Function* function = Runtime::FunctionForId(fid);
1468     CallRuntime(function, function->nargs, save_doubles);
1469   }
1470 
1471   // Convenience function: Same as above, but takes the fid instead.
1472   void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1473                    SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1474     CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
1475   }
1476 
1477   // Convenience function: call an external reference.
1478   void CallExternalReference(const ExternalReference& ext,
1479                              int num_arguments);
1480 
1481   // Convenience function: tail call a runtime routine (jump)
1482   void TailCallRuntime(Runtime::FunctionId fid);
1483 
1484   // Jump to a runtime routines
1485   void JumpToExternalReference(const ExternalReference& ext,
1486                                bool builtin_exit_frame = false);
1487 
1488   // Before calling a C-function from generated code, align arguments on stack.
1489   // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
1490   // etc., not pushed. The argument count assumes all arguments are word sized.
1491   // The number of slots reserved for arguments depends on platform. On Windows
1492   // stack slots are reserved for the arguments passed in registers. On other
1493   // platforms stack slots are only reserved for the arguments actually passed
1494   // on the stack.
1495   void PrepareCallCFunction(int num_arguments);
1496 
1497   // Calls a C function and cleans up the space for arguments allocated
1498   // by PrepareCallCFunction. The called function is not allowed to trigger a
1499   // garbage collection, since that might move the code and invalidate the
1500   // return address (unless this is somehow accounted for by the called
1501   // function).
1502   void CallCFunction(ExternalReference function, int num_arguments);
1503   void CallCFunction(Register function, int num_arguments);
1504 
1505   // Calculate the number of stack slots to reserve for arguments when calling a
1506   // C function.
1507   int ArgumentStackSlotsForCFunctionCall(int num_arguments);
1508 
1509   // ---------------------------------------------------------------------------
1510   // Utilities
1511 
1512   void Ret();
1513 
1514   // Return and drop arguments from stack, where the number of arguments
1515   // may be bigger than 2^16 - 1.  Requires a scratch register.
1516   void Ret(int bytes_dropped, Register scratch);
1517 
CodeObject()1518   Handle<Object> CodeObject() {
1519     DCHECK(!code_object_.is_null());
1520     return code_object_;
1521   }
1522 
1523   // Initialize fields with filler values.  Fields starting at |current_address|
1524   // not including |end_address| are overwritten with the value in |filler|.  At
1525   // the end the loop, |current_address| takes the value of |end_address|.
1526   void InitializeFieldsWithFiller(Register current_address,
1527                                   Register end_address, Register filler);
1528 
1529 
1530   // Emit code for a truncating division by a constant. The dividend register is
1531   // unchanged, the result is in rdx, and rax gets clobbered.
1532   void TruncatingDiv(Register dividend, int32_t divisor);
1533 
1534   // ---------------------------------------------------------------------------
1535   // StatsCounter support
1536 
1537   void SetCounter(StatsCounter* counter, int value);
1538   void IncrementCounter(StatsCounter* counter, int value);
1539   void DecrementCounter(StatsCounter* counter, int value);
1540 
1541 
1542   // ---------------------------------------------------------------------------
1543   // Debugging
1544 
1545   // Calls Abort(msg) if the condition cc is not satisfied.
1546   // Use --debug_code to enable.
1547   void Assert(Condition cc, BailoutReason reason);
1548 
1549   void AssertFastElements(Register elements);
1550 
1551   // Like Assert(), but always enabled.
1552   void Check(Condition cc, BailoutReason reason);
1553 
1554   // Print a message to stdout and abort execution.
1555   void Abort(BailoutReason msg);
1556 
1557   // Check that the stack is aligned.
1558   void CheckStackAlignment();
1559 
1560   // Verify restrictions about code generated in stubs.
set_generating_stub(bool value)1561   void set_generating_stub(bool value) { generating_stub_ = value; }
generating_stub()1562   bool generating_stub() { return generating_stub_; }
set_has_frame(bool value)1563   void set_has_frame(bool value) { has_frame_ = value; }
has_frame()1564   bool has_frame() { return has_frame_; }
1565   inline bool AllowThisStubCall(CodeStub* stub);
1566 
SafepointRegisterStackIndex(Register reg)1567   static int SafepointRegisterStackIndex(Register reg) {
1568     return SafepointRegisterStackIndex(reg.code());
1569   }
1570 
1571   // Load the type feedback vector from a JavaScript frame.
1572   void EmitLoadTypeFeedbackVector(Register vector);
1573 
1574   // Activation support.
1575   void EnterFrame(StackFrame::Type type);
1576   void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1577   void LeaveFrame(StackFrame::Type type);
1578 
1579   void EnterBuiltinFrame(Register context, Register target, Register argc);
1580   void LeaveBuiltinFrame(Register context, Register target, Register argc);
1581 
1582   // Expects object in rax and returns map with validated enum cache
1583   // in rax.  Assumes that any other register can be used as a scratch.
1584   void CheckEnumCache(Label* call_runtime);
1585 
1586   // AllocationMemento support. Arrays may have an associated
1587   // AllocationMemento object that can be checked for in order to pretransition
1588   // to another type.
1589   // On entry, receiver_reg should point to the array object.
1590   // scratch_reg gets clobbered.
1591   // If allocation info is present, condition flags are set to equal.
1592   void TestJSArrayForAllocationMemento(Register receiver_reg,
1593                                        Register scratch_reg,
1594                                        Label* no_memento_found);
1595 
JumpIfJSArrayHasAllocationMemento(Register receiver_reg,Register scratch_reg,Label * memento_found)1596   void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1597                                          Register scratch_reg,
1598                                          Label* memento_found) {
1599     Label no_memento_found;
1600     TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1601                                     &no_memento_found);
1602     j(equal, memento_found);
1603     bind(&no_memento_found);
1604   }
1605 
1606   // Jumps to found label if a prototype map has dictionary elements.
1607   void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1608                                         Register scratch1, Label* found);
1609 
1610  private:
1611   // Order general registers are pushed by Pushad.
1612   // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
1613   static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
1614   static const int kNumSafepointSavedRegisters = 12;
1615   static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1616 
1617   bool generating_stub_;
1618   bool has_frame_;
1619   bool root_array_available_;
1620 
1621   // Returns a register holding the smi value. The register MUST NOT be
1622   // modified. It may be the "smi 1 constant" register.
1623   Register GetSmiConstant(Smi* value);
1624 
1625   int64_t RootRegisterDelta(ExternalReference other);
1626 
1627   // Moves the smi value to the destination register.
1628   void LoadSmiConstant(Register dst, Smi* value);
1629 
1630   // This handle will be patched with the code object on installation.
1631   Handle<Object> code_object_;
1632 
1633   // Helper functions for generating invokes.
1634   void InvokePrologue(const ParameterCount& expected,
1635                       const ParameterCount& actual,
1636                       Label* done,
1637                       bool* definitely_mismatches,
1638                       InvokeFlag flag,
1639                       Label::Distance near_jump,
1640                       const CallWrapper& call_wrapper);
1641 
1642   void EnterExitFramePrologue(bool save_rax, StackFrame::Type frame_type);
1643 
1644   // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1645   // accessible via StackSpaceOperand.
1646   void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
1647 
1648   void LeaveExitFrameEpilogue(bool restore_context);
1649 
1650   // Allocation support helpers.
1651   // Loads the top of new-space into the result register.
1652   // Otherwise the address of the new-space top is loaded into scratch (if
1653   // scratch is valid), and the new-space top is loaded into result.
1654   void LoadAllocationTopHelper(Register result,
1655                                Register scratch,
1656                                AllocationFlags flags);
1657 
1658   void MakeSureDoubleAlignedHelper(Register result,
1659                                    Register scratch,
1660                                    Label* gc_required,
1661                                    AllocationFlags flags);
1662 
1663   // Update allocation top with value in result_end register.
1664   // If scratch is valid, it contains the address of the allocation top.
1665   void UpdateAllocationTopHelper(Register result_end,
1666                                  Register scratch,
1667                                  AllocationFlags flags);
1668 
1669   // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1670   void InNewSpace(Register object,
1671                   Register scratch,
1672                   Condition cc,
1673                   Label* branch,
1674                   Label::Distance distance = Label::kFar);
1675 
1676   // Helper for finding the mark bits for an address.  Afterwards, the
1677   // bitmap register points at the word with the mark bits and the mask
1678   // the position of the first bit.  Uses rcx as scratch and leaves addr_reg
1679   // unchanged.
1680   inline void GetMarkBits(Register addr_reg,
1681                           Register bitmap_reg,
1682                           Register mask_reg);
1683 
1684   // Compute memory operands for safepoint stack slots.
1685   Operand SafepointRegisterSlot(Register reg);
SafepointRegisterStackIndex(int reg_code)1686   static int SafepointRegisterStackIndex(int reg_code) {
1687     return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1688   }
1689 
1690   // Needs access to SafepointRegisterStackIndex for compiled frame
1691   // traversal.
1692   friend class StandardFrame;
1693 };
1694 
1695 
1696 // The code patcher is used to patch (typically) small parts of code e.g. for
1697 // debugging and other types of instrumentation. When using the code patcher
1698 // the exact number of bytes specified must be emitted. Is not legal to emit
1699 // relocation information. If any of these constraints are violated it causes
1700 // an assertion.
1701 class CodePatcher {
1702  public:
1703   CodePatcher(Isolate* isolate, byte* address, int size);
1704   ~CodePatcher();
1705 
1706   // Macro assembler to emit code.
masm()1707   MacroAssembler* masm() { return &masm_; }
1708 
1709  private:
1710   byte* address_;  // The address of the code being patched.
1711   int size_;  // Number of bytes of the expected patch size.
1712   MacroAssembler masm_;  // Macro assembler used to generate the code.
1713 };
1714 
1715 
1716 // -----------------------------------------------------------------------------
1717 // Static helper functions.
1718 
1719 // Generate an Operand for loading a field from an object.
FieldOperand(Register object,int offset)1720 inline Operand FieldOperand(Register object, int offset) {
1721   return Operand(object, offset - kHeapObjectTag);
1722 }
1723 
1724 
1725 // Generate an Operand for loading an indexed field from an object.
FieldOperand(Register object,Register index,ScaleFactor scale,int offset)1726 inline Operand FieldOperand(Register object,
1727                             Register index,
1728                             ScaleFactor scale,
1729                             int offset) {
1730   return Operand(object, index, scale, offset - kHeapObjectTag);
1731 }
1732 
1733 
ContextOperand(Register context,int index)1734 inline Operand ContextOperand(Register context, int index) {
1735   return Operand(context, Context::SlotOffset(index));
1736 }
1737 
1738 
ContextOperand(Register context,Register index)1739 inline Operand ContextOperand(Register context, Register index) {
1740   return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1741 }
1742 
1743 
NativeContextOperand()1744 inline Operand NativeContextOperand() {
1745   return ContextOperand(rsi, Context::NATIVE_CONTEXT_INDEX);
1746 }
1747 
1748 
1749 // Provides access to exit frame stack space (not GCed).
StackSpaceOperand(int index)1750 inline Operand StackSpaceOperand(int index) {
1751 #ifdef _WIN64
1752   const int kShaddowSpace = 4;
1753   return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1754 #else
1755   return Operand(rsp, index * kPointerSize);
1756 #endif
1757 }
1758 
1759 
StackOperandForReturnAddress(int32_t disp)1760 inline Operand StackOperandForReturnAddress(int32_t disp) {
1761   return Operand(rsp, disp);
1762 }
1763 
1764 #define ACCESS_MASM(masm) masm->
1765 
1766 }  // namespace internal
1767 }  // namespace v8
1768 
1769 #endif  // V8_X64_MACRO_ASSEMBLER_X64_H_
1770