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_X87_MACRO_ASSEMBLER_X87_H_
6 #define V8_X87_MACRO_ASSEMBLER_X87_H_
8 #include "src/assembler.h"
9 #include "src/frames.h"
10 #include "src/globals.h"
15 // Convenience for platform-independent signatures. We do not normally
16 // distinguish memory operands from other operands on ia32.
17 typedef Operand MemOperand;
19 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
20 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
21 enum PointersToHereCheck {
22 kPointersToHereMaybeInteresting,
23 kPointersToHereAreAlwaysInteresting
27 enum RegisterValueType {
28 REGISTER_VALUE_IS_SMI,
29 REGISTER_VALUE_IS_INT32
34 bool AreAliased(Register reg1,
36 Register reg3 = no_reg,
37 Register reg4 = no_reg,
38 Register reg5 = no_reg,
39 Register reg6 = no_reg,
40 Register reg7 = no_reg,
41 Register reg8 = no_reg);
45 // MacroAssembler implements a collection of frequently used macros.
46 class MacroAssembler: public Assembler {
48 // The isolate parameter can be NULL if the macro assembler should
49 // not use isolate-dependent functionality. In this case, it's the
50 // responsibility of the caller to never invoke such function on the
52 MacroAssembler(Isolate* isolate, void* buffer, int size);
54 void Load(Register dst, const Operand& src, Representation r);
55 void Store(Register src, const Operand& dst, Representation r);
57 // Operations on roots in the root-array.
58 void LoadRoot(Register destination, Heap::RootListIndex index);
59 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
60 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
61 // These methods can only be used with constant roots (i.e. non-writable
62 // and not in new space).
63 void CompareRoot(Register with, Heap::RootListIndex index);
64 void CompareRoot(const Operand& with, Heap::RootListIndex index);
66 // ---------------------------------------------------------------------------
68 enum RememberedSetFinalAction {
73 // Record in the remembered set the fact that we have a pointer to new space
74 // at the address pointed to by the addr register. Only works if addr is not
76 void RememberedSetHelper(Register object, // Used for debug code.
79 RememberedSetFinalAction and_then);
81 void CheckPageFlag(Register object,
86 Label::Distance condition_met_distance = Label::kFar);
88 void CheckPageFlagForMap(
93 Label::Distance condition_met_distance = Label::kFar);
95 void CheckMapDeprecated(Handle<Map> map,
97 Label* if_deprecated);
99 // Check if object is in new space. Jumps if the object is not in new space.
100 // The register scratch can be object itself, but scratch will be clobbered.
101 void JumpIfNotInNewSpace(Register object,
104 Label::Distance distance = Label::kFar) {
105 InNewSpace(object, scratch, zero, branch, distance);
108 // Check if object is in new space. Jumps if the object is in new space.
109 // The register scratch can be object itself, but it will be clobbered.
110 void JumpIfInNewSpace(Register object,
113 Label::Distance distance = Label::kFar) {
114 InNewSpace(object, scratch, not_zero, branch, distance);
117 // Check if an object has a given incremental marking color. Also uses ecx!
118 void HasColor(Register object,
122 Label::Distance has_color_distance,
126 void JumpIfBlack(Register object,
130 Label::Distance on_black_distance = Label::kFar);
132 // Checks the color of an object. If the object is already grey or black
133 // then we just fall through, since it is already live. If it is white and
134 // we can determine that it doesn't need to be scanned, then we just mark it
135 // black and fall through. For the rest we jump to the label so the
136 // incremental marker can fix its assumptions.
137 void EnsureNotWhite(Register object,
140 Label* object_is_white_and_not_data,
141 Label::Distance distance);
143 // Notify the garbage collector that we wrote a pointer into an object.
144 // |object| is the object being stored into, |value| is the object being
145 // stored. value and scratch registers are clobbered by the operation.
146 // The offset is the offset from the start of the object, not the offset from
147 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
148 void RecordWriteField(
153 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
154 SmiCheck smi_check = INLINE_SMI_CHECK,
155 PointersToHereCheck pointers_to_here_check_for_value =
156 kPointersToHereMaybeInteresting);
158 // As above, but the offset has the tag presubtracted. For use with
159 // Operand(reg, off).
160 void RecordWriteContextSlot(
165 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
166 SmiCheck smi_check = INLINE_SMI_CHECK,
167 PointersToHereCheck pointers_to_here_check_for_value =
168 kPointersToHereMaybeInteresting) {
169 RecordWriteField(context,
170 offset + kHeapObjectTag,
173 remembered_set_action,
175 pointers_to_here_check_for_value);
178 // Notify the garbage collector that we wrote a pointer into a fixed array.
179 // |array| is the array being stored into, |value| is the
180 // object being stored. |index| is the array index represented as a
181 // Smi. All registers are clobbered by the operation RecordWriteArray
182 // filters out smis so it does not update the write barrier if the
184 void RecordWriteArray(
188 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
189 SmiCheck smi_check = INLINE_SMI_CHECK,
190 PointersToHereCheck pointers_to_here_check_for_value =
191 kPointersToHereMaybeInteresting);
193 // For page containing |object| mark region covering |address|
194 // dirty. |object| is the object being stored into, |value| is the
195 // object being stored. The address and value registers are clobbered by the
196 // operation. RecordWrite filters out smis so it does not update the
197 // write barrier if the value is a smi.
202 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
203 SmiCheck smi_check = INLINE_SMI_CHECK,
204 PointersToHereCheck pointers_to_here_check_for_value =
205 kPointersToHereMaybeInteresting);
207 // For page containing |object| mark the region covering the object's map
208 // dirty. |object| is the object being stored into, |map| is the Map object
210 void RecordWriteForMap(
216 // ---------------------------------------------------------------------------
221 // Generates function and stub prologue code.
223 void Prologue(bool code_pre_aging);
225 // Enter specific kind of exit frame. Expects the number of
226 // arguments in register eax and sets up the number of arguments in
227 // register edi and the pointer to the first argument in register
229 void EnterExitFrame();
231 void EnterApiExitFrame(int argc);
233 // Leave the current exit frame. Expects the return value in
234 // register eax:edx (untouched) and the pointer to the first
235 // argument in register esi.
236 void LeaveExitFrame();
238 // Leave the current exit frame. Expects the return value in
239 // register eax (untouched).
240 void LeaveApiExitFrame(bool restore_context);
242 // Find the function context up the context chain.
243 void LoadContext(Register dst, int context_chain_length);
245 // Conditionally load the cached Array transitioned map of type
246 // transitioned_kind from the native context if the map in register
247 // map_in_out is the cached Array map in the native context of
249 void LoadTransitionedArrayMapConditional(
250 ElementsKind expected_kind,
251 ElementsKind transitioned_kind,
254 Label* no_map_match);
256 // Load the global function with the given index.
257 void LoadGlobalFunction(int index, Register function);
259 // Load the initial map from the global function. The registers
260 // function and map can be the same.
261 void LoadGlobalFunctionInitialMap(Register function, Register map);
263 // Push and pop the registers that can hold pointers.
264 void PushSafepointRegisters() { pushad(); }
265 void PopSafepointRegisters() { popad(); }
266 // Store the value in register/immediate src in the safepoint
267 // register stack slot for register dst.
268 void StoreToSafepointRegisterSlot(Register dst, Register src);
269 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
270 void LoadFromSafepointRegisterSlot(Register dst, Register src);
272 void LoadHeapObject(Register result, Handle<HeapObject> object);
273 void CmpHeapObject(Register reg, Handle<HeapObject> object);
274 void PushHeapObject(Handle<HeapObject> object);
276 void LoadObject(Register result, Handle<Object> object) {
277 AllowDeferredHandleDereference heap_object_check;
278 if (object->IsHeapObject()) {
279 LoadHeapObject(result, Handle<HeapObject>::cast(object));
281 Move(result, Immediate(object));
285 void CmpObject(Register reg, Handle<Object> object) {
286 AllowDeferredHandleDereference heap_object_check;
287 if (object->IsHeapObject()) {
288 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
290 cmp(reg, Immediate(object));
294 // ---------------------------------------------------------------------------
295 // JavaScript invokes
297 // Invoke the JavaScript function code by either calling or jumping.
298 void InvokeCode(Register code,
299 const ParameterCount& expected,
300 const ParameterCount& actual,
302 const CallWrapper& call_wrapper) {
303 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
306 void InvokeCode(const Operand& code,
307 const ParameterCount& expected,
308 const ParameterCount& actual,
310 const CallWrapper& call_wrapper);
312 // Invoke the JavaScript function in the given register. Changes the
313 // current context to the context in the function before invoking.
314 void InvokeFunction(Register function,
315 const ParameterCount& actual,
317 const CallWrapper& call_wrapper);
319 void InvokeFunction(Register function,
320 const ParameterCount& expected,
321 const ParameterCount& actual,
323 const CallWrapper& call_wrapper);
325 void InvokeFunction(Handle<JSFunction> function,
326 const ParameterCount& expected,
327 const ParameterCount& actual,
329 const CallWrapper& call_wrapper);
331 // Invoke specified builtin JavaScript function. Adds an entry to
332 // the unresolved list if the name does not resolve.
333 void InvokeBuiltin(Builtins::JavaScript id,
335 const CallWrapper& call_wrapper = NullCallWrapper());
337 // Store the function for the given builtin in the target register.
338 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
340 // Store the code object for the given builtin in the target register.
341 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
343 // Expression support
344 // Support for constant splitting.
345 bool IsUnsafeImmediate(const Immediate& x);
346 void SafeMove(Register dst, const Immediate& x);
347 void SafePush(const Immediate& x);
349 // Compare object type for heap object.
350 // Incoming register is heap_object and outgoing register is map.
351 void CmpObjectType(Register heap_object, InstanceType type, Register map);
353 // Compare instance type for map.
354 void CmpInstanceType(Register map, InstanceType type);
356 // Check if a map for a JSObject indicates that the object has fast elements.
357 // Jump to the specified label if it does not.
358 void CheckFastElements(Register map,
360 Label::Distance distance = Label::kFar);
362 // Check if a map for a JSObject indicates that the object can have both smi
363 // and HeapObject elements. Jump to the specified label if it does not.
364 void CheckFastObjectElements(Register map,
366 Label::Distance distance = Label::kFar);
368 // Check if a map for a JSObject indicates that the object has fast smi only
369 // elements. Jump to the specified label if it does not.
370 void CheckFastSmiElements(Register map,
372 Label::Distance distance = Label::kFar);
374 // Check to see if maybe_number can be stored as a double in
375 // FastDoubleElements. If it can, store it at the index specified by key in
376 // the FastDoubleElements array elements, otherwise jump to fail.
377 void StoreNumberToDoubleElements(Register maybe_number,
384 // Compare an object's map with the specified map.
385 void CompareMap(Register obj, Handle<Map> map);
387 // Check if the map of an object is equal to a specified map and branch to
388 // label if not. Skip the smi check if not required (object is known to be a
389 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
390 // against maps that are ElementsKind transition maps of the specified map.
391 void CheckMap(Register obj,
394 SmiCheckType smi_check_type);
396 // Check if the map of an object is equal to a specified map and branch to a
397 // specified target if equal. Skip the smi check if not required (object is
398 // known to be a heap object)
399 void DispatchMap(Register obj,
402 Handle<Code> success,
403 SmiCheckType smi_check_type);
405 // Check if the object in register heap_object is a string. Afterwards the
406 // register map contains the object map and the register instance_type
407 // contains the instance_type. The registers map and instance_type can be the
408 // same in which case it contains the instance type afterwards. Either of the
409 // registers map and instance_type can be the same as heap_object.
410 Condition IsObjectStringType(Register heap_object,
412 Register instance_type);
414 // Check if the object in register heap_object is a name. Afterwards the
415 // register map contains the object map and the register instance_type
416 // contains the instance_type. The registers map and instance_type can be the
417 // same in which case it contains the instance type afterwards. Either of the
418 // registers map and instance_type can be the same as heap_object.
419 Condition IsObjectNameType(Register heap_object,
421 Register instance_type);
423 // Check if a heap object's type is in the JSObject range, not including
424 // JSFunction. The object's map will be loaded in the map register.
425 // Any or all of the three registers may be the same.
426 // The contents of the scratch register will always be overwritten.
427 void IsObjectJSObjectType(Register heap_object,
432 // The contents of the scratch register will be overwritten.
433 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
435 // FCmp is similar to integer cmp, but requires unsigned
436 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
439 void ClampUint8(Register reg);
441 void SlowTruncateToI(Register result_reg, Register input_reg,
442 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
444 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
445 void TruncateX87TOSToI(Register result_reg);
447 void X87TOSToI(Register result_reg, MinusZeroMode minus_zero_mode,
448 Label* conversion_failed, Label::Distance dst = Label::kFar);
450 void TaggedToI(Register result_reg, Register input_reg,
451 MinusZeroMode minus_zero_mode, Label* lost_precision);
453 // Smi tagging support.
454 void SmiTag(Register reg) {
455 STATIC_ASSERT(kSmiTag == 0);
456 STATIC_ASSERT(kSmiTagSize == 1);
459 void SmiUntag(Register reg) {
460 sar(reg, kSmiTagSize);
463 // Modifies the register even if it does not contain a Smi!
464 void SmiUntag(Register reg, Label* is_smi) {
465 STATIC_ASSERT(kSmiTagSize == 1);
466 sar(reg, kSmiTagSize);
467 STATIC_ASSERT(kSmiTag == 0);
468 j(not_carry, is_smi);
471 void LoadUint32NoSSE2(Register src);
473 // Jump the register contains a smi.
474 inline void JumpIfSmi(Register value,
476 Label::Distance distance = Label::kFar) {
477 test(value, Immediate(kSmiTagMask));
478 j(zero, smi_label, distance);
480 // Jump if the operand is a smi.
481 inline void JumpIfSmi(Operand value,
483 Label::Distance distance = Label::kFar) {
484 test(value, Immediate(kSmiTagMask));
485 j(zero, smi_label, distance);
487 // Jump if register contain a non-smi.
488 inline void JumpIfNotSmi(Register value,
489 Label* not_smi_label,
490 Label::Distance distance = Label::kFar) {
491 test(value, Immediate(kSmiTagMask));
492 j(not_zero, not_smi_label, distance);
495 void LoadInstanceDescriptors(Register map, Register descriptors);
496 void EnumLength(Register dst, Register map);
497 void NumberOfOwnDescriptors(Register dst, Register map);
499 template<typename Field>
500 void DecodeField(Register reg) {
501 static const int shift = Field::kShift;
502 static const int mask = Field::kMask >> Field::kShift;
506 and_(reg, Immediate(mask));
509 template<typename Field>
510 void DecodeFieldToSmi(Register reg) {
511 static const int shift = Field::kShift;
512 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
513 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
514 STATIC_ASSERT(kSmiTag == 0);
515 if (shift < kSmiTagSize) {
516 shl(reg, kSmiTagSize - shift);
517 } else if (shift > kSmiTagSize) {
518 sar(reg, shift - kSmiTagSize);
520 and_(reg, Immediate(mask));
523 // Abort execution if argument is not a number, enabled via --debug-code.
524 void AssertNumber(Register object);
526 // Abort execution if argument is not a smi, enabled via --debug-code.
527 void AssertSmi(Register object);
529 // Abort execution if argument is a smi, enabled via --debug-code.
530 void AssertNotSmi(Register object);
532 // Abort execution if argument is not a string, enabled via --debug-code.
533 void AssertString(Register object);
535 // Abort execution if argument is not a name, enabled via --debug-code.
536 void AssertName(Register object);
538 // Abort execution if argument is not undefined or an AllocationSite, enabled
540 void AssertUndefinedOrAllocationSite(Register object);
542 // ---------------------------------------------------------------------------
543 // Exception handling
545 // Push a new try handler and link it into try handler chain.
546 void PushTryHandler(StackHandler::Kind kind, int handler_index);
548 // Unlink the stack handler on top of the stack from the try handler chain.
549 void PopTryHandler();
551 // Throw to the top handler in the try hander chain.
552 void Throw(Register value);
554 // Throw past all JS frames to the top JS entry frame.
555 void ThrowUncatchable(Register value);
557 // ---------------------------------------------------------------------------
558 // Inline caching support
560 // Generate code for checking access rights - used for security checks
561 // on access to global objects across environments. The holder register
562 // is left untouched, but the scratch register is clobbered.
563 void CheckAccessGlobalProxy(Register holder_reg,
568 void GetNumberHash(Register r0, Register scratch);
570 void LoadFromNumberDictionary(Label* miss,
579 // ---------------------------------------------------------------------------
580 // Allocation support
582 // Allocate an object in new space or old pointer space. If the given space
583 // is exhausted control continues at the gc_required label. The allocated
584 // object is returned in result and end of the new object is returned in
585 // result_end. The register scratch can be passed as no_reg in which case
586 // an additional object reference will be added to the reloc info. The
587 // returned pointers in result and result_end have not yet been tagged as
588 // heap objects. If result_contains_top_on_entry is true the content of
589 // result is known to be the allocation top on entry (could be result_end
590 // from a previous call). If result_contains_top_on_entry is true scratch
591 // should be no_reg as it is never used.
592 void Allocate(int object_size,
597 AllocationFlags flags);
599 void Allocate(int header_size,
600 ScaleFactor element_size,
601 Register element_count,
602 RegisterValueType element_count_type,
607 AllocationFlags flags);
609 void Allocate(Register object_size,
614 AllocationFlags flags);
616 // Undo allocation in new space. The object passed and objects allocated after
617 // it will no longer be allocated. Make sure that no pointers are left to the
618 // object(s) no longer allocated as they would be invalid when allocation is
620 void UndoAllocationInNewSpace(Register object);
622 // Allocate a heap number in new space with undefined value. The
623 // register scratch2 can be passed as no_reg; the others must be
624 // valid registers. Returns tagged pointer in result register, or
625 // jumps to gc_required if new space is full.
626 void AllocateHeapNumber(Register result,
630 MutableMode mode = IMMUTABLE);
632 // Allocate a sequential string. All the header fields of the string object
634 void AllocateTwoByteString(Register result,
640 void AllocateOneByteString(Register result, Register length,
641 Register scratch1, Register scratch2,
642 Register scratch3, Label* gc_required);
643 void AllocateOneByteString(Register result, int length, Register scratch1,
644 Register scratch2, Label* gc_required);
646 // Allocate a raw cons string object. Only the map field of the result is
648 void AllocateTwoByteConsString(Register result,
652 void AllocateOneByteConsString(Register result, Register scratch1,
653 Register scratch2, Label* gc_required);
655 // Allocate a raw sliced string object. Only the map field of the result is
657 void AllocateTwoByteSlicedString(Register result,
661 void AllocateOneByteSlicedString(Register result, Register scratch1,
662 Register scratch2, Label* gc_required);
664 // Copy memory, byte-by-byte, from source to destination. Not optimized for
665 // long or aligned copies.
666 // The contents of index and scratch are destroyed.
667 void CopyBytes(Register source,
668 Register destination,
672 // Initialize fields with filler values. Fields starting at |start_offset|
673 // not including end_offset are overwritten with the value in |filler|. At
674 // the end the loop, |start_offset| takes the value of |end_offset|.
675 void InitializeFieldsWithFiller(Register start_offset,
679 // ---------------------------------------------------------------------------
680 // Support functions.
682 // Check a boolean-bit of a Smi field.
683 void BooleanBitTest(Register object, int field_offset, int bit_index);
685 // Check if result is zero and op is negative.
686 void NegativeZeroTest(Register result, Register op, Label* then_label);
688 // Check if result is zero and any of op1 and op2 are negative.
689 // Register scratch is destroyed, and it must be different from op2.
690 void NegativeZeroTest(Register result, Register op1, Register op2,
691 Register scratch, Label* then_label);
693 // Try to get function prototype of a function and puts the value in
694 // the result register. Checks that the function really is a
695 // function and jumps to the miss label if the fast checks fail. The
696 // function register will be untouched; the other registers may be
698 void TryGetFunctionPrototype(Register function,
702 bool miss_on_bound_function = false);
704 // Picks out an array index from the hash field.
706 // hash - holds the index's hash. Clobbered.
707 // index - holds the overwritten index on exit.
708 void IndexFromHash(Register hash, Register index);
710 // ---------------------------------------------------------------------------
713 // Call a code stub. Generate the code if necessary.
714 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
716 // Tail call a code stub (jump). Generate the code if necessary.
717 void TailCallStub(CodeStub* stub);
719 // Return from a code stub after popping its arguments.
720 void StubReturn(int argc);
722 // Call a runtime routine.
723 void CallRuntime(const Runtime::Function* f, int num_arguments);
724 // Convenience function: Same as above, but takes the fid instead.
725 void CallRuntime(Runtime::FunctionId id) {
726 const Runtime::Function* function = Runtime::FunctionForId(id);
727 CallRuntime(function, function->nargs);
729 void CallRuntime(Runtime::FunctionId id, int num_arguments) {
730 CallRuntime(Runtime::FunctionForId(id), num_arguments);
733 // Convenience function: call an external reference.
734 void CallExternalReference(ExternalReference ref, int num_arguments);
736 // Tail call of a runtime routine (jump).
737 // Like JumpToExternalReference, but also takes care of passing the number
739 void TailCallExternalReference(const ExternalReference& ext,
743 // Convenience function: tail call a runtime routine (jump).
744 void TailCallRuntime(Runtime::FunctionId fid,
748 // Before calling a C-function from generated code, align arguments on stack.
749 // After aligning the frame, arguments must be stored in esp[0], esp[4],
750 // etc., not pushed. The argument count assumes all arguments are word sized.
751 // Some compilers/platforms require the stack to be aligned when calling
753 // Needs a scratch register to do some arithmetic. This register will be
755 void PrepareCallCFunction(int num_arguments, Register scratch);
757 // Calls a C function and cleans up the space for arguments allocated
758 // by PrepareCallCFunction. The called function is not allowed to trigger a
759 // garbage collection, since that might move the code and invalidate the
760 // return address (unless this is somehow accounted for by the called
762 void CallCFunction(ExternalReference function, int num_arguments);
763 void CallCFunction(Register function, int num_arguments);
765 // Prepares stack to put arguments (aligns and so on). Reserves
766 // space for return value if needed (assumes the return value is a handle).
767 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
768 // etc. Saves context (esi). If space was reserved for return value then
769 // stores the pointer to the reserved slot into esi.
770 void PrepareCallApiFunction(int argc);
772 // Calls an API function. Allocates HandleScope, extracts returned value
773 // from handle and propagates exceptions. Clobbers ebx, edi and
774 // caller-save registers. Restores context. On return removes
775 // stack_space * kPointerSize (GCed).
776 void CallApiFunctionAndReturn(Register function_address,
777 ExternalReference thunk_ref,
778 Operand thunk_last_arg,
780 Operand return_value_operand,
781 Operand* context_restore_operand);
783 // Jump to a runtime routine.
784 void JumpToExternalReference(const ExternalReference& ext);
786 // ---------------------------------------------------------------------------
791 // Return and drop arguments from stack, where the number of arguments
792 // may be bigger than 2^16 - 1. Requires a scratch register.
793 void Ret(int bytes_dropped, Register scratch);
795 // Emit code to discard a non-negative number of pointer-sized elements
796 // from the stack, clobbering only the esp register.
797 void Drop(int element_count);
799 void Call(Label* target) { call(target); }
800 void Push(Register src) { push(src); }
801 void Pop(Register dst) { pop(dst); }
803 // Emit call to the code we are currently generating.
805 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
806 call(self, RelocInfo::CODE_TARGET);
809 // Move if the registers are not identical.
810 void Move(Register target, Register source);
812 // Move a constant into a destination using the most efficient encoding.
813 void Move(Register dst, const Immediate& x);
814 void Move(const Operand& dst, const Immediate& x);
816 // Push a handle value.
817 void Push(Handle<Object> handle) { push(Immediate(handle)); }
818 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
820 Handle<Object> CodeObject() {
821 DCHECK(!code_object_.is_null());
825 // Insert code to verify that the x87 stack has the specified depth (0-7)
826 void VerifyX87StackDepth(uint32_t depth);
828 // Emit code for a truncating division by a constant. The dividend register is
829 // unchanged, the result is in edx, and eax gets clobbered.
830 void TruncatingDiv(Register dividend, int32_t divisor);
832 // ---------------------------------------------------------------------------
833 // StatsCounter support
835 void SetCounter(StatsCounter* counter, int value);
836 void IncrementCounter(StatsCounter* counter, int value);
837 void DecrementCounter(StatsCounter* counter, int value);
838 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
839 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
842 // ---------------------------------------------------------------------------
845 // Calls Abort(msg) if the condition cc is not satisfied.
846 // Use --debug_code to enable.
847 void Assert(Condition cc, BailoutReason reason);
849 void AssertFastElements(Register elements);
851 // Like Assert(), but always enabled.
852 void Check(Condition cc, BailoutReason reason);
854 // Print a message to stdout and abort execution.
855 void Abort(BailoutReason reason);
857 // Check that the stack is aligned.
858 void CheckStackAlignment();
860 // Verify restrictions about code generated in stubs.
861 void set_generating_stub(bool value) { generating_stub_ = value; }
862 bool generating_stub() { return generating_stub_; }
863 void set_has_frame(bool value) { has_frame_ = value; }
864 bool has_frame() { return has_frame_; }
865 inline bool AllowThisStubCall(CodeStub* stub);
867 // ---------------------------------------------------------------------------
870 // Generate code to do a lookup in the number string cache. If the number in
871 // the register object is found in the cache the generated code falls through
872 // with the result in the result register. The object and the result register
873 // can be the same. If the number is not found in the cache the code jumps to
874 // the label not_found with only the content of register object unchanged.
875 void LookupNumberStringCache(Register object,
881 // Check whether the instance type represents a flat one-byte string. Jump to
882 // the label if not. If the instance type can be scratched specify same
883 // register for both instance type and scratch.
884 void JumpIfInstanceTypeIsNotSequentialOneByte(
885 Register instance_type, Register scratch,
886 Label* on_not_flat_one_byte_string);
888 // Checks if both objects are sequential one-byte strings, and jumps to label
890 void JumpIfNotBothSequentialOneByteStrings(
891 Register object1, Register object2, Register scratch1, Register scratch2,
892 Label* on_not_flat_one_byte_strings);
894 // Checks if the given register or operand is a unique name
895 void JumpIfNotUniqueName(Register reg, Label* not_unique_name,
896 Label::Distance distance = Label::kFar) {
897 JumpIfNotUniqueName(Operand(reg), not_unique_name, distance);
900 void JumpIfNotUniqueName(Operand operand, Label* not_unique_name,
901 Label::Distance distance = Label::kFar);
903 void EmitSeqStringSetCharCheck(Register string,
906 uint32_t encoding_mask);
908 static int SafepointRegisterStackIndex(Register reg) {
909 return SafepointRegisterStackIndex(reg.code());
912 // Activation support.
913 void EnterFrame(StackFrame::Type type);
914 void LeaveFrame(StackFrame::Type type);
916 // Expects object in eax and returns map with validated enum cache
917 // in eax. Assumes that any other register can be used as a scratch.
918 void CheckEnumCache(Label* call_runtime);
920 // AllocationMemento support. Arrays may have an associated
921 // AllocationMemento object that can be checked for in order to pretransition
923 // On entry, receiver_reg should point to the array object.
924 // scratch_reg gets clobbered.
925 // If allocation info is present, conditional code is set to equal.
926 void TestJSArrayForAllocationMemento(Register receiver_reg,
927 Register scratch_reg,
928 Label* no_memento_found);
930 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
931 Register scratch_reg,
932 Label* memento_found) {
933 Label no_memento_found;
934 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
936 j(equal, memento_found);
937 bind(&no_memento_found);
940 // Jumps to found label if a prototype map has dictionary elements.
941 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
942 Register scratch1, Label* found);
945 bool generating_stub_;
947 // This handle will be patched with the code object on installation.
948 Handle<Object> code_object_;
950 // Helper functions for generating invokes.
951 void InvokePrologue(const ParameterCount& expected,
952 const ParameterCount& actual,
953 Handle<Code> code_constant,
954 const Operand& code_operand,
956 bool* definitely_mismatches,
958 Label::Distance done_distance,
959 const CallWrapper& call_wrapper = NullCallWrapper());
961 void EnterExitFramePrologue();
962 void EnterExitFrameEpilogue(int argc);
964 void LeaveExitFrameEpilogue(bool restore_context);
966 // Allocation support helpers.
967 void LoadAllocationTopHelper(Register result,
969 AllocationFlags flags);
971 void UpdateAllocationTopHelper(Register result_end,
973 AllocationFlags flags);
975 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
976 void InNewSpace(Register object,
979 Label* condition_met,
980 Label::Distance condition_met_distance = Label::kFar);
982 // Helper for finding the mark bits for an address. Afterwards, the
983 // bitmap register points at the word with the mark bits and the mask
984 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
986 inline void GetMarkBits(Register addr_reg,
990 // Helper for throwing exceptions. Compute a handler address and jump to
991 // it. See the implementation for register usage.
992 void JumpToHandlerEntry();
994 // Compute memory operands for safepoint stack slots.
995 Operand SafepointRegisterSlot(Register reg);
996 static int SafepointRegisterStackIndex(int reg_code);
998 // Needs access to SafepointRegisterStackIndex for compiled frame
1000 friend class StandardFrame;
1004 // The code patcher is used to patch (typically) small parts of code e.g. for
1005 // debugging and other types of instrumentation. When using the code patcher
1006 // the exact number of bytes specified must be emitted. Is not legal to emit
1007 // relocation information. If any of these constraints are violated it causes
1011 CodePatcher(byte* address, int size);
1012 virtual ~CodePatcher();
1014 // Macro assembler to emit code.
1015 MacroAssembler* masm() { return &masm_; }
1018 byte* address_; // The address of the code being patched.
1019 int size_; // Number of bytes of the expected patch size.
1020 MacroAssembler masm_; // Macro assembler used to generate the code.
1024 // -----------------------------------------------------------------------------
1025 // Static helper functions.
1027 // Generate an Operand for loading a field from an object.
1028 inline Operand FieldOperand(Register object, int offset) {
1029 return Operand(object, offset - kHeapObjectTag);
1033 // Generate an Operand for loading an indexed field from an object.
1034 inline Operand FieldOperand(Register object,
1038 return Operand(object, index, scale, offset - kHeapObjectTag);
1042 inline Operand FixedArrayElementOperand(Register array,
1043 Register index_as_smi,
1044 int additional_offset = 0) {
1045 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1046 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1050 inline Operand ContextOperand(Register context, int index) {
1051 return Operand(context, Context::SlotOffset(index));
1055 inline Operand GlobalObjectOperand() {
1056 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1060 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1061 Operand ApiParameterOperand(int index);
1064 #ifdef GENERATED_CODE_COVERAGE
1065 extern void LogGeneratedCodeCoverage(const char* file_line);
1066 #define CODE_COVERAGE_STRINGIFY(x) #x
1067 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1068 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1069 #define ACCESS_MASM(masm) { \
1070 byte* ia32_coverage_function = \
1071 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1074 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1075 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1082 #define ACCESS_MASM(masm) masm->
1086 } } // namespace v8::internal
1088 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_