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 StoreRoot(Register source, Heap::RootListIndex index);
137 // Load a root value where the index (or part of it) is variable.
138 // The variable_offset register is added to the fixed_offset value
139 // to get the index into the root-array.
140 void LoadRootIndexed(Register destination,
141 Register variable_offset,
143 void CompareRoot(Register with, Heap::RootListIndex index);
144 void CompareRoot(const Operand& with, Heap::RootListIndex index);
145 void PushRoot(Heap::RootListIndex index);
147 // These functions do not arrange the registers in any particular order so
148 // they are not useful for calls that can cause a GC. The caller can
149 // exclude up to 3 registers that do not need to be saved and restored.
150 void PushCallerSaved(SaveFPRegsMode fp_mode,
151 Register exclusion1 = no_reg,
152 Register exclusion2 = no_reg,
153 Register exclusion3 = no_reg);
154 void PopCallerSaved(SaveFPRegsMode fp_mode,
155 Register exclusion1 = no_reg,
156 Register exclusion2 = no_reg,
157 Register exclusion3 = no_reg);
159 // ---------------------------------------------------------------------------
163 enum RememberedSetFinalAction {
168 // Record in the remembered set the fact that we have a pointer to new space
169 // at the address pointed to by the addr register. Only works if addr is not
171 void RememberedSetHelper(Register object, // Used for debug code.
174 SaveFPRegsMode save_fp,
175 RememberedSetFinalAction and_then);
177 void CheckPageFlag(Register object,
181 Label* condition_met,
182 Label::Distance condition_met_distance = Label::kFar);
184 // Check if object is in new space. Jumps if the object is not in new space.
185 // The register scratch can be object itself, but scratch will be clobbered.
186 void JumpIfNotInNewSpace(Register object,
189 Label::Distance distance = Label::kFar) {
190 InNewSpace(object, scratch, not_equal, branch, distance);
193 // Check if object is in new space. Jumps if the object is in new space.
194 // The register scratch can be object itself, but it will be clobbered.
195 void JumpIfInNewSpace(Register object,
198 Label::Distance distance = Label::kFar) {
199 InNewSpace(object, scratch, equal, branch, distance);
202 // Check if an object has the black incremental marking color. Also uses rcx!
203 void JumpIfBlack(Register object,
207 Label::Distance on_black_distance = Label::kFar);
209 // Detects conservatively whether an object is data-only, i.e. it does need to
210 // be scanned by the garbage collector.
211 void JumpIfDataObject(Register value,
213 Label* not_data_object,
214 Label::Distance not_data_object_distance);
216 // Checks the color of an object. If the object is already grey or black
217 // then we just fall through, since it is already live. If it is white and
218 // we can determine that it doesn't need to be scanned, then we just mark it
219 // black and fall through. For the rest we jump to the label so the
220 // incremental marker can fix its assumptions.
221 void EnsureNotWhite(Register object,
224 Label* object_is_white_and_not_data,
225 Label::Distance distance);
227 // Notify the garbage collector that we wrote a pointer into an object.
228 // |object| is the object being stored into, |value| is the object being
229 // stored. value and scratch registers are clobbered by the operation.
230 // The offset is the offset from the start of the object, not the offset from
231 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
232 void RecordWriteField(
237 SaveFPRegsMode save_fp,
238 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
239 SmiCheck smi_check = INLINE_SMI_CHECK,
240 PointersToHereCheck pointers_to_here_check_for_value =
241 kPointersToHereMaybeInteresting);
243 // As above, but the offset has the tag presubtracted. For use with
244 // Operand(reg, off).
245 void RecordWriteContextSlot(
250 SaveFPRegsMode save_fp,
251 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
252 SmiCheck smi_check = INLINE_SMI_CHECK,
253 PointersToHereCheck pointers_to_here_check_for_value =
254 kPointersToHereMaybeInteresting) {
255 RecordWriteField(context,
256 offset + kHeapObjectTag,
260 remembered_set_action,
262 pointers_to_here_check_for_value);
265 // Notify the garbage collector that we wrote a pointer into a fixed array.
266 // |array| is the array being stored into, |value| is the
267 // object being stored. |index| is the array index represented as a non-smi.
268 // All registers are clobbered by the operation RecordWriteArray
269 // filters out smis so it does not update the write barrier if the
271 void RecordWriteArray(
275 SaveFPRegsMode save_fp,
276 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
277 SmiCheck smi_check = INLINE_SMI_CHECK,
278 PointersToHereCheck pointers_to_here_check_for_value =
279 kPointersToHereMaybeInteresting);
281 void RecordWriteForMap(
285 SaveFPRegsMode save_fp);
287 // For page containing |object| mark region covering |address|
288 // dirty. |object| is the object being stored into, |value| is the
289 // object being stored. The address and value registers are clobbered by the
290 // operation. RecordWrite filters out smis so it does not update
291 // the write barrier if the value is a smi.
296 SaveFPRegsMode save_fp,
297 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
298 SmiCheck smi_check = INLINE_SMI_CHECK,
299 PointersToHereCheck pointers_to_here_check_for_value =
300 kPointersToHereMaybeInteresting);
302 // ---------------------------------------------------------------------------
307 // Generates function and stub prologue code.
309 void Prologue(bool code_pre_aging);
311 // Enter specific kind of exit frame; either in normal or
312 // debug mode. Expects the number of arguments in register rax and
313 // sets up the number of arguments in register rdi and the pointer
314 // to the first argument in register rsi.
316 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
317 // accessible via StackSpaceOperand.
318 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
320 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
321 // memory (not GCed) on the stack accessible via StackSpaceOperand.
322 void EnterApiExitFrame(int arg_stack_space);
324 // Leave the current exit frame. Expects/provides the return value in
325 // register rax:rdx (untouched) and the pointer to the first
326 // argument in register rsi.
327 void LeaveExitFrame(bool save_doubles = false);
329 // Leave the current exit frame. Expects/provides the return value in
330 // register rax (untouched).
331 void LeaveApiExitFrame(bool restore_context);
333 // Push and pop the registers that can hold pointers.
334 void PushSafepointRegisters() { Pushad(); }
335 void PopSafepointRegisters() { Popad(); }
336 // Store the value in register src in the safepoint register stack
337 // slot for register dst.
338 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
339 void StoreToSafepointRegisterSlot(Register dst, Register src);
340 void LoadFromSafepointRegisterSlot(Register dst, Register src);
342 void InitializeRootRegister() {
343 ExternalReference roots_array_start =
344 ExternalReference::roots_array_start(isolate());
345 Move(kRootRegister, roots_array_start);
346 addp(kRootRegister, Immediate(kRootRegisterBias));
349 // ---------------------------------------------------------------------------
350 // JavaScript invokes
352 // Invoke the JavaScript function code by either calling or jumping.
353 void InvokeCode(Register code,
354 const ParameterCount& expected,
355 const ParameterCount& actual,
357 const CallWrapper& call_wrapper);
359 // Invoke the JavaScript function in the given register. Changes the
360 // current context to the context in the function before invoking.
361 void InvokeFunction(Register function,
362 const ParameterCount& actual,
364 const CallWrapper& call_wrapper);
366 void InvokeFunction(Register function,
367 const ParameterCount& expected,
368 const ParameterCount& actual,
370 const CallWrapper& call_wrapper);
372 void InvokeFunction(Handle<JSFunction> function,
373 const ParameterCount& expected,
374 const ParameterCount& actual,
376 const CallWrapper& call_wrapper);
378 // Invoke specified builtin JavaScript function. Adds an entry to
379 // the unresolved list if the name does not resolve.
380 void InvokeBuiltin(Builtins::JavaScript id,
382 const CallWrapper& call_wrapper = NullCallWrapper());
384 // Store the function for the given builtin in the target register.
385 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
387 // Store the code object for the given builtin in the target register.
388 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
391 // ---------------------------------------------------------------------------
392 // Smi tagging, untagging and operations on tagged smis.
394 // Support for constant splitting.
395 bool IsUnsafeInt(const int32_t x);
396 void SafeMove(Register dst, Smi* src);
397 void SafePush(Smi* src);
399 // Conversions between tagged smi values and non-tagged integer values.
401 // Tag an integer value. The result must be known to be a valid smi value.
402 // Only uses the low 32 bits of the src register. Sets the N and Z flags
403 // based on the value of the resulting smi.
404 void Integer32ToSmi(Register dst, Register src);
406 // Stores an integer32 value into a memory field that already holds a smi.
407 void Integer32ToSmiField(const Operand& dst, Register src);
409 // Adds constant to src and tags the result as a smi.
410 // Result must be a valid smi.
411 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
413 // Convert smi to 32-bit integer. I.e., not sign extended into
414 // high 32 bits of destination.
415 void SmiToInteger32(Register dst, Register src);
416 void SmiToInteger32(Register dst, const Operand& src);
418 // Convert smi to 64-bit integer (sign extended if necessary).
419 void SmiToInteger64(Register dst, Register src);
420 void SmiToInteger64(Register dst, const Operand& src);
422 // Multiply a positive smi's integer value by a power of two.
423 // Provides result as 64-bit integer value.
424 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
428 // Divide a positive smi's integer value by a power of two.
429 // Provides result as 32-bit integer value.
430 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
434 // Perform the logical or of two smi values and return a smi value.
435 // If either argument is not a smi, jump to on_not_smis and retain
436 // the original values of source registers. The destination register
437 // may be changed if it's not one of the source registers.
438 void SmiOrIfSmis(Register dst,
442 Label::Distance near_jump = Label::kFar);
445 // Simple comparison of smis. Both sides must be known smis to use these,
446 // otherwise use Cmp.
447 void SmiCompare(Register smi1, Register smi2);
448 void SmiCompare(Register dst, Smi* src);
449 void SmiCompare(Register dst, const Operand& src);
450 void SmiCompare(const Operand& dst, Register src);
451 void SmiCompare(const Operand& dst, Smi* src);
452 // Compare the int32 in src register to the value of the smi stored at dst.
453 void SmiCompareInteger32(const Operand& dst, Register src);
454 // Sets sign and zero flags depending on value of smi in register.
455 void SmiTest(Register src);
457 // Functions performing a check on a known or potential smi. Returns
458 // a condition that is satisfied if the check is successful.
460 // Is the value a tagged smi.
461 Condition CheckSmi(Register src);
462 Condition CheckSmi(const Operand& src);
464 // Is the value a non-negative tagged smi.
465 Condition CheckNonNegativeSmi(Register src);
467 // Are both values tagged smis.
468 Condition CheckBothSmi(Register first, Register second);
470 // Are both values non-negative tagged smis.
471 Condition CheckBothNonNegativeSmi(Register first, Register second);
473 // Are either value a tagged smi.
474 Condition CheckEitherSmi(Register first,
476 Register scratch = kScratchRegister);
478 // Checks whether an 32-bit integer value is a valid for conversion
480 Condition CheckInteger32ValidSmiValue(Register src);
482 // Checks whether an 32-bit unsigned integer value is a valid for
483 // conversion to a smi.
484 Condition CheckUInteger32ValidSmiValue(Register src);
486 // Check whether src is a Smi, and set dst to zero if it is a smi,
487 // and to one if it isn't.
488 void CheckSmiToIndicator(Register dst, Register src);
489 void CheckSmiToIndicator(Register dst, const Operand& src);
491 // Test-and-jump functions. Typically combines a check function
492 // above with a conditional jump.
494 // Jump if the value can be represented by a smi.
495 void JumpIfValidSmiValue(Register src, Label* on_valid,
496 Label::Distance near_jump = Label::kFar);
498 // Jump if the value cannot be represented by a smi.
499 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
500 Label::Distance near_jump = Label::kFar);
502 // Jump if the unsigned integer value can be represented by a smi.
503 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
504 Label::Distance near_jump = Label::kFar);
506 // Jump if the unsigned integer value cannot be represented by a smi.
507 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
508 Label::Distance near_jump = Label::kFar);
510 // Jump to label if the value is a tagged smi.
511 void JumpIfSmi(Register src,
513 Label::Distance near_jump = Label::kFar);
515 // Jump to label if the value is not a tagged smi.
516 void JumpIfNotSmi(Register src,
518 Label::Distance near_jump = Label::kFar);
520 // Jump to label if the value is not a non-negative tagged smi.
521 void JumpUnlessNonNegativeSmi(Register src,
523 Label::Distance near_jump = Label::kFar);
525 // Jump to label if the value, which must be a tagged smi, has value equal
527 void JumpIfSmiEqualsConstant(Register src,
530 Label::Distance near_jump = Label::kFar);
532 // Jump if either or both register are not smi values.
533 void JumpIfNotBothSmi(Register src1,
535 Label* on_not_both_smi,
536 Label::Distance near_jump = Label::kFar);
538 // Jump if either or both register are not non-negative smi values.
539 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
540 Label* on_not_both_smi,
541 Label::Distance near_jump = Label::kFar);
543 // Operations on tagged smi values.
545 // Smis represent a subset of integers. The subset is always equivalent to
546 // a two's complement interpretation of a fixed number of bits.
548 // Add an integer constant to a tagged smi, giving a tagged smi as result.
549 // No overflow testing on the result is done.
550 void SmiAddConstant(Register dst, Register src, Smi* constant);
552 // Add an integer constant to a tagged smi, giving a tagged smi as result.
553 // No overflow testing on the result is done.
554 void SmiAddConstant(const Operand& dst, Smi* constant);
556 // Add an integer constant to a tagged smi, giving a tagged smi as result,
557 // or jumping to a label if the result cannot be represented by a smi.
558 void SmiAddConstant(Register dst, Register src, Smi* constant,
559 SmiOperationConstraints constraints, Label* bailout_label,
560 Label::Distance near_jump = Label::kFar);
562 // Subtract an integer constant from a tagged smi, giving a tagged smi as
563 // result. No testing on the result is done. Sets the N and Z flags
564 // based on the value of the resulting integer.
565 void SmiSubConstant(Register dst, Register src, Smi* constant);
567 // Subtract an integer constant from a tagged smi, giving a tagged smi as
568 // result, or jumping to a label if the result cannot be represented by a smi.
569 void SmiSubConstant(Register dst, Register src, Smi* constant,
570 SmiOperationConstraints constraints, Label* bailout_label,
571 Label::Distance near_jump = Label::kFar);
573 // Negating a smi can give a negative zero or too large positive value.
574 // NOTICE: This operation jumps on success, not failure!
575 void SmiNeg(Register dst,
577 Label* on_smi_result,
578 Label::Distance near_jump = Label::kFar);
580 // Adds smi values and return the result as a smi.
581 // If dst is src1, then src1 will be destroyed if the operation is
582 // successful, otherwise kept intact.
583 void SmiAdd(Register dst,
586 Label* on_not_smi_result,
587 Label::Distance near_jump = Label::kFar);
588 void SmiAdd(Register dst,
591 Label* on_not_smi_result,
592 Label::Distance near_jump = Label::kFar);
594 void SmiAdd(Register dst,
598 // Subtracts smi values and return the result as a smi.
599 // If dst is src1, then src1 will be destroyed if the operation is
600 // successful, otherwise kept intact.
601 void SmiSub(Register dst,
604 Label* on_not_smi_result,
605 Label::Distance near_jump = Label::kFar);
606 void SmiSub(Register dst,
609 Label* on_not_smi_result,
610 Label::Distance near_jump = Label::kFar);
612 void SmiSub(Register dst,
616 void SmiSub(Register dst,
618 const Operand& src2);
620 // Multiplies smi values and return the result as a smi,
622 // If dst is src1, then src1 will be destroyed, even if
623 // the operation is unsuccessful.
624 void SmiMul(Register dst,
627 Label* on_not_smi_result,
628 Label::Distance near_jump = Label::kFar);
630 // Divides one smi by another and returns the quotient.
631 // Clobbers rax and rdx registers.
632 void SmiDiv(Register dst,
635 Label* on_not_smi_result,
636 Label::Distance near_jump = Label::kFar);
638 // Divides one smi by another and returns the remainder.
639 // Clobbers rax and rdx registers.
640 void SmiMod(Register dst,
643 Label* on_not_smi_result,
644 Label::Distance near_jump = Label::kFar);
646 // Bitwise operations.
647 void SmiNot(Register dst, Register src);
648 void SmiAnd(Register dst, Register src1, Register src2);
649 void SmiOr(Register dst, Register src1, Register src2);
650 void SmiXor(Register dst, Register src1, Register src2);
651 void SmiAndConstant(Register dst, Register src1, Smi* constant);
652 void SmiOrConstant(Register dst, Register src1, Smi* constant);
653 void SmiXorConstant(Register dst, Register src1, Smi* constant);
655 void SmiShiftLeftConstant(Register dst,
658 Label* on_not_smi_result = NULL,
659 Label::Distance near_jump = Label::kFar);
660 void SmiShiftLogicalRightConstant(Register dst,
663 Label* on_not_smi_result,
664 Label::Distance near_jump = Label::kFar);
665 void SmiShiftArithmeticRightConstant(Register dst,
669 // Shifts a smi value to the left, and returns the result if that is a smi.
670 // Uses and clobbers rcx, so dst may not be rcx.
671 void SmiShiftLeft(Register dst,
674 Label* on_not_smi_result = NULL,
675 Label::Distance near_jump = Label::kFar);
676 // Shifts a smi value to the right, shifting in zero bits at the top, and
677 // returns the unsigned intepretation of the result if that is a smi.
678 // Uses and clobbers rcx, so dst may not be rcx.
679 void SmiShiftLogicalRight(Register dst,
682 Label* on_not_smi_result,
683 Label::Distance near_jump = Label::kFar);
684 // Shifts a smi value to the right, sign extending the top, and
685 // returns the signed intepretation of the result. That will always
686 // be a valid smi value, since it's numerically smaller than the
688 // Uses and clobbers rcx, so dst may not be rcx.
689 void SmiShiftArithmeticRight(Register dst,
693 // Specialized operations
695 // Select the non-smi register of two registers where exactly one is a
696 // smi. If neither are smis, jump to the failure label.
697 void SelectNonSmi(Register dst,
701 Label::Distance near_jump = Label::kFar);
703 // Converts, if necessary, a smi to a combination of number and
704 // multiplier to be used as a scaled index.
705 // The src register contains a *positive* smi value. The shift is the
706 // power of two to multiply the index value by (e.g.
707 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
708 // The returned index register may be either src or dst, depending
709 // on what is most efficient. If src and dst are different registers,
710 // src is always unchanged.
711 SmiIndex SmiToIndex(Register dst, Register src, int shift);
713 // Converts a positive smi to a negative index.
714 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
716 // Add the value of a smi in memory to an int32 register.
717 // Sets flags as a normal add.
718 void AddSmiField(Register dst, const Operand& src);
720 // Basic Smi operations.
721 void Move(Register dst, Smi* source) {
722 LoadSmiConstant(dst, source);
725 void Move(const Operand& dst, Smi* source) {
726 Register constant = GetSmiConstant(source);
732 // Save away a raw integer with pointer size on the stack as two integers
733 // masquerading as smis so that the garbage collector skips visiting them.
734 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
735 // Reconstruct a raw integer with pointer size from two integers masquerading
736 // as smis on the top of stack.
737 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
739 void Test(const Operand& dst, Smi* source);
742 // ---------------------------------------------------------------------------
745 // Generate code to do a lookup in the number string cache. If the number in
746 // the register object is found in the cache the generated code falls through
747 // with the result in the result register. The object and the result register
748 // can be the same. If the number is not found in the cache the code jumps to
749 // the label not_found with only the content of register object unchanged.
750 void LookupNumberStringCache(Register object,
756 // If object is a string, its map is loaded into object_map.
757 void JumpIfNotString(Register object,
760 Label::Distance near_jump = Label::kFar);
763 void JumpIfNotBothSequentialOneByteStrings(
764 Register first_object, Register second_object, Register scratch1,
765 Register scratch2, Label* on_not_both_flat_one_byte,
766 Label::Distance near_jump = Label::kFar);
768 // Check whether the instance type represents a flat one-byte string. Jump
769 // to the label if not. If the instance type can be scratched specify same
770 // register for both instance type and scratch.
771 void JumpIfInstanceTypeIsNotSequentialOneByte(
772 Register instance_type, Register scratch,
773 Label* on_not_flat_one_byte_string,
774 Label::Distance near_jump = Label::kFar);
776 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
777 Register first_object_instance_type, Register second_object_instance_type,
778 Register scratch1, Register scratch2, Label* on_fail,
779 Label::Distance near_jump = Label::kFar);
781 void EmitSeqStringSetCharCheck(Register string,
784 uint32_t encoding_mask);
786 // Checks if the given register or operand is a unique name
787 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
788 Label::Distance distance = Label::kFar);
789 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
790 Label::Distance distance = Label::kFar);
792 // ---------------------------------------------------------------------------
793 // Macro instructions.
795 // Load/store with specific representation.
796 void Load(Register dst, const Operand& src, Representation r);
797 void Store(const Operand& dst, Register src, Representation r);
799 // Load a register with a long value as efficiently as possible.
800 void Set(Register dst, int64_t x);
801 void Set(const Operand& dst, intptr_t x);
803 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
804 // hinders register renaming and makes dependence chains longer. So we use
805 // xorps to clear the dst register before cvtsi2sd to solve this issue.
806 void Cvtlsi2sd(XMMRegister dst, Register src);
807 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
809 // Move if the registers are not identical.
810 void Move(Register target, Register source);
812 // TestBit and Load SharedFunctionInfo special field.
813 void TestBitSharedFunctionInfoSpecialField(Register base,
816 void LoadSharedFunctionInfoSpecialField(Register dst,
821 void Move(Register dst, Handle<Object> source);
822 void Move(const Operand& dst, Handle<Object> source);
823 void Cmp(Register dst, Handle<Object> source);
824 void Cmp(const Operand& dst, Handle<Object> source);
825 void Cmp(Register dst, Smi* src);
826 void Cmp(const Operand& dst, Smi* src);
827 void Push(Handle<Object> source);
829 // Load a heap object and handle the case of new-space objects by
830 // indirecting via a global cell.
831 void MoveHeapObject(Register result, Handle<Object> object);
833 // Load a global cell into a register.
834 void LoadGlobalCell(Register dst, Handle<Cell> cell);
836 // Compare the given value and the value of weak cell.
837 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
839 void GetWeakValue(Register value, Handle<WeakCell> cell);
841 // Load the value of the weak cell in the value register. Branch to the given
842 // miss label if the weak cell was cleared.
843 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
845 // Emit code to discard a non-negative number of pointer-sized elements
846 // from the stack, clobbering only the rsp register.
847 void Drop(int stack_elements);
848 // Emit code to discard a positive number of pointer-sized elements
849 // from the stack under the return address which remains on the top,
850 // clobbering the rsp register.
851 void DropUnderReturnAddress(int stack_elements,
852 Register scratch = kScratchRegister);
854 void Call(Label* target) { call(target); }
855 void Push(Register src);
856 void Push(const Operand& src);
857 void PushQuad(const Operand& src);
858 void Push(Immediate value);
859 void PushImm32(int32_t imm32);
860 void Pop(Register dst);
861 void Pop(const Operand& dst);
862 void PopQuad(const Operand& dst);
863 void PushReturnAddressFrom(Register src) { pushq(src); }
864 void PopReturnAddressTo(Register dst) { popq(dst); }
865 void Move(Register dst, ExternalReference ext) {
866 movp(dst, reinterpret_cast<void*>(ext.address()),
867 RelocInfo::EXTERNAL_REFERENCE);
870 // Loads a pointer into a register with a relocation mode.
871 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
872 // This method must not be used with heap object references. The stored
873 // address is not GC safe. Use the handle version instead.
874 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
875 movp(dst, ptr, rmode);
878 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
879 AllowDeferredHandleDereference using_raw_address;
880 DCHECK(!RelocInfo::IsNone(rmode));
881 DCHECK(value->IsHeapObject());
882 DCHECK(!isolate()->heap()->InNewSpace(*value));
883 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
886 void Move(XMMRegister dst, uint32_t src);
887 void Move(XMMRegister dst, uint64_t src);
888 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
889 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
892 void Jump(Address destination, RelocInfo::Mode rmode);
893 void Jump(ExternalReference ext);
894 void Jump(const Operand& op);
895 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
897 void Call(Address destination, RelocInfo::Mode rmode);
898 void Call(ExternalReference ext);
899 void Call(const Operand& op);
900 void Call(Handle<Code> code_object,
901 RelocInfo::Mode rmode,
902 TypeFeedbackId ast_id = TypeFeedbackId::None());
904 // The size of the code generated for different call instructions.
905 int CallSize(Address destination) {
906 return kCallSequenceLength;
908 int CallSize(ExternalReference ext);
909 int CallSize(Handle<Code> code_object) {
910 // Code calls use 32-bit relative addressing.
911 return kShortCallInstructionLength;
913 int CallSize(Register target) {
914 // Opcode: REX_opt FF /2 m64
915 return (target.high_bit() != 0) ? 3 : 2;
917 int CallSize(const Operand& target) {
918 // Opcode: REX_opt FF /2 m64
919 return (target.requires_rex() ? 2 : 1) + target.operand_size();
922 // Emit call to the code we are currently generating.
924 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
925 Call(self, RelocInfo::CODE_TARGET);
928 // Non-SSE2 instructions.
929 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
930 void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
931 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
933 void Lzcntl(Register dst, Register src);
934 void Lzcntl(Register dst, const Operand& src);
936 // Non-x64 instructions.
937 // Push/pop all general purpose registers.
938 // Does not push rsp/rbp nor any of the assembler's special purpose registers
939 // (kScratchRegister, kRootRegister).
942 // Sets the stack as after performing Popad, without actually loading the
946 // Compare object type for heap object.
947 // Always use unsigned comparisons: above and below, not less and greater.
948 // Incoming register is heap_object and outgoing register is map.
949 // They may be the same register, and may be kScratchRegister.
950 void CmpObjectType(Register heap_object, InstanceType type, Register map);
952 // Compare instance type for map.
953 // Always use unsigned comparisons: above and below, not less and greater.
954 void CmpInstanceType(Register map, InstanceType type);
956 // Check if a map for a JSObject indicates that the object has fast elements.
957 // Jump to the specified label if it does not.
958 void CheckFastElements(Register map,
960 Label::Distance distance = Label::kFar);
962 // Check if a map for a JSObject indicates that the object can have both smi
963 // and HeapObject elements. Jump to the specified label if it does not.
964 void CheckFastObjectElements(Register map,
966 Label::Distance distance = Label::kFar);
968 // Check if a map for a JSObject indicates that the object has fast smi only
969 // elements. Jump to the specified label if it does not.
970 void CheckFastSmiElements(Register map,
972 Label::Distance distance = Label::kFar);
974 // Check to see if maybe_number can be stored as a double in
975 // FastDoubleElements. If it can, store it at the index specified by index in
976 // the FastDoubleElements array elements, otherwise jump to fail. Note that
977 // index must not be smi-tagged.
978 void StoreNumberToDoubleElements(Register maybe_number,
981 XMMRegister xmm_scratch,
983 int elements_offset = 0);
985 // Compare an object's map with the specified map.
986 void CompareMap(Register obj, Handle<Map> map);
988 // Check if the map of an object is equal to a specified map and branch to
989 // label if not. Skip the smi check if not required (object is known to be a
990 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
991 // against maps that are ElementsKind transition maps of the specified map.
992 void CheckMap(Register obj,
995 SmiCheckType smi_check_type);
997 // Check if the map of an object is equal to a specified weak map and branch
998 // to a specified target if equal. Skip the smi check if not required
999 // (object is known to be a heap object)
1000 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1001 Handle<WeakCell> cell, Handle<Code> success,
1002 SmiCheckType smi_check_type);
1004 // Check if the object in register heap_object is a string. Afterwards the
1005 // register map contains the object map and the register instance_type
1006 // contains the instance_type. The registers map and instance_type can be the
1007 // same in which case it contains the instance type afterwards. Either of the
1008 // registers map and instance_type can be the same as heap_object.
1009 Condition IsObjectStringType(Register heap_object,
1011 Register instance_type);
1013 // Check if the object in register heap_object is a name. Afterwards the
1014 // register map contains the object map and the register instance_type
1015 // contains the instance_type. The registers map and instance_type can be the
1016 // same in which case it contains the instance type afterwards. Either of the
1017 // registers map and instance_type can be the same as heap_object.
1018 Condition IsObjectNameType(Register heap_object,
1020 Register instance_type);
1022 // FCmp compares and pops the two values on top of the FPU stack.
1023 // The flag results are similar to integer cmp, but requires unsigned
1024 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1027 void ClampUint8(Register reg);
1029 void ClampDoubleToUint8(XMMRegister input_reg,
1030 XMMRegister temp_xmm_reg,
1031 Register result_reg);
1033 void SlowTruncateToI(Register result_reg, Register input_reg,
1034 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1036 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1037 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1039 void DoubleToI(Register result_reg, XMMRegister input_reg,
1040 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1041 Label* lost_precision, Label* is_nan, Label* minus_zero,
1042 Label::Distance dst = Label::kFar);
1044 void LoadUint32(XMMRegister dst, Register src);
1046 void LoadInstanceDescriptors(Register map, Register descriptors);
1047 void EnumLength(Register dst, Register map);
1048 void NumberOfOwnDescriptors(Register dst, Register map);
1049 void LoadAccessor(Register dst, Register holder, int accessor_index,
1050 AccessorComponent accessor);
1052 template<typename Field>
1053 void DecodeField(Register reg) {
1054 static const int shift = Field::kShift;
1055 static const int mask = Field::kMask >> Field::kShift;
1057 shrp(reg, Immediate(shift));
1059 andp(reg, Immediate(mask));
1062 template<typename Field>
1063 void DecodeFieldToSmi(Register reg) {
1064 if (SmiValuesAre32Bits()) {
1065 andp(reg, Immediate(Field::kMask));
1066 shlp(reg, Immediate(kSmiShift - Field::kShift));
1068 static const int shift = Field::kShift;
1069 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1070 DCHECK(SmiValuesAre31Bits());
1071 DCHECK(kSmiShift == kSmiTagSize);
1072 DCHECK((mask & 0x80000000u) == 0);
1073 if (shift < kSmiShift) {
1074 shlp(reg, Immediate(kSmiShift - shift));
1075 } else if (shift > kSmiShift) {
1076 sarp(reg, Immediate(shift - kSmiShift));
1078 andp(reg, Immediate(mask));
1082 // Abort execution if argument is not a number, enabled via --debug-code.
1083 void AssertNumber(Register object);
1085 // Abort execution if argument is a smi, enabled via --debug-code.
1086 void AssertNotSmi(Register object);
1088 // Abort execution if argument is not a smi, enabled via --debug-code.
1089 void AssertSmi(Register object);
1090 void AssertSmi(const Operand& object);
1092 // Abort execution if a 64 bit register containing a 32 bit payload does not
1093 // have zeros in the top 32 bits, enabled via --debug-code.
1094 void AssertZeroExtended(Register reg);
1096 // Abort execution if argument is not a string, enabled via --debug-code.
1097 void AssertString(Register object);
1099 // Abort execution if argument is not a name, enabled via --debug-code.
1100 void AssertName(Register object);
1102 // Abort execution if argument is not undefined or an AllocationSite, enabled
1103 // via --debug-code.
1104 void AssertUndefinedOrAllocationSite(Register object);
1106 // Abort execution if argument is not the root value with the given index,
1107 // enabled via --debug-code.
1108 void AssertRootValue(Register src,
1109 Heap::RootListIndex root_value_index,
1110 BailoutReason reason);
1112 // ---------------------------------------------------------------------------
1113 // Exception handling
1115 // Push a new stack handler and link it into stack handler chain.
1116 void PushStackHandler();
1118 // Unlink the stack handler on top of the stack from the stack handler chain.
1119 void PopStackHandler();
1121 // ---------------------------------------------------------------------------
1122 // Inline caching support
1124 // Generate code for checking access rights - used for security checks
1125 // on access to global objects across environments. The holder register
1126 // is left untouched, but the scratch register and kScratchRegister,
1127 // which must be different, are clobbered.
1128 void CheckAccessGlobalProxy(Register holder_reg,
1132 void GetNumberHash(Register r0, Register scratch);
1134 void LoadFromNumberDictionary(Label* miss,
1143 // ---------------------------------------------------------------------------
1144 // Allocation support
1146 // Allocate an object in new space or old space. If the given space
1147 // is exhausted control continues at the gc_required label. The allocated
1148 // object is returned in result and end of the new object is returned in
1149 // result_end. The register scratch can be passed as no_reg in which case
1150 // an additional object reference will be added to the reloc info. The
1151 // returned pointers in result and result_end have not yet been tagged as
1152 // heap objects. If result_contains_top_on_entry is true the content of
1153 // result is known to be the allocation top on entry (could be result_end
1154 // from a previous call). If result_contains_top_on_entry is true scratch
1155 // should be no_reg as it is never used.
1156 void Allocate(int object_size,
1158 Register result_end,
1161 AllocationFlags flags);
1163 void Allocate(int header_size,
1164 ScaleFactor element_size,
1165 Register element_count,
1167 Register result_end,
1170 AllocationFlags flags);
1172 void Allocate(Register object_size,
1174 Register result_end,
1177 AllocationFlags flags);
1179 // Allocate a heap number in new space with undefined value. Returns
1180 // tagged pointer in result register, or jumps to gc_required if new
1182 void AllocateHeapNumber(Register result,
1185 MutableMode mode = IMMUTABLE);
1187 // Allocate a sequential string. All the header fields of the string object
1189 void AllocateTwoByteString(Register result,
1194 Label* gc_required);
1195 void AllocateOneByteString(Register result, Register length,
1196 Register scratch1, Register scratch2,
1197 Register scratch3, Label* gc_required);
1199 // Allocate a raw cons string object. Only the map field of the result is
1201 void AllocateTwoByteConsString(Register result,
1204 Label* gc_required);
1205 void AllocateOneByteConsString(Register result, Register scratch1,
1206 Register scratch2, Label* gc_required);
1208 // Allocate a raw sliced string object. Only the map field of the result is
1210 void AllocateTwoByteSlicedString(Register result,
1213 Label* gc_required);
1214 void AllocateOneByteSlicedString(Register result, Register scratch1,
1215 Register scratch2, Label* gc_required);
1217 // ---------------------------------------------------------------------------
1218 // Support functions.
1220 // Check if result is zero and op is negative.
1221 void NegativeZeroTest(Register result, Register op, Label* then_label);
1223 // Check if result is zero and op is negative in code using jump targets.
1224 void NegativeZeroTest(CodeGenerator* cgen,
1227 JumpTarget* then_target);
1229 // Check if result is zero and any of op1 and op2 are negative.
1230 // Register scratch is destroyed, and it must be different from op2.
1231 void NegativeZeroTest(Register result, Register op1, Register op2,
1232 Register scratch, Label* then_label);
1234 // Machine code version of Map::GetConstructor().
1235 // |temp| holds |result|'s map when done.
1236 void GetMapConstructor(Register result, Register map, Register temp);
1238 // Try to get function prototype of a function and puts the value in
1239 // the result register. Checks that the function really is a
1240 // function and jumps to the miss label if the fast checks fail. The
1241 // function register will be untouched; the other register may be
1243 void TryGetFunctionPrototype(Register function, Register result, Label* miss);
1245 // Picks out an array index from the hash field.
1247 // hash - holds the index's hash. Clobbered.
1248 // index - holds the overwritten index on exit.
1249 void IndexFromHash(Register hash, Register index);
1251 // Find the function context up the context chain.
1252 void LoadContext(Register dst, int context_chain_length);
1254 // Conditionally load the cached Array transitioned map of type
1255 // transitioned_kind from the native context if the map in register
1256 // map_in_out is the cached Array map in the native context of
1258 void LoadTransitionedArrayMapConditional(
1259 ElementsKind expected_kind,
1260 ElementsKind transitioned_kind,
1261 Register map_in_out,
1263 Label* no_map_match);
1265 // Load the global function with the given index.
1266 void LoadGlobalFunction(int index, Register function);
1268 // Load the initial map from the global function. The registers
1269 // function and map can be the same.
1270 void LoadGlobalFunctionInitialMap(Register function, Register map);
1272 // ---------------------------------------------------------------------------
1275 // Call a code stub.
1276 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1278 // Tail call a code stub (jump).
1279 void TailCallStub(CodeStub* stub);
1281 // Return from a code stub after popping its arguments.
1282 void StubReturn(int argc);
1284 // Call a runtime routine.
1285 void CallRuntime(const Runtime::Function* f,
1287 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1289 // Call a runtime function and save the value of XMM registers.
1290 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1291 const Runtime::Function* function = Runtime::FunctionForId(id);
1292 CallRuntime(function, function->nargs, kSaveFPRegs);
1295 // Convenience function: Same as above, but takes the fid instead.
1296 void CallRuntime(Runtime::FunctionId id,
1298 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1299 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1302 // Convenience function: call an external reference.
1303 void CallExternalReference(const ExternalReference& ext,
1306 // Tail call of a runtime routine (jump).
1307 // Like JumpToExternalReference, but also takes care of passing the number
1309 void TailCallExternalReference(const ExternalReference& ext,
1313 // Convenience function: tail call a runtime routine (jump).
1314 void TailCallRuntime(Runtime::FunctionId fid,
1318 // Jump to a runtime routine.
1319 void JumpToExternalReference(const ExternalReference& ext, int result_size);
1321 // Before calling a C-function from generated code, align arguments on stack.
1322 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
1323 // etc., not pushed. The argument count assumes all arguments are word sized.
1324 // The number of slots reserved for arguments depends on platform. On Windows
1325 // stack slots are reserved for the arguments passed in registers. On other
1326 // platforms stack slots are only reserved for the arguments actually passed
1328 void PrepareCallCFunction(int num_arguments);
1330 // Calls a C function and cleans up the space for arguments allocated
1331 // by PrepareCallCFunction. The called function is not allowed to trigger a
1332 // garbage collection, since that might move the code and invalidate the
1333 // return address (unless this is somehow accounted for by the called
1335 void CallCFunction(ExternalReference function, int num_arguments);
1336 void CallCFunction(Register function, int num_arguments);
1338 // Calculate the number of stack slots to reserve for arguments when calling a
1340 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
1342 // ---------------------------------------------------------------------------
1347 // Return and drop arguments from stack, where the number of arguments
1348 // may be bigger than 2^16 - 1. Requires a scratch register.
1349 void Ret(int bytes_dropped, Register scratch);
1351 Handle<Object> CodeObject() {
1352 DCHECK(!code_object_.is_null());
1353 return code_object_;
1356 // Copy length bytes from source to destination.
1357 // Uses scratch register internally (if you have a low-eight register
1358 // free, do use it, otherwise kScratchRegister will be used).
1359 // The min_length is a minimum limit on the value that length will have.
1360 // The algorithm has some special cases that might be omitted if the string
1361 // is known to always be long.
1362 void CopyBytes(Register destination,
1366 Register scratch = kScratchRegister);
1368 // Initialize fields with filler values. Fields starting at |start_offset|
1369 // not including end_offset are overwritten with the value in |filler|. At
1370 // the end the loop, |start_offset| takes the value of |end_offset|.
1371 void InitializeFieldsWithFiller(Register start_offset,
1372 Register end_offset,
1376 // Emit code for a truncating division by a constant. The dividend register is
1377 // unchanged, the result is in rdx, and rax gets clobbered.
1378 void TruncatingDiv(Register dividend, int32_t divisor);
1380 // ---------------------------------------------------------------------------
1381 // StatsCounter support
1383 void SetCounter(StatsCounter* counter, int value);
1384 void IncrementCounter(StatsCounter* counter, int value);
1385 void DecrementCounter(StatsCounter* counter, int value);
1388 // ---------------------------------------------------------------------------
1391 // Calls Abort(msg) if the condition cc is not satisfied.
1392 // Use --debug_code to enable.
1393 void Assert(Condition cc, BailoutReason reason);
1395 void AssertFastElements(Register elements);
1397 // Like Assert(), but always enabled.
1398 void Check(Condition cc, BailoutReason reason);
1400 // Print a message to stdout and abort execution.
1401 void Abort(BailoutReason msg);
1403 // Check that the stack is aligned.
1404 void CheckStackAlignment();
1406 // Verify restrictions about code generated in stubs.
1407 void set_generating_stub(bool value) { generating_stub_ = value; }
1408 bool generating_stub() { return generating_stub_; }
1409 void set_has_frame(bool value) { has_frame_ = value; }
1410 bool has_frame() { return has_frame_; }
1411 inline bool AllowThisStubCall(CodeStub* stub);
1413 static int SafepointRegisterStackIndex(Register reg) {
1414 return SafepointRegisterStackIndex(reg.code());
1417 // Activation support.
1418 void EnterFrame(StackFrame::Type type);
1419 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1420 void LeaveFrame(StackFrame::Type type);
1422 // Expects object in rax and returns map with validated enum cache
1423 // in rax. Assumes that any other register can be used as a scratch.
1424 void CheckEnumCache(Register null_value,
1425 Label* call_runtime);
1427 // AllocationMemento support. Arrays may have an associated
1428 // AllocationMemento object that can be checked for in order to pretransition
1430 // On entry, receiver_reg should point to the array object.
1431 // scratch_reg gets clobbered.
1432 // If allocation info is present, condition flags are set to equal.
1433 void TestJSArrayForAllocationMemento(Register receiver_reg,
1434 Register scratch_reg,
1435 Label* no_memento_found);
1437 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1438 Register scratch_reg,
1439 Label* memento_found) {
1440 Label no_memento_found;
1441 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1443 j(equal, memento_found);
1444 bind(&no_memento_found);
1447 // Jumps to found label if a prototype map has dictionary elements.
1448 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1449 Register scratch1, Label* found);
1452 // Order general registers are pushed by Pushad.
1453 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
1454 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
1455 static const int kNumSafepointSavedRegisters = 12;
1456 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1458 bool generating_stub_;
1460 bool root_array_available_;
1462 // Returns a register holding the smi value. The register MUST NOT be
1463 // modified. It may be the "smi 1 constant" register.
1464 Register GetSmiConstant(Smi* value);
1466 int64_t RootRegisterDelta(ExternalReference other);
1468 // Moves the smi value to the destination register.
1469 void LoadSmiConstant(Register dst, Smi* value);
1471 // This handle will be patched with the code object on installation.
1472 Handle<Object> code_object_;
1474 // Helper functions for generating invokes.
1475 void InvokePrologue(const ParameterCount& expected,
1476 const ParameterCount& actual,
1477 Handle<Code> code_constant,
1478 Register code_register,
1480 bool* definitely_mismatches,
1482 Label::Distance near_jump = Label::kFar,
1483 const CallWrapper& call_wrapper = NullCallWrapper());
1485 void EnterExitFramePrologue(bool save_rax);
1487 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1488 // accessible via StackSpaceOperand.
1489 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
1491 void LeaveExitFrameEpilogue(bool restore_context);
1493 // Allocation support helpers.
1494 // Loads the top of new-space into the result register.
1495 // Otherwise the address of the new-space top is loaded into scratch (if
1496 // scratch is valid), and the new-space top is loaded into result.
1497 void LoadAllocationTopHelper(Register result,
1499 AllocationFlags flags);
1501 void MakeSureDoubleAlignedHelper(Register result,
1504 AllocationFlags flags);
1506 // Update allocation top with value in result_end register.
1507 // If scratch is valid, it contains the address of the allocation top.
1508 void UpdateAllocationTopHelper(Register result_end,
1510 AllocationFlags flags);
1512 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1513 void InNewSpace(Register object,
1517 Label::Distance distance = Label::kFar);
1519 // Helper for finding the mark bits for an address. Afterwards, the
1520 // bitmap register points at the word with the mark bits and the mask
1521 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1523 inline void GetMarkBits(Register addr_reg,
1524 Register bitmap_reg,
1527 // Compute memory operands for safepoint stack slots.
1528 Operand SafepointRegisterSlot(Register reg);
1529 static int SafepointRegisterStackIndex(int reg_code) {
1530 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1533 // Needs access to SafepointRegisterStackIndex for compiled frame
1535 friend class StandardFrame;
1539 // The code patcher is used to patch (typically) small parts of code e.g. for
1540 // debugging and other types of instrumentation. When using the code patcher
1541 // the exact number of bytes specified must be emitted. Is not legal to emit
1542 // relocation information. If any of these constraints are violated it causes
1546 CodePatcher(byte* address, int size);
1549 // Macro assembler to emit code.
1550 MacroAssembler* masm() { return &masm_; }
1553 byte* address_; // The address of the code being patched.
1554 int size_; // Number of bytes of the expected patch size.
1555 MacroAssembler masm_; // Macro assembler used to generate the code.
1559 // -----------------------------------------------------------------------------
1560 // Static helper functions.
1562 // Generate an Operand for loading a field from an object.
1563 inline Operand FieldOperand(Register object, int offset) {
1564 return Operand(object, offset - kHeapObjectTag);
1568 // Generate an Operand for loading an indexed field from an object.
1569 inline Operand FieldOperand(Register object,
1573 return Operand(object, index, scale, offset - kHeapObjectTag);
1577 inline Operand ContextOperand(Register context, int index) {
1578 return Operand(context, Context::SlotOffset(index));
1582 inline Operand ContextOperand(Register context, Register index) {
1583 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1587 inline Operand GlobalObjectOperand() {
1588 return ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX);
1592 // Provides access to exit frame stack space (not GCed).
1593 inline Operand StackSpaceOperand(int index) {
1595 const int kShaddowSpace = 4;
1596 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1598 return Operand(rsp, index * kPointerSize);
1603 inline Operand StackOperandForReturnAddress(int32_t disp) {
1604 return Operand(rsp, disp);
1608 #ifdef GENERATED_CODE_COVERAGE
1609 extern void LogGeneratedCodeCoverage(const char* file_line);
1610 #define CODE_COVERAGE_STRINGIFY(x) #x
1611 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1612 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1613 #define ACCESS_MASM(masm) { \
1614 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1617 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1618 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1625 #define ACCESS_MASM(masm) masm->
1628 } } // namespace v8::internal
1630 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_