1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_
29 #define V8_IA32_MACRO_ASSEMBLER_IA32_H_
31 #include "assembler.h"
33 #include "v8globals.h"
38 // Convenience for platform-independent signatures. We do not normally
39 // distinguish memory operands from other operands on ia32.
40 typedef Operand MemOperand;
42 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
43 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
46 enum RegisterValueType {
47 REGISTER_VALUE_IS_SMI,
48 REGISTER_VALUE_IS_INT32
52 bool AreAliased(Register r1, Register r2, Register r3, Register r4);
55 // MacroAssembler implements a collection of frequently used macros.
56 class MacroAssembler: public Assembler {
58 // The isolate parameter can be NULL if the macro assembler should
59 // not use isolate-dependent functionality. In this case, it's the
60 // responsibility of the caller to never invoke such function on the
62 MacroAssembler(Isolate* isolate, void* buffer, int size);
64 // ---------------------------------------------------------------------------
66 enum RememberedSetFinalAction {
71 // Record in the remembered set the fact that we have a pointer to new space
72 // at the address pointed to by the addr register. Only works if addr is not
74 void RememberedSetHelper(Register object, // Used for debug code.
77 SaveFPRegsMode save_fp,
78 RememberedSetFinalAction and_then);
80 void CheckPageFlag(Register object,
85 Label::Distance condition_met_distance = Label::kFar);
87 void CheckPageFlagForMap(
92 Label::Distance condition_met_distance = Label::kFar);
94 // Check if object is in new space. Jumps if the object is not in new space.
95 // The register scratch can be object itself, but scratch will be clobbered.
96 void JumpIfNotInNewSpace(Register object,
99 Label::Distance distance = Label::kFar) {
100 InNewSpace(object, scratch, zero, branch, distance);
103 // Check if object is in new space. Jumps if the object is in new space.
104 // The register scratch can be object itself, but it will be clobbered.
105 void JumpIfInNewSpace(Register object,
108 Label::Distance distance = Label::kFar) {
109 InNewSpace(object, scratch, not_zero, branch, distance);
112 // Check if an object has a given incremental marking color. Also uses ecx!
113 void HasColor(Register object,
117 Label::Distance has_color_distance,
121 void JumpIfBlack(Register object,
125 Label::Distance on_black_distance = Label::kFar);
127 // Checks the color of an object. If the object is already grey or black
128 // then we just fall through, since it is already live. If it is white and
129 // we can determine that it doesn't need to be scanned, then we just mark it
130 // black and fall through. For the rest we jump to the label so the
131 // incremental marker can fix its assumptions.
132 void EnsureNotWhite(Register object,
135 Label* object_is_white_and_not_data,
136 Label::Distance distance);
138 // Notify the garbage collector that we wrote a pointer into an object.
139 // |object| is the object being stored into, |value| is the object being
140 // stored. value and scratch registers are clobbered by the operation.
141 // The offset is the offset from the start of the object, not the offset from
142 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
143 void RecordWriteField(
148 SaveFPRegsMode save_fp,
149 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
150 SmiCheck smi_check = INLINE_SMI_CHECK);
152 // As above, but the offset has the tag presubtracted. For use with
153 // Operand(reg, off).
154 void RecordWriteContextSlot(
159 SaveFPRegsMode save_fp,
160 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
161 SmiCheck smi_check = INLINE_SMI_CHECK) {
162 RecordWriteField(context,
163 offset + kHeapObjectTag,
167 remembered_set_action,
171 // Notify the garbage collector that we wrote a pointer into a fixed array.
172 // |array| is the array being stored into, |value| is the
173 // object being stored. |index| is the array index represented as a
174 // Smi. All registers are clobbered by the operation RecordWriteArray
175 // filters out smis so it does not update the write barrier if the
177 void RecordWriteArray(
181 SaveFPRegsMode save_fp,
182 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
183 SmiCheck smi_check = INLINE_SMI_CHECK);
185 // For page containing |object| mark region covering |address|
186 // dirty. |object| is the object being stored into, |value| is the
187 // object being stored. The address and value registers are clobbered by the
188 // operation. RecordWrite filters out smis so it does not update the
189 // write barrier if the value is a smi.
194 SaveFPRegsMode save_fp,
195 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
196 SmiCheck smi_check = INLINE_SMI_CHECK);
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(
206 SaveFPRegsMode save_fp);
208 #ifdef ENABLE_DEBUGGER_SUPPORT
209 // ---------------------------------------------------------------------------
215 // Enter specific kind of exit frame. Expects the number of
216 // arguments in register eax and sets up the number of arguments in
217 // register edi and the pointer to the first argument in register
219 void EnterExitFrame(bool save_doubles);
221 void EnterApiExitFrame(int argc);
223 // Leave the current exit frame. Expects the return value in
224 // register eax:edx (untouched) and the pointer to the first
225 // argument in register esi.
226 void LeaveExitFrame(bool save_doubles);
228 // Leave the current exit frame. Expects the return value in
229 // register eax (untouched).
230 void LeaveApiExitFrame();
232 // Find the function context up the context chain.
233 void LoadContext(Register dst, int context_chain_length);
235 // Conditionally load the cached Array transitioned map of type
236 // transitioned_kind from the native context if the map in register
237 // map_in_out is the cached Array map in the native context of
239 void LoadTransitionedArrayMapConditional(
240 ElementsKind expected_kind,
241 ElementsKind transitioned_kind,
244 Label* no_map_match);
246 // Load the initial map for new Arrays from a JSFunction.
247 void LoadInitialArrayMap(Register function_in,
250 bool can_have_holes);
252 void LoadGlobalContext(Register global_context);
254 // Load the global function with the given index.
255 void LoadGlobalFunction(int index, Register function);
257 // Load the initial map from the global function. The registers
258 // function and map can be the same.
259 void LoadGlobalFunctionInitialMap(Register function, Register map);
261 // Push and pop the registers that can hold pointers.
262 void PushSafepointRegisters() { pushad(); }
263 void PopSafepointRegisters() { popad(); }
264 // Store the value in register/immediate src in the safepoint
265 // register stack slot for register dst.
266 void StoreToSafepointRegisterSlot(Register dst, Register src);
267 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
268 void LoadFromSafepointRegisterSlot(Register dst, Register src);
270 void LoadHeapObject(Register result, Handle<HeapObject> object);
271 void PushHeapObject(Handle<HeapObject> object);
273 void LoadObject(Register result, Handle<Object> object) {
274 if (object->IsHeapObject()) {
275 LoadHeapObject(result, Handle<HeapObject>::cast(object));
277 Set(result, Immediate(object));
281 // ---------------------------------------------------------------------------
282 // JavaScript invokes
284 // Set up call kind marking in ecx. The method takes ecx as an
285 // explicit first parameter to make the code more readable at the
287 void SetCallKind(Register dst, CallKind kind);
289 // Invoke the JavaScript function code by either calling or jumping.
290 void InvokeCode(Register code,
291 const ParameterCount& expected,
292 const ParameterCount& actual,
294 const CallWrapper& call_wrapper,
295 CallKind call_kind) {
296 InvokeCode(Operand(code), expected, actual, flag, call_wrapper, call_kind);
299 void InvokeCode(const Operand& code,
300 const ParameterCount& expected,
301 const ParameterCount& actual,
303 const CallWrapper& call_wrapper,
306 void InvokeCode(Handle<Code> code,
307 const ParameterCount& expected,
308 const ParameterCount& actual,
309 RelocInfo::Mode rmode,
311 const CallWrapper& call_wrapper,
314 // Invoke the JavaScript function in the given register. Changes the
315 // current context to the context in the function before invoking.
316 void InvokeFunction(Register function,
317 const ParameterCount& actual,
319 const CallWrapper& call_wrapper,
322 void InvokeFunction(Handle<JSFunction> function,
323 const ParameterCount& actual,
325 const CallWrapper& call_wrapper,
328 // Invoke specified builtin JavaScript function. Adds an entry to
329 // the unresolved list if the name does not resolve.
330 void InvokeBuiltin(Builtins::JavaScript id,
332 const CallWrapper& call_wrapper = NullCallWrapper());
334 // Store the function for the given builtin in the target register.
335 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
337 // Store the code object for the given builtin in the target register.
338 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
340 // Expression support
341 void Set(Register dst, const Immediate& x);
342 void Set(const Operand& dst, const Immediate& x);
344 // Support for constant splitting.
345 bool IsUnsafeImmediate(const Immediate& x);
346 void SafeSet(Register dst, const Immediate& x);
347 void SafePush(const Immediate& x);
349 // Compare against a known root, e.g. undefined, null, true, ...
350 void CompareRoot(Register with, Heap::RootListIndex index);
351 void CompareRoot(const Operand& with, Heap::RootListIndex index);
353 // Compare object type for heap object.
354 // Incoming register is heap_object and outgoing register is map.
355 void CmpObjectType(Register heap_object, InstanceType type, Register map);
357 // Compare instance type for map.
358 void CmpInstanceType(Register map, InstanceType type);
360 // Check if a map for a JSObject indicates that the object has fast elements.
361 // Jump to the specified label if it does not.
362 void CheckFastElements(Register map,
364 Label::Distance distance = Label::kFar);
366 // Check if a map for a JSObject indicates that the object can have both smi
367 // and HeapObject elements. Jump to the specified label if it does not.
368 void CheckFastObjectElements(Register map,
370 Label::Distance distance = Label::kFar);
372 // Check if a map for a JSObject indicates that the object has fast smi only
373 // elements. Jump to the specified label if it does not.
374 void CheckFastSmiElements(Register map,
376 Label::Distance distance = Label::kFar);
378 // Check to see if maybe_number can be stored as a double in
379 // FastDoubleElements. If it can, store it at the index specified by key in
380 // the FastDoubleElements array elements, otherwise jump to fail.
381 void StoreNumberToDoubleElements(Register maybe_number,
385 XMMRegister scratch2,
387 bool specialize_for_processor,
390 // Compare an object's map with the specified map and its transitioned
391 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. FLAGS are set with
392 // result of map compare. If multiple map compares are required, the compare
393 // sequences branches to early_success.
394 void CompareMap(Register obj,
396 Label* early_success,
397 CompareMapMode mode = REQUIRE_EXACT_MAP);
399 // Check if the map of an object is equal to a specified map and branch to
400 // label if not. Skip the smi check if not required (object is known to be a
401 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
402 // against maps that are ElementsKind transition maps of the specified map.
403 void CheckMap(Register obj,
406 SmiCheckType smi_check_type,
407 CompareMapMode mode = REQUIRE_EXACT_MAP);
409 // Check if the map of an object is equal to a specified map and branch to a
410 // specified target if equal. Skip the smi check if not required (object is
411 // known to be a heap object)
412 void DispatchMap(Register obj,
415 Handle<Code> success,
416 SmiCheckType smi_check_type);
418 // Check if the object in register heap_object is a string. Afterwards the
419 // register map contains the object map and the register instance_type
420 // contains the instance_type. The registers map and instance_type can be the
421 // same in which case it contains the instance type afterwards. Either of the
422 // registers map and instance_type can be the same as heap_object.
423 Condition IsObjectStringType(Register heap_object,
425 Register instance_type);
427 // Check if the object in register heap_object is a name. Afterwards the
428 // register map contains the object map and the register instance_type
429 // contains the instance_type. The registers map and instance_type can be the
430 // same in which case it contains the instance type afterwards. Either of the
431 // registers map and instance_type can be the same as heap_object.
432 Condition IsObjectNameType(Register heap_object,
434 Register instance_type);
436 // Check if a heap object's type is in the JSObject range, not including
437 // JSFunction. The object's map will be loaded in the map register.
438 // Any or all of the three registers may be the same.
439 // The contents of the scratch register will always be overwritten.
440 void IsObjectJSObjectType(Register heap_object,
445 // The contents of the scratch register will be overwritten.
446 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
448 // FCmp is similar to integer cmp, but requires unsigned
449 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
452 void ClampUint8(Register reg);
454 void ClampDoubleToUint8(XMMRegister input_reg,
455 XMMRegister scratch_reg,
456 Register result_reg);
459 // Smi tagging support.
460 void SmiTag(Register reg) {
461 STATIC_ASSERT(kSmiTag == 0);
462 STATIC_ASSERT(kSmiTagSize == 1);
465 void SmiUntag(Register reg) {
466 sar(reg, kSmiTagSize);
469 // Modifies the register even if it does not contain a Smi!
470 void SmiUntag(Register reg, Label* is_smi) {
471 STATIC_ASSERT(kSmiTagSize == 1);
472 sar(reg, kSmiTagSize);
473 STATIC_ASSERT(kSmiTag == 0);
474 j(not_carry, is_smi);
477 void LoadUint32(XMMRegister dst, Register src, XMMRegister scratch);
479 // Jump the register contains a smi.
480 inline void JumpIfSmi(Register value,
482 Label::Distance distance = Label::kFar) {
483 test(value, Immediate(kSmiTagMask));
484 j(zero, smi_label, distance);
486 // Jump if the operand is a smi.
487 inline void JumpIfSmi(Operand value,
489 Label::Distance distance = Label::kFar) {
490 test(value, Immediate(kSmiTagMask));
491 j(zero, smi_label, distance);
493 // Jump if register contain a non-smi.
494 inline void JumpIfNotSmi(Register value,
495 Label* not_smi_label,
496 Label::Distance distance = Label::kFar) {
497 test(value, Immediate(kSmiTagMask));
498 j(not_zero, not_smi_label, distance);
501 void LoadInstanceDescriptors(Register map, Register descriptors);
502 void EnumLength(Register dst, Register map);
503 void NumberOfOwnDescriptors(Register dst, Register map);
505 template<typename Field>
506 void DecodeField(Register reg) {
507 static const int shift = Field::kShift;
508 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
510 and_(reg, Immediate(mask));
512 void LoadPowerOf2(XMMRegister dst, Register scratch, int power);
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 // ---------------------------------------------------------------------------
530 // Exception handling
532 // Push a new try handler and link it into try handler chain.
533 void PushTryHandler(StackHandler::Kind kind, int handler_index);
535 // Unlink the stack handler on top of the stack from the try handler chain.
536 void PopTryHandler();
538 // Throw to the top handler in the try hander chain.
539 void Throw(Register value);
541 // Throw past all JS frames to the top JS entry frame.
542 void ThrowUncatchable(Register value);
544 // ---------------------------------------------------------------------------
545 // Inline caching support
547 // Generate code for checking access rights - used for security checks
548 // on access to global objects across environments. The holder register
549 // is left untouched, but the scratch register is clobbered.
550 void CheckAccessGlobalProxy(Register holder_reg,
554 void GetNumberHash(Register r0, Register scratch);
556 void LoadFromNumberDictionary(Label* miss,
565 // ---------------------------------------------------------------------------
566 // Allocation support
568 // Allocate an object in new space or old pointer space. If the given space
569 // is exhausted control continues at the gc_required label. The allocated
570 // object is returned in result and end of the new object is returned in
571 // result_end. The register scratch can be passed as no_reg in which case
572 // an additional object reference will be added to the reloc info. The
573 // returned pointers in result and result_end have not yet been tagged as
574 // heap objects. If result_contains_top_on_entry is true the content of
575 // result is known to be the allocation top on entry (could be result_end
576 // from a previous call). If result_contains_top_on_entry is true scratch
577 // should be no_reg as it is never used.
578 void Allocate(int object_size,
583 AllocationFlags flags);
585 void Allocate(int header_size,
586 ScaleFactor element_size,
587 Register element_count,
588 RegisterValueType element_count_type,
593 AllocationFlags flags);
595 void Allocate(Register object_size,
600 AllocationFlags flags);
602 // Undo allocation in new space. The object passed and objects allocated after
603 // it will no longer be allocated. Make sure that no pointers are left to the
604 // object(s) no longer allocated as they would be invalid when allocation is
606 void UndoAllocationInNewSpace(Register object);
608 // Allocate a heap number in new space with undefined value. The
609 // register scratch2 can be passed as no_reg; the others must be
610 // valid registers. Returns tagged pointer in result register, or
611 // jumps to gc_required if new space is full.
612 void AllocateHeapNumber(Register result,
617 // Allocate a sequential string. All the header fields of the string object
619 void AllocateTwoByteString(Register result,
625 void AllocateAsciiString(Register result,
631 void AllocateAsciiString(Register result,
637 // Allocate a raw cons string object. Only the map field of the result is
639 void AllocateTwoByteConsString(Register result,
643 void AllocateAsciiConsString(Register result,
648 // Allocate a raw sliced string object. Only the map field of the result is
650 void AllocateTwoByteSlicedString(Register result,
654 void AllocateAsciiSlicedString(Register result,
659 // Copy memory, byte-by-byte, from source to destination. Not optimized for
660 // long or aligned copies.
661 // The contents of index and scratch are destroyed.
662 void CopyBytes(Register source,
663 Register destination,
667 // Initialize fields with filler values. Fields starting at |start_offset|
668 // not including end_offset are overwritten with the value in |filler|. At
669 // the end the loop, |start_offset| takes the value of |end_offset|.
670 void InitializeFieldsWithFiller(Register start_offset,
674 // ---------------------------------------------------------------------------
675 // Support functions.
677 // Check a boolean-bit of a Smi field.
678 void BooleanBitTest(Register object, int field_offset, int bit_index);
680 // Check if result is zero and op is negative.
681 void NegativeZeroTest(Register result, Register op, Label* then_label);
683 // Check if result is zero and any of op1 and op2 are negative.
684 // Register scratch is destroyed, and it must be different from op2.
685 void NegativeZeroTest(Register result, Register op1, Register op2,
686 Register scratch, Label* then_label);
688 // Try to get function prototype of a function and puts the value in
689 // the result register. Checks that the function really is a
690 // function and jumps to the miss label if the fast checks fail. The
691 // function register will be untouched; the other registers may be
693 void TryGetFunctionPrototype(Register function,
697 bool miss_on_bound_function = false);
699 // Generates code for reporting that an illegal operation has
701 void IllegalOperation(int num_arguments);
703 // Picks out an array index from the hash field.
705 // hash - holds the index's hash. Clobbered.
706 // index - holds the overwritten index on exit.
707 void IndexFromHash(Register hash, Register index);
709 // ---------------------------------------------------------------------------
712 // Call a code stub. Generate the code if necessary.
713 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
715 // Tail call a code stub (jump). Generate the code if necessary.
716 void TailCallStub(CodeStub* stub);
718 // Return from a code stub after popping its arguments.
719 void StubReturn(int argc);
721 // Call a runtime routine.
722 void CallRuntime(const Runtime::Function* f, int num_arguments);
723 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
725 // Convenience function: Same as above, but takes the fid instead.
726 void CallRuntime(Runtime::FunctionId id, int num_arguments);
728 // Convenience function: call an external reference.
729 void CallExternalReference(ExternalReference ref, int num_arguments);
731 // Tail call of a runtime routine (jump).
732 // Like JumpToExternalReference, but also takes care of passing the number
734 void TailCallExternalReference(const ExternalReference& ext,
738 // Convenience function: tail call a runtime routine (jump).
739 void TailCallRuntime(Runtime::FunctionId fid,
743 // Before calling a C-function from generated code, align arguments on stack.
744 // After aligning the frame, arguments must be stored in esp[0], esp[4],
745 // etc., not pushed. The argument count assumes all arguments are word sized.
746 // Some compilers/platforms require the stack to be aligned when calling
748 // Needs a scratch register to do some arithmetic. This register will be
750 void PrepareCallCFunction(int num_arguments, Register scratch);
752 // Calls a C function and cleans up the space for arguments allocated
753 // by PrepareCallCFunction. The called function is not allowed to trigger a
754 // garbage collection, since that might move the code and invalidate the
755 // return address (unless this is somehow accounted for by the called
757 void CallCFunction(ExternalReference function, int num_arguments);
758 void CallCFunction(Register function, int num_arguments);
760 // Prepares stack to put arguments (aligns and so on). Reserves
761 // space for return value if needed (assumes the return value is a handle).
762 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
763 // etc. Saves context (esi). If space was reserved for return value then
764 // stores the pointer to the reserved slot into esi.
765 void PrepareCallApiFunction(int argc);
767 // Calls an API function. Allocates HandleScope, extracts returned value
768 // from handle and propagates exceptions. Clobbers ebx, edi and
769 // caller-save registers. Restores context. On return removes
770 // stack_space * kPointerSize (GCed).
771 void CallApiFunctionAndReturn(Address function_address, int stack_space);
773 // Jump to a runtime routine.
774 void JumpToExternalReference(const ExternalReference& ext);
776 // ---------------------------------------------------------------------------
781 // Return and drop arguments from stack, where the number of arguments
782 // may be bigger than 2^16 - 1. Requires a scratch register.
783 void Ret(int bytes_dropped, Register scratch);
785 // Emit code to discard a non-negative number of pointer-sized elements
786 // from the stack, clobbering only the esp register.
787 void Drop(int element_count);
789 void Call(Label* target) { call(target); }
791 // Emit call to the code we are currently generating.
793 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
794 call(self, RelocInfo::CODE_TARGET);
797 // Move if the registers are not identical.
798 void Move(Register target, Register source);
800 // Push a handle value.
801 void Push(Handle<Object> handle) { push(Immediate(handle)); }
802 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
804 Handle<Object> CodeObject() {
805 ASSERT(!code_object_.is_null());
810 // ---------------------------------------------------------------------------
811 // StatsCounter support
813 void SetCounter(StatsCounter* counter, int value);
814 void IncrementCounter(StatsCounter* counter, int value);
815 void DecrementCounter(StatsCounter* counter, int value);
816 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
817 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
820 // ---------------------------------------------------------------------------
823 // Calls Abort(msg) if the condition cc is not satisfied.
824 // Use --debug_code to enable.
825 void Assert(Condition cc, const char* msg);
827 void AssertFastElements(Register elements);
829 // Like Assert(), but always enabled.
830 void Check(Condition cc, const char* msg);
832 // Print a message to stdout and abort execution.
833 void Abort(const char* msg);
835 // Check that the stack is aligned.
836 void CheckStackAlignment();
838 // Verify restrictions about code generated in stubs.
839 void set_generating_stub(bool value) { generating_stub_ = value; }
840 bool generating_stub() { return generating_stub_; }
841 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
842 bool allow_stub_calls() { return allow_stub_calls_; }
843 void set_has_frame(bool value) { has_frame_ = value; }
844 bool has_frame() { return has_frame_; }
845 inline bool AllowThisStubCall(CodeStub* stub);
847 // ---------------------------------------------------------------------------
850 // Check whether the instance type represents a flat ASCII string. Jump to the
851 // label if not. If the instance type can be scratched specify same register
852 // for both instance type and scratch.
853 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
855 Label* on_not_flat_ascii_string);
857 // Checks if both objects are sequential ASCII strings, and jumps to label
859 void JumpIfNotBothSequentialAsciiStrings(Register object1,
863 Label* on_not_flat_ascii_strings);
865 static int SafepointRegisterStackIndex(Register reg) {
866 return SafepointRegisterStackIndex(reg.code());
869 // Activation support.
870 void EnterFrame(StackFrame::Type type);
871 void LeaveFrame(StackFrame::Type type);
873 // Expects object in eax and returns map with validated enum cache
874 // in eax. Assumes that any other register can be used as a scratch.
875 void CheckEnumCache(Label* call_runtime);
877 // AllocationSiteInfo support. Arrays may have an associated
878 // AllocationSiteInfo object that can be checked for in order to pretransition
880 // On entry, receiver_reg should point to the array object.
881 // scratch_reg gets clobbered.
882 // If allocation info is present, conditional code is set to equal
883 void TestJSArrayForAllocationSiteInfo(Register receiver_reg,
884 Register scratch_reg);
887 bool generating_stub_;
888 bool allow_stub_calls_;
890 // This handle will be patched with the code object on installation.
891 Handle<Object> code_object_;
893 // Helper functions for generating invokes.
894 void InvokePrologue(const ParameterCount& expected,
895 const ParameterCount& actual,
896 Handle<Code> code_constant,
897 const Operand& code_operand,
899 bool* definitely_mismatches,
901 Label::Distance done_distance,
902 const CallWrapper& call_wrapper = NullCallWrapper(),
903 CallKind call_kind = CALL_AS_METHOD);
905 void EnterExitFramePrologue();
906 void EnterExitFrameEpilogue(int argc, bool save_doubles);
908 void LeaveExitFrameEpilogue();
910 // Allocation support helpers.
911 void LoadAllocationTopHelper(Register result,
913 AllocationFlags flags);
915 void UpdateAllocationTopHelper(Register result_end,
917 AllocationFlags flags);
919 // Helper for PopHandleScope. Allowed to perform a GC and returns
920 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
921 // possibly returns a failure object indicating an allocation failure.
922 MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved,
926 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
927 void InNewSpace(Register object,
930 Label* condition_met,
931 Label::Distance condition_met_distance = Label::kFar);
933 // Helper for finding the mark bits for an address. Afterwards, the
934 // bitmap register points at the word with the mark bits and the mask
935 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
937 inline void GetMarkBits(Register addr_reg,
941 // Helper for throwing exceptions. Compute a handler address and jump to
942 // it. See the implementation for register usage.
943 void JumpToHandlerEntry();
945 // Compute memory operands for safepoint stack slots.
946 Operand SafepointRegisterSlot(Register reg);
947 static int SafepointRegisterStackIndex(int reg_code);
949 // Needs access to SafepointRegisterStackIndex for compiled frame
951 friend class StandardFrame;
955 // The code patcher is used to patch (typically) small parts of code e.g. for
956 // debugging and other types of instrumentation. When using the code patcher
957 // the exact number of bytes specified must be emitted. Is not legal to emit
958 // relocation information. If any of these constraints are violated it causes
962 CodePatcher(byte* address, int size);
963 virtual ~CodePatcher();
965 // Macro assembler to emit code.
966 MacroAssembler* masm() { return &masm_; }
969 byte* address_; // The address of the code being patched.
970 int size_; // Number of bytes of the expected patch size.
971 MacroAssembler masm_; // Macro assembler used to generate the code.
975 // -----------------------------------------------------------------------------
976 // Static helper functions.
978 // Generate an Operand for loading a field from an object.
979 inline Operand FieldOperand(Register object, int offset) {
980 return Operand(object, offset - kHeapObjectTag);
984 // Generate an Operand for loading an indexed field from an object.
985 inline Operand FieldOperand(Register object,
989 return Operand(object, index, scale, offset - kHeapObjectTag);
993 inline Operand ContextOperand(Register context, int index) {
994 return Operand(context, Context::SlotOffset(index));
998 inline Operand GlobalObjectOperand() {
999 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1003 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1004 Operand ApiParameterOperand(int index);
1007 #ifdef GENERATED_CODE_COVERAGE
1008 extern void LogGeneratedCodeCoverage(const char* file_line);
1009 #define CODE_COVERAGE_STRINGIFY(x) #x
1010 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1011 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1012 #define ACCESS_MASM(masm) { \
1013 byte* ia32_coverage_function = \
1014 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1017 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1018 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1025 #define ACCESS_MASM(masm) masm->
1029 } } // namespace v8::internal
1031 #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_