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
33 bool AreAliased(Register r1, Register r2, Register r3, Register r4);
36 // MacroAssembler implements a collection of frequently used macros.
37 class MacroAssembler: public Assembler {
39 // The isolate parameter can be NULL if the macro assembler should
40 // not use isolate-dependent functionality. In this case, it's the
41 // responsibility of the caller to never invoke such function on the
43 MacroAssembler(Isolate* isolate, void* buffer, int size);
45 void Load(Register dst, const Operand& src, Representation r);
46 void Store(Register src, const Operand& dst, Representation r);
48 // Operations on roots in the root-array.
49 void LoadRoot(Register destination, Heap::RootListIndex index);
50 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
51 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
52 // These methods can only be used with constant roots (i.e. non-writable
53 // and not in new space).
54 void CompareRoot(Register with, Heap::RootListIndex index);
55 void CompareRoot(const Operand& with, Heap::RootListIndex index);
57 // ---------------------------------------------------------------------------
59 enum RememberedSetFinalAction {
64 // Record in the remembered set the fact that we have a pointer to new space
65 // at the address pointed to by the addr register. Only works if addr is not
67 void RememberedSetHelper(Register object, // Used for debug code.
70 RememberedSetFinalAction and_then);
72 void CheckPageFlag(Register object,
77 Label::Distance condition_met_distance = Label::kFar);
79 void CheckPageFlagForMap(
84 Label::Distance condition_met_distance = Label::kFar);
86 void CheckMapDeprecated(Handle<Map> map,
88 Label* if_deprecated);
90 // Check if object is in new space. Jumps if the object is not in new space.
91 // The register scratch can be object itself, but scratch will be clobbered.
92 void JumpIfNotInNewSpace(Register object,
95 Label::Distance distance = Label::kFar) {
96 InNewSpace(object, scratch, zero, branch, distance);
99 // Check if object is in new space. Jumps if the object is in new space.
100 // The register scratch can be object itself, but it will be clobbered.
101 void JumpIfInNewSpace(Register object,
104 Label::Distance distance = Label::kFar) {
105 InNewSpace(object, scratch, not_zero, branch, distance);
108 // Check if an object has a given incremental marking color. Also uses ecx!
109 void HasColor(Register object,
113 Label::Distance has_color_distance,
117 void JumpIfBlack(Register object,
121 Label::Distance on_black_distance = Label::kFar);
123 // Checks the color of an object. If the object is already grey or black
124 // then we just fall through, since it is already live. If it is white and
125 // we can determine that it doesn't need to be scanned, then we just mark it
126 // black and fall through. For the rest we jump to the label so the
127 // incremental marker can fix its assumptions.
128 void EnsureNotWhite(Register object,
131 Label* object_is_white_and_not_data,
132 Label::Distance distance);
134 // Notify the garbage collector that we wrote a pointer into an object.
135 // |object| is the object being stored into, |value| is the object being
136 // stored. value and scratch registers are clobbered by the operation.
137 // The offset is the offset from the start of the object, not the offset from
138 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
139 void RecordWriteField(
144 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
145 SmiCheck smi_check = INLINE_SMI_CHECK,
146 PointersToHereCheck pointers_to_here_check_for_value =
147 kPointersToHereMaybeInteresting);
149 // As above, but the offset has the tag presubtracted. For use with
150 // Operand(reg, off).
151 void RecordWriteContextSlot(
156 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
157 SmiCheck smi_check = INLINE_SMI_CHECK,
158 PointersToHereCheck pointers_to_here_check_for_value =
159 kPointersToHereMaybeInteresting) {
160 RecordWriteField(context,
161 offset + kHeapObjectTag,
164 remembered_set_action,
166 pointers_to_here_check_for_value);
169 // Notify the garbage collector that we wrote a pointer into a fixed array.
170 // |array| is the array being stored into, |value| is the
171 // object being stored. |index| is the array index represented as a
172 // Smi. All registers are clobbered by the operation RecordWriteArray
173 // filters out smis so it does not update the write barrier if the
175 void RecordWriteArray(
179 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
180 SmiCheck smi_check = INLINE_SMI_CHECK,
181 PointersToHereCheck pointers_to_here_check_for_value =
182 kPointersToHereMaybeInteresting);
184 // For page containing |object| mark region covering |address|
185 // dirty. |object| is the object being stored into, |value| is the
186 // object being stored. The address and value registers are clobbered by the
187 // operation. RecordWrite filters out smis so it does not update the
188 // write barrier if the value is a smi.
193 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
194 SmiCheck smi_check = INLINE_SMI_CHECK,
195 PointersToHereCheck pointers_to_here_check_for_value =
196 kPointersToHereMaybeInteresting);
198 // For page containing |object| mark the region covering the object's map
199 // dirty. |object| is the object being stored into, |map| is the Map object
201 void RecordWriteForMap(
207 // ---------------------------------------------------------------------------
212 // Generates function and stub prologue code.
214 void Prologue(bool code_pre_aging);
216 // Enter specific kind of exit frame. Expects the number of
217 // arguments in register eax and sets up the number of arguments in
218 // register edi and the pointer to the first argument in register
220 void EnterExitFrame();
222 void EnterApiExitFrame(int argc);
224 // Leave the current exit frame. Expects the return value in
225 // register eax:edx (untouched) and the pointer to the first
226 // argument in register esi.
227 void LeaveExitFrame();
229 // Leave the current exit frame. Expects the return value in
230 // register eax (untouched).
231 void LeaveApiExitFrame(bool restore_context);
233 // Find the function context up the context chain.
234 void LoadContext(Register dst, int context_chain_length);
236 // Conditionally load the cached Array transitioned map of type
237 // transitioned_kind from the native context if the map in register
238 // map_in_out is the cached Array map in the native context of
240 void LoadTransitionedArrayMapConditional(
241 ElementsKind expected_kind,
242 ElementsKind transitioned_kind,
245 Label* no_map_match);
247 // Load the global function with the given index.
248 void LoadGlobalFunction(int index, Register function);
250 // Load the initial map from the global function. The registers
251 // function and map can be the same.
252 void LoadGlobalFunctionInitialMap(Register function, Register map);
254 // Push and pop the registers that can hold pointers.
255 void PushSafepointRegisters() { pushad(); }
256 void PopSafepointRegisters() { popad(); }
257 // Store the value in register/immediate src in the safepoint
258 // register stack slot for register dst.
259 void StoreToSafepointRegisterSlot(Register dst, Register src);
260 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
261 void LoadFromSafepointRegisterSlot(Register dst, Register src);
263 void LoadHeapObject(Register result, Handle<HeapObject> object);
264 void CmpHeapObject(Register reg, Handle<HeapObject> object);
265 void PushHeapObject(Handle<HeapObject> object);
267 void LoadObject(Register result, Handle<Object> object) {
268 AllowDeferredHandleDereference heap_object_check;
269 if (object->IsHeapObject()) {
270 LoadHeapObject(result, Handle<HeapObject>::cast(object));
272 Move(result, Immediate(object));
276 void CmpObject(Register reg, Handle<Object> object) {
277 AllowDeferredHandleDereference heap_object_check;
278 if (object->IsHeapObject()) {
279 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
281 cmp(reg, Immediate(object));
285 // ---------------------------------------------------------------------------
286 // JavaScript invokes
288 // Invoke the JavaScript function code by either calling or jumping.
289 void InvokeCode(Register code,
290 const ParameterCount& expected,
291 const ParameterCount& actual,
293 const CallWrapper& call_wrapper) {
294 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
297 void InvokeCode(const Operand& code,
298 const ParameterCount& expected,
299 const ParameterCount& actual,
301 const CallWrapper& call_wrapper);
303 // Invoke the JavaScript function in the given register. Changes the
304 // current context to the context in the function before invoking.
305 void InvokeFunction(Register function,
306 const ParameterCount& actual,
308 const CallWrapper& call_wrapper);
310 void InvokeFunction(Register function,
311 const ParameterCount& expected,
312 const ParameterCount& actual,
314 const CallWrapper& call_wrapper);
316 void InvokeFunction(Handle<JSFunction> function,
317 const ParameterCount& expected,
318 const ParameterCount& actual,
320 const CallWrapper& call_wrapper);
322 // Invoke specified builtin JavaScript function. Adds an entry to
323 // the unresolved list if the name does not resolve.
324 void InvokeBuiltin(Builtins::JavaScript id,
326 const CallWrapper& call_wrapper = NullCallWrapper());
328 // Store the function for the given builtin in the target register.
329 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
331 // Store the code object for the given builtin in the target register.
332 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
334 // Expression support
335 // Support for constant splitting.
336 bool IsUnsafeImmediate(const Immediate& x);
337 void SafeMove(Register dst, const Immediate& x);
338 void SafePush(const Immediate& x);
340 // Compare object type for heap object.
341 // Incoming register is heap_object and outgoing register is map.
342 void CmpObjectType(Register heap_object, InstanceType type, Register map);
344 // Compare instance type for map.
345 void CmpInstanceType(Register map, InstanceType type);
347 // Check if a map for a JSObject indicates that the object has fast elements.
348 // Jump to the specified label if it does not.
349 void CheckFastElements(Register map,
351 Label::Distance distance = Label::kFar);
353 // Check if a map for a JSObject indicates that the object can have both smi
354 // and HeapObject elements. Jump to the specified label if it does not.
355 void CheckFastObjectElements(Register map,
357 Label::Distance distance = Label::kFar);
359 // Check if a map for a JSObject indicates that the object has fast smi only
360 // elements. Jump to the specified label if it does not.
361 void CheckFastSmiElements(Register map,
363 Label::Distance distance = Label::kFar);
365 // Check to see if maybe_number can be stored as a double in
366 // FastDoubleElements. If it can, store it at the index specified by key in
367 // the FastDoubleElements array elements, otherwise jump to fail.
368 void StoreNumberToDoubleElements(Register maybe_number,
375 // Compare an object's map with the specified map.
376 void CompareMap(Register obj, Handle<Map> map);
378 // Check if the map of an object is equal to a specified map and branch to
379 // label if not. Skip the smi check if not required (object is known to be a
380 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
381 // against maps that are ElementsKind transition maps of the specified map.
382 void CheckMap(Register obj,
385 SmiCheckType smi_check_type);
387 // Check if the map of an object is equal to a specified map and branch to a
388 // specified target if equal. Skip the smi check if not required (object is
389 // known to be a heap object)
390 void DispatchMap(Register obj,
393 Handle<Code> success,
394 SmiCheckType smi_check_type);
396 // Check if the object in register heap_object is a string. Afterwards the
397 // register map contains the object map and the register instance_type
398 // contains the instance_type. The registers map and instance_type can be the
399 // same in which case it contains the instance type afterwards. Either of the
400 // registers map and instance_type can be the same as heap_object.
401 Condition IsObjectStringType(Register heap_object,
403 Register instance_type);
405 // Check if the object in register heap_object is a name. 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 IsObjectNameType(Register heap_object,
412 Register instance_type);
414 // Check if a heap object's type is in the JSObject range, not including
415 // JSFunction. The object's map will be loaded in the map register.
416 // Any or all of the three registers may be the same.
417 // The contents of the scratch register will always be overwritten.
418 void IsObjectJSObjectType(Register heap_object,
423 // The contents of the scratch register will be overwritten.
424 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
426 // FCmp is similar to integer cmp, but requires unsigned
427 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
430 void ClampUint8(Register reg);
432 void SlowTruncateToI(Register result_reg, Register input_reg,
433 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
435 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
436 void TruncateX87TOSToI(Register result_reg);
438 void X87TOSToI(Register result_reg, MinusZeroMode minus_zero_mode,
439 Label* conversion_failed, Label::Distance dst = Label::kFar);
441 void TaggedToI(Register result_reg, Register input_reg,
442 MinusZeroMode minus_zero_mode, Label* lost_precision);
444 // Smi tagging support.
445 void SmiTag(Register reg) {
446 STATIC_ASSERT(kSmiTag == 0);
447 STATIC_ASSERT(kSmiTagSize == 1);
450 void SmiUntag(Register reg) {
451 sar(reg, kSmiTagSize);
454 // Modifies the register even if it does not contain a Smi!
455 void SmiUntag(Register reg, Label* is_smi) {
456 STATIC_ASSERT(kSmiTagSize == 1);
457 sar(reg, kSmiTagSize);
458 STATIC_ASSERT(kSmiTag == 0);
459 j(not_carry, is_smi);
462 void LoadUint32NoSSE2(Register src);
464 // Jump the register contains a smi.
465 inline void JumpIfSmi(Register value,
467 Label::Distance distance = Label::kFar) {
468 test(value, Immediate(kSmiTagMask));
469 j(zero, smi_label, distance);
471 // Jump if the operand is a smi.
472 inline void JumpIfSmi(Operand value,
474 Label::Distance distance = Label::kFar) {
475 test(value, Immediate(kSmiTagMask));
476 j(zero, smi_label, distance);
478 // Jump if register contain a non-smi.
479 inline void JumpIfNotSmi(Register value,
480 Label* not_smi_label,
481 Label::Distance distance = Label::kFar) {
482 test(value, Immediate(kSmiTagMask));
483 j(not_zero, not_smi_label, distance);
486 void LoadInstanceDescriptors(Register map, Register descriptors);
487 void EnumLength(Register dst, Register map);
488 void NumberOfOwnDescriptors(Register dst, Register map);
490 template<typename Field>
491 void DecodeField(Register reg) {
492 static const int shift = Field::kShift;
493 static const int mask = Field::kMask >> Field::kShift;
497 and_(reg, Immediate(mask));
500 template<typename Field>
501 void DecodeFieldToSmi(Register reg) {
502 static const int shift = Field::kShift;
503 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
504 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
505 STATIC_ASSERT(kSmiTag == 0);
506 if (shift < kSmiTagSize) {
507 shl(reg, kSmiTagSize - shift);
508 } else if (shift > kSmiTagSize) {
509 sar(reg, shift - kSmiTagSize);
511 and_(reg, Immediate(mask));
514 // Abort execution if argument is not a number, enabled via --debug-code.
515 void AssertNumber(Register object);
517 // Abort execution if argument is not a smi, enabled via --debug-code.
518 void AssertSmi(Register object);
520 // Abort execution if argument is a smi, enabled via --debug-code.
521 void AssertNotSmi(Register object);
523 // Abort execution if argument is not a string, enabled via --debug-code.
524 void AssertString(Register object);
526 // Abort execution if argument is not a name, enabled via --debug-code.
527 void AssertName(Register object);
529 // Abort execution if argument is not undefined or an AllocationSite, enabled
531 void AssertUndefinedOrAllocationSite(Register object);
533 // ---------------------------------------------------------------------------
534 // Exception handling
536 // Push a new try handler and link it into try handler chain.
537 void PushTryHandler(StackHandler::Kind kind, int handler_index);
539 // Unlink the stack handler on top of the stack from the try handler chain.
540 void PopTryHandler();
542 // Throw to the top handler in the try hander chain.
543 void Throw(Register value);
545 // Throw past all JS frames to the top JS entry frame.
546 void ThrowUncatchable(Register value);
548 // ---------------------------------------------------------------------------
549 // Inline caching support
551 // Generate code for checking access rights - used for security checks
552 // on access to global objects across environments. The holder register
553 // is left untouched, but the scratch register is clobbered.
554 void CheckAccessGlobalProxy(Register holder_reg,
559 void GetNumberHash(Register r0, Register scratch);
561 void LoadFromNumberDictionary(Label* miss,
570 // ---------------------------------------------------------------------------
571 // Allocation support
573 // Allocate an object in new space or old pointer space. If the given space
574 // is exhausted control continues at the gc_required label. The allocated
575 // object is returned in result and end of the new object is returned in
576 // result_end. The register scratch can be passed as no_reg in which case
577 // an additional object reference will be added to the reloc info. The
578 // returned pointers in result and result_end have not yet been tagged as
579 // heap objects. If result_contains_top_on_entry is true the content of
580 // result is known to be the allocation top on entry (could be result_end
581 // from a previous call). If result_contains_top_on_entry is true scratch
582 // should be no_reg as it is never used.
583 void Allocate(int object_size,
588 AllocationFlags flags);
590 void Allocate(int header_size,
591 ScaleFactor element_size,
592 Register element_count,
593 RegisterValueType element_count_type,
598 AllocationFlags flags);
600 void Allocate(Register object_size,
605 AllocationFlags flags);
607 // Undo allocation in new space. The object passed and objects allocated after
608 // it will no longer be allocated. Make sure that no pointers are left to the
609 // object(s) no longer allocated as they would be invalid when allocation is
611 void UndoAllocationInNewSpace(Register object);
613 // Allocate a heap number in new space with undefined value. The
614 // register scratch2 can be passed as no_reg; the others must be
615 // valid registers. Returns tagged pointer in result register, or
616 // jumps to gc_required if new space is full.
617 void AllocateHeapNumber(Register result,
621 MutableMode mode = IMMUTABLE);
623 // Allocate a sequential string. All the header fields of the string object
625 void AllocateTwoByteString(Register result,
631 void AllocateAsciiString(Register result,
637 void AllocateAsciiString(Register result,
643 // Allocate a raw cons string object. Only the map field of the result is
645 void AllocateTwoByteConsString(Register result,
649 void AllocateAsciiConsString(Register result,
654 // Allocate a raw sliced string object. Only the map field of the result is
656 void AllocateTwoByteSlicedString(Register result,
660 void AllocateAsciiSlicedString(Register result,
665 // Copy memory, byte-by-byte, from source to destination. Not optimized for
666 // long or aligned copies.
667 // The contents of index and scratch are destroyed.
668 void CopyBytes(Register source,
669 Register destination,
673 // Initialize fields with filler values. Fields starting at |start_offset|
674 // not including end_offset are overwritten with the value in |filler|. At
675 // the end the loop, |start_offset| takes the value of |end_offset|.
676 void InitializeFieldsWithFiller(Register start_offset,
680 // ---------------------------------------------------------------------------
681 // Support functions.
683 // Check a boolean-bit of a Smi field.
684 void BooleanBitTest(Register object, int field_offset, int bit_index);
686 // Check if result is zero and op is negative.
687 void NegativeZeroTest(Register result, Register op, Label* then_label);
689 // Check if result is zero and any of op1 and op2 are negative.
690 // Register scratch is destroyed, and it must be different from op2.
691 void NegativeZeroTest(Register result, Register op1, Register op2,
692 Register scratch, Label* then_label);
694 // Try to get function prototype of a function and puts the value in
695 // the result register. Checks that the function really is a
696 // function and jumps to the miss label if the fast checks fail. The
697 // function register will be untouched; the other registers may be
699 void TryGetFunctionPrototype(Register function,
703 bool miss_on_bound_function = false);
705 // Picks out an array index from the hash field.
707 // hash - holds the index's hash. Clobbered.
708 // index - holds the overwritten index on exit.
709 void IndexFromHash(Register hash, Register index);
711 // ---------------------------------------------------------------------------
714 // Call a code stub. Generate the code if necessary.
715 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
717 // Tail call a code stub (jump). Generate the code if necessary.
718 void TailCallStub(CodeStub* stub);
720 // Return from a code stub after popping its arguments.
721 void StubReturn(int argc);
723 // Call a runtime routine.
724 void CallRuntime(const Runtime::Function* f, int num_arguments);
725 // Convenience function: Same as above, but takes the fid instead.
726 void CallRuntime(Runtime::FunctionId id) {
727 const Runtime::Function* function = Runtime::FunctionForId(id);
728 CallRuntime(function, function->nargs);
730 void CallRuntime(Runtime::FunctionId id, int num_arguments) {
731 CallRuntime(Runtime::FunctionForId(id), num_arguments);
734 // Convenience function: call an external reference.
735 void CallExternalReference(ExternalReference ref, int num_arguments);
737 // Tail call of a runtime routine (jump).
738 // Like JumpToExternalReference, but also takes care of passing the number
740 void TailCallExternalReference(const ExternalReference& ext,
744 // Convenience function: tail call a runtime routine (jump).
745 void TailCallRuntime(Runtime::FunctionId fid,
749 // Before calling a C-function from generated code, align arguments on stack.
750 // After aligning the frame, arguments must be stored in esp[0], esp[4],
751 // etc., not pushed. The argument count assumes all arguments are word sized.
752 // Some compilers/platforms require the stack to be aligned when calling
754 // Needs a scratch register to do some arithmetic. This register will be
756 void PrepareCallCFunction(int num_arguments, Register scratch);
758 // Calls a C function and cleans up the space for arguments allocated
759 // by PrepareCallCFunction. The called function is not allowed to trigger a
760 // garbage collection, since that might move the code and invalidate the
761 // return address (unless this is somehow accounted for by the called
763 void CallCFunction(ExternalReference function, int num_arguments);
764 void CallCFunction(Register function, int num_arguments);
766 // Prepares stack to put arguments (aligns and so on). Reserves
767 // space for return value if needed (assumes the return value is a handle).
768 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
769 // etc. Saves context (esi). If space was reserved for return value then
770 // stores the pointer to the reserved slot into esi.
771 void PrepareCallApiFunction(int argc);
773 // Calls an API function. Allocates HandleScope, extracts returned value
774 // from handle and propagates exceptions. Clobbers ebx, edi and
775 // caller-save registers. Restores context. On return removes
776 // stack_space * kPointerSize (GCed).
777 void CallApiFunctionAndReturn(Register function_address,
778 ExternalReference thunk_ref,
779 Operand thunk_last_arg,
781 Operand return_value_operand,
782 Operand* context_restore_operand);
784 // Jump to a runtime routine.
785 void JumpToExternalReference(const ExternalReference& ext);
787 // ---------------------------------------------------------------------------
792 // Return and drop arguments from stack, where the number of arguments
793 // may be bigger than 2^16 - 1. Requires a scratch register.
794 void Ret(int bytes_dropped, Register scratch);
796 // Emit code to discard a non-negative number of pointer-sized elements
797 // from the stack, clobbering only the esp register.
798 void Drop(int element_count);
800 void Call(Label* target) { call(target); }
801 void Push(Register src) { push(src); }
802 void Pop(Register dst) { pop(dst); }
804 // Emit call to the code we are currently generating.
806 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
807 call(self, RelocInfo::CODE_TARGET);
810 // Move if the registers are not identical.
811 void Move(Register target, Register source);
813 // Move a constant into a destination using the most efficient encoding.
814 void Move(Register dst, const Immediate& x);
815 void Move(const Operand& dst, const Immediate& x);
817 // Push a handle value.
818 void Push(Handle<Object> handle) { push(Immediate(handle)); }
819 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
821 Handle<Object> CodeObject() {
822 ASSERT(!code_object_.is_null());
826 // Insert code to verify that the x87 stack has the specified depth (0-7)
827 void VerifyX87StackDepth(uint32_t depth);
829 // Emit code for a truncating division by a constant. The dividend register is
830 // unchanged, the result is in edx, and eax gets clobbered.
831 void TruncatingDiv(Register dividend, int32_t divisor);
833 // ---------------------------------------------------------------------------
834 // StatsCounter support
836 void SetCounter(StatsCounter* counter, int value);
837 void IncrementCounter(StatsCounter* counter, int value);
838 void DecrementCounter(StatsCounter* counter, int value);
839 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
840 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
843 // ---------------------------------------------------------------------------
846 // Calls Abort(msg) if the condition cc is not satisfied.
847 // Use --debug_code to enable.
848 void Assert(Condition cc, BailoutReason reason);
850 void AssertFastElements(Register elements);
852 // Like Assert(), but always enabled.
853 void Check(Condition cc, BailoutReason reason);
855 // Print a message to stdout and abort execution.
856 void Abort(BailoutReason reason);
858 // Check that the stack is aligned.
859 void CheckStackAlignment();
861 // Verify restrictions about code generated in stubs.
862 void set_generating_stub(bool value) { generating_stub_ = value; }
863 bool generating_stub() { return generating_stub_; }
864 void set_has_frame(bool value) { has_frame_ = value; }
865 bool has_frame() { return has_frame_; }
866 inline bool AllowThisStubCall(CodeStub* stub);
868 // ---------------------------------------------------------------------------
871 // Generate code to do a lookup in the number string cache. If the number in
872 // the register object is found in the cache the generated code falls through
873 // with the result in the result register. The object and the result register
874 // can be the same. If the number is not found in the cache the code jumps to
875 // the label not_found with only the content of register object unchanged.
876 void LookupNumberStringCache(Register object,
882 // Check whether the instance type represents a flat ASCII string. Jump to the
883 // label if not. If the instance type can be scratched specify same register
884 // for both instance type and scratch.
885 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
887 Label* on_not_flat_ascii_string);
889 // Checks if both objects are sequential ASCII strings, and jumps to label
891 void JumpIfNotBothSequentialAsciiStrings(Register object1,
895 Label* on_not_flat_ascii_strings);
897 // Checks if the given register or operand is a unique name
898 void JumpIfNotUniqueName(Register reg, Label* not_unique_name,
899 Label::Distance distance = Label::kFar) {
900 JumpIfNotUniqueName(Operand(reg), not_unique_name, distance);
903 void JumpIfNotUniqueName(Operand operand, Label* not_unique_name,
904 Label::Distance distance = Label::kFar);
906 void EmitSeqStringSetCharCheck(Register string,
909 uint32_t encoding_mask);
911 static int SafepointRegisterStackIndex(Register reg) {
912 return SafepointRegisterStackIndex(reg.code());
915 // Activation support.
916 void EnterFrame(StackFrame::Type type);
917 void LeaveFrame(StackFrame::Type type);
919 // Expects object in eax and returns map with validated enum cache
920 // in eax. Assumes that any other register can be used as a scratch.
921 void CheckEnumCache(Label* call_runtime);
923 // AllocationMemento support. Arrays may have an associated
924 // AllocationMemento object that can be checked for in order to pretransition
926 // On entry, receiver_reg should point to the array object.
927 // scratch_reg gets clobbered.
928 // If allocation info is present, conditional code is set to equal.
929 void TestJSArrayForAllocationMemento(Register receiver_reg,
930 Register scratch_reg,
931 Label* no_memento_found);
933 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
934 Register scratch_reg,
935 Label* memento_found) {
936 Label no_memento_found;
937 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
939 j(equal, memento_found);
940 bind(&no_memento_found);
943 // Jumps to found label if a prototype map has dictionary elements.
944 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
945 Register scratch1, Label* found);
948 bool generating_stub_;
950 // This handle will be patched with the code object on installation.
951 Handle<Object> code_object_;
953 // Helper functions for generating invokes.
954 void InvokePrologue(const ParameterCount& expected,
955 const ParameterCount& actual,
956 Handle<Code> code_constant,
957 const Operand& code_operand,
959 bool* definitely_mismatches,
961 Label::Distance done_distance,
962 const CallWrapper& call_wrapper = NullCallWrapper());
964 void EnterExitFramePrologue();
965 void EnterExitFrameEpilogue(int argc);
967 void LeaveExitFrameEpilogue(bool restore_context);
969 // Allocation support helpers.
970 void LoadAllocationTopHelper(Register result,
972 AllocationFlags flags);
974 void UpdateAllocationTopHelper(Register result_end,
976 AllocationFlags flags);
978 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
979 void InNewSpace(Register object,
982 Label* condition_met,
983 Label::Distance condition_met_distance = Label::kFar);
985 // Helper for finding the mark bits for an address. Afterwards, the
986 // bitmap register points at the word with the mark bits and the mask
987 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
989 inline void GetMarkBits(Register addr_reg,
993 // Helper for throwing exceptions. Compute a handler address and jump to
994 // it. See the implementation for register usage.
995 void JumpToHandlerEntry();
997 // Compute memory operands for safepoint stack slots.
998 Operand SafepointRegisterSlot(Register reg);
999 static int SafepointRegisterStackIndex(int reg_code);
1001 // Needs access to SafepointRegisterStackIndex for compiled frame
1003 friend class StandardFrame;
1007 // The code patcher is used to patch (typically) small parts of code e.g. for
1008 // debugging and other types of instrumentation. When using the code patcher
1009 // the exact number of bytes specified must be emitted. Is not legal to emit
1010 // relocation information. If any of these constraints are violated it causes
1014 CodePatcher(byte* address, int size);
1015 virtual ~CodePatcher();
1017 // Macro assembler to emit code.
1018 MacroAssembler* masm() { return &masm_; }
1021 byte* address_; // The address of the code being patched.
1022 int size_; // Number of bytes of the expected patch size.
1023 MacroAssembler masm_; // Macro assembler used to generate the code.
1027 // -----------------------------------------------------------------------------
1028 // Static helper functions.
1030 // Generate an Operand for loading a field from an object.
1031 inline Operand FieldOperand(Register object, int offset) {
1032 return Operand(object, offset - kHeapObjectTag);
1036 // Generate an Operand for loading an indexed field from an object.
1037 inline Operand FieldOperand(Register object,
1041 return Operand(object, index, scale, offset - kHeapObjectTag);
1045 inline Operand FixedArrayElementOperand(Register array,
1046 Register index_as_smi,
1047 int additional_offset = 0) {
1048 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1049 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1053 inline Operand ContextOperand(Register context, int index) {
1054 return Operand(context, Context::SlotOffset(index));
1058 inline Operand GlobalObjectOperand() {
1059 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1063 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1064 Operand ApiParameterOperand(int index);
1067 #ifdef GENERATED_CODE_COVERAGE
1068 extern void LogGeneratedCodeCoverage(const char* file_line);
1069 #define CODE_COVERAGE_STRINGIFY(x) #x
1070 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1071 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1072 #define ACCESS_MASM(masm) { \
1073 byte* ia32_coverage_function = \
1074 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1077 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1078 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1085 #define ACCESS_MASM(masm) masm->
1089 } } // namespace v8::internal
1091 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_