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 AllocateAsciiString(Register result,
646 void AllocateAsciiString(Register result,
652 // Allocate a raw cons string object. Only the map field of the result is
654 void AllocateTwoByteConsString(Register result,
658 void AllocateAsciiConsString(Register result,
663 // Allocate a raw sliced string object. Only the map field of the result is
665 void AllocateTwoByteSlicedString(Register result,
669 void AllocateAsciiSlicedString(Register result,
674 // Copy memory, byte-by-byte, from source to destination. Not optimized for
675 // long or aligned copies.
676 // The contents of index and scratch are destroyed.
677 void CopyBytes(Register source,
678 Register destination,
682 // Initialize fields with filler values. Fields starting at |start_offset|
683 // not including end_offset are overwritten with the value in |filler|. At
684 // the end the loop, |start_offset| takes the value of |end_offset|.
685 void InitializeFieldsWithFiller(Register start_offset,
689 // ---------------------------------------------------------------------------
690 // Support functions.
692 // Check a boolean-bit of a Smi field.
693 void BooleanBitTest(Register object, int field_offset, int bit_index);
695 // Check if result is zero and op is negative.
696 void NegativeZeroTest(Register result, Register op, Label* then_label);
698 // Check if result is zero and any of op1 and op2 are negative.
699 // Register scratch is destroyed, and it must be different from op2.
700 void NegativeZeroTest(Register result, Register op1, Register op2,
701 Register scratch, Label* then_label);
703 // Try to get function prototype of a function and puts the value in
704 // the result register. Checks that the function really is a
705 // function and jumps to the miss label if the fast checks fail. The
706 // function register will be untouched; the other registers may be
708 void TryGetFunctionPrototype(Register function,
712 bool miss_on_bound_function = false);
714 // Picks out an array index from the hash field.
716 // hash - holds the index's hash. Clobbered.
717 // index - holds the overwritten index on exit.
718 void IndexFromHash(Register hash, Register index);
720 // ---------------------------------------------------------------------------
723 // Call a code stub. Generate the code if necessary.
724 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
726 // Tail call a code stub (jump). Generate the code if necessary.
727 void TailCallStub(CodeStub* stub);
729 // Return from a code stub after popping its arguments.
730 void StubReturn(int argc);
732 // Call a runtime routine.
733 void CallRuntime(const Runtime::Function* f, int num_arguments);
734 // Convenience function: Same as above, but takes the fid instead.
735 void CallRuntime(Runtime::FunctionId id) {
736 const Runtime::Function* function = Runtime::FunctionForId(id);
737 CallRuntime(function, function->nargs);
739 void CallRuntime(Runtime::FunctionId id, int num_arguments) {
740 CallRuntime(Runtime::FunctionForId(id), num_arguments);
743 // Convenience function: call an external reference.
744 void CallExternalReference(ExternalReference ref, int num_arguments);
746 // Tail call of a runtime routine (jump).
747 // Like JumpToExternalReference, but also takes care of passing the number
749 void TailCallExternalReference(const ExternalReference& ext,
753 // Convenience function: tail call a runtime routine (jump).
754 void TailCallRuntime(Runtime::FunctionId fid,
758 // Before calling a C-function from generated code, align arguments on stack.
759 // After aligning the frame, arguments must be stored in esp[0], esp[4],
760 // etc., not pushed. The argument count assumes all arguments are word sized.
761 // Some compilers/platforms require the stack to be aligned when calling
763 // Needs a scratch register to do some arithmetic. This register will be
765 void PrepareCallCFunction(int num_arguments, Register scratch);
767 // Calls a C function and cleans up the space for arguments allocated
768 // by PrepareCallCFunction. The called function is not allowed to trigger a
769 // garbage collection, since that might move the code and invalidate the
770 // return address (unless this is somehow accounted for by the called
772 void CallCFunction(ExternalReference function, int num_arguments);
773 void CallCFunction(Register function, int num_arguments);
775 // Prepares stack to put arguments (aligns and so on). Reserves
776 // space for return value if needed (assumes the return value is a handle).
777 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
778 // etc. Saves context (esi). If space was reserved for return value then
779 // stores the pointer to the reserved slot into esi.
780 void PrepareCallApiFunction(int argc);
782 // Calls an API function. Allocates HandleScope, extracts returned value
783 // from handle and propagates exceptions. Clobbers ebx, edi and
784 // caller-save registers. Restores context. On return removes
785 // stack_space * kPointerSize (GCed).
786 void CallApiFunctionAndReturn(Register function_address,
787 ExternalReference thunk_ref,
788 Operand thunk_last_arg,
790 Operand return_value_operand,
791 Operand* context_restore_operand);
793 // Jump to a runtime routine.
794 void JumpToExternalReference(const ExternalReference& ext);
796 // ---------------------------------------------------------------------------
801 // Return and drop arguments from stack, where the number of arguments
802 // may be bigger than 2^16 - 1. Requires a scratch register.
803 void Ret(int bytes_dropped, Register scratch);
805 // Emit code to discard a non-negative number of pointer-sized elements
806 // from the stack, clobbering only the esp register.
807 void Drop(int element_count);
809 void Call(Label* target) { call(target); }
810 void Push(Register src) { push(src); }
811 void Pop(Register dst) { pop(dst); }
813 // Emit call to the code we are currently generating.
815 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
816 call(self, RelocInfo::CODE_TARGET);
819 // Move if the registers are not identical.
820 void Move(Register target, Register source);
822 // Move a constant into a destination using the most efficient encoding.
823 void Move(Register dst, const Immediate& x);
824 void Move(const Operand& dst, const Immediate& x);
826 // Push a handle value.
827 void Push(Handle<Object> handle) { push(Immediate(handle)); }
828 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
830 Handle<Object> CodeObject() {
831 ASSERT(!code_object_.is_null());
835 // Insert code to verify that the x87 stack has the specified depth (0-7)
836 void VerifyX87StackDepth(uint32_t depth);
838 // Emit code for a truncating division by a constant. The dividend register is
839 // unchanged, the result is in edx, and eax gets clobbered.
840 void TruncatingDiv(Register dividend, int32_t divisor);
842 // ---------------------------------------------------------------------------
843 // StatsCounter support
845 void SetCounter(StatsCounter* counter, int value);
846 void IncrementCounter(StatsCounter* counter, int value);
847 void DecrementCounter(StatsCounter* counter, int value);
848 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
849 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
852 // ---------------------------------------------------------------------------
855 // Calls Abort(msg) if the condition cc is not satisfied.
856 // Use --debug_code to enable.
857 void Assert(Condition cc, BailoutReason reason);
859 void AssertFastElements(Register elements);
861 // Like Assert(), but always enabled.
862 void Check(Condition cc, BailoutReason reason);
864 // Print a message to stdout and abort execution.
865 void Abort(BailoutReason reason);
867 // Check that the stack is aligned.
868 void CheckStackAlignment();
870 // Verify restrictions about code generated in stubs.
871 void set_generating_stub(bool value) { generating_stub_ = value; }
872 bool generating_stub() { return generating_stub_; }
873 void set_has_frame(bool value) { has_frame_ = value; }
874 bool has_frame() { return has_frame_; }
875 inline bool AllowThisStubCall(CodeStub* stub);
877 // ---------------------------------------------------------------------------
880 // Generate code to do a lookup in the number string cache. If the number in
881 // the register object is found in the cache the generated code falls through
882 // with the result in the result register. The object and the result register
883 // can be the same. If the number is not found in the cache the code jumps to
884 // the label not_found with only the content of register object unchanged.
885 void LookupNumberStringCache(Register object,
891 // Check whether the instance type represents a flat ASCII string. Jump to the
892 // label if not. If the instance type can be scratched specify same register
893 // for both instance type and scratch.
894 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
896 Label* on_not_flat_ascii_string);
898 // Checks if both objects are sequential ASCII strings, and jumps to label
900 void JumpIfNotBothSequentialAsciiStrings(Register object1,
904 Label* on_not_flat_ascii_strings);
906 // Checks if the given register or operand is a unique name
907 void JumpIfNotUniqueName(Register reg, Label* not_unique_name,
908 Label::Distance distance = Label::kFar) {
909 JumpIfNotUniqueName(Operand(reg), not_unique_name, distance);
912 void JumpIfNotUniqueName(Operand operand, Label* not_unique_name,
913 Label::Distance distance = Label::kFar);
915 void EmitSeqStringSetCharCheck(Register string,
918 uint32_t encoding_mask);
920 static int SafepointRegisterStackIndex(Register reg) {
921 return SafepointRegisterStackIndex(reg.code());
924 // Activation support.
925 void EnterFrame(StackFrame::Type type);
926 void LeaveFrame(StackFrame::Type type);
928 // Expects object in eax and returns map with validated enum cache
929 // in eax. Assumes that any other register can be used as a scratch.
930 void CheckEnumCache(Label* call_runtime);
932 // AllocationMemento support. Arrays may have an associated
933 // AllocationMemento object that can be checked for in order to pretransition
935 // On entry, receiver_reg should point to the array object.
936 // scratch_reg gets clobbered.
937 // If allocation info is present, conditional code is set to equal.
938 void TestJSArrayForAllocationMemento(Register receiver_reg,
939 Register scratch_reg,
940 Label* no_memento_found);
942 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
943 Register scratch_reg,
944 Label* memento_found) {
945 Label no_memento_found;
946 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
948 j(equal, memento_found);
949 bind(&no_memento_found);
952 // Jumps to found label if a prototype map has dictionary elements.
953 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
954 Register scratch1, Label* found);
957 bool generating_stub_;
959 // This handle will be patched with the code object on installation.
960 Handle<Object> code_object_;
962 // Helper functions for generating invokes.
963 void InvokePrologue(const ParameterCount& expected,
964 const ParameterCount& actual,
965 Handle<Code> code_constant,
966 const Operand& code_operand,
968 bool* definitely_mismatches,
970 Label::Distance done_distance,
971 const CallWrapper& call_wrapper = NullCallWrapper());
973 void EnterExitFramePrologue();
974 void EnterExitFrameEpilogue(int argc);
976 void LeaveExitFrameEpilogue(bool restore_context);
978 // Allocation support helpers.
979 void LoadAllocationTopHelper(Register result,
981 AllocationFlags flags);
983 void UpdateAllocationTopHelper(Register result_end,
985 AllocationFlags flags);
987 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
988 void InNewSpace(Register object,
991 Label* condition_met,
992 Label::Distance condition_met_distance = Label::kFar);
994 // Helper for finding the mark bits for an address. Afterwards, the
995 // bitmap register points at the word with the mark bits and the mask
996 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
998 inline void GetMarkBits(Register addr_reg,
1002 // Helper for throwing exceptions. Compute a handler address and jump to
1003 // it. See the implementation for register usage.
1004 void JumpToHandlerEntry();
1006 // Compute memory operands for safepoint stack slots.
1007 Operand SafepointRegisterSlot(Register reg);
1008 static int SafepointRegisterStackIndex(int reg_code);
1010 // Needs access to SafepointRegisterStackIndex for compiled frame
1012 friend class StandardFrame;
1016 // The code patcher is used to patch (typically) small parts of code e.g. for
1017 // debugging and other types of instrumentation. When using the code patcher
1018 // the exact number of bytes specified must be emitted. Is not legal to emit
1019 // relocation information. If any of these constraints are violated it causes
1023 CodePatcher(byte* address, int size);
1024 virtual ~CodePatcher();
1026 // Macro assembler to emit code.
1027 MacroAssembler* masm() { return &masm_; }
1030 byte* address_; // The address of the code being patched.
1031 int size_; // Number of bytes of the expected patch size.
1032 MacroAssembler masm_; // Macro assembler used to generate the code.
1036 // -----------------------------------------------------------------------------
1037 // Static helper functions.
1039 // Generate an Operand for loading a field from an object.
1040 inline Operand FieldOperand(Register object, int offset) {
1041 return Operand(object, offset - kHeapObjectTag);
1045 // Generate an Operand for loading an indexed field from an object.
1046 inline Operand FieldOperand(Register object,
1050 return Operand(object, index, scale, offset - kHeapObjectTag);
1054 inline Operand FixedArrayElementOperand(Register array,
1055 Register index_as_smi,
1056 int additional_offset = 0) {
1057 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1058 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1062 inline Operand ContextOperand(Register context, int index) {
1063 return Operand(context, Context::SlotOffset(index));
1067 inline Operand GlobalObjectOperand() {
1068 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1072 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1073 Operand ApiParameterOperand(int index);
1076 #ifdef GENERATED_CODE_COVERAGE
1077 extern void LogGeneratedCodeCoverage(const char* file_line);
1078 #define CODE_COVERAGE_STRINGIFY(x) #x
1079 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1080 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1081 #define ACCESS_MASM(masm) { \
1082 byte* ia32_coverage_function = \
1083 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1086 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1087 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1094 #define ACCESS_MASM(masm) masm->
1098 } } // namespace v8::internal
1100 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_