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.
5 #ifndef V8_X64_MACRO_ASSEMBLER_X64_H_
6 #define V8_X64_MACRO_ASSEMBLER_X64_H_
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"
18 // Give alias names to registers for calling conventions.
19 const Register kReturnRegister0 = {kRegister_rax_Code};
20 const Register kReturnRegister1 = {kRegister_rdx_Code};
21 const Register kJSFunctionRegister = {kRegister_rdi_Code};
22 const Register kContextRegister = {kRegister_rsi_Code};
23 const Register kInterpreterAccumulatorRegister = {kRegister_rax_Code};
24 const Register kInterpreterRegisterFileRegister = {kRegister_r11_Code};
25 const Register kInterpreterBytecodeOffsetRegister = {kRegister_r12_Code};
26 const Register kInterpreterBytecodeArrayRegister = {kRegister_r14_Code};
27 const Register kInterpreterDispatchTableRegister = {kRegister_r15_Code};
28 const Register kRuntimeCallFunctionRegister = {kRegister_rbx_Code};
29 const Register kRuntimeCallArgCountRegister = {kRegister_rax_Code};
31 // Default scratch register used by MacroAssembler (and other code that needs
32 // a spare register). The register isn't callee save, and not used by the
33 // function calling convention.
34 const Register kScratchRegister = { 10 }; // r10.
35 const Register kRootRegister = { 13 }; // r13 (callee save).
36 // Actual value of root register is offset from the root array's start
37 // to take advantage of negitive 8-bit displacement values.
38 const int kRootRegisterBias = 128;
40 // Convenience for platform-independent signatures.
41 typedef Operand MemOperand;
43 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
44 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
45 enum PointersToHereCheck {
46 kPointersToHereMaybeInteresting,
47 kPointersToHereAreAlwaysInteresting
50 enum class SmiOperationConstraint {
51 kPreserveSourceRegister = 1 << 0,
52 kBailoutOnNoOverflow = 1 << 1,
53 kBailoutOnOverflow = 1 << 2
56 typedef base::Flags<SmiOperationConstraint> SmiOperationConstraints;
58 DEFINE_OPERATORS_FOR_FLAGS(SmiOperationConstraints)
61 bool AreAliased(Register reg1,
63 Register reg3 = no_reg,
64 Register reg4 = no_reg,
65 Register reg5 = no_reg,
66 Register reg6 = no_reg,
67 Register reg7 = no_reg,
68 Register reg8 = no_reg);
71 // Forward declaration.
75 SmiIndex(Register index_register, ScaleFactor scale)
76 : reg(index_register),
83 // MacroAssembler implements a collection of frequently used macros.
84 class MacroAssembler: public Assembler {
86 // The isolate parameter can be NULL if the macro assembler should
87 // not use isolate-dependent functionality. In this case, it's the
88 // responsibility of the caller to never invoke such function on the
90 MacroAssembler(Isolate* isolate, void* buffer, int size);
92 // Prevent the use of the RootArray during the lifetime of this
94 class NoRootArrayScope BASE_EMBEDDED {
96 explicit NoRootArrayScope(MacroAssembler* assembler)
97 : variable_(&assembler->root_array_available_),
98 old_value_(assembler->root_array_available_) {
99 assembler->root_array_available_ = false;
101 ~NoRootArrayScope() {
102 *variable_ = old_value_;
109 // Operand pointing to an external reference.
110 // May emit code to set up the scratch register. The operand is
111 // only guaranteed to be correct as long as the scratch register
113 // If the operand is used more than once, use a scratch register
114 // that is guaranteed not to be clobbered.
115 Operand ExternalOperand(ExternalReference reference,
116 Register scratch = kScratchRegister);
117 // Loads and stores the value of an external reference.
118 // Special case code for load and store to take advantage of
119 // load_rax/store_rax if possible/necessary.
120 // For other operations, just use:
121 // Operand operand = ExternalOperand(extref);
122 // operation(operand, ..);
123 void Load(Register destination, ExternalReference source);
124 void Store(ExternalReference destination, Register source);
125 // Loads the address of the external reference into the destination
127 void LoadAddress(Register destination, ExternalReference source);
128 // Returns the size of the code generated by LoadAddress.
129 // Used by CallSize(ExternalReference) to find the size of a call.
130 int LoadAddressSize(ExternalReference source);
131 // Pushes the address of the external reference onto the stack.
132 void PushAddress(ExternalReference source);
134 // Operations on roots in the root-array.
135 void LoadRoot(Register destination, Heap::RootListIndex index);
136 void LoadRoot(const Operand& destination, Heap::RootListIndex index) {
137 LoadRoot(kScratchRegister, index);
138 movp(destination, kScratchRegister);
140 void StoreRoot(Register source, Heap::RootListIndex index);
141 // Load a root value where the index (or part of it) is variable.
142 // The variable_offset register is added to the fixed_offset value
143 // to get the index into the root-array.
144 void LoadRootIndexed(Register destination,
145 Register variable_offset,
147 void CompareRoot(Register with, Heap::RootListIndex index);
148 void CompareRoot(const Operand& with, Heap::RootListIndex index);
149 void PushRoot(Heap::RootListIndex index);
151 // These functions do not arrange the registers in any particular order so
152 // they are not useful for calls that can cause a GC. The caller can
153 // exclude up to 3 registers that do not need to be saved and restored.
154 void PushCallerSaved(SaveFPRegsMode fp_mode,
155 Register exclusion1 = no_reg,
156 Register exclusion2 = no_reg,
157 Register exclusion3 = no_reg);
158 void PopCallerSaved(SaveFPRegsMode fp_mode,
159 Register exclusion1 = no_reg,
160 Register exclusion2 = no_reg,
161 Register exclusion3 = no_reg);
163 // ---------------------------------------------------------------------------
167 enum RememberedSetFinalAction {
172 // Record in the remembered set the fact that we have a pointer to new space
173 // at the address pointed to by the addr register. Only works if addr is not
175 void RememberedSetHelper(Register object, // Used for debug code.
178 SaveFPRegsMode save_fp,
179 RememberedSetFinalAction and_then);
181 void CheckPageFlag(Register object,
185 Label* condition_met,
186 Label::Distance condition_met_distance = Label::kFar);
188 // Check if object is in new space. Jumps if the object is not in new space.
189 // The register scratch can be object itself, but scratch will be clobbered.
190 void JumpIfNotInNewSpace(Register object,
193 Label::Distance distance = Label::kFar) {
194 InNewSpace(object, scratch, not_equal, branch, distance);
197 // Check if object is in new space. Jumps if the object is in new space.
198 // The register scratch can be object itself, but it will be clobbered.
199 void JumpIfInNewSpace(Register object,
202 Label::Distance distance = Label::kFar) {
203 InNewSpace(object, scratch, equal, branch, distance);
206 // Check if an object has the black incremental marking color. Also uses rcx!
207 void JumpIfBlack(Register object,
211 Label::Distance on_black_distance = Label::kFar);
213 // Detects conservatively whether an object is data-only, i.e. it does need to
214 // be scanned by the garbage collector.
215 void JumpIfDataObject(Register value,
217 Label* not_data_object,
218 Label::Distance not_data_object_distance);
220 // Checks the color of an object. If the object is already grey or black
221 // then we just fall through, since it is already live. If it is white and
222 // we can determine that it doesn't need to be scanned, then we just mark it
223 // black and fall through. For the rest we jump to the label so the
224 // incremental marker can fix its assumptions.
225 void EnsureNotWhite(Register object,
228 Label* object_is_white_and_not_data,
229 Label::Distance distance);
231 // Notify the garbage collector that we wrote a pointer into an object.
232 // |object| is the object being stored into, |value| is the object being
233 // stored. value and scratch registers are clobbered by the operation.
234 // The offset is the offset from the start of the object, not the offset from
235 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
236 void RecordWriteField(
241 SaveFPRegsMode save_fp,
242 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
243 SmiCheck smi_check = INLINE_SMI_CHECK,
244 PointersToHereCheck pointers_to_here_check_for_value =
245 kPointersToHereMaybeInteresting);
247 // As above, but the offset has the tag presubtracted. For use with
248 // Operand(reg, off).
249 void RecordWriteContextSlot(
254 SaveFPRegsMode save_fp,
255 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
256 SmiCheck smi_check = INLINE_SMI_CHECK,
257 PointersToHereCheck pointers_to_here_check_for_value =
258 kPointersToHereMaybeInteresting) {
259 RecordWriteField(context,
260 offset + kHeapObjectTag,
264 remembered_set_action,
266 pointers_to_here_check_for_value);
269 // Notify the garbage collector that we wrote a pointer into a fixed array.
270 // |array| is the array being stored into, |value| is the
271 // object being stored. |index| is the array index represented as a non-smi.
272 // All registers are clobbered by the operation RecordWriteArray
273 // filters out smis so it does not update the write barrier if the
275 void RecordWriteArray(
279 SaveFPRegsMode save_fp,
280 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
281 SmiCheck smi_check = INLINE_SMI_CHECK,
282 PointersToHereCheck pointers_to_here_check_for_value =
283 kPointersToHereMaybeInteresting);
285 void RecordWriteForMap(
289 SaveFPRegsMode save_fp);
291 // For page containing |object| mark region covering |address|
292 // dirty. |object| is the object being stored into, |value| is the
293 // object being stored. The address and value registers are clobbered by the
294 // operation. RecordWrite filters out smis so it does not update
295 // the write barrier if the value is a smi.
300 SaveFPRegsMode save_fp,
301 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
302 SmiCheck smi_check = INLINE_SMI_CHECK,
303 PointersToHereCheck pointers_to_here_check_for_value =
304 kPointersToHereMaybeInteresting);
306 // ---------------------------------------------------------------------------
311 // Generates function and stub prologue code.
313 void Prologue(bool code_pre_aging);
315 // Enter specific kind of exit frame; either in normal or
316 // debug mode. Expects the number of arguments in register rax and
317 // sets up the number of arguments in register rdi and the pointer
318 // to the first argument in register rsi.
320 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
321 // accessible via StackSpaceOperand.
322 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
324 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
325 // memory (not GCed) on the stack accessible via StackSpaceOperand.
326 void EnterApiExitFrame(int arg_stack_space);
328 // Leave the current exit frame. Expects/provides the return value in
329 // register rax:rdx (untouched) and the pointer to the first
330 // argument in register rsi.
331 void LeaveExitFrame(bool save_doubles = false);
333 // Leave the current exit frame. Expects/provides the return value in
334 // register rax (untouched).
335 void LeaveApiExitFrame(bool restore_context);
337 // Push and pop the registers that can hold pointers.
338 void PushSafepointRegisters() { Pushad(); }
339 void PopSafepointRegisters() { Popad(); }
340 // Store the value in register src in the safepoint register stack
341 // slot for register dst.
342 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
343 void StoreToSafepointRegisterSlot(Register dst, Register src);
344 void LoadFromSafepointRegisterSlot(Register dst, Register src);
346 void InitializeRootRegister() {
347 ExternalReference roots_array_start =
348 ExternalReference::roots_array_start(isolate());
349 Move(kRootRegister, roots_array_start);
350 addp(kRootRegister, Immediate(kRootRegisterBias));
353 // ---------------------------------------------------------------------------
354 // JavaScript invokes
356 // Invoke the JavaScript function code by either calling or jumping.
357 void InvokeCode(Register code,
358 const ParameterCount& expected,
359 const ParameterCount& actual,
361 const CallWrapper& call_wrapper);
363 // Invoke the JavaScript function in the given register. Changes the
364 // current context to the context in the function before invoking.
365 void InvokeFunction(Register function,
366 const ParameterCount& actual,
368 const CallWrapper& call_wrapper);
370 void InvokeFunction(Register function,
371 const ParameterCount& expected,
372 const ParameterCount& actual,
374 const CallWrapper& call_wrapper);
376 void InvokeFunction(Handle<JSFunction> function,
377 const ParameterCount& expected,
378 const ParameterCount& actual,
380 const CallWrapper& call_wrapper);
382 // Invoke specified builtin JavaScript function.
383 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
384 const CallWrapper& call_wrapper = NullCallWrapper());
386 // Store the function for the given builtin in the target register.
387 void GetBuiltinFunction(Register target, int native_context_index);
389 // Store the code object for the given builtin in the target register.
390 void GetBuiltinEntry(Register target, int native_context_index);
393 // ---------------------------------------------------------------------------
394 // Smi tagging, untagging and operations on tagged smis.
396 // Support for constant splitting.
397 bool IsUnsafeInt(const int32_t x);
398 void SafeMove(Register dst, Smi* src);
399 void SafePush(Smi* src);
401 // Conversions between tagged smi values and non-tagged integer values.
403 // Tag an integer value. The result must be known to be a valid smi value.
404 // Only uses the low 32 bits of the src register. Sets the N and Z flags
405 // based on the value of the resulting smi.
406 void Integer32ToSmi(Register dst, Register src);
408 // Stores an integer32 value into a memory field that already holds a smi.
409 void Integer32ToSmiField(const Operand& dst, Register src);
411 // Adds constant to src and tags the result as a smi.
412 // Result must be a valid smi.
413 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
415 // Convert smi to 32-bit integer. I.e., not sign extended into
416 // high 32 bits of destination.
417 void SmiToInteger32(Register dst, Register src);
418 void SmiToInteger32(Register dst, const Operand& src);
420 // Convert smi to 64-bit integer (sign extended if necessary).
421 void SmiToInteger64(Register dst, Register src);
422 void SmiToInteger64(Register dst, const Operand& src);
424 // Multiply a positive smi's integer value by a power of two.
425 // Provides result as 64-bit integer value.
426 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
430 // Divide a positive smi's integer value by a power of two.
431 // Provides result as 32-bit integer value.
432 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
436 // Perform the logical or of two smi values and return a smi value.
437 // If either argument is not a smi, jump to on_not_smis and retain
438 // the original values of source registers. The destination register
439 // may be changed if it's not one of the source registers.
440 void SmiOrIfSmis(Register dst,
444 Label::Distance near_jump = Label::kFar);
447 // Simple comparison of smis. Both sides must be known smis to use these,
448 // otherwise use Cmp.
449 void SmiCompare(Register smi1, Register smi2);
450 void SmiCompare(Register dst, Smi* src);
451 void SmiCompare(Register dst, const Operand& src);
452 void SmiCompare(const Operand& dst, Register src);
453 void SmiCompare(const Operand& dst, Smi* src);
454 // Compare the int32 in src register to the value of the smi stored at dst.
455 void SmiCompareInteger32(const Operand& dst, Register src);
456 // Sets sign and zero flags depending on value of smi in register.
457 void SmiTest(Register src);
459 // Functions performing a check on a known or potential smi. Returns
460 // a condition that is satisfied if the check is successful.
462 // Is the value a tagged smi.
463 Condition CheckSmi(Register src);
464 Condition CheckSmi(const Operand& src);
466 // Is the value a non-negative tagged smi.
467 Condition CheckNonNegativeSmi(Register src);
469 // Are both values tagged smis.
470 Condition CheckBothSmi(Register first, Register second);
472 // Are both values non-negative tagged smis.
473 Condition CheckBothNonNegativeSmi(Register first, Register second);
475 // Are either value a tagged smi.
476 Condition CheckEitherSmi(Register first,
478 Register scratch = kScratchRegister);
480 // Checks whether an 32-bit integer value is a valid for conversion
482 Condition CheckInteger32ValidSmiValue(Register src);
484 // Checks whether an 32-bit unsigned integer value is a valid for
485 // conversion to a smi.
486 Condition CheckUInteger32ValidSmiValue(Register src);
488 // Check whether src is a Smi, and set dst to zero if it is a smi,
489 // and to one if it isn't.
490 void CheckSmiToIndicator(Register dst, Register src);
491 void CheckSmiToIndicator(Register dst, const Operand& src);
493 // Test-and-jump functions. Typically combines a check function
494 // above with a conditional jump.
496 // Jump if the value can be represented by a smi.
497 void JumpIfValidSmiValue(Register src, Label* on_valid,
498 Label::Distance near_jump = Label::kFar);
500 // Jump if the value cannot be represented by a smi.
501 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
502 Label::Distance near_jump = Label::kFar);
504 // Jump if the unsigned integer value can be represented by a smi.
505 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
506 Label::Distance near_jump = Label::kFar);
508 // Jump if the unsigned integer value cannot be represented by a smi.
509 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
510 Label::Distance near_jump = Label::kFar);
512 // Jump to label if the value is a tagged smi.
513 void JumpIfSmi(Register src,
515 Label::Distance near_jump = Label::kFar);
517 // Jump to label if the value is not a tagged smi.
518 void JumpIfNotSmi(Register src,
520 Label::Distance near_jump = Label::kFar);
522 // Jump to label if the value is not a non-negative tagged smi.
523 void JumpUnlessNonNegativeSmi(Register src,
525 Label::Distance near_jump = Label::kFar);
527 // Jump to label if the value, which must be a tagged smi, has value equal
529 void JumpIfSmiEqualsConstant(Register src,
532 Label::Distance near_jump = Label::kFar);
534 // Jump if either or both register are not smi values.
535 void JumpIfNotBothSmi(Register src1,
537 Label* on_not_both_smi,
538 Label::Distance near_jump = Label::kFar);
540 // Jump if either or both register are not non-negative smi values.
541 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
542 Label* on_not_both_smi,
543 Label::Distance near_jump = Label::kFar);
545 // Operations on tagged smi values.
547 // Smis represent a subset of integers. The subset is always equivalent to
548 // a two's complement interpretation of a fixed number of bits.
550 // Add an integer constant to a tagged smi, giving a tagged smi as result.
551 // No overflow testing on the result is done.
552 void SmiAddConstant(Register dst, Register src, Smi* constant);
554 // Add an integer constant to a tagged smi, giving a tagged smi as result.
555 // No overflow testing on the result is done.
556 void SmiAddConstant(const Operand& dst, Smi* constant);
558 // Add an integer constant to a tagged smi, giving a tagged smi as result,
559 // or jumping to a label if the result cannot be represented by a smi.
560 void SmiAddConstant(Register dst, Register src, Smi* constant,
561 SmiOperationConstraints constraints, Label* bailout_label,
562 Label::Distance near_jump = Label::kFar);
564 // Subtract an integer constant from a tagged smi, giving a tagged smi as
565 // result. No testing on the result is done. Sets the N and Z flags
566 // based on the value of the resulting integer.
567 void SmiSubConstant(Register dst, Register src, Smi* constant);
569 // Subtract an integer constant from a tagged smi, giving a tagged smi as
570 // result, or jumping to a label if the result cannot be represented by a smi.
571 void SmiSubConstant(Register dst, Register src, Smi* constant,
572 SmiOperationConstraints constraints, Label* bailout_label,
573 Label::Distance near_jump = Label::kFar);
575 // Negating a smi can give a negative zero or too large positive value.
576 // NOTICE: This operation jumps on success, not failure!
577 void SmiNeg(Register dst,
579 Label* on_smi_result,
580 Label::Distance near_jump = Label::kFar);
582 // Adds smi values and return the result as a smi.
583 // If dst is src1, then src1 will be destroyed if the operation is
584 // successful, otherwise kept intact.
585 void SmiAdd(Register dst,
588 Label* on_not_smi_result,
589 Label::Distance near_jump = Label::kFar);
590 void SmiAdd(Register dst,
593 Label* on_not_smi_result,
594 Label::Distance near_jump = Label::kFar);
596 void SmiAdd(Register dst,
600 // Subtracts smi values and return the result as a smi.
601 // If dst is src1, then src1 will be destroyed if the operation is
602 // successful, otherwise kept intact.
603 void SmiSub(Register dst,
606 Label* on_not_smi_result,
607 Label::Distance near_jump = Label::kFar);
608 void SmiSub(Register dst,
611 Label* on_not_smi_result,
612 Label::Distance near_jump = Label::kFar);
614 void SmiSub(Register dst,
618 void SmiSub(Register dst,
620 const Operand& src2);
622 // Multiplies smi values and return the result as a smi,
624 // If dst is src1, then src1 will be destroyed, even if
625 // the operation is unsuccessful.
626 void SmiMul(Register dst,
629 Label* on_not_smi_result,
630 Label::Distance near_jump = Label::kFar);
632 // Divides one smi by another and returns the quotient.
633 // Clobbers rax and rdx registers.
634 void SmiDiv(Register dst,
637 Label* on_not_smi_result,
638 Label::Distance near_jump = Label::kFar);
640 // Divides one smi by another and returns the remainder.
641 // Clobbers rax and rdx registers.
642 void SmiMod(Register dst,
645 Label* on_not_smi_result,
646 Label::Distance near_jump = Label::kFar);
648 // Bitwise operations.
649 void SmiNot(Register dst, Register src);
650 void SmiAnd(Register dst, Register src1, Register src2);
651 void SmiOr(Register dst, Register src1, Register src2);
652 void SmiXor(Register dst, Register src1, Register src2);
653 void SmiAndConstant(Register dst, Register src1, Smi* constant);
654 void SmiOrConstant(Register dst, Register src1, Smi* constant);
655 void SmiXorConstant(Register dst, Register src1, Smi* constant);
657 void SmiShiftLeftConstant(Register dst,
660 Label* on_not_smi_result = NULL,
661 Label::Distance near_jump = Label::kFar);
662 void SmiShiftLogicalRightConstant(Register dst,
665 Label* on_not_smi_result,
666 Label::Distance near_jump = Label::kFar);
667 void SmiShiftArithmeticRightConstant(Register dst,
671 // Shifts a smi value to the left, and returns the result if that is a smi.
672 // Uses and clobbers rcx, so dst may not be rcx.
673 void SmiShiftLeft(Register dst,
676 Label* on_not_smi_result = NULL,
677 Label::Distance near_jump = Label::kFar);
678 // Shifts a smi value to the right, shifting in zero bits at the top, and
679 // returns the unsigned intepretation of the result if that is a smi.
680 // Uses and clobbers rcx, so dst may not be rcx.
681 void SmiShiftLogicalRight(Register dst,
684 Label* on_not_smi_result,
685 Label::Distance near_jump = Label::kFar);
686 // Shifts a smi value to the right, sign extending the top, and
687 // returns the signed intepretation of the result. That will always
688 // be a valid smi value, since it's numerically smaller than the
690 // Uses and clobbers rcx, so dst may not be rcx.
691 void SmiShiftArithmeticRight(Register dst,
695 // Specialized operations
697 // Select the non-smi register of two registers where exactly one is a
698 // smi. If neither are smis, jump to the failure label.
699 void SelectNonSmi(Register dst,
703 Label::Distance near_jump = Label::kFar);
705 // Converts, if necessary, a smi to a combination of number and
706 // multiplier to be used as a scaled index.
707 // The src register contains a *positive* smi value. The shift is the
708 // power of two to multiply the index value by (e.g.
709 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
710 // The returned index register may be either src or dst, depending
711 // on what is most efficient. If src and dst are different registers,
712 // src is always unchanged.
713 SmiIndex SmiToIndex(Register dst, Register src, int shift);
715 // Converts a positive smi to a negative index.
716 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
718 // Add the value of a smi in memory to an int32 register.
719 // Sets flags as a normal add.
720 void AddSmiField(Register dst, const Operand& src);
722 // Basic Smi operations.
723 void Move(Register dst, Smi* source) {
724 LoadSmiConstant(dst, source);
727 void Move(const Operand& dst, Smi* source) {
728 Register constant = GetSmiConstant(source);
734 // Save away a raw integer with pointer size on the stack as two integers
735 // masquerading as smis so that the garbage collector skips visiting them.
736 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
737 // Reconstruct a raw integer with pointer size from two integers masquerading
738 // as smis on the top of stack.
739 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
741 void Test(const Operand& dst, Smi* source);
744 // ---------------------------------------------------------------------------
747 // Generate code to do a lookup in the number string cache. If the number in
748 // the register object is found in the cache the generated code falls through
749 // with the result in the result register. The object and the result register
750 // can be the same. If the number is not found in the cache the code jumps to
751 // the label not_found with only the content of register object unchanged.
752 void LookupNumberStringCache(Register object,
758 // If object is a string, its map is loaded into object_map.
759 void JumpIfNotString(Register object,
762 Label::Distance near_jump = Label::kFar);
765 void JumpIfNotBothSequentialOneByteStrings(
766 Register first_object, Register second_object, Register scratch1,
767 Register scratch2, Label* on_not_both_flat_one_byte,
768 Label::Distance near_jump = Label::kFar);
770 // Check whether the instance type represents a flat one-byte string. Jump
771 // to the label if not. If the instance type can be scratched specify same
772 // register for both instance type and scratch.
773 void JumpIfInstanceTypeIsNotSequentialOneByte(
774 Register instance_type, Register scratch,
775 Label* on_not_flat_one_byte_string,
776 Label::Distance near_jump = Label::kFar);
778 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
779 Register first_object_instance_type, Register second_object_instance_type,
780 Register scratch1, Register scratch2, Label* on_fail,
781 Label::Distance near_jump = Label::kFar);
783 void EmitSeqStringSetCharCheck(Register string,
786 uint32_t encoding_mask);
788 // Checks if the given register or operand is a unique name
789 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
790 Label::Distance distance = Label::kFar);
791 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
792 Label::Distance distance = Label::kFar);
794 // ---------------------------------------------------------------------------
795 // Macro instructions.
797 // Load/store with specific representation.
798 void Load(Register dst, const Operand& src, Representation r);
799 void Store(const Operand& dst, Register src, Representation r);
801 // Load a register with a long value as efficiently as possible.
802 void Set(Register dst, int64_t x);
803 void Set(const Operand& dst, intptr_t x);
805 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
806 // hinders register renaming and makes dependence chains longer. So we use
807 // xorps to clear the dst register before cvtsi2sd to solve this issue.
808 void Cvtlsi2sd(XMMRegister dst, Register src);
809 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
811 // Move if the registers are not identical.
812 void Move(Register target, Register source);
814 // TestBit and Load SharedFunctionInfo special field.
815 void TestBitSharedFunctionInfoSpecialField(Register base,
818 void LoadSharedFunctionInfoSpecialField(Register dst,
823 void Move(Register dst, Handle<Object> source);
824 void Move(const Operand& dst, Handle<Object> source);
825 void Cmp(Register dst, Handle<Object> source);
826 void Cmp(const Operand& dst, Handle<Object> source);
827 void Cmp(Register dst, Smi* src);
828 void Cmp(const Operand& dst, Smi* src);
829 void Push(Handle<Object> source);
831 // Load a heap object and handle the case of new-space objects by
832 // indirecting via a global cell.
833 void MoveHeapObject(Register result, Handle<Object> object);
835 // Load a global cell into a register.
836 void LoadGlobalCell(Register dst, Handle<Cell> cell);
838 // Compare the given value and the value of weak cell.
839 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
841 void GetWeakValue(Register value, Handle<WeakCell> cell);
843 // Load the value of the weak cell in the value register. Branch to the given
844 // miss label if the weak cell was cleared.
845 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
847 // Emit code to discard a non-negative number of pointer-sized elements
848 // from the stack, clobbering only the rsp register.
849 void Drop(int stack_elements);
850 // Emit code to discard a positive number of pointer-sized elements
851 // from the stack under the return address which remains on the top,
852 // clobbering the rsp register.
853 void DropUnderReturnAddress(int stack_elements,
854 Register scratch = kScratchRegister);
856 void Call(Label* target) { call(target); }
857 void Push(Register src);
858 void Push(const Operand& src);
859 void PushQuad(const Operand& src);
860 void Push(Immediate value);
861 void PushImm32(int32_t imm32);
862 void Pop(Register dst);
863 void Pop(const Operand& dst);
864 void PopQuad(const Operand& dst);
865 void PushReturnAddressFrom(Register src) { pushq(src); }
866 void PopReturnAddressTo(Register dst) { popq(dst); }
867 void Move(Register dst, ExternalReference ext) {
868 movp(dst, reinterpret_cast<void*>(ext.address()),
869 RelocInfo::EXTERNAL_REFERENCE);
872 // Loads a pointer into a register with a relocation mode.
873 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
874 // This method must not be used with heap object references. The stored
875 // address is not GC safe. Use the handle version instead.
876 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
877 movp(dst, ptr, rmode);
880 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
881 AllowDeferredHandleDereference using_raw_address;
882 DCHECK(!RelocInfo::IsNone(rmode));
883 DCHECK(value->IsHeapObject());
884 DCHECK(!isolate()->heap()->InNewSpace(*value));
885 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
888 void Move(XMMRegister dst, uint32_t src);
889 void Move(XMMRegister dst, uint64_t src);
890 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
891 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
894 void Jump(Address destination, RelocInfo::Mode rmode);
895 void Jump(ExternalReference ext);
896 void Jump(const Operand& op);
897 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
899 void Call(Address destination, RelocInfo::Mode rmode);
900 void Call(ExternalReference ext);
901 void Call(const Operand& op);
902 void Call(Handle<Code> code_object,
903 RelocInfo::Mode rmode,
904 TypeFeedbackId ast_id = TypeFeedbackId::None());
906 // The size of the code generated for different call instructions.
907 int CallSize(Address destination) {
908 return kCallSequenceLength;
910 int CallSize(ExternalReference ext);
911 int CallSize(Handle<Code> code_object) {
912 // Code calls use 32-bit relative addressing.
913 return kShortCallInstructionLength;
915 int CallSize(Register target) {
916 // Opcode: REX_opt FF /2 m64
917 return (target.high_bit() != 0) ? 3 : 2;
919 int CallSize(const Operand& target) {
920 // Opcode: REX_opt FF /2 m64
921 return (target.requires_rex() ? 2 : 1) + target.operand_size();
924 // Emit call to the code we are currently generating.
926 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
927 Call(self, RelocInfo::CODE_TARGET);
930 // Non-SSE2 instructions.
931 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
932 void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
933 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
935 void Lzcntl(Register dst, Register src);
936 void Lzcntl(Register dst, const Operand& src);
938 // Non-x64 instructions.
939 // Push/pop all general purpose registers.
940 // Does not push rsp/rbp nor any of the assembler's special purpose registers
941 // (kScratchRegister, kRootRegister).
944 // Sets the stack as after performing Popad, without actually loading the
948 // Compare object type for heap object.
949 // Always use unsigned comparisons: above and below, not less and greater.
950 // Incoming register is heap_object and outgoing register is map.
951 // They may be the same register, and may be kScratchRegister.
952 void CmpObjectType(Register heap_object, InstanceType type, Register map);
954 // Compare instance type for map.
955 // Always use unsigned comparisons: above and below, not less and greater.
956 void CmpInstanceType(Register map, InstanceType type);
958 // Check if a map for a JSObject indicates that the object has fast elements.
959 // Jump to the specified label if it does not.
960 void CheckFastElements(Register map,
962 Label::Distance distance = Label::kFar);
964 // Check if a map for a JSObject indicates that the object can have both smi
965 // and HeapObject elements. Jump to the specified label if it does not.
966 void CheckFastObjectElements(Register map,
968 Label::Distance distance = Label::kFar);
970 // Check if a map for a JSObject indicates that the object has fast smi only
971 // elements. Jump to the specified label if it does not.
972 void CheckFastSmiElements(Register map,
974 Label::Distance distance = Label::kFar);
976 // Check to see if maybe_number can be stored as a double in
977 // FastDoubleElements. If it can, store it at the index specified by index in
978 // the FastDoubleElements array elements, otherwise jump to fail. Note that
979 // index must not be smi-tagged.
980 void StoreNumberToDoubleElements(Register maybe_number,
983 XMMRegister xmm_scratch,
985 int elements_offset = 0);
987 // Compare an object's map with the specified map.
988 void CompareMap(Register obj, Handle<Map> map);
990 // Check if the map of an object is equal to a specified map and branch to
991 // label if not. Skip the smi check if not required (object is known to be a
992 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
993 // against maps that are ElementsKind transition maps of the specified map.
994 void CheckMap(Register obj,
997 SmiCheckType smi_check_type);
999 // Check if the map of an object is equal to a specified weak map and branch
1000 // to a specified target if equal. Skip the smi check if not required
1001 // (object is known to be a heap object)
1002 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1003 Handle<WeakCell> cell, Handle<Code> success,
1004 SmiCheckType smi_check_type);
1006 // Check if the object in register heap_object is a string. Afterwards the
1007 // register map contains the object map and the register instance_type
1008 // contains the instance_type. The registers map and instance_type can be the
1009 // same in which case it contains the instance type afterwards. Either of the
1010 // registers map and instance_type can be the same as heap_object.
1011 Condition IsObjectStringType(Register heap_object,
1013 Register instance_type);
1015 // Check if the object in register heap_object is a name. Afterwards the
1016 // register map contains the object map and the register instance_type
1017 // contains the instance_type. The registers map and instance_type can be the
1018 // same in which case it contains the instance type afterwards. Either of the
1019 // registers map and instance_type can be the same as heap_object.
1020 Condition IsObjectNameType(Register heap_object,
1022 Register instance_type);
1024 // FCmp compares and pops the two values on top of the FPU stack.
1025 // The flag results are similar to integer cmp, but requires unsigned
1026 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1029 void ClampUint8(Register reg);
1031 void ClampDoubleToUint8(XMMRegister input_reg,
1032 XMMRegister temp_xmm_reg,
1033 Register result_reg);
1035 void SlowTruncateToI(Register result_reg, Register input_reg,
1036 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1038 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1039 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1041 void DoubleToI(Register result_reg, XMMRegister input_reg,
1042 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1043 Label* lost_precision, Label* is_nan, Label* minus_zero,
1044 Label::Distance dst = Label::kFar);
1046 void LoadUint32(XMMRegister dst, Register src);
1048 void LoadInstanceDescriptors(Register map, Register descriptors);
1049 void EnumLength(Register dst, Register map);
1050 void NumberOfOwnDescriptors(Register dst, Register map);
1051 void LoadAccessor(Register dst, Register holder, int accessor_index,
1052 AccessorComponent accessor);
1054 template<typename Field>
1055 void DecodeField(Register reg) {
1056 static const int shift = Field::kShift;
1057 static const int mask = Field::kMask >> Field::kShift;
1059 shrp(reg, Immediate(shift));
1061 andp(reg, Immediate(mask));
1064 template<typename Field>
1065 void DecodeFieldToSmi(Register reg) {
1066 if (SmiValuesAre32Bits()) {
1067 andp(reg, Immediate(Field::kMask));
1068 shlp(reg, Immediate(kSmiShift - Field::kShift));
1070 static const int shift = Field::kShift;
1071 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1072 DCHECK(SmiValuesAre31Bits());
1073 DCHECK(kSmiShift == kSmiTagSize);
1074 DCHECK((mask & 0x80000000u) == 0);
1075 if (shift < kSmiShift) {
1076 shlp(reg, Immediate(kSmiShift - shift));
1077 } else if (shift > kSmiShift) {
1078 sarp(reg, Immediate(shift - kSmiShift));
1080 andp(reg, Immediate(mask));
1084 // Abort execution if argument is not a number, enabled via --debug-code.
1085 void AssertNumber(Register object);
1087 // Abort execution if argument is a smi, enabled via --debug-code.
1088 void AssertNotSmi(Register object);
1090 // Abort execution if argument is not a smi, enabled via --debug-code.
1091 void AssertSmi(Register object);
1092 void AssertSmi(const Operand& object);
1094 // Abort execution if a 64 bit register containing a 32 bit payload does not
1095 // have zeros in the top 32 bits, enabled via --debug-code.
1096 void AssertZeroExtended(Register reg);
1098 // Abort execution if argument is not a string, enabled via --debug-code.
1099 void AssertString(Register object);
1101 // Abort execution if argument is not a name, enabled via --debug-code.
1102 void AssertName(Register object);
1104 // Abort execution if argument is not undefined or an AllocationSite, enabled
1105 // via --debug-code.
1106 void AssertUndefinedOrAllocationSite(Register object);
1108 // Abort execution if argument is not the root value with the given index,
1109 // enabled via --debug-code.
1110 void AssertRootValue(Register src,
1111 Heap::RootListIndex root_value_index,
1112 BailoutReason reason);
1114 // ---------------------------------------------------------------------------
1115 // Exception handling
1117 // Push a new stack handler and link it into stack handler chain.
1118 void PushStackHandler();
1120 // Unlink the stack handler on top of the stack from the stack handler chain.
1121 void PopStackHandler();
1123 // ---------------------------------------------------------------------------
1124 // Inline caching support
1126 // Generate code for checking access rights - used for security checks
1127 // on access to global objects across environments. The holder register
1128 // is left untouched, but the scratch register and kScratchRegister,
1129 // which must be different, are clobbered.
1130 void CheckAccessGlobalProxy(Register holder_reg,
1134 void GetNumberHash(Register r0, Register scratch);
1136 void LoadFromNumberDictionary(Label* miss,
1145 // ---------------------------------------------------------------------------
1146 // Allocation support
1148 // Allocate an object in new space or old space. If the given space
1149 // is exhausted control continues at the gc_required label. The allocated
1150 // object is returned in result and end of the new object is returned in
1151 // result_end. The register scratch can be passed as no_reg in which case
1152 // an additional object reference will be added to the reloc info. The
1153 // returned pointers in result and result_end have not yet been tagged as
1154 // heap objects. If result_contains_top_on_entry is true the content of
1155 // result is known to be the allocation top on entry (could be result_end
1156 // from a previous call). If result_contains_top_on_entry is true scratch
1157 // should be no_reg as it is never used.
1158 void Allocate(int object_size,
1160 Register result_end,
1163 AllocationFlags flags);
1165 void Allocate(int header_size,
1166 ScaleFactor element_size,
1167 Register element_count,
1169 Register result_end,
1172 AllocationFlags flags);
1174 void Allocate(Register object_size,
1176 Register result_end,
1179 AllocationFlags flags);
1181 // Allocate a heap number in new space with undefined value. Returns
1182 // tagged pointer in result register, or jumps to gc_required if new
1184 void AllocateHeapNumber(Register result,
1187 MutableMode mode = IMMUTABLE);
1189 // Allocate a sequential string. All the header fields of the string object
1191 void AllocateTwoByteString(Register result,
1196 Label* gc_required);
1197 void AllocateOneByteString(Register result, Register length,
1198 Register scratch1, Register scratch2,
1199 Register scratch3, Label* gc_required);
1201 // Allocate a raw cons string object. Only the map field of the result is
1203 void AllocateTwoByteConsString(Register result,
1206 Label* gc_required);
1207 void AllocateOneByteConsString(Register result, Register scratch1,
1208 Register scratch2, Label* gc_required);
1210 // Allocate a raw sliced string object. Only the map field of the result is
1212 void AllocateTwoByteSlicedString(Register result,
1215 Label* gc_required);
1216 void AllocateOneByteSlicedString(Register result, Register scratch1,
1217 Register scratch2, Label* gc_required);
1219 // ---------------------------------------------------------------------------
1220 // Support functions.
1222 // Check if result is zero and op is negative.
1223 void NegativeZeroTest(Register result, Register op, Label* then_label);
1225 // Check if result is zero and op is negative in code using jump targets.
1226 void NegativeZeroTest(CodeGenerator* cgen,
1229 JumpTarget* then_target);
1231 // Check if result is zero and any of op1 and op2 are negative.
1232 // Register scratch is destroyed, and it must be different from op2.
1233 void NegativeZeroTest(Register result, Register op1, Register op2,
1234 Register scratch, Label* then_label);
1236 // Machine code version of Map::GetConstructor().
1237 // |temp| holds |result|'s map when done.
1238 void GetMapConstructor(Register result, Register map, Register temp);
1240 // Try to get function prototype of a function and puts the value in
1241 // the result register. Checks that the function really is a
1242 // function and jumps to the miss label if the fast checks fail. The
1243 // function register will be untouched; the other register may be
1245 void TryGetFunctionPrototype(Register function, Register result, Label* miss);
1247 // Picks out an array index from the hash field.
1249 // hash - holds the index's hash. Clobbered.
1250 // index - holds the overwritten index on exit.
1251 void IndexFromHash(Register hash, Register index);
1253 // Find the function context up the context chain.
1254 void LoadContext(Register dst, int context_chain_length);
1256 // Conditionally load the cached Array transitioned map of type
1257 // transitioned_kind from the native context if the map in register
1258 // map_in_out is the cached Array map in the native context of
1260 void LoadTransitionedArrayMapConditional(
1261 ElementsKind expected_kind,
1262 ElementsKind transitioned_kind,
1263 Register map_in_out,
1265 Label* no_map_match);
1267 // Load the global function with the given index.
1268 void LoadGlobalFunction(int index, Register function);
1270 // Load the initial map from the global function. The registers
1271 // function and map can be the same.
1272 void LoadGlobalFunctionInitialMap(Register function, Register map);
1274 // ---------------------------------------------------------------------------
1277 // Call a code stub.
1278 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1280 // Tail call a code stub (jump).
1281 void TailCallStub(CodeStub* stub);
1283 // Return from a code stub after popping its arguments.
1284 void StubReturn(int argc);
1286 // Call a runtime routine.
1287 void CallRuntime(const Runtime::Function* f,
1289 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1291 // Call a runtime function and save the value of XMM registers.
1292 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1293 const Runtime::Function* function = Runtime::FunctionForId(id);
1294 CallRuntime(function, function->nargs, kSaveFPRegs);
1297 // Convenience function: Same as above, but takes the fid instead.
1298 void CallRuntime(Runtime::FunctionId id,
1300 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1301 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1304 // Convenience function: call an external reference.
1305 void CallExternalReference(const ExternalReference& ext,
1308 // Tail call of a runtime routine (jump).
1309 // Like JumpToExternalReference, but also takes care of passing the number
1311 void TailCallExternalReference(const ExternalReference& ext,
1315 // Convenience function: tail call a runtime routine (jump).
1316 void TailCallRuntime(Runtime::FunctionId fid,
1320 // Jump to a runtime routine.
1321 void JumpToExternalReference(const ExternalReference& ext, int result_size);
1323 // Before calling a C-function from generated code, align arguments on stack.
1324 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
1325 // etc., not pushed. The argument count assumes all arguments are word sized.
1326 // The number of slots reserved for arguments depends on platform. On Windows
1327 // stack slots are reserved for the arguments passed in registers. On other
1328 // platforms stack slots are only reserved for the arguments actually passed
1330 void PrepareCallCFunction(int num_arguments);
1332 // Calls a C function and cleans up the space for arguments allocated
1333 // by PrepareCallCFunction. The called function is not allowed to trigger a
1334 // garbage collection, since that might move the code and invalidate the
1335 // return address (unless this is somehow accounted for by the called
1337 void CallCFunction(ExternalReference function, int num_arguments);
1338 void CallCFunction(Register function, int num_arguments);
1340 // Calculate the number of stack slots to reserve for arguments when calling a
1342 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
1344 // ---------------------------------------------------------------------------
1349 // Return and drop arguments from stack, where the number of arguments
1350 // may be bigger than 2^16 - 1. Requires a scratch register.
1351 void Ret(int bytes_dropped, Register scratch);
1353 Handle<Object> CodeObject() {
1354 DCHECK(!code_object_.is_null());
1355 return code_object_;
1358 // Copy length bytes from source to destination.
1359 // Uses scratch register internally (if you have a low-eight register
1360 // free, do use it, otherwise kScratchRegister will be used).
1361 // The min_length is a minimum limit on the value that length will have.
1362 // The algorithm has some special cases that might be omitted if the string
1363 // is known to always be long.
1364 void CopyBytes(Register destination,
1368 Register scratch = kScratchRegister);
1370 // Initialize fields with filler values. Fields starting at |start_offset|
1371 // not including end_offset are overwritten with the value in |filler|. At
1372 // the end the loop, |start_offset| takes the value of |end_offset|.
1373 void InitializeFieldsWithFiller(Register start_offset,
1374 Register end_offset,
1378 // Emit code for a truncating division by a constant. The dividend register is
1379 // unchanged, the result is in rdx, and rax gets clobbered.
1380 void TruncatingDiv(Register dividend, int32_t divisor);
1382 // ---------------------------------------------------------------------------
1383 // StatsCounter support
1385 void SetCounter(StatsCounter* counter, int value);
1386 void IncrementCounter(StatsCounter* counter, int value);
1387 void DecrementCounter(StatsCounter* counter, int value);
1390 // ---------------------------------------------------------------------------
1393 // Calls Abort(msg) if the condition cc is not satisfied.
1394 // Use --debug_code to enable.
1395 void Assert(Condition cc, BailoutReason reason);
1397 void AssertFastElements(Register elements);
1399 // Like Assert(), but always enabled.
1400 void Check(Condition cc, BailoutReason reason);
1402 // Print a message to stdout and abort execution.
1403 void Abort(BailoutReason msg);
1405 // Check that the stack is aligned.
1406 void CheckStackAlignment();
1408 // Verify restrictions about code generated in stubs.
1409 void set_generating_stub(bool value) { generating_stub_ = value; }
1410 bool generating_stub() { return generating_stub_; }
1411 void set_has_frame(bool value) { has_frame_ = value; }
1412 bool has_frame() { return has_frame_; }
1413 inline bool AllowThisStubCall(CodeStub* stub);
1415 static int SafepointRegisterStackIndex(Register reg) {
1416 return SafepointRegisterStackIndex(reg.code());
1419 // Activation support.
1420 void EnterFrame(StackFrame::Type type);
1421 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1422 void LeaveFrame(StackFrame::Type type);
1424 // Expects object in rax and returns map with validated enum cache
1425 // in rax. Assumes that any other register can be used as a scratch.
1426 void CheckEnumCache(Register null_value,
1427 Label* call_runtime);
1429 // AllocationMemento support. Arrays may have an associated
1430 // AllocationMemento object that can be checked for in order to pretransition
1432 // On entry, receiver_reg should point to the array object.
1433 // scratch_reg gets clobbered.
1434 // If allocation info is present, condition flags are set to equal.
1435 void TestJSArrayForAllocationMemento(Register receiver_reg,
1436 Register scratch_reg,
1437 Label* no_memento_found);
1439 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1440 Register scratch_reg,
1441 Label* memento_found) {
1442 Label no_memento_found;
1443 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1445 j(equal, memento_found);
1446 bind(&no_memento_found);
1449 // Jumps to found label if a prototype map has dictionary elements.
1450 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1451 Register scratch1, Label* found);
1454 // Order general registers are pushed by Pushad.
1455 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
1456 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
1457 static const int kNumSafepointSavedRegisters = 12;
1458 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1460 bool generating_stub_;
1462 bool root_array_available_;
1464 // Returns a register holding the smi value. The register MUST NOT be
1465 // modified. It may be the "smi 1 constant" register.
1466 Register GetSmiConstant(Smi* value);
1468 int64_t RootRegisterDelta(ExternalReference other);
1470 // Moves the smi value to the destination register.
1471 void LoadSmiConstant(Register dst, Smi* value);
1473 // This handle will be patched with the code object on installation.
1474 Handle<Object> code_object_;
1476 // Helper functions for generating invokes.
1477 void InvokePrologue(const ParameterCount& expected,
1478 const ParameterCount& actual,
1479 Handle<Code> code_constant,
1480 Register code_register,
1482 bool* definitely_mismatches,
1484 Label::Distance near_jump = Label::kFar,
1485 const CallWrapper& call_wrapper = NullCallWrapper());
1487 void EnterExitFramePrologue(bool save_rax);
1489 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1490 // accessible via StackSpaceOperand.
1491 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
1493 void LeaveExitFrameEpilogue(bool restore_context);
1495 // Allocation support helpers.
1496 // Loads the top of new-space into the result register.
1497 // Otherwise the address of the new-space top is loaded into scratch (if
1498 // scratch is valid), and the new-space top is loaded into result.
1499 void LoadAllocationTopHelper(Register result,
1501 AllocationFlags flags);
1503 void MakeSureDoubleAlignedHelper(Register result,
1506 AllocationFlags flags);
1508 // Update allocation top with value in result_end register.
1509 // If scratch is valid, it contains the address of the allocation top.
1510 void UpdateAllocationTopHelper(Register result_end,
1512 AllocationFlags flags);
1514 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1515 void InNewSpace(Register object,
1519 Label::Distance distance = Label::kFar);
1521 // Helper for finding the mark bits for an address. Afterwards, the
1522 // bitmap register points at the word with the mark bits and the mask
1523 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1525 inline void GetMarkBits(Register addr_reg,
1526 Register bitmap_reg,
1529 // Compute memory operands for safepoint stack slots.
1530 Operand SafepointRegisterSlot(Register reg);
1531 static int SafepointRegisterStackIndex(int reg_code) {
1532 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1535 // Needs access to SafepointRegisterStackIndex for compiled frame
1537 friend class StandardFrame;
1541 // The code patcher is used to patch (typically) small parts of code e.g. for
1542 // debugging and other types of instrumentation. When using the code patcher
1543 // the exact number of bytes specified must be emitted. Is not legal to emit
1544 // relocation information. If any of these constraints are violated it causes
1548 CodePatcher(byte* address, int size);
1551 // Macro assembler to emit code.
1552 MacroAssembler* masm() { return &masm_; }
1555 byte* address_; // The address of the code being patched.
1556 int size_; // Number of bytes of the expected patch size.
1557 MacroAssembler masm_; // Macro assembler used to generate the code.
1561 // -----------------------------------------------------------------------------
1562 // Static helper functions.
1564 // Generate an Operand for loading a field from an object.
1565 inline Operand FieldOperand(Register object, int offset) {
1566 return Operand(object, offset - kHeapObjectTag);
1570 // Generate an Operand for loading an indexed field from an object.
1571 inline Operand FieldOperand(Register object,
1575 return Operand(object, index, scale, offset - kHeapObjectTag);
1579 inline Operand ContextOperand(Register context, int index) {
1580 return Operand(context, Context::SlotOffset(index));
1584 inline Operand ContextOperand(Register context, Register index) {
1585 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1589 inline Operand GlobalObjectOperand() {
1590 return ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX);
1594 // Provides access to exit frame stack space (not GCed).
1595 inline Operand StackSpaceOperand(int index) {
1597 const int kShaddowSpace = 4;
1598 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1600 return Operand(rsp, index * kPointerSize);
1605 inline Operand StackOperandForReturnAddress(int32_t disp) {
1606 return Operand(rsp, disp);
1610 #ifdef GENERATED_CODE_COVERAGE
1611 extern void LogGeneratedCodeCoverage(const char* file_line);
1612 #define CODE_COVERAGE_STRINGIFY(x) #x
1613 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1614 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1615 #define ACCESS_MASM(masm) { \
1616 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1619 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1620 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1627 #define ACCESS_MASM(masm) masm->
1630 } } // namespace v8::internal
1632 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_