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/frames.h"
11 #include "src/globals.h"
16 // Default scratch register used by MacroAssembler (and other code that needs
17 // a spare register). The register isn't callee save, and not used by the
18 // function calling convention.
19 const Register kScratchRegister = { 10 }; // r10.
20 const Register kSmiConstantRegister = { 12 }; // r12 (callee save).
21 const Register kRootRegister = { 13 }; // r13 (callee save).
22 // Value of smi in kSmiConstantRegister.
23 const int kSmiConstantRegisterValue = 1;
24 // Actual value of root register is offset from the root array's start
25 // to take advantage of negitive 8-bit displacement values.
26 const int kRootRegisterBias = 128;
28 // Convenience for platform-independent signatures.
29 typedef Operand MemOperand;
31 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
32 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
33 enum PointersToHereCheck {
34 kPointersToHereMaybeInteresting,
35 kPointersToHereAreAlwaysInteresting
38 enum SmiOperationConstraint {
39 PRESERVE_SOURCE_REGISTER,
40 BAILOUT_ON_NO_OVERFLOW,
45 STATIC_ASSERT(NUMBER_OF_CONSTRAINTS <= 8);
47 class SmiOperationExecutionMode : public EnumSet<SmiOperationConstraint, byte> {
49 SmiOperationExecutionMode() : EnumSet<SmiOperationConstraint, byte>(0) { }
50 explicit SmiOperationExecutionMode(byte bits)
51 : EnumSet<SmiOperationConstraint, byte>(bits) { }
55 bool AreAliased(Register reg1,
57 Register reg3 = no_reg,
58 Register reg4 = no_reg,
59 Register reg5 = no_reg,
60 Register reg6 = no_reg,
61 Register reg7 = no_reg,
62 Register reg8 = no_reg);
65 // Forward declaration.
69 SmiIndex(Register index_register, ScaleFactor scale)
70 : reg(index_register),
77 // MacroAssembler implements a collection of frequently used macros.
78 class MacroAssembler: public Assembler {
80 // The isolate parameter can be NULL if the macro assembler should
81 // not use isolate-dependent functionality. In this case, it's the
82 // responsibility of the caller to never invoke such function on the
84 MacroAssembler(Isolate* isolate, void* buffer, int size);
86 // Prevent the use of the RootArray during the lifetime of this
88 class NoRootArrayScope BASE_EMBEDDED {
90 explicit NoRootArrayScope(MacroAssembler* assembler)
91 : variable_(&assembler->root_array_available_),
92 old_value_(assembler->root_array_available_) {
93 assembler->root_array_available_ = false;
96 *variable_ = old_value_;
103 // Operand pointing to an external reference.
104 // May emit code to set up the scratch register. The operand is
105 // only guaranteed to be correct as long as the scratch register
107 // If the operand is used more than once, use a scratch register
108 // that is guaranteed not to be clobbered.
109 Operand ExternalOperand(ExternalReference reference,
110 Register scratch = kScratchRegister);
111 // Loads and stores the value of an external reference.
112 // Special case code for load and store to take advantage of
113 // load_rax/store_rax if possible/necessary.
114 // For other operations, just use:
115 // Operand operand = ExternalOperand(extref);
116 // operation(operand, ..);
117 void Load(Register destination, ExternalReference source);
118 void Store(ExternalReference destination, Register source);
119 // Loads the address of the external reference into the destination
121 void LoadAddress(Register destination, ExternalReference source);
122 // Returns the size of the code generated by LoadAddress.
123 // Used by CallSize(ExternalReference) to find the size of a call.
124 int LoadAddressSize(ExternalReference source);
125 // Pushes the address of the external reference onto the stack.
126 void PushAddress(ExternalReference source);
128 // Operations on roots in the root-array.
129 void LoadRoot(Register destination, Heap::RootListIndex index);
130 void StoreRoot(Register source, Heap::RootListIndex index);
131 // Load a root value where the index (or part of it) is variable.
132 // The variable_offset register is added to the fixed_offset value
133 // to get the index into the root-array.
134 void LoadRootIndexed(Register destination,
135 Register variable_offset,
137 void CompareRoot(Register with, Heap::RootListIndex index);
138 void CompareRoot(const Operand& with, Heap::RootListIndex index);
139 void PushRoot(Heap::RootListIndex index);
141 // These functions do not arrange the registers in any particular order so
142 // they are not useful for calls that can cause a GC. The caller can
143 // exclude up to 3 registers that do not need to be saved and restored.
144 void PushCallerSaved(SaveFPRegsMode fp_mode,
145 Register exclusion1 = no_reg,
146 Register exclusion2 = no_reg,
147 Register exclusion3 = no_reg);
148 void PopCallerSaved(SaveFPRegsMode fp_mode,
149 Register exclusion1 = no_reg,
150 Register exclusion2 = no_reg,
151 Register exclusion3 = no_reg);
153 // ---------------------------------------------------------------------------
157 enum RememberedSetFinalAction {
162 // Record in the remembered set the fact that we have a pointer to new space
163 // at the address pointed to by the addr register. Only works if addr is not
165 void RememberedSetHelper(Register object, // Used for debug code.
168 SaveFPRegsMode save_fp,
169 RememberedSetFinalAction and_then);
171 void CheckPageFlag(Register object,
175 Label* condition_met,
176 Label::Distance condition_met_distance = Label::kFar);
178 void CheckMapDeprecated(Handle<Map> map,
180 Label* if_deprecated);
182 // Check if object is in new space. Jumps if the object is not in new space.
183 // The register scratch can be object itself, but scratch will be clobbered.
184 void JumpIfNotInNewSpace(Register object,
187 Label::Distance distance = Label::kFar) {
188 InNewSpace(object, scratch, not_equal, branch, distance);
191 // Check if object is in new space. Jumps if the object is in new space.
192 // The register scratch can be object itself, but it will be clobbered.
193 void JumpIfInNewSpace(Register object,
196 Label::Distance distance = Label::kFar) {
197 InNewSpace(object, scratch, equal, branch, distance);
200 // Check if an object has the black incremental marking color. Also uses rcx!
201 void JumpIfBlack(Register object,
205 Label::Distance on_black_distance = Label::kFar);
207 // Detects conservatively whether an object is data-only, i.e. it does need to
208 // be scanned by the garbage collector.
209 void JumpIfDataObject(Register value,
211 Label* not_data_object,
212 Label::Distance not_data_object_distance);
214 // Checks the color of an object. If the object is already grey or black
215 // then we just fall through, since it is already live. If it is white and
216 // we can determine that it doesn't need to be scanned, then we just mark it
217 // black and fall through. For the rest we jump to the label so the
218 // incremental marker can fix its assumptions.
219 void EnsureNotWhite(Register object,
222 Label* object_is_white_and_not_data,
223 Label::Distance distance);
225 // Notify the garbage collector that we wrote a pointer into an object.
226 // |object| is the object being stored into, |value| is the object being
227 // stored. value and scratch registers are clobbered by the operation.
228 // The offset is the offset from the start of the object, not the offset from
229 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
230 void RecordWriteField(
235 SaveFPRegsMode save_fp,
236 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
237 SmiCheck smi_check = INLINE_SMI_CHECK,
238 PointersToHereCheck pointers_to_here_check_for_value =
239 kPointersToHereMaybeInteresting);
241 // As above, but the offset has the tag presubtracted. For use with
242 // Operand(reg, off).
243 void RecordWriteContextSlot(
248 SaveFPRegsMode save_fp,
249 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
250 SmiCheck smi_check = INLINE_SMI_CHECK,
251 PointersToHereCheck pointers_to_here_check_for_value =
252 kPointersToHereMaybeInteresting) {
253 RecordWriteField(context,
254 offset + kHeapObjectTag,
258 remembered_set_action,
260 pointers_to_here_check_for_value);
263 // Notify the garbage collector that we wrote a pointer into a fixed array.
264 // |array| is the array being stored into, |value| is the
265 // object being stored. |index| is the array index represented as a non-smi.
266 // All registers are clobbered by the operation RecordWriteArray
267 // filters out smis so it does not update the write barrier if the
269 void RecordWriteArray(
273 SaveFPRegsMode save_fp,
274 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
275 SmiCheck smi_check = INLINE_SMI_CHECK,
276 PointersToHereCheck pointers_to_here_check_for_value =
277 kPointersToHereMaybeInteresting);
279 void RecordWriteForMap(
283 SaveFPRegsMode save_fp);
285 // For page containing |object| mark region covering |address|
286 // dirty. |object| is the object being stored into, |value| is the
287 // object being stored. The address and value registers are clobbered by the
288 // operation. RecordWrite filters out smis so it does not update
289 // the write barrier if the value is a smi.
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 // ---------------------------------------------------------------------------
305 // Generates function and stub prologue code.
307 void Prologue(bool code_pre_aging);
309 // Enter specific kind of exit frame; either in normal or
310 // debug mode. Expects the number of arguments in register rax and
311 // sets up the number of arguments in register rdi and the pointer
312 // to the first argument in register rsi.
314 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
315 // accessible via StackSpaceOperand.
316 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
318 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
319 // memory (not GCed) on the stack accessible via StackSpaceOperand.
320 void EnterApiExitFrame(int arg_stack_space);
322 // Leave the current exit frame. Expects/provides the return value in
323 // register rax:rdx (untouched) and the pointer to the first
324 // argument in register rsi.
325 void LeaveExitFrame(bool save_doubles = false);
327 // Leave the current exit frame. Expects/provides the return value in
328 // register rax (untouched).
329 void LeaveApiExitFrame(bool restore_context);
331 // Push and pop the registers that can hold pointers.
332 void PushSafepointRegisters() { Pushad(); }
333 void PopSafepointRegisters() { Popad(); }
334 // Store the value in register src in the safepoint register stack
335 // slot for register dst.
336 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
337 void StoreToSafepointRegisterSlot(Register dst, Register src);
338 void LoadFromSafepointRegisterSlot(Register dst, Register src);
340 void InitializeRootRegister() {
341 ExternalReference roots_array_start =
342 ExternalReference::roots_array_start(isolate());
343 Move(kRootRegister, roots_array_start);
344 addp(kRootRegister, Immediate(kRootRegisterBias));
347 // ---------------------------------------------------------------------------
348 // JavaScript invokes
350 // Invoke the JavaScript function code by either calling or jumping.
351 void InvokeCode(Register code,
352 const ParameterCount& expected,
353 const ParameterCount& actual,
355 const CallWrapper& call_wrapper);
357 // Invoke the JavaScript function in the given register. Changes the
358 // current context to the context in the function before invoking.
359 void InvokeFunction(Register function,
360 const ParameterCount& actual,
362 const CallWrapper& call_wrapper);
364 void InvokeFunction(Register function,
365 const ParameterCount& expected,
366 const ParameterCount& actual,
368 const CallWrapper& call_wrapper);
370 void InvokeFunction(Handle<JSFunction> function,
371 const ParameterCount& expected,
372 const ParameterCount& actual,
374 const CallWrapper& call_wrapper);
376 // Invoke specified builtin JavaScript function. Adds an entry to
377 // the unresolved list if the name does not resolve.
378 void InvokeBuiltin(Builtins::JavaScript id,
380 const CallWrapper& call_wrapper = NullCallWrapper());
382 // Store the function for the given builtin in the target register.
383 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
385 // Store the code object for the given builtin in the target register.
386 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
389 // ---------------------------------------------------------------------------
390 // Smi tagging, untagging and operations on tagged smis.
392 // Support for constant splitting.
393 bool IsUnsafeInt(const int32_t x);
394 void SafeMove(Register dst, Smi* src);
395 void SafePush(Smi* src);
397 void InitializeSmiConstantRegister() {
398 Move(kSmiConstantRegister, Smi::FromInt(kSmiConstantRegisterValue),
399 Assembler::RelocInfoNone());
402 // Conversions between tagged smi values and non-tagged integer values.
404 // Tag an integer value. The result must be known to be a valid smi value.
405 // Only uses the low 32 bits of the src register. Sets the N and Z flags
406 // based on the value of the resulting smi.
407 void Integer32ToSmi(Register dst, Register src);
409 // Stores an integer32 value into a memory field that already holds a smi.
410 void Integer32ToSmiField(const Operand& dst, Register src);
412 // Adds constant to src and tags the result as a smi.
413 // Result must be a valid smi.
414 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
416 // Convert smi to 32-bit integer. I.e., not sign extended into
417 // high 32 bits of destination.
418 void SmiToInteger32(Register dst, Register src);
419 void SmiToInteger32(Register dst, const Operand& src);
421 // Convert smi to 64-bit integer (sign extended if necessary).
422 void SmiToInteger64(Register dst, Register src);
423 void SmiToInteger64(Register dst, const Operand& src);
425 // Multiply a positive smi's integer value by a power of two.
426 // Provides result as 64-bit integer value.
427 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
431 // Divide a positive smi's integer value by a power of two.
432 // Provides result as 32-bit integer value.
433 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
437 // Perform the logical or of two smi values and return a smi value.
438 // If either argument is not a smi, jump to on_not_smis and retain
439 // the original values of source registers. The destination register
440 // may be changed if it's not one of the source registers.
441 void SmiOrIfSmis(Register dst,
445 Label::Distance near_jump = Label::kFar);
448 // Simple comparison of smis. Both sides must be known smis to use these,
449 // otherwise use Cmp.
450 void SmiCompare(Register smi1, Register smi2);
451 void SmiCompare(Register dst, Smi* src);
452 void SmiCompare(Register dst, const Operand& src);
453 void SmiCompare(const Operand& dst, Register src);
454 void SmiCompare(const Operand& dst, Smi* src);
455 // Compare the int32 in src register to the value of the smi stored at dst.
456 void SmiCompareInteger32(const Operand& dst, Register src);
457 // Sets sign and zero flags depending on value of smi in register.
458 void SmiTest(Register src);
460 // Functions performing a check on a known or potential smi. Returns
461 // a condition that is satisfied if the check is successful.
463 // Is the value a tagged smi.
464 Condition CheckSmi(Register src);
465 Condition CheckSmi(const Operand& src);
467 // Is the value a non-negative tagged smi.
468 Condition CheckNonNegativeSmi(Register src);
470 // Are both values tagged smis.
471 Condition CheckBothSmi(Register first, Register second);
473 // Are both values non-negative tagged smis.
474 Condition CheckBothNonNegativeSmi(Register first, Register second);
476 // Are either value a tagged smi.
477 Condition CheckEitherSmi(Register first,
479 Register scratch = kScratchRegister);
481 // Is the value the minimum smi value (since we are using
482 // two's complement numbers, negating the value is known to yield
484 Condition CheckIsMinSmi(Register src);
486 // Checks whether an 32-bit integer value is a valid for conversion
488 Condition CheckInteger32ValidSmiValue(Register src);
490 // Checks whether an 32-bit unsigned integer value is a valid for
491 // conversion to a smi.
492 Condition CheckUInteger32ValidSmiValue(Register src);
494 // Check whether src is a Smi, and set dst to zero if it is a smi,
495 // and to one if it isn't.
496 void CheckSmiToIndicator(Register dst, Register src);
497 void CheckSmiToIndicator(Register dst, const Operand& src);
499 // Test-and-jump functions. Typically combines a check function
500 // above with a conditional jump.
502 // Jump if the value can be represented by a smi.
503 void JumpIfValidSmiValue(Register src, Label* on_valid,
504 Label::Distance near_jump = Label::kFar);
506 // Jump if the value cannot be represented by a smi.
507 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
508 Label::Distance near_jump = Label::kFar);
510 // Jump if the unsigned integer value can be represented by a smi.
511 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
512 Label::Distance near_jump = Label::kFar);
514 // Jump if the unsigned integer value cannot be represented by a smi.
515 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
516 Label::Distance near_jump = Label::kFar);
518 // Jump to label if the value is a tagged smi.
519 void JumpIfSmi(Register src,
521 Label::Distance near_jump = Label::kFar);
523 // Jump to label if the value is not a tagged smi.
524 void JumpIfNotSmi(Register src,
526 Label::Distance near_jump = Label::kFar);
528 // Jump to label if the value is not a non-negative tagged smi.
529 void JumpUnlessNonNegativeSmi(Register src,
531 Label::Distance near_jump = Label::kFar);
533 // Jump to label if the value, which must be a tagged smi, has value equal
535 void JumpIfSmiEqualsConstant(Register src,
538 Label::Distance near_jump = Label::kFar);
540 // Jump if either or both register are not smi values.
541 void JumpIfNotBothSmi(Register src1,
543 Label* on_not_both_smi,
544 Label::Distance near_jump = Label::kFar);
546 // Jump if either or both register are not non-negative smi values.
547 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
548 Label* on_not_both_smi,
549 Label::Distance near_jump = Label::kFar);
551 // Operations on tagged smi values.
553 // Smis represent a subset of integers. The subset is always equivalent to
554 // a two's complement interpretation of a fixed number of bits.
556 // Add an integer constant to a tagged smi, giving a tagged smi as result.
557 // No overflow testing on the result is done.
558 void SmiAddConstant(Register dst, Register src, Smi* constant);
560 // Add an integer constant to a tagged smi, giving a tagged smi as result.
561 // No overflow testing on the result is done.
562 void SmiAddConstant(const Operand& dst, Smi* constant);
564 // Add an integer constant to a tagged smi, giving a tagged smi as result,
565 // or jumping to a label if the result cannot be represented by a smi.
566 void SmiAddConstant(Register dst,
569 SmiOperationExecutionMode mode,
570 Label* bailout_label,
571 Label::Distance near_jump = Label::kFar);
573 // Subtract an integer constant from a tagged smi, giving a tagged smi as
574 // result. No testing on the result is done. Sets the N and Z flags
575 // based on the value of the resulting integer.
576 void SmiSubConstant(Register dst, Register src, Smi* constant);
578 // Subtract an integer constant from a tagged smi, giving a tagged smi as
579 // result, or jumping to a label if the result cannot be represented by a smi.
580 void SmiSubConstant(Register dst,
583 SmiOperationExecutionMode mode,
584 Label* bailout_label,
585 Label::Distance near_jump = Label::kFar);
587 // Negating a smi can give a negative zero or too large positive value.
588 // NOTICE: This operation jumps on success, not failure!
589 void SmiNeg(Register dst,
591 Label* on_smi_result,
592 Label::Distance near_jump = Label::kFar);
594 // Adds smi values and return the result as a smi.
595 // If dst is src1, then src1 will be destroyed if the operation is
596 // successful, otherwise kept intact.
597 void SmiAdd(Register dst,
600 Label* on_not_smi_result,
601 Label::Distance near_jump = Label::kFar);
602 void SmiAdd(Register dst,
605 Label* on_not_smi_result,
606 Label::Distance near_jump = Label::kFar);
608 void SmiAdd(Register dst,
612 // Subtracts smi values and return the result as a smi.
613 // If dst is src1, then src1 will be destroyed if the operation is
614 // successful, otherwise kept intact.
615 void SmiSub(Register dst,
618 Label* on_not_smi_result,
619 Label::Distance near_jump = Label::kFar);
620 void SmiSub(Register dst,
623 Label* on_not_smi_result,
624 Label::Distance near_jump = Label::kFar);
626 void SmiSub(Register dst,
630 void SmiSub(Register dst,
632 const Operand& src2);
634 // Multiplies smi values and return the result as a smi,
636 // If dst is src1, then src1 will be destroyed, even if
637 // the operation is unsuccessful.
638 void SmiMul(Register dst,
641 Label* on_not_smi_result,
642 Label::Distance near_jump = Label::kFar);
644 // Divides one smi by another and returns the quotient.
645 // Clobbers rax and rdx registers.
646 void SmiDiv(Register dst,
649 Label* on_not_smi_result,
650 Label::Distance near_jump = Label::kFar);
652 // Divides one smi by another and returns the remainder.
653 // Clobbers rax and rdx registers.
654 void SmiMod(Register dst,
657 Label* on_not_smi_result,
658 Label::Distance near_jump = Label::kFar);
660 // Bitwise operations.
661 void SmiNot(Register dst, Register src);
662 void SmiAnd(Register dst, Register src1, Register src2);
663 void SmiOr(Register dst, Register src1, Register src2);
664 void SmiXor(Register dst, Register src1, Register src2);
665 void SmiAndConstant(Register dst, Register src1, Smi* constant);
666 void SmiOrConstant(Register dst, Register src1, Smi* constant);
667 void SmiXorConstant(Register dst, Register src1, Smi* constant);
669 void SmiShiftLeftConstant(Register dst,
672 Label* on_not_smi_result = NULL,
673 Label::Distance near_jump = Label::kFar);
674 void SmiShiftLogicalRightConstant(Register dst,
677 Label* on_not_smi_result,
678 Label::Distance near_jump = Label::kFar);
679 void SmiShiftArithmeticRightConstant(Register dst,
683 // Shifts a smi value to the left, and returns the result if that is a smi.
684 // Uses and clobbers rcx, so dst may not be rcx.
685 void SmiShiftLeft(Register dst,
688 Label* on_not_smi_result = NULL,
689 Label::Distance near_jump = Label::kFar);
690 // Shifts a smi value to the right, shifting in zero bits at the top, and
691 // returns the unsigned intepretation of the result if that is a smi.
692 // Uses and clobbers rcx, so dst may not be rcx.
693 void SmiShiftLogicalRight(Register dst,
696 Label* on_not_smi_result,
697 Label::Distance near_jump = Label::kFar);
698 // Shifts a smi value to the right, sign extending the top, and
699 // returns the signed intepretation of the result. That will always
700 // be a valid smi value, since it's numerically smaller than the
702 // Uses and clobbers rcx, so dst may not be rcx.
703 void SmiShiftArithmeticRight(Register dst,
707 // Specialized operations
709 // Select the non-smi register of two registers where exactly one is a
710 // smi. If neither are smis, jump to the failure label.
711 void SelectNonSmi(Register dst,
715 Label::Distance near_jump = Label::kFar);
717 // Converts, if necessary, a smi to a combination of number and
718 // multiplier to be used as a scaled index.
719 // The src register contains a *positive* smi value. The shift is the
720 // power of two to multiply the index value by (e.g.
721 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
722 // The returned index register may be either src or dst, depending
723 // on what is most efficient. If src and dst are different registers,
724 // src is always unchanged.
725 SmiIndex SmiToIndex(Register dst, Register src, int shift);
727 // Converts a positive smi to a negative index.
728 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
730 // Add the value of a smi in memory to an int32 register.
731 // Sets flags as a normal add.
732 void AddSmiField(Register dst, const Operand& src);
734 // Basic Smi operations.
735 void Move(Register dst, Smi* source) {
736 LoadSmiConstant(dst, source);
739 void Move(const Operand& dst, Smi* source) {
740 Register constant = GetSmiConstant(source);
746 // Save away a raw integer with pointer size on the stack as two integers
747 // masquerading as smis so that the garbage collector skips visiting them.
748 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
749 // Reconstruct a raw integer with pointer size from two integers masquerading
750 // as smis on the top of stack.
751 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
753 void Test(const Operand& dst, Smi* source);
756 // ---------------------------------------------------------------------------
759 // Generate code to do a lookup in the number string cache. If the number in
760 // the register object is found in the cache the generated code falls through
761 // with the result in the result register. The object and the result register
762 // can be the same. If the number is not found in the cache the code jumps to
763 // the label not_found with only the content of register object unchanged.
764 void LookupNumberStringCache(Register object,
770 // If object is a string, its map is loaded into object_map.
771 void JumpIfNotString(Register object,
774 Label::Distance near_jump = Label::kFar);
777 void JumpIfNotBothSequentialOneByteStrings(
778 Register first_object, Register second_object, Register scratch1,
779 Register scratch2, Label* on_not_both_flat_one_byte,
780 Label::Distance near_jump = Label::kFar);
782 // Check whether the instance type represents a flat one-byte string. Jump
783 // to the label if not. If the instance type can be scratched specify same
784 // register for both instance type and scratch.
785 void JumpIfInstanceTypeIsNotSequentialOneByte(
786 Register instance_type, Register scratch,
787 Label* on_not_flat_one_byte_string,
788 Label::Distance near_jump = Label::kFar);
790 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
791 Register first_object_instance_type, Register second_object_instance_type,
792 Register scratch1, Register scratch2, Label* on_fail,
793 Label::Distance near_jump = Label::kFar);
795 void EmitSeqStringSetCharCheck(Register string,
798 uint32_t encoding_mask);
800 // Checks if the given register or operand is a unique name
801 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
802 Label::Distance distance = Label::kFar);
803 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
804 Label::Distance distance = Label::kFar);
806 // ---------------------------------------------------------------------------
807 // Macro instructions.
809 // Load/store with specific representation.
810 void Load(Register dst, const Operand& src, Representation r);
811 void Store(const Operand& dst, Register src, Representation r);
813 // Load a register with a long value as efficiently as possible.
814 void Set(Register dst, int64_t x);
815 void Set(const Operand& dst, intptr_t x);
817 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
818 // hinders register renaming and makes dependence chains longer. So we use
819 // xorps to clear the dst register before cvtsi2sd to solve this issue.
820 void Cvtlsi2sd(XMMRegister dst, Register src);
821 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
823 // Move if the registers are not identical.
824 void Move(Register target, Register source);
826 // TestBit and Load SharedFunctionInfo special field.
827 void TestBitSharedFunctionInfoSpecialField(Register base,
830 void LoadSharedFunctionInfoSpecialField(Register dst,
835 void Move(Register dst, Handle<Object> source);
836 void Move(const Operand& dst, Handle<Object> source);
837 void Cmp(Register dst, Handle<Object> source);
838 void Cmp(const Operand& dst, Handle<Object> source);
839 void Cmp(Register dst, Smi* src);
840 void Cmp(const Operand& dst, Smi* src);
841 void Push(Handle<Object> source);
843 // Load a heap object and handle the case of new-space objects by
844 // indirecting via a global cell.
845 void MoveHeapObject(Register result, Handle<Object> object);
847 // Load a global cell into a register.
848 void LoadGlobalCell(Register dst, Handle<Cell> cell);
850 // Emit code to discard a non-negative number of pointer-sized elements
851 // from the stack, clobbering only the rsp register.
852 void Drop(int stack_elements);
853 // Emit code to discard a positive number of pointer-sized elements
854 // from the stack under the return address which remains on the top,
855 // clobbering the rsp register.
856 void DropUnderReturnAddress(int stack_elements,
857 Register scratch = kScratchRegister);
859 void Call(Label* target) { call(target); }
860 void Push(Register src);
861 void Push(const Operand& src);
862 void PushQuad(const Operand& src);
863 void Push(Immediate value);
864 void PushImm32(int32_t imm32);
865 void Pop(Register dst);
866 void Pop(const Operand& dst);
867 void PopQuad(const Operand& dst);
868 void PushReturnAddressFrom(Register src) { pushq(src); }
869 void PopReturnAddressTo(Register dst) { popq(dst); }
870 void Move(Register dst, ExternalReference ext) {
871 movp(dst, reinterpret_cast<void*>(ext.address()),
872 RelocInfo::EXTERNAL_REFERENCE);
875 // Loads a pointer into a register with a relocation mode.
876 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
877 // This method must not be used with heap object references. The stored
878 // address is not GC safe. Use the handle version instead.
879 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
880 movp(dst, ptr, rmode);
883 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
884 AllowDeferredHandleDereference using_raw_address;
885 DCHECK(!RelocInfo::IsNone(rmode));
886 DCHECK(value->IsHeapObject());
887 DCHECK(!isolate()->heap()->InNewSpace(*value));
888 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
891 void Move(XMMRegister dst, uint32_t src);
892 void Move(XMMRegister dst, uint64_t src);
895 void Jump(Address destination, RelocInfo::Mode rmode);
896 void Jump(ExternalReference ext);
897 void Jump(const Operand& op);
898 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
900 void Call(Address destination, RelocInfo::Mode rmode);
901 void Call(ExternalReference ext);
902 void Call(const Operand& op);
903 void Call(Handle<Code> code_object,
904 RelocInfo::Mode rmode,
905 TypeFeedbackId ast_id = TypeFeedbackId::None());
907 // The size of the code generated for different call instructions.
908 int CallSize(Address destination) {
909 return kCallSequenceLength;
911 int CallSize(ExternalReference ext);
912 int CallSize(Handle<Code> code_object) {
913 // Code calls use 32-bit relative addressing.
914 return kShortCallInstructionLength;
916 int CallSize(Register target) {
917 // Opcode: REX_opt FF /2 m64
918 return (target.high_bit() != 0) ? 3 : 2;
920 int CallSize(const Operand& target) {
921 // Opcode: REX_opt FF /2 m64
922 return (target.requires_rex() ? 2 : 1) + target.operand_size();
925 // Emit call to the code we are currently generating.
927 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
928 Call(self, RelocInfo::CODE_TARGET);
931 // Non-x64 instructions.
932 // Push/pop all general purpose registers.
933 // Does not push rsp/rbp nor any of the assembler's special purpose registers
934 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
937 // Sets the stack as after performing Popad, without actually loading the
941 // Compare object type for heap object.
942 // Always use unsigned comparisons: above and below, not less and greater.
943 // Incoming register is heap_object and outgoing register is map.
944 // They may be the same register, and may be kScratchRegister.
945 void CmpObjectType(Register heap_object, InstanceType type, Register map);
947 // Compare instance type for map.
948 // Always use unsigned comparisons: above and below, not less and greater.
949 void CmpInstanceType(Register map, InstanceType type);
951 // Check if a map for a JSObject indicates that the object has fast elements.
952 // Jump to the specified label if it does not.
953 void CheckFastElements(Register map,
955 Label::Distance distance = Label::kFar);
957 // Check if a map for a JSObject indicates that the object can have both smi
958 // and HeapObject elements. Jump to the specified label if it does not.
959 void CheckFastObjectElements(Register map,
961 Label::Distance distance = Label::kFar);
963 // Check if a map for a JSObject indicates that the object has fast smi only
964 // elements. Jump to the specified label if it does not.
965 void CheckFastSmiElements(Register map,
967 Label::Distance distance = Label::kFar);
969 // Check to see if maybe_number can be stored as a double in
970 // FastDoubleElements. If it can, store it at the index specified by index in
971 // the FastDoubleElements array elements, otherwise jump to fail. Note that
972 // index must not be smi-tagged.
973 void StoreNumberToDoubleElements(Register maybe_number,
976 XMMRegister xmm_scratch,
978 int elements_offset = 0);
980 // Compare an object's map with the specified map.
981 void CompareMap(Register obj, Handle<Map> map);
983 // Check if the map of an object is equal to a specified map and branch to
984 // label if not. Skip the smi check if not required (object is known to be a
985 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
986 // against maps that are ElementsKind transition maps of the specified map.
987 void CheckMap(Register obj,
990 SmiCheckType smi_check_type);
992 // Check if the map of an object is equal to a specified map and branch to a
993 // specified target if equal. Skip the smi check if not required (object is
994 // known to be a heap object)
995 void DispatchMap(Register obj,
998 Handle<Code> success,
999 SmiCheckType smi_check_type);
1001 // Check if the object in register heap_object is a string. Afterwards the
1002 // register map contains the object map and the register instance_type
1003 // contains the instance_type. The registers map and instance_type can be the
1004 // same in which case it contains the instance type afterwards. Either of the
1005 // registers map and instance_type can be the same as heap_object.
1006 Condition IsObjectStringType(Register heap_object,
1008 Register instance_type);
1010 // Check if the object in register heap_object is a name. Afterwards the
1011 // register map contains the object map and the register instance_type
1012 // contains the instance_type. The registers map and instance_type can be the
1013 // same in which case it contains the instance type afterwards. Either of the
1014 // registers map and instance_type can be the same as heap_object.
1015 Condition IsObjectNameType(Register heap_object,
1017 Register instance_type);
1019 // FCmp compares and pops the two values on top of the FPU stack.
1020 // The flag results are similar to integer cmp, but requires unsigned
1021 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1024 void ClampUint8(Register reg);
1026 void ClampDoubleToUint8(XMMRegister input_reg,
1027 XMMRegister temp_xmm_reg,
1028 Register result_reg);
1030 void SlowTruncateToI(Register result_reg, Register input_reg,
1031 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1033 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1034 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1036 void DoubleToI(Register result_reg, XMMRegister input_reg,
1037 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1038 Label* lost_precision, Label* is_nan, Label* minus_zero,
1039 Label::Distance dst = Label::kFar);
1041 void LoadUint32(XMMRegister dst, Register src);
1043 void LoadInstanceDescriptors(Register map, Register descriptors);
1044 void EnumLength(Register dst, Register map);
1045 void NumberOfOwnDescriptors(Register dst, Register map);
1047 template<typename Field>
1048 void DecodeField(Register reg) {
1049 static const int shift = Field::kShift;
1050 static const int mask = Field::kMask >> Field::kShift;
1052 shrp(reg, Immediate(shift));
1054 andp(reg, Immediate(mask));
1057 template<typename Field>
1058 void DecodeFieldToSmi(Register reg) {
1059 if (SmiValuesAre32Bits()) {
1060 andp(reg, Immediate(Field::kMask));
1061 shlp(reg, Immediate(kSmiShift - Field::kShift));
1063 static const int shift = Field::kShift;
1064 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1065 DCHECK(SmiValuesAre31Bits());
1066 DCHECK(kSmiShift == kSmiTagSize);
1067 DCHECK((mask & 0x80000000u) == 0);
1068 if (shift < kSmiShift) {
1069 shlp(reg, Immediate(kSmiShift - shift));
1070 } else if (shift > kSmiShift) {
1071 sarp(reg, Immediate(shift - kSmiShift));
1073 andp(reg, Immediate(mask));
1077 // Abort execution if argument is not a number, enabled via --debug-code.
1078 void AssertNumber(Register object);
1080 // Abort execution if argument is a smi, enabled via --debug-code.
1081 void AssertNotSmi(Register object);
1083 // Abort execution if argument is not a smi, enabled via --debug-code.
1084 void AssertSmi(Register object);
1085 void AssertSmi(const Operand& object);
1087 // Abort execution if a 64 bit register containing a 32 bit payload does not
1088 // have zeros in the top 32 bits, enabled via --debug-code.
1089 void AssertZeroExtended(Register reg);
1091 // Abort execution if argument is not a string, enabled via --debug-code.
1092 void AssertString(Register object);
1094 // Abort execution if argument is not a name, enabled via --debug-code.
1095 void AssertName(Register object);
1097 // Abort execution if argument is not undefined or an AllocationSite, enabled
1098 // via --debug-code.
1099 void AssertUndefinedOrAllocationSite(Register object);
1101 // Abort execution if argument is not the root value with the given index,
1102 // enabled via --debug-code.
1103 void AssertRootValue(Register src,
1104 Heap::RootListIndex root_value_index,
1105 BailoutReason reason);
1107 // ---------------------------------------------------------------------------
1108 // Exception handling
1110 // Push a new try handler and link it into try handler chain.
1111 void PushTryHandler(StackHandler::Kind kind, int handler_index);
1113 // Unlink the stack handler on top of the stack from the try handler chain.
1114 void PopTryHandler();
1116 // Activate the top handler in the try hander chain and pass the
1118 void Throw(Register value);
1120 // Propagate an uncatchable exception out of the current JS stack.
1121 void ThrowUncatchable(Register value);
1123 // ---------------------------------------------------------------------------
1124 // Inline caching support
1126 // Generate code for checking access rights - used for security checks
1127 // on access to global objects across environments. The holder register
1128 // is left untouched, but the scratch register and kScratchRegister,
1129 // which must be different, are clobbered.
1130 void CheckAccessGlobalProxy(Register holder_reg,
1134 void GetNumberHash(Register r0, Register scratch);
1136 void LoadFromNumberDictionary(Label* miss,
1145 // ---------------------------------------------------------------------------
1146 // Allocation support
1148 // Allocate an object in new space or old pointer space. If the given space
1149 // is exhausted control continues at the gc_required label. The allocated
1150 // object is returned in result and end of the new object is returned in
1151 // result_end. The register scratch can be passed as no_reg in which case
1152 // an additional object reference will be added to the reloc info. The
1153 // returned pointers in result and result_end have not yet been tagged as
1154 // heap objects. If result_contains_top_on_entry is true the content of
1155 // result is known to be the allocation top on entry (could be result_end
1156 // from a previous call). If result_contains_top_on_entry is true scratch
1157 // should be no_reg as it is never used.
1158 void Allocate(int object_size,
1160 Register result_end,
1163 AllocationFlags flags);
1165 void Allocate(int header_size,
1166 ScaleFactor element_size,
1167 Register element_count,
1169 Register result_end,
1172 AllocationFlags flags);
1174 void Allocate(Register object_size,
1176 Register result_end,
1179 AllocationFlags flags);
1181 // Undo allocation in new space. The object passed and objects allocated after
1182 // it will no longer be allocated. Make sure that no pointers are left to the
1183 // object(s) no longer allocated as they would be invalid when allocation is
1185 void UndoAllocationInNewSpace(Register object);
1187 // Allocate a heap number in new space with undefined value. Returns
1188 // tagged pointer in result register, or jumps to gc_required if new
1190 void AllocateHeapNumber(Register result,
1193 MutableMode mode = IMMUTABLE);
1195 // Allocate a sequential string. All the header fields of the string object
1197 void AllocateTwoByteString(Register result,
1202 Label* gc_required);
1203 void AllocateOneByteString(Register result, Register length,
1204 Register scratch1, Register scratch2,
1205 Register scratch3, Label* gc_required);
1207 // Allocate a raw cons string object. Only the map field of the result is
1209 void AllocateTwoByteConsString(Register result,
1212 Label* gc_required);
1213 void AllocateOneByteConsString(Register result, Register scratch1,
1214 Register scratch2, Label* gc_required);
1216 // Allocate a raw sliced string object. Only the map field of the result is
1218 void AllocateTwoByteSlicedString(Register result,
1221 Label* gc_required);
1222 void AllocateOneByteSlicedString(Register result, Register scratch1,
1223 Register scratch2, Label* gc_required);
1225 // ---------------------------------------------------------------------------
1226 // Support functions.
1228 // Check if result is zero and op is negative.
1229 void NegativeZeroTest(Register result, Register op, Label* then_label);
1231 // Check if result is zero and op is negative in code using jump targets.
1232 void NegativeZeroTest(CodeGenerator* cgen,
1235 JumpTarget* then_target);
1237 // Check if result is zero and any of op1 and op2 are negative.
1238 // Register scratch is destroyed, and it must be different from op2.
1239 void NegativeZeroTest(Register result, Register op1, Register op2,
1240 Register scratch, Label* then_label);
1242 // Try to get function prototype of a function and puts the value in
1243 // the result register. Checks that the function really is a
1244 // function and jumps to the miss label if the fast checks fail. The
1245 // function register will be untouched; the other register may be
1247 void TryGetFunctionPrototype(Register function,
1250 bool miss_on_bound_function = false);
1252 // Picks out an array index from the hash field.
1254 // hash - holds the index's hash. Clobbered.
1255 // index - holds the overwritten index on exit.
1256 void IndexFromHash(Register hash, Register index);
1258 // Find the function context up the context chain.
1259 void LoadContext(Register dst, int context_chain_length);
1261 // Conditionally load the cached Array transitioned map of type
1262 // transitioned_kind from the native context if the map in register
1263 // map_in_out is the cached Array map in the native context of
1265 void LoadTransitionedArrayMapConditional(
1266 ElementsKind expected_kind,
1267 ElementsKind transitioned_kind,
1268 Register map_in_out,
1270 Label* no_map_match);
1272 // Load the global function with the given index.
1273 void LoadGlobalFunction(int index, Register function);
1275 // Load the initial map from the global function. The registers
1276 // function and map can be the same.
1277 void LoadGlobalFunctionInitialMap(Register function, Register map);
1279 // ---------------------------------------------------------------------------
1282 // Call a code stub.
1283 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
1285 // Tail call a code stub (jump).
1286 void TailCallStub(CodeStub* stub);
1288 // Return from a code stub after popping its arguments.
1289 void StubReturn(int argc);
1291 // Call a runtime routine.
1292 void CallRuntime(const Runtime::Function* f,
1294 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1296 // Call a runtime function and save the value of XMM registers.
1297 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1298 const Runtime::Function* function = Runtime::FunctionForId(id);
1299 CallRuntime(function, function->nargs, kSaveFPRegs);
1302 // Convenience function: Same as above, but takes the fid instead.
1303 void CallRuntime(Runtime::FunctionId id,
1305 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1306 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1309 // Convenience function: call an external reference.
1310 void CallExternalReference(const ExternalReference& ext,
1313 // Tail call of a runtime routine (jump).
1314 // Like JumpToExternalReference, but also takes care of passing the number
1316 void TailCallExternalReference(const ExternalReference& ext,
1320 // Convenience function: tail call a runtime routine (jump).
1321 void TailCallRuntime(Runtime::FunctionId fid,
1325 // Jump to a runtime routine.
1326 void JumpToExternalReference(const ExternalReference& ext, int result_size);
1328 // Prepares stack to put arguments (aligns and so on). WIN64 calling
1329 // convention requires to put the pointer to the return value slot into
1330 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
1331 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
1332 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1333 void PrepareCallApiFunction(int arg_stack_space);
1335 // Calls an API function. Allocates HandleScope, extracts returned value
1336 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
1337 // caller-save registers. Restores context. On return removes
1338 // stack_space * kPointerSize (GCed).
1339 void CallApiFunctionAndReturn(Register function_address,
1340 ExternalReference thunk_ref,
1341 Register thunk_last_arg,
1343 Operand return_value_operand,
1344 Operand* context_restore_operand);
1346 // Before calling a C-function from generated code, align arguments on stack.
1347 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
1348 // etc., not pushed. The argument count assumes all arguments are word sized.
1349 // The number of slots reserved for arguments depends on platform. On Windows
1350 // stack slots are reserved for the arguments passed in registers. On other
1351 // platforms stack slots are only reserved for the arguments actually passed
1353 void PrepareCallCFunction(int num_arguments);
1355 // Calls a C function and cleans up the space for arguments allocated
1356 // by PrepareCallCFunction. The called function is not allowed to trigger a
1357 // garbage collection, since that might move the code and invalidate the
1358 // return address (unless this is somehow accounted for by the called
1360 void CallCFunction(ExternalReference function, int num_arguments);
1361 void CallCFunction(Register function, int num_arguments);
1363 // Calculate the number of stack slots to reserve for arguments when calling a
1365 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
1367 // ---------------------------------------------------------------------------
1372 // Return and drop arguments from stack, where the number of arguments
1373 // may be bigger than 2^16 - 1. Requires a scratch register.
1374 void Ret(int bytes_dropped, Register scratch);
1376 Handle<Object> CodeObject() {
1377 DCHECK(!code_object_.is_null());
1378 return code_object_;
1381 // Copy length bytes from source to destination.
1382 // Uses scratch register internally (if you have a low-eight register
1383 // free, do use it, otherwise kScratchRegister will be used).
1384 // The min_length is a minimum limit on the value that length will have.
1385 // The algorithm has some special cases that might be omitted if the string
1386 // is known to always be long.
1387 void CopyBytes(Register destination,
1391 Register scratch = kScratchRegister);
1393 // Initialize fields with filler values. Fields starting at |start_offset|
1394 // not including end_offset are overwritten with the value in |filler|. At
1395 // the end the loop, |start_offset| takes the value of |end_offset|.
1396 void InitializeFieldsWithFiller(Register start_offset,
1397 Register end_offset,
1401 // Emit code for a truncating division by a constant. The dividend register is
1402 // unchanged, the result is in rdx, and rax gets clobbered.
1403 void TruncatingDiv(Register dividend, int32_t divisor);
1405 // ---------------------------------------------------------------------------
1406 // StatsCounter support
1408 void SetCounter(StatsCounter* counter, int value);
1409 void IncrementCounter(StatsCounter* counter, int value);
1410 void DecrementCounter(StatsCounter* counter, int value);
1413 // ---------------------------------------------------------------------------
1416 // Calls Abort(msg) if the condition cc is not satisfied.
1417 // Use --debug_code to enable.
1418 void Assert(Condition cc, BailoutReason reason);
1420 void AssertFastElements(Register elements);
1422 // Like Assert(), but always enabled.
1423 void Check(Condition cc, BailoutReason reason);
1425 // Print a message to stdout and abort execution.
1426 void Abort(BailoutReason msg);
1428 // Check that the stack is aligned.
1429 void CheckStackAlignment();
1431 // Verify restrictions about code generated in stubs.
1432 void set_generating_stub(bool value) { generating_stub_ = value; }
1433 bool generating_stub() { return generating_stub_; }
1434 void set_has_frame(bool value) { has_frame_ = value; }
1435 bool has_frame() { return has_frame_; }
1436 inline bool AllowThisStubCall(CodeStub* stub);
1438 static int SafepointRegisterStackIndex(Register reg) {
1439 return SafepointRegisterStackIndex(reg.code());
1442 // Activation support.
1443 void EnterFrame(StackFrame::Type type);
1444 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
1445 void LeaveFrame(StackFrame::Type type);
1447 // Expects object in rax and returns map with validated enum cache
1448 // in rax. Assumes that any other register can be used as a scratch.
1449 void CheckEnumCache(Register null_value,
1450 Label* call_runtime);
1452 // AllocationMemento support. Arrays may have an associated
1453 // AllocationMemento object that can be checked for in order to pretransition
1455 // On entry, receiver_reg should point to the array object.
1456 // scratch_reg gets clobbered.
1457 // If allocation info is present, condition flags are set to equal.
1458 void TestJSArrayForAllocationMemento(Register receiver_reg,
1459 Register scratch_reg,
1460 Label* no_memento_found);
1462 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1463 Register scratch_reg,
1464 Label* memento_found) {
1465 Label no_memento_found;
1466 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1468 j(equal, memento_found);
1469 bind(&no_memento_found);
1472 // Jumps to found label if a prototype map has dictionary elements.
1473 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1474 Register scratch1, Label* found);
1477 // Order general registers are pushed by Pushad.
1478 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
1479 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
1480 static const int kNumSafepointSavedRegisters = 11;
1481 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
1483 bool generating_stub_;
1485 bool root_array_available_;
1487 // Returns a register holding the smi value. The register MUST NOT be
1488 // modified. It may be the "smi 1 constant" register.
1489 Register GetSmiConstant(Smi* value);
1491 int64_t RootRegisterDelta(ExternalReference other);
1493 // Moves the smi value to the destination register.
1494 void LoadSmiConstant(Register dst, Smi* value);
1496 // This handle will be patched with the code object on installation.
1497 Handle<Object> code_object_;
1499 // Helper functions for generating invokes.
1500 void InvokePrologue(const ParameterCount& expected,
1501 const ParameterCount& actual,
1502 Handle<Code> code_constant,
1503 Register code_register,
1505 bool* definitely_mismatches,
1507 Label::Distance near_jump = Label::kFar,
1508 const CallWrapper& call_wrapper = NullCallWrapper());
1510 void EnterExitFramePrologue(bool save_rax);
1512 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1513 // accessible via StackSpaceOperand.
1514 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
1516 void LeaveExitFrameEpilogue(bool restore_context);
1518 // Allocation support helpers.
1519 // Loads the top of new-space into the result register.
1520 // Otherwise the address of the new-space top is loaded into scratch (if
1521 // scratch is valid), and the new-space top is loaded into result.
1522 void LoadAllocationTopHelper(Register result,
1524 AllocationFlags flags);
1526 void MakeSureDoubleAlignedHelper(Register result,
1529 AllocationFlags flags);
1531 // Update allocation top with value in result_end register.
1532 // If scratch is valid, it contains the address of the allocation top.
1533 void UpdateAllocationTopHelper(Register result_end,
1535 AllocationFlags flags);
1537 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1538 void InNewSpace(Register object,
1542 Label::Distance distance = Label::kFar);
1544 // Helper for finding the mark bits for an address. Afterwards, the
1545 // bitmap register points at the word with the mark bits and the mask
1546 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1548 inline void GetMarkBits(Register addr_reg,
1549 Register bitmap_reg,
1552 // Helper for throwing exceptions. Compute a handler address and jump to
1553 // it. See the implementation for register usage.
1554 void JumpToHandlerEntry();
1556 // Compute memory operands for safepoint stack slots.
1557 Operand SafepointRegisterSlot(Register reg);
1558 static int SafepointRegisterStackIndex(int reg_code) {
1559 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1562 // Needs access to SafepointRegisterStackIndex for compiled frame
1564 friend class StandardFrame;
1568 // The code patcher is used to patch (typically) small parts of code e.g. for
1569 // debugging and other types of instrumentation. When using the code patcher
1570 // the exact number of bytes specified must be emitted. Is not legal to emit
1571 // relocation information. If any of these constraints are violated it causes
1575 CodePatcher(byte* address, int size);
1576 virtual ~CodePatcher();
1578 // Macro assembler to emit code.
1579 MacroAssembler* masm() { return &masm_; }
1582 byte* address_; // The address of the code being patched.
1583 int size_; // Number of bytes of the expected patch size.
1584 MacroAssembler masm_; // Macro assembler used to generate the code.
1588 // -----------------------------------------------------------------------------
1589 // Static helper functions.
1591 // Generate an Operand for loading a field from an object.
1592 inline Operand FieldOperand(Register object, int offset) {
1593 return Operand(object, offset - kHeapObjectTag);
1597 // Generate an Operand for loading an indexed field from an object.
1598 inline Operand FieldOperand(Register object,
1602 return Operand(object, index, scale, offset - kHeapObjectTag);
1606 inline Operand ContextOperand(Register context, int index) {
1607 return Operand(context, Context::SlotOffset(index));
1611 inline Operand GlobalObjectOperand() {
1612 return ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX);
1616 // Provides access to exit frame stack space (not GCed).
1617 inline Operand StackSpaceOperand(int index) {
1619 const int kShaddowSpace = 4;
1620 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1622 return Operand(rsp, index * kPointerSize);
1627 inline Operand StackOperandForReturnAddress(int32_t disp) {
1628 return Operand(rsp, disp);
1632 #ifdef GENERATED_CODE_COVERAGE
1633 extern void LogGeneratedCodeCoverage(const char* file_line);
1634 #define CODE_COVERAGE_STRINGIFY(x) #x
1635 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1636 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1637 #define ACCESS_MASM(masm) { \
1638 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1641 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1642 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1649 #define ACCESS_MASM(masm) masm->
1652 } } // namespace v8::internal
1654 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_