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 // Compare the object in a register to a value and jump if they are equal.
152 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal,
153 Label::Distance if_equal_distance = Label::kNear) {
154 CompareRoot(with, index);
155 j(equal, if_equal, if_equal_distance);
158 // Compare the object in a register to a value and jump if they are not equal.
159 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
161 Label::Distance if_not_equal_distance = Label::kNear) {
162 CompareRoot(with, index);
163 j(not_equal, if_not_equal, if_not_equal_distance);
166 // These functions do not arrange the registers in any particular order so
167 // they are not useful for calls that can cause a GC. The caller can
168 // exclude up to 3 registers that do not need to be saved and restored.
169 void PushCallerSaved(SaveFPRegsMode fp_mode,
170 Register exclusion1 = no_reg,
171 Register exclusion2 = no_reg,
172 Register exclusion3 = no_reg);
173 void PopCallerSaved(SaveFPRegsMode fp_mode,
174 Register exclusion1 = no_reg,
175 Register exclusion2 = no_reg,
176 Register exclusion3 = no_reg);
178 // ---------------------------------------------------------------------------
182 enum RememberedSetFinalAction {
187 // Record in the remembered set the fact that we have a pointer to new space
188 // at the address pointed to by the addr register. Only works if addr is not
190 void RememberedSetHelper(Register object, // Used for debug code.
193 SaveFPRegsMode save_fp,
194 RememberedSetFinalAction and_then);
196 void CheckPageFlag(Register object,
200 Label* condition_met,
201 Label::Distance condition_met_distance = Label::kFar);
203 // Check if object is in new space. Jumps if the object is not in new space.
204 // The register scratch can be object itself, but scratch will be clobbered.
205 void JumpIfNotInNewSpace(Register object,
208 Label::Distance distance = Label::kFar) {
209 InNewSpace(object, scratch, not_equal, branch, distance);
212 // Check if object is in new space. Jumps if the object is in new space.
213 // The register scratch can be object itself, but it will be clobbered.
214 void JumpIfInNewSpace(Register object,
217 Label::Distance distance = Label::kFar) {
218 InNewSpace(object, scratch, equal, branch, distance);
221 // Check if an object has the black incremental marking color. Also uses rcx!
222 void JumpIfBlack(Register object,
226 Label::Distance on_black_distance = Label::kFar);
228 // Detects conservatively whether an object is data-only, i.e. it does need to
229 // be scanned by the garbage collector.
230 void JumpIfDataObject(Register value,
232 Label* not_data_object,
233 Label::Distance not_data_object_distance);
235 // Checks the color of an object. If the object is already grey or black
236 // then we just fall through, since it is already live. If it is white and
237 // we can determine that it doesn't need to be scanned, then we just mark it
238 // black and fall through. For the rest we jump to the label so the
239 // incremental marker can fix its assumptions.
240 void EnsureNotWhite(Register object,
243 Label* object_is_white_and_not_data,
244 Label::Distance distance);
246 // Notify the garbage collector that we wrote a pointer into an object.
247 // |object| is the object being stored into, |value| is the object being
248 // stored. value and scratch registers are clobbered by the operation.
249 // The offset is the offset from the start of the object, not the offset from
250 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
251 void RecordWriteField(
256 SaveFPRegsMode save_fp,
257 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
258 SmiCheck smi_check = INLINE_SMI_CHECK,
259 PointersToHereCheck pointers_to_here_check_for_value =
260 kPointersToHereMaybeInteresting);
262 // As above, but the offset has the tag presubtracted. For use with
263 // Operand(reg, off).
264 void RecordWriteContextSlot(
269 SaveFPRegsMode save_fp,
270 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
271 SmiCheck smi_check = INLINE_SMI_CHECK,
272 PointersToHereCheck pointers_to_here_check_for_value =
273 kPointersToHereMaybeInteresting) {
274 RecordWriteField(context,
275 offset + kHeapObjectTag,
279 remembered_set_action,
281 pointers_to_here_check_for_value);
284 // Notify the garbage collector that we wrote a pointer into a fixed array.
285 // |array| is the array being stored into, |value| is the
286 // object being stored. |index| is the array index represented as a non-smi.
287 // All registers are clobbered by the operation RecordWriteArray
288 // filters out smis so it does not update the write barrier if the
290 void RecordWriteArray(
294 SaveFPRegsMode save_fp,
295 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
296 SmiCheck smi_check = INLINE_SMI_CHECK,
297 PointersToHereCheck pointers_to_here_check_for_value =
298 kPointersToHereMaybeInteresting);
300 void RecordWriteForMap(
304 SaveFPRegsMode save_fp);
306 // For page containing |object| mark region covering |address|
307 // dirty. |object| is the object being stored into, |value| is the
308 // object being stored. The address and value registers are clobbered by the
309 // operation. RecordWrite filters out smis so it does not update
310 // the write barrier if the value is a smi.
315 SaveFPRegsMode save_fp,
316 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
317 SmiCheck smi_check = INLINE_SMI_CHECK,
318 PointersToHereCheck pointers_to_here_check_for_value =
319 kPointersToHereMaybeInteresting);
321 // ---------------------------------------------------------------------------
326 // Generates function and stub prologue code.
328 void Prologue(bool code_pre_aging);
330 // Enter specific kind of exit frame; either in normal or
331 // debug mode. Expects the number of arguments in register rax and
332 // sets up the number of arguments in register rdi and the pointer
333 // to the first argument in register rsi.
335 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
336 // accessible via StackSpaceOperand.
337 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
339 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
340 // memory (not GCed) on the stack accessible via StackSpaceOperand.
341 void EnterApiExitFrame(int arg_stack_space);
343 // Leave the current exit frame. Expects/provides the return value in
344 // register rax:rdx (untouched) and the pointer to the first
345 // argument in register rsi.
346 void LeaveExitFrame(bool save_doubles = false);
348 // Leave the current exit frame. Expects/provides the return value in
349 // register rax (untouched).
350 void LeaveApiExitFrame(bool restore_context);
352 // Push and pop the registers that can hold pointers.
353 void PushSafepointRegisters() { Pushad(); }
354 void PopSafepointRegisters() { Popad(); }
355 // Store the value in register src in the safepoint register stack
356 // slot for register dst.
357 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
358 void StoreToSafepointRegisterSlot(Register dst, Register src);
359 void LoadFromSafepointRegisterSlot(Register dst, Register src);
361 void InitializeRootRegister() {
362 ExternalReference roots_array_start =
363 ExternalReference::roots_array_start(isolate());
364 Move(kRootRegister, roots_array_start);
365 addp(kRootRegister, Immediate(kRootRegisterBias));
368 // ---------------------------------------------------------------------------
369 // JavaScript invokes
371 // Invoke the JavaScript function code by either calling or jumping.
372 void InvokeCode(Register code,
373 const ParameterCount& expected,
374 const ParameterCount& actual,
376 const CallWrapper& call_wrapper);
378 // Invoke the JavaScript function in the given register. Changes the
379 // current context to the context in the function before invoking.
380 void InvokeFunction(Register function,
381 const ParameterCount& actual,
383 const CallWrapper& call_wrapper);
385 void InvokeFunction(Register function,
386 const ParameterCount& expected,
387 const ParameterCount& actual,
389 const CallWrapper& call_wrapper);
391 void InvokeFunction(Handle<JSFunction> function,
392 const ParameterCount& expected,
393 const ParameterCount& actual,
395 const CallWrapper& call_wrapper);
397 // Invoke specified builtin JavaScript function.
398 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
399 const CallWrapper& call_wrapper = NullCallWrapper());
401 // Store the function for the given builtin in the target register.
402 void GetBuiltinFunction(Register target, int native_context_index);
404 // Store the code object for the given builtin in the target register.
405 void GetBuiltinEntry(Register target, int native_context_index);
408 // ---------------------------------------------------------------------------
409 // Smi tagging, untagging and operations on tagged smis.
411 // Support for constant splitting.
412 bool IsUnsafeInt(const int32_t x);
413 void SafeMove(Register dst, Smi* src);
414 void SafePush(Smi* src);
416 // Conversions between tagged smi values and non-tagged integer values.
418 // Tag an integer value. The result must be known to be a valid smi value.
419 // Only uses the low 32 bits of the src register. Sets the N and Z flags
420 // based on the value of the resulting smi.
421 void Integer32ToSmi(Register dst, Register src);
423 // Stores an integer32 value into a memory field that already holds a smi.
424 void Integer32ToSmiField(const Operand& dst, Register src);
426 // Adds constant to src and tags the result as a smi.
427 // Result must be a valid smi.
428 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
430 // Convert smi to 32-bit integer. I.e., not sign extended into
431 // high 32 bits of destination.
432 void SmiToInteger32(Register dst, Register src);
433 void SmiToInteger32(Register dst, const Operand& src);
435 // Convert smi to 64-bit integer (sign extended if necessary).
436 void SmiToInteger64(Register dst, Register src);
437 void SmiToInteger64(Register dst, const Operand& src);
439 // Multiply a positive smi's integer value by a power of two.
440 // Provides result as 64-bit integer value.
441 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
445 // Divide a positive smi's integer value by a power of two.
446 // Provides result as 32-bit integer value.
447 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
451 // Perform the logical or of two smi values and return a smi value.
452 // If either argument is not a smi, jump to on_not_smis and retain
453 // the original values of source registers. The destination register
454 // may be changed if it's not one of the source registers.
455 void SmiOrIfSmis(Register dst,
459 Label::Distance near_jump = Label::kFar);
462 // Simple comparison of smis. Both sides must be known smis to use these,
463 // otherwise use Cmp.
464 void SmiCompare(Register smi1, Register smi2);
465 void SmiCompare(Register dst, Smi* src);
466 void SmiCompare(Register dst, const Operand& src);
467 void SmiCompare(const Operand& dst, Register src);
468 void SmiCompare(const Operand& dst, Smi* src);
469 // Compare the int32 in src register to the value of the smi stored at dst.
470 void SmiCompareInteger32(const Operand& dst, Register src);
471 // Sets sign and zero flags depending on value of smi in register.
472 void SmiTest(Register src);
474 // Functions performing a check on a known or potential smi. Returns
475 // a condition that is satisfied if the check is successful.
477 // Is the value a tagged smi.
478 Condition CheckSmi(Register src);
479 Condition CheckSmi(const Operand& src);
481 // Is the value a non-negative tagged smi.
482 Condition CheckNonNegativeSmi(Register src);
484 // Are both values tagged smis.
485 Condition CheckBothSmi(Register first, Register second);
487 // Are both values non-negative tagged smis.
488 Condition CheckBothNonNegativeSmi(Register first, Register second);
490 // Are either value a tagged smi.
491 Condition CheckEitherSmi(Register first,
493 Register scratch = kScratchRegister);
495 // Checks whether an 32-bit integer value is a valid for conversion
497 Condition CheckInteger32ValidSmiValue(Register src);
499 // Checks whether an 32-bit unsigned integer value is a valid for
500 // conversion to a smi.
501 Condition CheckUInteger32ValidSmiValue(Register src);
503 // Check whether src is a Smi, and set dst to zero if it is a smi,
504 // and to one if it isn't.
505 void CheckSmiToIndicator(Register dst, Register src);
506 void CheckSmiToIndicator(Register dst, const Operand& src);
508 // Test-and-jump functions. Typically combines a check function
509 // above with a conditional jump.
511 // Jump if the value can be represented by a smi.
512 void JumpIfValidSmiValue(Register src, Label* on_valid,
513 Label::Distance near_jump = Label::kFar);
515 // Jump if the value cannot be represented by a smi.
516 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
517 Label::Distance near_jump = Label::kFar);
519 // Jump if the unsigned integer value can be represented by a smi.
520 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
521 Label::Distance near_jump = Label::kFar);
523 // Jump if the unsigned integer value cannot be represented by a smi.
524 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
525 Label::Distance near_jump = Label::kFar);
527 // Jump to label if the value is a tagged smi.
528 void JumpIfSmi(Register src,
530 Label::Distance near_jump = Label::kFar);
532 // Jump to label if the value is not a tagged smi.
533 void JumpIfNotSmi(Register src,
535 Label::Distance near_jump = Label::kFar);
537 // Jump to label if the value is not a non-negative tagged smi.
538 void JumpUnlessNonNegativeSmi(Register src,
540 Label::Distance near_jump = Label::kFar);
542 // Jump to label if the value, which must be a tagged smi, has value equal
544 void JumpIfSmiEqualsConstant(Register src,
547 Label::Distance near_jump = Label::kFar);
549 // Jump if either or both register are not smi values.
550 void JumpIfNotBothSmi(Register src1,
552 Label* on_not_both_smi,
553 Label::Distance near_jump = Label::kFar);
555 // Jump if either or both register are not non-negative smi values.
556 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
557 Label* on_not_both_smi,
558 Label::Distance near_jump = Label::kFar);
560 // Operations on tagged smi values.
562 // Smis represent a subset of integers. The subset is always equivalent to
563 // a two's complement interpretation of a fixed number of bits.
565 // Add an integer constant to a tagged smi, giving a tagged smi as result.
566 // No overflow testing on the result is done.
567 void SmiAddConstant(Register dst, Register src, Smi* constant);
569 // Add an integer constant to a tagged smi, giving a tagged smi as result.
570 // No overflow testing on the result is done.
571 void SmiAddConstant(const Operand& dst, Smi* constant);
573 // Add an integer constant to a tagged smi, giving a tagged smi as result,
574 // or jumping to a label if the result cannot be represented by a smi.
575 void SmiAddConstant(Register dst, Register src, Smi* constant,
576 SmiOperationConstraints constraints, Label* bailout_label,
577 Label::Distance near_jump = Label::kFar);
579 // Subtract an integer constant from a tagged smi, giving a tagged smi as
580 // result. No testing on the result is done. Sets the N and Z flags
581 // based on the value of the resulting integer.
582 void SmiSubConstant(Register dst, Register src, Smi* constant);
584 // Subtract an integer constant from a tagged smi, giving a tagged smi as
585 // result, or jumping to a label if the result cannot be represented by a smi.
586 void SmiSubConstant(Register dst, Register src, Smi* constant,
587 SmiOperationConstraints constraints, Label* bailout_label,
588 Label::Distance near_jump = Label::kFar);
590 // Negating a smi can give a negative zero or too large positive value.
591 // NOTICE: This operation jumps on success, not failure!
592 void SmiNeg(Register dst,
594 Label* on_smi_result,
595 Label::Distance near_jump = Label::kFar);
597 // Adds smi values and return the result as a smi.
598 // If dst is src1, then src1 will be destroyed if the operation is
599 // successful, otherwise kept intact.
600 void SmiAdd(Register dst,
603 Label* on_not_smi_result,
604 Label::Distance near_jump = Label::kFar);
605 void SmiAdd(Register dst,
608 Label* on_not_smi_result,
609 Label::Distance near_jump = Label::kFar);
611 void SmiAdd(Register dst,
615 // Subtracts smi values and return the result as a smi.
616 // If dst is src1, then src1 will be destroyed if the operation is
617 // successful, otherwise kept intact.
618 void SmiSub(Register dst,
621 Label* on_not_smi_result,
622 Label::Distance near_jump = Label::kFar);
623 void SmiSub(Register dst,
626 Label* on_not_smi_result,
627 Label::Distance near_jump = Label::kFar);
629 void SmiSub(Register dst,
633 void SmiSub(Register dst,
635 const Operand& src2);
637 // Multiplies smi values and return the result as a smi,
639 // If dst is src1, then src1 will be destroyed, even if
640 // the operation is unsuccessful.
641 void SmiMul(Register dst,
644 Label* on_not_smi_result,
645 Label::Distance near_jump = Label::kFar);
647 // Divides one smi by another and returns the quotient.
648 // Clobbers rax and rdx registers.
649 void SmiDiv(Register dst,
652 Label* on_not_smi_result,
653 Label::Distance near_jump = Label::kFar);
655 // Divides one smi by another and returns the remainder.
656 // Clobbers rax and rdx registers.
657 void SmiMod(Register dst,
660 Label* on_not_smi_result,
661 Label::Distance near_jump = Label::kFar);
663 // Bitwise operations.
664 void SmiNot(Register dst, Register src);
665 void SmiAnd(Register dst, Register src1, Register src2);
666 void SmiOr(Register dst, Register src1, Register src2);
667 void SmiXor(Register dst, Register src1, Register src2);
668 void SmiAndConstant(Register dst, Register src1, Smi* constant);
669 void SmiOrConstant(Register dst, Register src1, Smi* constant);
670 void SmiXorConstant(Register dst, Register src1, Smi* constant);
672 void SmiShiftLeftConstant(Register dst,
675 Label* on_not_smi_result = NULL,
676 Label::Distance near_jump = Label::kFar);
677 void SmiShiftLogicalRightConstant(Register dst,
680 Label* on_not_smi_result,
681 Label::Distance near_jump = Label::kFar);
682 void SmiShiftArithmeticRightConstant(Register dst,
686 // Shifts a smi value to the left, and returns the result if that is a smi.
687 // Uses and clobbers rcx, so dst may not be rcx.
688 void SmiShiftLeft(Register dst,
691 Label* on_not_smi_result = NULL,
692 Label::Distance near_jump = Label::kFar);
693 // Shifts a smi value to the right, shifting in zero bits at the top, and
694 // returns the unsigned intepretation of the result if that is a smi.
695 // Uses and clobbers rcx, so dst may not be rcx.
696 void SmiShiftLogicalRight(Register dst,
699 Label* on_not_smi_result,
700 Label::Distance near_jump = Label::kFar);
701 // Shifts a smi value to the right, sign extending the top, and
702 // returns the signed intepretation of the result. That will always
703 // be a valid smi value, since it's numerically smaller than the
705 // Uses and clobbers rcx, so dst may not be rcx.
706 void SmiShiftArithmeticRight(Register dst,
710 // Specialized operations
712 // Select the non-smi register of two registers where exactly one is a
713 // smi. If neither are smis, jump to the failure label.
714 void SelectNonSmi(Register dst,
718 Label::Distance near_jump = Label::kFar);
720 // Converts, if necessary, a smi to a combination of number and
721 // multiplier to be used as a scaled index.
722 // The src register contains a *positive* smi value. The shift is the
723 // power of two to multiply the index value by (e.g.
724 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
725 // The returned index register may be either src or dst, depending
726 // on what is most efficient. If src and dst are different registers,
727 // src is always unchanged.
728 SmiIndex SmiToIndex(Register dst, Register src, int shift);
730 // Converts a positive smi to a negative index.
731 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
733 // Add the value of a smi in memory to an int32 register.
734 // Sets flags as a normal add.
735 void AddSmiField(Register dst, const Operand& src);
737 // Basic Smi operations.
738 void Move(Register dst, Smi* source) {
739 LoadSmiConstant(dst, source);
742 void Move(const Operand& dst, Smi* source) {
743 Register constant = GetSmiConstant(source);
749 // Save away a raw integer with pointer size on the stack as two integers
750 // masquerading as smis so that the garbage collector skips visiting them.
751 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
752 // Reconstruct a raw integer with pointer size from two integers masquerading
753 // as smis on the top of stack.
754 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
756 void Test(const Operand& dst, Smi* source);
759 // ---------------------------------------------------------------------------
762 // Generate code to do a lookup in the number string cache. If the number in
763 // the register object is found in the cache the generated code falls through
764 // with the result in the result register. The object and the result register
765 // can be the same. If the number is not found in the cache the code jumps to
766 // the label not_found with only the content of register object unchanged.
767 void LookupNumberStringCache(Register object,
773 // If object is a string, its map is loaded into object_map.
774 void JumpIfNotString(Register object,
777 Label::Distance near_jump = Label::kFar);
780 void JumpIfNotBothSequentialOneByteStrings(
781 Register first_object, Register second_object, Register scratch1,
782 Register scratch2, Label* on_not_both_flat_one_byte,
783 Label::Distance near_jump = Label::kFar);
785 // Check whether the instance type represents a flat one-byte string. Jump
786 // to the label if not. If the instance type can be scratched specify same
787 // register for both instance type and scratch.
788 void JumpIfInstanceTypeIsNotSequentialOneByte(
789 Register instance_type, Register scratch,
790 Label* on_not_flat_one_byte_string,
791 Label::Distance near_jump = Label::kFar);
793 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
794 Register first_object_instance_type, Register second_object_instance_type,
795 Register scratch1, Register scratch2, Label* on_fail,
796 Label::Distance near_jump = Label::kFar);
798 void EmitSeqStringSetCharCheck(Register string,
801 uint32_t encoding_mask);
803 // Checks if the given register or operand is a unique name
804 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
805 Label::Distance distance = Label::kFar);
806 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
807 Label::Distance distance = Label::kFar);
809 // ---------------------------------------------------------------------------
810 // Macro instructions.
812 // Load/store with specific representation.
813 void Load(Register dst, const Operand& src, Representation r);
814 void Store(const Operand& dst, Register src, Representation r);
816 // Load a register with a long value as efficiently as possible.
817 void Set(Register dst, int64_t x);
818 void Set(const Operand& dst, intptr_t x);
820 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
821 // hinders register renaming and makes dependence chains longer. So we use
822 // xorps to clear the dst register before cvtsi2sd to solve this issue.
823 void Cvtlsi2sd(XMMRegister dst, Register src);
824 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
826 // Move if the registers are not identical.
827 void Move(Register target, Register source);
829 // TestBit and Load SharedFunctionInfo special field.
830 void TestBitSharedFunctionInfoSpecialField(Register base,
833 void LoadSharedFunctionInfoSpecialField(Register dst,
838 void Move(Register dst, Handle<Object> source);
839 void Move(const Operand& dst, Handle<Object> source);
840 void Cmp(Register dst, Handle<Object> source);
841 void Cmp(const Operand& dst, Handle<Object> source);
842 void Cmp(Register dst, Smi* src);
843 void Cmp(const Operand& dst, Smi* src);
844 void Push(Handle<Object> source);
846 // Load a heap object and handle the case of new-space objects by
847 // indirecting via a global cell.
848 void MoveHeapObject(Register result, Handle<Object> object);
850 // Load a global cell into a register.
851 void LoadGlobalCell(Register dst, Handle<Cell> cell);
853 // Compare the given value and the value of weak cell.
854 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
856 void GetWeakValue(Register value, Handle<WeakCell> cell);
858 // Load the value of the weak cell in the value register. Branch to the given
859 // miss label if the weak cell was cleared.
860 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
862 // Emit code to discard a non-negative number of pointer-sized elements
863 // from the stack, clobbering only the rsp register.
864 void Drop(int stack_elements);
865 // Emit code to discard a positive number of pointer-sized elements
866 // from the stack under the return address which remains on the top,
867 // clobbering the rsp register.
868 void DropUnderReturnAddress(int stack_elements,
869 Register scratch = kScratchRegister);
871 void Call(Label* target) { call(target); }
872 void Push(Register src);
873 void Push(const Operand& src);
874 void PushQuad(const Operand& src);
875 void Push(Immediate value);
876 void PushImm32(int32_t imm32);
877 void Pop(Register dst);
878 void Pop(const Operand& dst);
879 void PopQuad(const Operand& dst);
880 void PushReturnAddressFrom(Register src) { pushq(src); }
881 void PopReturnAddressTo(Register dst) { popq(dst); }
882 void Move(Register dst, ExternalReference ext) {
883 movp(dst, reinterpret_cast<void*>(ext.address()),
884 RelocInfo::EXTERNAL_REFERENCE);
887 // Loads a pointer into a register with a relocation mode.
888 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
889 // This method must not be used with heap object references. The stored
890 // address is not GC safe. Use the handle version instead.
891 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
892 movp(dst, ptr, rmode);
895 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
896 AllowDeferredHandleDereference using_raw_address;
897 DCHECK(!RelocInfo::IsNone(rmode));
898 DCHECK(value->IsHeapObject());
899 DCHECK(!isolate()->heap()->InNewSpace(*value));
900 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
903 void Move(XMMRegister dst, uint32_t src);
904 void Move(XMMRegister dst, uint64_t src);
905 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
906 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
909 void Jump(Address destination, RelocInfo::Mode rmode);
910 void Jump(ExternalReference ext);
911 void Jump(const Operand& op);
912 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
914 void Call(Address destination, RelocInfo::Mode rmode);
915 void Call(ExternalReference ext);
916 void Call(const Operand& op);
917 void Call(Handle<Code> code_object,
918 RelocInfo::Mode rmode,
919 TypeFeedbackId ast_id = TypeFeedbackId::None());
921 // The size of the code generated for different call instructions.
922 int CallSize(Address destination) {
923 return kCallSequenceLength;
925 int CallSize(ExternalReference ext);
926 int CallSize(Handle<Code> code_object) {
927 // Code calls use 32-bit relative addressing.
928 return kShortCallInstructionLength;
930 int CallSize(Register target) {
931 // Opcode: REX_opt FF /2 m64
932 return (target.high_bit() != 0) ? 3 : 2;
934 int CallSize(const Operand& target) {
935 // Opcode: REX_opt FF /2 m64
936 return (target.requires_rex() ? 2 : 1) + target.operand_size();
939 // Emit call to the code we are currently generating.
941 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
942 Call(self, RelocInfo::CODE_TARGET);
945 // Non-SSE2 instructions.
946 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
947 void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
948 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
950 void Lzcntl(Register dst, Register src);
951 void Lzcntl(Register dst, const Operand& src);
953 // Non-x64 instructions.
954 // Push/pop all general purpose registers.
955 // Does not push rsp/rbp nor any of the assembler's special purpose registers
956 // (kScratchRegister, kRootRegister).
959 // Sets the stack as after performing Popad, without actually loading the
963 // Compare object type for heap object.
964 // Always use unsigned comparisons: above and below, not less and greater.
965 // Incoming register is heap_object and outgoing register is map.
966 // They may be the same register, and may be kScratchRegister.
967 void CmpObjectType(Register heap_object, InstanceType type, Register map);
969 // Compare instance type for map.
970 // Always use unsigned comparisons: above and below, not less and greater.
971 void CmpInstanceType(Register map, InstanceType type);
973 // Check if a map for a JSObject indicates that the object has fast elements.
974 // Jump to the specified label if it does not.
975 void CheckFastElements(Register map,
977 Label::Distance distance = Label::kFar);
979 // Check if a map for a JSObject indicates that the object can have both smi
980 // and HeapObject elements. Jump to the specified label if it does not.
981 void CheckFastObjectElements(Register map,
983 Label::Distance distance = Label::kFar);
985 // Check if a map for a JSObject indicates that the object has fast smi only
986 // elements. Jump to the specified label if it does not.
987 void CheckFastSmiElements(Register map,
989 Label::Distance distance = Label::kFar);
991 // Check to see if maybe_number can be stored as a double in
992 // FastDoubleElements. If it can, store it at the index specified by index in
993 // the FastDoubleElements array elements, otherwise jump to fail. Note that
994 // index must not be smi-tagged.
995 void StoreNumberToDoubleElements(Register maybe_number,
998 XMMRegister xmm_scratch,
1000 int elements_offset = 0);
1002 // Compare an object's map with the specified map.
1003 void CompareMap(Register obj, Handle<Map> map);
1005 // Check if the map of an object is equal to a specified map and branch to
1006 // label if not. Skip the smi check if not required (object is known to be a
1007 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1008 // against maps that are ElementsKind transition maps of the specified map.
1009 void CheckMap(Register obj,
1012 SmiCheckType smi_check_type);
1014 // Check if the map of an object is equal to a specified weak map and branch
1015 // to a specified target if equal. Skip the smi check if not required
1016 // (object is known to be a heap object)
1017 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1018 Handle<WeakCell> cell, Handle<Code> success,
1019 SmiCheckType smi_check_type);
1021 // Check if the object in register heap_object is a string. Afterwards the
1022 // register map contains the object map and the register instance_type
1023 // contains the instance_type. The registers map and instance_type can be the
1024 // same in which case it contains the instance type afterwards. Either of the
1025 // registers map and instance_type can be the same as heap_object.
1026 Condition IsObjectStringType(Register heap_object,
1028 Register instance_type);
1030 // Check if the object in register heap_object is a name. Afterwards the
1031 // register map contains the object map and the register instance_type
1032 // contains the instance_type. The registers map and instance_type can be the
1033 // same in which case it contains the instance type afterwards. Either of the
1034 // registers map and instance_type can be the same as heap_object.
1035 Condition IsObjectNameType(Register heap_object,
1037 Register instance_type);
1039 // FCmp compares and pops the two values on top of the FPU stack.
1040 // The flag results are similar to integer cmp, but requires unsigned
1041 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1044 void ClampUint8(Register reg);
1046 void ClampDoubleToUint8(XMMRegister input_reg,
1047 XMMRegister temp_xmm_reg,
1048 Register result_reg);
1050 void SlowTruncateToI(Register result_reg, Register input_reg,
1051 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1053 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1054 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1056 void DoubleToI(Register result_reg, XMMRegister input_reg,
1057 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1058 Label* lost_precision, Label* is_nan, Label* minus_zero,
1059 Label::Distance dst = Label::kFar);
1061 void LoadUint32(XMMRegister dst, Register src);
1063 void LoadInstanceDescriptors(Register map, Register descriptors);
1064 void EnumLength(Register dst, Register map);
1065 void NumberOfOwnDescriptors(Register dst, Register map);
1066 void LoadAccessor(Register dst, Register holder, int accessor_index,
1067 AccessorComponent accessor);
1069 template<typename Field>
1070 void DecodeField(Register reg) {
1071 static const int shift = Field::kShift;
1072 static const int mask = Field::kMask >> Field::kShift;
1074 shrp(reg, Immediate(shift));
1076 andp(reg, Immediate(mask));
1079 template<typename Field>
1080 void DecodeFieldToSmi(Register reg) {
1081 if (SmiValuesAre32Bits()) {
1082 andp(reg, Immediate(Field::kMask));
1083 shlp(reg, Immediate(kSmiShift - Field::kShift));
1085 static const int shift = Field::kShift;
1086 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1087 DCHECK(SmiValuesAre31Bits());
1088 DCHECK(kSmiShift == kSmiTagSize);
1089 DCHECK((mask & 0x80000000u) == 0);
1090 if (shift < kSmiShift) {
1091 shlp(reg, Immediate(kSmiShift - shift));
1092 } else if (shift > kSmiShift) {
1093 sarp(reg, Immediate(shift - kSmiShift));
1095 andp(reg, Immediate(mask));
1099 // Abort execution if argument is not a number, enabled via --debug-code.
1100 void AssertNumber(Register object);
1102 // Abort execution if argument is a smi, enabled via --debug-code.
1103 void AssertNotSmi(Register object);
1105 // Abort execution if argument is not a smi, enabled via --debug-code.
1106 void AssertSmi(Register object);
1107 void AssertSmi(const Operand& object);
1109 // Abort execution if a 64 bit register containing a 32 bit payload does not
1110 // have zeros in the top 32 bits, enabled via --debug-code.
1111 void AssertZeroExtended(Register reg);
1113 // Abort execution if argument is not a string, enabled via --debug-code.
1114 void AssertString(Register object);
1116 // Abort execution if argument is not a name, enabled via --debug-code.
1117 void AssertName(Register object);
1119 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1120 void AssertFunction(Register object);
1122 // Abort execution if argument is not undefined or an AllocationSite, enabled
1123 // via --debug-code.
1124 void AssertUndefinedOrAllocationSite(Register object);
1126 // Abort execution if argument is not the root value with the given index,
1127 // enabled via --debug-code.
1128 void AssertRootValue(Register src,
1129 Heap::RootListIndex root_value_index,
1130 BailoutReason reason);
1132 // ---------------------------------------------------------------------------
1133 // Exception handling
1135 // Push a new stack handler and link it into stack handler chain.
1136 void PushStackHandler();
1138 // Unlink the stack handler on top of the stack from the stack handler chain.
1139 void PopStackHandler();
1141 // ---------------------------------------------------------------------------
1142 // Inline caching support
1144 // Generate code for checking access rights - used for security checks
1145 // on access to global objects across environments. The holder register
1146 // is left untouched, but the scratch register and kScratchRegister,
1147 // which must be different, are clobbered.
1148 void CheckAccessGlobalProxy(Register holder_reg,
1152 void GetNumberHash(Register r0, Register scratch);
1154 void LoadFromNumberDictionary(Label* miss,
1163 // ---------------------------------------------------------------------------
1164 // Allocation support
1166 // Allocate an object in new space or old space. If the given space
1167 // is exhausted control continues at the gc_required label. The allocated
1168 // object is returned in result and end of the new object is returned in
1169 // result_end. The register scratch can be passed as no_reg in which case
1170 // an additional object reference will be added to the reloc info. The
1171 // returned pointers in result and result_end have not yet been tagged as
1172 // heap objects. If result_contains_top_on_entry is true the content of
1173 // result is known to be the allocation top on entry (could be result_end
1174 // from a previous call). If result_contains_top_on_entry is true scratch
1175 // should be no_reg as it is never used.
1176 void Allocate(int object_size,
1178 Register result_end,
1181 AllocationFlags flags);
1183 void Allocate(int header_size,
1184 ScaleFactor element_size,
1185 Register element_count,
1187 Register result_end,
1190 AllocationFlags flags);
1192 void Allocate(Register object_size,
1194 Register result_end,
1197 AllocationFlags flags);
1199 // Allocate a heap number in new space with undefined value. Returns
1200 // tagged pointer in result register, or jumps to gc_required if new
1202 void AllocateHeapNumber(Register result,
1205 MutableMode mode = IMMUTABLE);
1207 // Allocate a sequential string. All the header fields of the string object
1209 void AllocateTwoByteString(Register result,
1214 Label* gc_required);
1215 void AllocateOneByteString(Register result, Register length,
1216 Register scratch1, Register scratch2,
1217 Register scratch3, Label* gc_required);
1219 // Allocate a raw cons string object. Only the map field of the result is
1221 void AllocateTwoByteConsString(Register result,
1224 Label* gc_required);
1225 void AllocateOneByteConsString(Register result, Register scratch1,
1226 Register scratch2, Label* gc_required);
1228 // Allocate a raw sliced string object. Only the map field of the result is
1230 void AllocateTwoByteSlicedString(Register result,
1233 Label* gc_required);
1234 void AllocateOneByteSlicedString(Register result, Register scratch1,
1235 Register scratch2, Label* gc_required);
1237 // ---------------------------------------------------------------------------
1238 // Support functions.
1240 // Check if result is zero and op is negative.
1241 void NegativeZeroTest(Register result, Register op, Label* then_label);
1243 // Check if result is zero and op is negative in code using jump targets.
1244 void NegativeZeroTest(CodeGenerator* cgen,
1247 JumpTarget* then_target);
1249 // Check if result is zero and any of op1 and op2 are negative.
1250 // Register scratch is destroyed, and it must be different from op2.
1251 void NegativeZeroTest(Register result, Register op1, Register op2,
1252 Register scratch, Label* then_label);
1254 // Machine code version of Map::GetConstructor().
1255 // |temp| holds |result|'s map when done.
1256 void GetMapConstructor(Register result, Register map, Register temp);
1258 // Try to get function prototype of a function and puts the value in
1259 // the result register. Checks that the function really is a
1260 // function and jumps to the miss label if the fast checks fail. The
1261 // function register will be untouched; the other register may be
1263 void TryGetFunctionPrototype(Register function, Register result, Label* miss);
1265 // Picks out an array index from the hash field.
1267 // hash - holds the index's hash. Clobbered.
1268 // index - holds the overwritten index on exit.
1269 void IndexFromHash(Register hash, Register index);
1271 // Find the function context up the context chain.
1272 void LoadContext(Register dst, int context_chain_length);
1274 // Load the global proxy from the current context.
1275 void LoadGlobalProxy(Register dst);
1277 // Conditionally load the cached Array transitioned map of type
1278 // transitioned_kind from the native context if the map in register
1279 // map_in_out is the cached Array map in the native context of
1281 void LoadTransitionedArrayMapConditional(
1282 ElementsKind expected_kind,
1283 ElementsKind transitioned_kind,
1284 Register map_in_out,
1286 Label* no_map_match);
1288 // Load the global function with the given index.
1289 void LoadGlobalFunction(int index, Register function);
1291 // Load the initial map from the global function. The registers
1292 // function and map can be the same.
1293 void LoadGlobalFunctionInitialMap(Register function, Register map);
1295 // ---------------------------------------------------------------------------
1298 // Call a code stub.
1299 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1301 // Tail call a code stub (jump).
1302 void TailCallStub(CodeStub* stub);
1304 // Return from a code stub after popping its arguments.
1305 void StubReturn(int argc);
1307 // Call a runtime routine.
1308 void CallRuntime(const Runtime::Function* f,
1310 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1312 // Call a runtime function and save the value of XMM registers.
1313 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1314 const Runtime::Function* function = Runtime::FunctionForId(id);
1315 CallRuntime(function, function->nargs, kSaveFPRegs);
1318 // Convenience function: Same as above, but takes the fid instead.
1319 void CallRuntime(Runtime::FunctionId id,
1321 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1322 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1325 // Convenience function: call an external reference.
1326 void CallExternalReference(const ExternalReference& ext,
1329 // Tail call of a runtime routine (jump).
1330 // Like JumpToExternalReference, but also takes care of passing the number
1332 void TailCallExternalReference(const ExternalReference& ext,
1336 // Convenience function: tail call a runtime routine (jump).
1337 void TailCallRuntime(Runtime::FunctionId fid,
1341 // Jump to a runtime routine.
1342 void JumpToExternalReference(const ExternalReference& ext, int result_size);
1344 // Before calling a C-function from generated code, align arguments on stack.
1345 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
1346 // etc., not pushed. The argument count assumes all arguments are word sized.
1347 // The number of slots reserved for arguments depends on platform. On Windows
1348 // stack slots are reserved for the arguments passed in registers. On other
1349 // platforms stack slots are only reserved for the arguments actually passed
1351 void PrepareCallCFunction(int num_arguments);
1353 // Calls a C function and cleans up the space for arguments allocated
1354 // by PrepareCallCFunction. The called function is not allowed to trigger a
1355 // garbage collection, since that might move the code and invalidate the
1356 // return address (unless this is somehow accounted for by the called
1358 void CallCFunction(ExternalReference function, int num_arguments);
1359 void CallCFunction(Register function, int num_arguments);
1361 // Calculate the number of stack slots to reserve for arguments when calling a
1363 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
1365 // ---------------------------------------------------------------------------
1370 // Return and drop arguments from stack, where the number of arguments
1371 // may be bigger than 2^16 - 1. Requires a scratch register.
1372 void Ret(int bytes_dropped, Register scratch);
1374 Handle<Object> CodeObject() {
1375 DCHECK(!code_object_.is_null());
1376 return code_object_;
1379 // Copy length bytes from source to destination.
1380 // Uses scratch register internally (if you have a low-eight register
1381 // free, do use it, otherwise kScratchRegister will be used).
1382 // The min_length is a minimum limit on the value that length will have.
1383 // The algorithm has some special cases that might be omitted if the string
1384 // is known to always be long.
1385 void CopyBytes(Register destination,
1389 Register scratch = kScratchRegister);
1391 // Initialize fields with filler values. Fields starting at |start_offset|
1392 // not including end_offset are overwritten with the value in |filler|. At
1393 // the end the loop, |start_offset| takes the value of |end_offset|.
1394 void InitializeFieldsWithFiller(Register start_offset,
1395 Register end_offset,
1399 // Emit code for a truncating division by a constant. The dividend register is
1400 // unchanged, the result is in rdx, and rax gets clobbered.
1401 void TruncatingDiv(Register dividend, int32_t divisor);
1403 // ---------------------------------------------------------------------------
1404 // StatsCounter support
1406 void SetCounter(StatsCounter* counter, int value);
1407 void IncrementCounter(StatsCounter* counter, int value);
1408 void DecrementCounter(StatsCounter* counter, int value);
1411 // ---------------------------------------------------------------------------
1414 // Calls Abort(msg) if the condition cc is not satisfied.
1415 // Use --debug_code to enable.
1416 void Assert(Condition cc, BailoutReason reason);
1418 void AssertFastElements(Register elements);
1420 // Like Assert(), but always enabled.
1421 void Check(Condition cc, BailoutReason reason);
1423 // Print a message to stdout and abort execution.
1424 void Abort(BailoutReason msg);
1426 // Check that the stack is aligned.
1427 void CheckStackAlignment();
1429 // Verify restrictions about code generated in stubs.
1430 void set_generating_stub(bool value) { generating_stub_ = value; }
1431 bool generating_stub() { return generating_stub_; }
1432 void set_has_frame(bool value) { has_frame_ = value; }
1433 bool has_frame() { return has_frame_; }
1434 inline bool AllowThisStubCall(CodeStub* stub);
1436 static int SafepointRegisterStackIndex(Register reg) {
1437 return SafepointRegisterStackIndex(reg.code());
1440 // Activation support.
1441 void EnterFrame(StackFrame::Type type);
1442 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1443 void LeaveFrame(StackFrame::Type type);
1445 // Expects object in rax and returns map with validated enum cache
1446 // in rax. Assumes that any other register can be used as a scratch.
1447 void CheckEnumCache(Register null_value,
1448 Label* call_runtime);
1450 // AllocationMemento support. Arrays may have an associated
1451 // AllocationMemento object that can be checked for in order to pretransition
1453 // On entry, receiver_reg should point to the array object.
1454 // scratch_reg gets clobbered.
1455 // If allocation info is present, condition flags are set to equal.
1456 void TestJSArrayForAllocationMemento(Register receiver_reg,
1457 Register scratch_reg,
1458 Label* no_memento_found);
1460 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1461 Register scratch_reg,
1462 Label* memento_found) {
1463 Label no_memento_found;
1464 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1466 j(equal, memento_found);
1467 bind(&no_memento_found);
1470 // Jumps to found label if a prototype map has dictionary elements.
1471 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1472 Register scratch1, Label* found);
1475 // Order general registers are pushed by Pushad.
1476 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
1477 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
1478 static const int kNumSafepointSavedRegisters = 12;
1479 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1481 bool generating_stub_;
1483 bool root_array_available_;
1485 // Returns a register holding the smi value. The register MUST NOT be
1486 // modified. It may be the "smi 1 constant" register.
1487 Register GetSmiConstant(Smi* value);
1489 int64_t RootRegisterDelta(ExternalReference other);
1491 // Moves the smi value to the destination register.
1492 void LoadSmiConstant(Register dst, Smi* value);
1494 // This handle will be patched with the code object on installation.
1495 Handle<Object> code_object_;
1497 // Helper functions for generating invokes.
1498 void InvokePrologue(const ParameterCount& expected,
1499 const ParameterCount& actual,
1500 Handle<Code> code_constant,
1501 Register code_register,
1503 bool* definitely_mismatches,
1505 Label::Distance near_jump = Label::kFar,
1506 const CallWrapper& call_wrapper = NullCallWrapper());
1508 void EnterExitFramePrologue(bool save_rax);
1510 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1511 // accessible via StackSpaceOperand.
1512 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
1514 void LeaveExitFrameEpilogue(bool restore_context);
1516 // Allocation support helpers.
1517 // Loads the top of new-space into the result register.
1518 // Otherwise the address of the new-space top is loaded into scratch (if
1519 // scratch is valid), and the new-space top is loaded into result.
1520 void LoadAllocationTopHelper(Register result,
1522 AllocationFlags flags);
1524 void MakeSureDoubleAlignedHelper(Register result,
1527 AllocationFlags flags);
1529 // Update allocation top with value in result_end register.
1530 // If scratch is valid, it contains the address of the allocation top.
1531 void UpdateAllocationTopHelper(Register result_end,
1533 AllocationFlags flags);
1535 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1536 void InNewSpace(Register object,
1540 Label::Distance distance = Label::kFar);
1542 // Helper for finding the mark bits for an address. Afterwards, the
1543 // bitmap register points at the word with the mark bits and the mask
1544 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1546 inline void GetMarkBits(Register addr_reg,
1547 Register bitmap_reg,
1550 // Compute memory operands for safepoint stack slots.
1551 Operand SafepointRegisterSlot(Register reg);
1552 static int SafepointRegisterStackIndex(int reg_code) {
1553 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1556 // Needs access to SafepointRegisterStackIndex for compiled frame
1558 friend class StandardFrame;
1562 // The code patcher is used to patch (typically) small parts of code e.g. for
1563 // debugging and other types of instrumentation. When using the code patcher
1564 // the exact number of bytes specified must be emitted. Is not legal to emit
1565 // relocation information. If any of these constraints are violated it causes
1569 CodePatcher(byte* address, int size);
1572 // Macro assembler to emit code.
1573 MacroAssembler* masm() { return &masm_; }
1576 byte* address_; // The address of the code being patched.
1577 int size_; // Number of bytes of the expected patch size.
1578 MacroAssembler masm_; // Macro assembler used to generate the code.
1582 // -----------------------------------------------------------------------------
1583 // Static helper functions.
1585 // Generate an Operand for loading a field from an object.
1586 inline Operand FieldOperand(Register object, int offset) {
1587 return Operand(object, offset - kHeapObjectTag);
1591 // Generate an Operand for loading an indexed field from an object.
1592 inline Operand FieldOperand(Register object,
1596 return Operand(object, index, scale, offset - kHeapObjectTag);
1600 inline Operand ContextOperand(Register context, int index) {
1601 return Operand(context, Context::SlotOffset(index));
1605 inline Operand ContextOperand(Register context, Register index) {
1606 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1610 inline Operand GlobalObjectOperand() {
1611 return ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX);
1615 // Provides access to exit frame stack space (not GCed).
1616 inline Operand StackSpaceOperand(int index) {
1618 const int kShaddowSpace = 4;
1619 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1621 return Operand(rsp, index * kPointerSize);
1626 inline Operand StackOperandForReturnAddress(int32_t disp) {
1627 return Operand(rsp, disp);
1631 #ifdef GENERATED_CODE_COVERAGE
1632 extern void LogGeneratedCodeCoverage(const char* file_line);
1633 #define CODE_COVERAGE_STRINGIFY(x) #x
1634 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1635 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1636 #define ACCESS_MASM(masm) { \
1637 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1640 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1641 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1648 #define ACCESS_MASM(masm) masm->
1651 } } // namespace v8::internal
1653 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_