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 };
23 enum RegisterValueType {
24 REGISTER_VALUE_IS_SMI,
25 REGISTER_VALUE_IS_INT32
29 bool AreAliased(Register r1, Register r2, Register r3, Register r4);
32 // MacroAssembler implements a collection of frequently used macros.
33 class MacroAssembler: public Assembler {
35 // The isolate parameter can be NULL if the macro assembler should
36 // not use isolate-dependent functionality. In this case, it's the
37 // responsibility of the caller to never invoke such function on the
39 MacroAssembler(Isolate* isolate, void* buffer, int size);
41 void Load(Register dst, const Operand& src, Representation r);
42 void Store(Register src, const Operand& dst, Representation r);
44 // Operations on roots in the root-array.
45 void LoadRoot(Register destination, Heap::RootListIndex index);
46 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
47 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
48 // These methods can only be used with constant roots (i.e. non-writable
49 // and not in new space).
50 void CompareRoot(Register with, Heap::RootListIndex index);
51 void CompareRoot(const Operand& with, Heap::RootListIndex index);
53 // ---------------------------------------------------------------------------
55 enum RememberedSetFinalAction {
60 // Record in the remembered set the fact that we have a pointer to new space
61 // at the address pointed to by the addr register. Only works if addr is not
63 void RememberedSetHelper(Register object, // Used for debug code.
66 RememberedSetFinalAction and_then);
68 void CheckPageFlag(Register object,
73 Label::Distance condition_met_distance = Label::kFar);
75 void CheckPageFlagForMap(
80 Label::Distance condition_met_distance = Label::kFar);
82 void CheckMapDeprecated(Handle<Map> map,
84 Label* if_deprecated);
86 // Check if object is in new space. Jumps if the object is not in new space.
87 // The register scratch can be object itself, but scratch will be clobbered.
88 void JumpIfNotInNewSpace(Register object,
91 Label::Distance distance = Label::kFar) {
92 InNewSpace(object, scratch, zero, branch, distance);
95 // Check if object is in new space. Jumps if the object is in new space.
96 // The register scratch can be object itself, but it will be clobbered.
97 void JumpIfInNewSpace(Register object,
100 Label::Distance distance = Label::kFar) {
101 InNewSpace(object, scratch, not_zero, branch, distance);
104 // Check if an object has a given incremental marking color. Also uses ecx!
105 void HasColor(Register object,
109 Label::Distance has_color_distance,
113 void JumpIfBlack(Register object,
117 Label::Distance on_black_distance = Label::kFar);
119 // Checks the color of an object. If the object is already grey or black
120 // then we just fall through, since it is already live. If it is white and
121 // we can determine that it doesn't need to be scanned, then we just mark it
122 // black and fall through. For the rest we jump to the label so the
123 // incremental marker can fix its assumptions.
124 void EnsureNotWhite(Register object,
127 Label* object_is_white_and_not_data,
128 Label::Distance distance);
130 // Notify the garbage collector that we wrote a pointer into an object.
131 // |object| is the object being stored into, |value| is the object being
132 // stored. value and scratch registers are clobbered by the operation.
133 // The offset is the offset from the start of the object, not the offset from
134 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
135 void RecordWriteField(
140 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
141 SmiCheck smi_check = INLINE_SMI_CHECK);
143 // As above, but the offset has the tag presubtracted. For use with
144 // Operand(reg, off).
145 void RecordWriteContextSlot(
150 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
151 SmiCheck smi_check = INLINE_SMI_CHECK) {
152 RecordWriteField(context,
153 offset + kHeapObjectTag,
156 remembered_set_action,
160 // Notify the garbage collector that we wrote a pointer into a fixed array.
161 // |array| is the array being stored into, |value| is the
162 // object being stored. |index| is the array index represented as a
163 // Smi. All registers are clobbered by the operation RecordWriteArray
164 // filters out smis so it does not update the write barrier if the
166 void RecordWriteArray(
170 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
171 SmiCheck smi_check = INLINE_SMI_CHECK);
173 // For page containing |object| mark region covering |address|
174 // dirty. |object| is the object being stored into, |value| is the
175 // object being stored. The address and value registers are clobbered by the
176 // operation. RecordWrite filters out smis so it does not update the
177 // write barrier if the value is a smi.
182 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
183 SmiCheck smi_check = INLINE_SMI_CHECK);
185 // For page containing |object| mark the region covering the object's map
186 // dirty. |object| is the object being stored into, |map| is the Map object
188 void RecordWriteForMap(
194 // ---------------------------------------------------------------------------
199 // Generates function and stub prologue code.
201 void Prologue(bool code_pre_aging);
203 // Enter specific kind of exit frame. Expects the number of
204 // arguments in register eax and sets up the number of arguments in
205 // register edi and the pointer to the first argument in register
207 void EnterExitFrame();
209 void EnterApiExitFrame(int argc);
211 // Leave the current exit frame. Expects the return value in
212 // register eax:edx (untouched) and the pointer to the first
213 // argument in register esi.
214 void LeaveExitFrame();
216 // Leave the current exit frame. Expects the return value in
217 // register eax (untouched).
218 void LeaveApiExitFrame(bool restore_context);
220 // Find the function context up the context chain.
221 void LoadContext(Register dst, int context_chain_length);
223 // Conditionally load the cached Array transitioned map of type
224 // transitioned_kind from the native context if the map in register
225 // map_in_out is the cached Array map in the native context of
227 void LoadTransitionedArrayMapConditional(
228 ElementsKind expected_kind,
229 ElementsKind transitioned_kind,
232 Label* no_map_match);
234 // Load the global function with the given index.
235 void LoadGlobalFunction(int index, Register function);
237 // Load the initial map from the global function. The registers
238 // function and map can be the same.
239 void LoadGlobalFunctionInitialMap(Register function, Register map);
241 // Push and pop the registers that can hold pointers.
242 void PushSafepointRegisters() { pushad(); }
243 void PopSafepointRegisters() { popad(); }
244 // Store the value in register/immediate src in the safepoint
245 // register stack slot for register dst.
246 void StoreToSafepointRegisterSlot(Register dst, Register src);
247 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
248 void LoadFromSafepointRegisterSlot(Register dst, Register src);
250 void LoadHeapObject(Register result, Handle<HeapObject> object);
251 void CmpHeapObject(Register reg, Handle<HeapObject> object);
252 void PushHeapObject(Handle<HeapObject> object);
254 void LoadObject(Register result, Handle<Object> object) {
255 AllowDeferredHandleDereference heap_object_check;
256 if (object->IsHeapObject()) {
257 LoadHeapObject(result, Handle<HeapObject>::cast(object));
259 Move(result, Immediate(object));
263 void CmpObject(Register reg, Handle<Object> object) {
264 AllowDeferredHandleDereference heap_object_check;
265 if (object->IsHeapObject()) {
266 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
268 cmp(reg, Immediate(object));
272 // ---------------------------------------------------------------------------
273 // JavaScript invokes
275 // Invoke the JavaScript function code by either calling or jumping.
276 void InvokeCode(Register code,
277 const ParameterCount& expected,
278 const ParameterCount& actual,
280 const CallWrapper& call_wrapper) {
281 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
284 void InvokeCode(const Operand& code,
285 const ParameterCount& expected,
286 const ParameterCount& actual,
288 const CallWrapper& call_wrapper);
290 // Invoke the JavaScript function in the given register. Changes the
291 // current context to the context in the function before invoking.
292 void InvokeFunction(Register function,
293 const ParameterCount& actual,
295 const CallWrapper& call_wrapper);
297 void InvokeFunction(Register function,
298 const ParameterCount& expected,
299 const ParameterCount& actual,
301 const CallWrapper& call_wrapper);
303 void InvokeFunction(Handle<JSFunction> function,
304 const ParameterCount& expected,
305 const ParameterCount& actual,
307 const CallWrapper& call_wrapper);
309 // Invoke specified builtin JavaScript function. Adds an entry to
310 // the unresolved list if the name does not resolve.
311 void InvokeBuiltin(Builtins::JavaScript id,
313 const CallWrapper& call_wrapper = NullCallWrapper());
315 // Store the function for the given builtin in the target register.
316 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
318 // Store the code object for the given builtin in the target register.
319 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
321 // Expression support
322 // Support for constant splitting.
323 bool IsUnsafeImmediate(const Immediate& x);
324 void SafeMove(Register dst, const Immediate& x);
325 void SafePush(const Immediate& x);
327 // Compare object type for heap object.
328 // Incoming register is heap_object and outgoing register is map.
329 void CmpObjectType(Register heap_object, InstanceType type, Register map);
331 // Compare instance type for map.
332 void CmpInstanceType(Register map, InstanceType type);
334 // Check if a map for a JSObject indicates that the object has fast elements.
335 // Jump to the specified label if it does not.
336 void CheckFastElements(Register map,
338 Label::Distance distance = Label::kFar);
340 // Check if a map for a JSObject indicates that the object can have both smi
341 // and HeapObject elements. Jump to the specified label if it does not.
342 void CheckFastObjectElements(Register map,
344 Label::Distance distance = Label::kFar);
346 // Check if a map for a JSObject indicates that the object has fast smi only
347 // elements. Jump to the specified label if it does not.
348 void CheckFastSmiElements(Register map,
350 Label::Distance distance = Label::kFar);
352 // Check to see if maybe_number can be stored as a double in
353 // FastDoubleElements. If it can, store it at the index specified by key in
354 // the FastDoubleElements array elements, otherwise jump to fail.
355 void StoreNumberToDoubleElements(Register maybe_number,
362 // Compare an object's map with the specified map.
363 void CompareMap(Register obj, Handle<Map> map);
365 // Check if the map of an object is equal to a specified map and branch to
366 // label if not. Skip the smi check if not required (object is known to be a
367 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
368 // against maps that are ElementsKind transition maps of the specified map.
369 void CheckMap(Register obj,
372 SmiCheckType smi_check_type);
374 // Check if the map of an object is equal to a specified map and branch to a
375 // specified target if equal. Skip the smi check if not required (object is
376 // known to be a heap object)
377 void DispatchMap(Register obj,
380 Handle<Code> success,
381 SmiCheckType smi_check_type);
383 // Check if the object in register heap_object is a string. Afterwards the
384 // register map contains the object map and the register instance_type
385 // contains the instance_type. The registers map and instance_type can be the
386 // same in which case it contains the instance type afterwards. Either of the
387 // registers map and instance_type can be the same as heap_object.
388 Condition IsObjectStringType(Register heap_object,
390 Register instance_type);
392 // Check if the object in register heap_object is a name. Afterwards the
393 // register map contains the object map and the register instance_type
394 // contains the instance_type. The registers map and instance_type can be the
395 // same in which case it contains the instance type afterwards. Either of the
396 // registers map and instance_type can be the same as heap_object.
397 Condition IsObjectNameType(Register heap_object,
399 Register instance_type);
401 // Check if a heap object's type is in the JSObject range, not including
402 // JSFunction. The object's map will be loaded in the map register.
403 // Any or all of the three registers may be the same.
404 // The contents of the scratch register will always be overwritten.
405 void IsObjectJSObjectType(Register heap_object,
410 // The contents of the scratch register will be overwritten.
411 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
413 // FCmp is similar to integer cmp, but requires unsigned
414 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
417 void ClampUint8(Register reg);
419 void SlowTruncateToI(Register result_reg, Register input_reg,
420 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
422 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
423 void TruncateX87TOSToI(Register result_reg);
425 void X87TOSToI(Register result_reg, MinusZeroMode minus_zero_mode,
426 Label* conversion_failed, Label::Distance dst = Label::kFar);
428 void TaggedToI(Register result_reg, Register input_reg,
429 MinusZeroMode minus_zero_mode, Label* lost_precision);
431 // Smi tagging support.
432 void SmiTag(Register reg) {
433 STATIC_ASSERT(kSmiTag == 0);
434 STATIC_ASSERT(kSmiTagSize == 1);
437 void SmiUntag(Register reg) {
438 sar(reg, kSmiTagSize);
441 // Modifies the register even if it does not contain a Smi!
442 void SmiUntag(Register reg, Label* is_smi) {
443 STATIC_ASSERT(kSmiTagSize == 1);
444 sar(reg, kSmiTagSize);
445 STATIC_ASSERT(kSmiTag == 0);
446 j(not_carry, is_smi);
449 void LoadUint32NoSSE2(Register src);
451 // Jump the register contains a smi.
452 inline void JumpIfSmi(Register value,
454 Label::Distance distance = Label::kFar) {
455 test(value, Immediate(kSmiTagMask));
456 j(zero, smi_label, distance);
458 // Jump if the operand is a smi.
459 inline void JumpIfSmi(Operand value,
461 Label::Distance distance = Label::kFar) {
462 test(value, Immediate(kSmiTagMask));
463 j(zero, smi_label, distance);
465 // Jump if register contain a non-smi.
466 inline void JumpIfNotSmi(Register value,
467 Label* not_smi_label,
468 Label::Distance distance = Label::kFar) {
469 test(value, Immediate(kSmiTagMask));
470 j(not_zero, not_smi_label, distance);
473 void LoadInstanceDescriptors(Register map, Register descriptors);
474 void EnumLength(Register dst, Register map);
475 void NumberOfOwnDescriptors(Register dst, Register map);
477 template<typename Field>
478 void DecodeField(Register reg) {
479 static const int shift = Field::kShift;
480 static const int mask = Field::kMask >> Field::kShift;
484 and_(reg, Immediate(mask));
487 template<typename Field>
488 void DecodeFieldToSmi(Register reg) {
489 static const int shift = Field::kShift;
490 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
491 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
492 STATIC_ASSERT(kSmiTag == 0);
493 if (shift < kSmiTagSize) {
494 shl(reg, kSmiTagSize - shift);
495 } else if (shift > kSmiTagSize) {
496 sar(reg, shift - kSmiTagSize);
498 and_(reg, Immediate(mask));
501 // Abort execution if argument is not a number, enabled via --debug-code.
502 void AssertNumber(Register object);
504 // Abort execution if argument is not a smi, enabled via --debug-code.
505 void AssertSmi(Register object);
507 // Abort execution if argument is a smi, enabled via --debug-code.
508 void AssertNotSmi(Register object);
510 // Abort execution if argument is not a string, enabled via --debug-code.
511 void AssertString(Register object);
513 // Abort execution if argument is not a name, enabled via --debug-code.
514 void AssertName(Register object);
516 // Abort execution if argument is not undefined or an AllocationSite, enabled
518 void AssertUndefinedOrAllocationSite(Register object);
520 // ---------------------------------------------------------------------------
521 // Exception handling
523 // Push a new try handler and link it into try handler chain.
524 void PushTryHandler(StackHandler::Kind kind, int handler_index);
526 // Unlink the stack handler on top of the stack from the try handler chain.
527 void PopTryHandler();
529 // Throw to the top handler in the try hander chain.
530 void Throw(Register value);
532 // Throw past all JS frames to the top JS entry frame.
533 void ThrowUncatchable(Register value);
535 // ---------------------------------------------------------------------------
536 // Inline caching support
538 // Generate code for checking access rights - used for security checks
539 // on access to global objects across environments. The holder register
540 // is left untouched, but the scratch register is clobbered.
541 void CheckAccessGlobalProxy(Register holder_reg,
546 void GetNumberHash(Register r0, Register scratch);
548 void LoadFromNumberDictionary(Label* miss,
557 // ---------------------------------------------------------------------------
558 // Allocation support
560 // Allocate an object in new space or old pointer space. If the given space
561 // is exhausted control continues at the gc_required label. The allocated
562 // object is returned in result and end of the new object is returned in
563 // result_end. The register scratch can be passed as no_reg in which case
564 // an additional object reference will be added to the reloc info. The
565 // returned pointers in result and result_end have not yet been tagged as
566 // heap objects. If result_contains_top_on_entry is true the content of
567 // result is known to be the allocation top on entry (could be result_end
568 // from a previous call). If result_contains_top_on_entry is true scratch
569 // should be no_reg as it is never used.
570 void Allocate(int object_size,
575 AllocationFlags flags);
577 void Allocate(int header_size,
578 ScaleFactor element_size,
579 Register element_count,
580 RegisterValueType element_count_type,
585 AllocationFlags flags);
587 void Allocate(Register object_size,
592 AllocationFlags flags);
594 // Undo allocation in new space. The object passed and objects allocated after
595 // it will no longer be allocated. Make sure that no pointers are left to the
596 // object(s) no longer allocated as they would be invalid when allocation is
598 void UndoAllocationInNewSpace(Register object);
600 // Allocate a heap number in new space with undefined value. The
601 // register scratch2 can be passed as no_reg; the others must be
602 // valid registers. Returns tagged pointer in result register, or
603 // jumps to gc_required if new space is full.
604 void AllocateHeapNumber(Register result,
609 // Allocate a sequential string. All the header fields of the string object
611 void AllocateTwoByteString(Register result,
617 void AllocateAsciiString(Register result,
623 void AllocateAsciiString(Register result,
629 // Allocate a raw cons string object. Only the map field of the result is
631 void AllocateTwoByteConsString(Register result,
635 void AllocateAsciiConsString(Register result,
640 // Allocate a raw sliced string object. Only the map field of the result is
642 void AllocateTwoByteSlicedString(Register result,
646 void AllocateAsciiSlicedString(Register result,
651 // Copy memory, byte-by-byte, from source to destination. Not optimized for
652 // long or aligned copies.
653 // The contents of index and scratch are destroyed.
654 void CopyBytes(Register source,
655 Register destination,
659 // Initialize fields with filler values. Fields starting at |start_offset|
660 // not including end_offset are overwritten with the value in |filler|. At
661 // the end the loop, |start_offset| takes the value of |end_offset|.
662 void InitializeFieldsWithFiller(Register start_offset,
666 // ---------------------------------------------------------------------------
667 // Support functions.
669 // Check a boolean-bit of a Smi field.
670 void BooleanBitTest(Register object, int field_offset, int bit_index);
672 // Check if result is zero and op is negative.
673 void NegativeZeroTest(Register result, Register op, Label* then_label);
675 // Check if result is zero and any of op1 and op2 are negative.
676 // Register scratch is destroyed, and it must be different from op2.
677 void NegativeZeroTest(Register result, Register op1, Register op2,
678 Register scratch, Label* then_label);
680 // Try to get function prototype of a function and puts the value in
681 // the result register. Checks that the function really is a
682 // function and jumps to the miss label if the fast checks fail. The
683 // function register will be untouched; the other registers may be
685 void TryGetFunctionPrototype(Register function,
689 bool miss_on_bound_function = false);
691 // Picks out an array index from the hash field.
693 // hash - holds the index's hash. Clobbered.
694 // index - holds the overwritten index on exit.
695 void IndexFromHash(Register hash, Register index);
697 // ---------------------------------------------------------------------------
700 // Call a code stub. Generate the code if necessary.
701 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
703 // Tail call a code stub (jump). Generate the code if necessary.
704 void TailCallStub(CodeStub* stub);
706 // Return from a code stub after popping its arguments.
707 void StubReturn(int argc);
709 // Call a runtime routine.
710 void CallRuntime(const Runtime::Function* f, int num_arguments);
711 // Convenience function: Same as above, but takes the fid instead.
712 void CallRuntime(Runtime::FunctionId id) {
713 const Runtime::Function* function = Runtime::FunctionForId(id);
714 CallRuntime(function, function->nargs);
716 void CallRuntime(Runtime::FunctionId id, int num_arguments) {
717 CallRuntime(Runtime::FunctionForId(id), num_arguments);
720 // Convenience function: call an external reference.
721 void CallExternalReference(ExternalReference ref, int num_arguments);
723 // Tail call of a runtime routine (jump).
724 // Like JumpToExternalReference, but also takes care of passing the number
726 void TailCallExternalReference(const ExternalReference& ext,
730 // Convenience function: tail call a runtime routine (jump).
731 void TailCallRuntime(Runtime::FunctionId fid,
735 // Before calling a C-function from generated code, align arguments on stack.
736 // After aligning the frame, arguments must be stored in esp[0], esp[4],
737 // etc., not pushed. The argument count assumes all arguments are word sized.
738 // Some compilers/platforms require the stack to be aligned when calling
740 // Needs a scratch register to do some arithmetic. This register will be
742 void PrepareCallCFunction(int num_arguments, Register scratch);
744 // Calls a C function and cleans up the space for arguments allocated
745 // by PrepareCallCFunction. The called function is not allowed to trigger a
746 // garbage collection, since that might move the code and invalidate the
747 // return address (unless this is somehow accounted for by the called
749 void CallCFunction(ExternalReference function, int num_arguments);
750 void CallCFunction(Register function, int num_arguments);
752 // Prepares stack to put arguments (aligns and so on). Reserves
753 // space for return value if needed (assumes the return value is a handle).
754 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
755 // etc. Saves context (esi). If space was reserved for return value then
756 // stores the pointer to the reserved slot into esi.
757 void PrepareCallApiFunction(int argc);
759 // Calls an API function. Allocates HandleScope, extracts returned value
760 // from handle and propagates exceptions. Clobbers ebx, edi and
761 // caller-save registers. Restores context. On return removes
762 // stack_space * kPointerSize (GCed).
763 void CallApiFunctionAndReturn(Register function_address,
764 ExternalReference thunk_ref,
765 Operand thunk_last_arg,
767 Operand return_value_operand,
768 Operand* context_restore_operand);
770 // Jump to a runtime routine.
771 void JumpToExternalReference(const ExternalReference& ext);
773 // ---------------------------------------------------------------------------
778 // Return and drop arguments from stack, where the number of arguments
779 // may be bigger than 2^16 - 1. Requires a scratch register.
780 void Ret(int bytes_dropped, Register scratch);
782 // Emit code to discard a non-negative number of pointer-sized elements
783 // from the stack, clobbering only the esp register.
784 void Drop(int element_count);
786 void Call(Label* target) { call(target); }
787 void Push(Register src) { push(src); }
788 void Pop(Register dst) { pop(dst); }
790 // Emit call to the code we are currently generating.
792 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
793 call(self, RelocInfo::CODE_TARGET);
796 // Move if the registers are not identical.
797 void Move(Register target, Register source);
799 // Move a constant into a destination using the most efficient encoding.
800 void Move(Register dst, const Immediate& x);
801 void Move(const Operand& dst, const Immediate& x);
803 // Push a handle value.
804 void Push(Handle<Object> handle) { push(Immediate(handle)); }
805 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
807 Handle<Object> CodeObject() {
808 ASSERT(!code_object_.is_null());
812 // Insert code to verify that the x87 stack has the specified depth (0-7)
813 void VerifyX87StackDepth(uint32_t depth);
815 // Emit code for a truncating division by a constant. The dividend register is
816 // unchanged, the result is in edx, and eax gets clobbered.
817 void TruncatingDiv(Register dividend, int32_t divisor);
819 // ---------------------------------------------------------------------------
820 // StatsCounter support
822 void SetCounter(StatsCounter* counter, int value);
823 void IncrementCounter(StatsCounter* counter, int value);
824 void DecrementCounter(StatsCounter* counter, int value);
825 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
826 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
829 // ---------------------------------------------------------------------------
832 // Calls Abort(msg) if the condition cc is not satisfied.
833 // Use --debug_code to enable.
834 void Assert(Condition cc, BailoutReason reason);
836 void AssertFastElements(Register elements);
838 // Like Assert(), but always enabled.
839 void Check(Condition cc, BailoutReason reason);
841 // Print a message to stdout and abort execution.
842 void Abort(BailoutReason reason);
844 // Check that the stack is aligned.
845 void CheckStackAlignment();
847 // Verify restrictions about code generated in stubs.
848 void set_generating_stub(bool value) { generating_stub_ = value; }
849 bool generating_stub() { return generating_stub_; }
850 void set_has_frame(bool value) { has_frame_ = value; }
851 bool has_frame() { return has_frame_; }
852 inline bool AllowThisStubCall(CodeStub* stub);
854 // ---------------------------------------------------------------------------
857 // Generate code to do a lookup in the number string cache. If the number in
858 // the register object is found in the cache the generated code falls through
859 // with the result in the result register. The object and the result register
860 // can be the same. If the number is not found in the cache the code jumps to
861 // the label not_found with only the content of register object unchanged.
862 void LookupNumberStringCache(Register object,
868 // Check whether the instance type represents a flat ASCII string. Jump to the
869 // label if not. If the instance type can be scratched specify same register
870 // for both instance type and scratch.
871 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
873 Label* on_not_flat_ascii_string);
875 // Checks if both objects are sequential ASCII strings, and jumps to label
877 void JumpIfNotBothSequentialAsciiStrings(Register object1,
881 Label* on_not_flat_ascii_strings);
883 // Checks if the given register or operand is a unique name
884 void JumpIfNotUniqueName(Register reg, Label* not_unique_name,
885 Label::Distance distance = Label::kFar) {
886 JumpIfNotUniqueName(Operand(reg), not_unique_name, distance);
889 void JumpIfNotUniqueName(Operand operand, Label* not_unique_name,
890 Label::Distance distance = Label::kFar);
892 void EmitSeqStringSetCharCheck(Register string,
895 uint32_t encoding_mask);
897 static int SafepointRegisterStackIndex(Register reg) {
898 return SafepointRegisterStackIndex(reg.code());
901 // Activation support.
902 void EnterFrame(StackFrame::Type type);
903 void LeaveFrame(StackFrame::Type type);
905 // Expects object in eax and returns map with validated enum cache
906 // in eax. Assumes that any other register can be used as a scratch.
907 void CheckEnumCache(Label* call_runtime);
909 // AllocationMemento support. Arrays may have an associated
910 // AllocationMemento object that can be checked for in order to pretransition
912 // On entry, receiver_reg should point to the array object.
913 // scratch_reg gets clobbered.
914 // If allocation info is present, conditional code is set to equal.
915 void TestJSArrayForAllocationMemento(Register receiver_reg,
916 Register scratch_reg,
917 Label* no_memento_found);
919 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
920 Register scratch_reg,
921 Label* memento_found) {
922 Label no_memento_found;
923 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
925 j(equal, memento_found);
926 bind(&no_memento_found);
929 // Jumps to found label if a prototype map has dictionary elements.
930 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
931 Register scratch1, Label* found);
934 bool generating_stub_;
936 // This handle will be patched with the code object on installation.
937 Handle<Object> code_object_;
939 // Helper functions for generating invokes.
940 void InvokePrologue(const ParameterCount& expected,
941 const ParameterCount& actual,
942 Handle<Code> code_constant,
943 const Operand& code_operand,
945 bool* definitely_mismatches,
947 Label::Distance done_distance,
948 const CallWrapper& call_wrapper = NullCallWrapper());
950 void EnterExitFramePrologue();
951 void EnterExitFrameEpilogue(int argc);
953 void LeaveExitFrameEpilogue(bool restore_context);
955 // Allocation support helpers.
956 void LoadAllocationTopHelper(Register result,
958 AllocationFlags flags);
960 void UpdateAllocationTopHelper(Register result_end,
962 AllocationFlags flags);
964 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
965 void InNewSpace(Register object,
968 Label* condition_met,
969 Label::Distance condition_met_distance = Label::kFar);
971 // Helper for finding the mark bits for an address. Afterwards, the
972 // bitmap register points at the word with the mark bits and the mask
973 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
975 inline void GetMarkBits(Register addr_reg,
979 // Helper for throwing exceptions. Compute a handler address and jump to
980 // it. See the implementation for register usage.
981 void JumpToHandlerEntry();
983 // Compute memory operands for safepoint stack slots.
984 Operand SafepointRegisterSlot(Register reg);
985 static int SafepointRegisterStackIndex(int reg_code);
987 // Needs access to SafepointRegisterStackIndex for compiled frame
989 friend class StandardFrame;
993 // The code patcher is used to patch (typically) small parts of code e.g. for
994 // debugging and other types of instrumentation. When using the code patcher
995 // the exact number of bytes specified must be emitted. Is not legal to emit
996 // relocation information. If any of these constraints are violated it causes
1000 CodePatcher(byte* address, int size);
1001 virtual ~CodePatcher();
1003 // Macro assembler to emit code.
1004 MacroAssembler* masm() { return &masm_; }
1007 byte* address_; // The address of the code being patched.
1008 int size_; // Number of bytes of the expected patch size.
1009 MacroAssembler masm_; // Macro assembler used to generate the code.
1013 // -----------------------------------------------------------------------------
1014 // Static helper functions.
1016 // Generate an Operand for loading a field from an object.
1017 inline Operand FieldOperand(Register object, int offset) {
1018 return Operand(object, offset - kHeapObjectTag);
1022 // Generate an Operand for loading an indexed field from an object.
1023 inline Operand FieldOperand(Register object,
1027 return Operand(object, index, scale, offset - kHeapObjectTag);
1031 inline Operand FixedArrayElementOperand(Register array,
1032 Register index_as_smi,
1033 int additional_offset = 0) {
1034 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1035 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1039 inline Operand ContextOperand(Register context, int index) {
1040 return Operand(context, Context::SlotOffset(index));
1044 inline Operand GlobalObjectOperand() {
1045 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1049 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1050 Operand ApiParameterOperand(int index);
1053 #ifdef GENERATED_CODE_COVERAGE
1054 extern void LogGeneratedCodeCoverage(const char* file_line);
1055 #define CODE_COVERAGE_STRINGIFY(x) #x
1056 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1057 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1058 #define ACCESS_MASM(masm) { \
1059 byte* ia32_coverage_function = \
1060 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1063 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1064 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1071 #define ACCESS_MASM(masm) masm->
1075 } } // namespace v8::internal
1077 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_