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/bailout-reason.h"
10 #include "src/frames.h"
11 #include "src/globals.h"
16 // Convenience for platform-independent signatures. We do not normally
17 // distinguish memory operands from other operands on ia32.
18 typedef Operand MemOperand;
20 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
21 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
22 enum PointersToHereCheck {
23 kPointersToHereMaybeInteresting,
24 kPointersToHereAreAlwaysInteresting
28 enum RegisterValueType {
29 REGISTER_VALUE_IS_SMI,
30 REGISTER_VALUE_IS_INT32
35 bool AreAliased(Register reg1,
37 Register reg3 = no_reg,
38 Register reg4 = no_reg,
39 Register reg5 = no_reg,
40 Register reg6 = no_reg,
41 Register reg7 = no_reg,
42 Register reg8 = no_reg);
46 // MacroAssembler implements a collection of frequently used macros.
47 class MacroAssembler: public Assembler {
49 // The isolate parameter can be NULL if the macro assembler should
50 // not use isolate-dependent functionality. In this case, it's the
51 // responsibility of the caller to never invoke such function on the
53 MacroAssembler(Isolate* isolate, void* buffer, int size);
55 void Load(Register dst, const Operand& src, Representation r);
56 void Store(Register src, const Operand& dst, Representation r);
58 // Operations on roots in the root-array.
59 void LoadRoot(Register destination, Heap::RootListIndex index);
60 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
61 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
62 // These methods can only be used with constant roots (i.e. non-writable
63 // and not in new space).
64 void CompareRoot(Register with, Heap::RootListIndex index);
65 void CompareRoot(const Operand& with, Heap::RootListIndex index);
67 // ---------------------------------------------------------------------------
69 enum RememberedSetFinalAction {
74 // Record in the remembered set the fact that we have a pointer to new space
75 // at the address pointed to by the addr register. Only works if addr is not
77 void RememberedSetHelper(Register object, // Used for debug code.
78 Register addr, Register scratch,
79 SaveFPRegsMode save_fp,
80 RememberedSetFinalAction and_then);
82 void CheckPageFlag(Register object,
87 Label::Distance condition_met_distance = Label::kFar);
89 void CheckPageFlagForMap(
94 Label::Distance condition_met_distance = Label::kFar);
96 void CheckMapDeprecated(Handle<Map> map,
98 Label* if_deprecated);
100 // Check if object is in new space. Jumps if the object is not in new space.
101 // The register scratch can be object itself, but scratch will be clobbered.
102 void JumpIfNotInNewSpace(Register object,
105 Label::Distance distance = Label::kFar) {
106 InNewSpace(object, scratch, zero, branch, distance);
109 // Check if object is in new space. Jumps if the object is in new space.
110 // The register scratch can be object itself, but it will be clobbered.
111 void JumpIfInNewSpace(Register object,
114 Label::Distance distance = Label::kFar) {
115 InNewSpace(object, scratch, not_zero, branch, distance);
118 // Check if an object has a given incremental marking color. Also uses ecx!
119 void HasColor(Register object,
123 Label::Distance has_color_distance,
127 void JumpIfBlack(Register object,
131 Label::Distance on_black_distance = Label::kFar);
133 // Checks the color of an object. If the object is already grey or black
134 // then we just fall through, since it is already live. If it is white and
135 // we can determine that it doesn't need to be scanned, then we just mark it
136 // black and fall through. For the rest we jump to the label so the
137 // incremental marker can fix its assumptions.
138 void EnsureNotWhite(Register object,
141 Label* object_is_white_and_not_data,
142 Label::Distance distance);
144 // Notify the garbage collector that we wrote a pointer into an object.
145 // |object| is the object being stored into, |value| is the object being
146 // stored. value and scratch registers are clobbered by the operation.
147 // The offset is the offset from the start of the object, not the offset from
148 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
149 void RecordWriteField(
150 Register object, int offset, Register value, Register scratch,
151 SaveFPRegsMode save_fp,
152 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
153 SmiCheck smi_check = INLINE_SMI_CHECK,
154 PointersToHereCheck pointers_to_here_check_for_value =
155 kPointersToHereMaybeInteresting);
157 // As above, but the offset has the tag presubtracted. For use with
158 // Operand(reg, off).
159 void RecordWriteContextSlot(
160 Register context, int offset, Register value, Register scratch,
161 SaveFPRegsMode save_fp,
162 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
163 SmiCheck smi_check = INLINE_SMI_CHECK,
164 PointersToHereCheck pointers_to_here_check_for_value =
165 kPointersToHereMaybeInteresting) {
166 RecordWriteField(context, offset + kHeapObjectTag, value, scratch, save_fp,
167 remembered_set_action, smi_check,
168 pointers_to_here_check_for_value);
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(
178 Register array, Register value, Register index, SaveFPRegsMode save_fp,
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.
190 Register object, Register address, Register value, SaveFPRegsMode save_fp,
191 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
192 SmiCheck smi_check = INLINE_SMI_CHECK,
193 PointersToHereCheck pointers_to_here_check_for_value =
194 kPointersToHereMaybeInteresting);
196 // For page containing |object| mark the region covering the object's map
197 // dirty. |object| is the object being stored into, |map| is the Map object
199 void RecordWriteForMap(Register object, Handle<Map> map, Register scratch1,
200 Register scratch2, SaveFPRegsMode save_fp);
202 // ---------------------------------------------------------------------------
207 // Generates function and stub prologue code.
209 void Prologue(bool code_pre_aging);
211 // Enter specific kind of exit frame. Expects the number of
212 // arguments in register eax and sets up the number of arguments in
213 // register edi and the pointer to the first argument in register
215 void EnterExitFrame(bool save_doubles);
217 void EnterApiExitFrame(int argc);
219 // Leave the current exit frame. Expects the return value in
220 // register eax:edx (untouched) and the pointer to the first
221 // argument in register esi.
222 void LeaveExitFrame(bool save_doubles);
224 // Leave the current exit frame. Expects the return value in
225 // register eax (untouched).
226 void LeaveApiExitFrame(bool restore_context);
228 // Find the function context up the context chain.
229 void LoadContext(Register dst, int context_chain_length);
231 // Conditionally load the cached Array transitioned map of type
232 // transitioned_kind from the native context if the map in register
233 // map_in_out is the cached Array map in the native context of
235 void LoadTransitionedArrayMapConditional(
236 ElementsKind expected_kind,
237 ElementsKind transitioned_kind,
240 Label* no_map_match);
242 // Load the global function with the given index.
243 void LoadGlobalFunction(int index, Register function);
245 // Load the initial map from the global function. The registers
246 // function and map can be the same.
247 void LoadGlobalFunctionInitialMap(Register function, Register map);
249 // Push and pop the registers that can hold pointers.
250 void PushSafepointRegisters() { pushad(); }
251 void PopSafepointRegisters() { popad(); }
252 // Store the value in register/immediate src in the safepoint
253 // register stack slot for register dst.
254 void StoreToSafepointRegisterSlot(Register dst, Register src);
255 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
256 void LoadFromSafepointRegisterSlot(Register dst, Register src);
258 void LoadHeapObject(Register result, Handle<HeapObject> object);
259 void CmpHeapObject(Register reg, Handle<HeapObject> object);
260 void PushHeapObject(Handle<HeapObject> object);
262 void LoadObject(Register result, Handle<Object> object) {
263 AllowDeferredHandleDereference heap_object_check;
264 if (object->IsHeapObject()) {
265 LoadHeapObject(result, Handle<HeapObject>::cast(object));
267 Move(result, Immediate(object));
271 void CmpObject(Register reg, Handle<Object> object) {
272 AllowDeferredHandleDereference heap_object_check;
273 if (object->IsHeapObject()) {
274 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
276 cmp(reg, Immediate(object));
280 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
281 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
283 // ---------------------------------------------------------------------------
284 // JavaScript invokes
286 // Invoke the JavaScript function code by either calling or jumping.
287 void InvokeCode(Register code,
288 const ParameterCount& expected,
289 const ParameterCount& actual,
291 const CallWrapper& call_wrapper) {
292 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
295 void InvokeCode(const Operand& code,
296 const ParameterCount& expected,
297 const ParameterCount& actual,
299 const CallWrapper& call_wrapper);
301 // Invoke the JavaScript function in the given register. Changes the
302 // current context to the context in the function before invoking.
303 void InvokeFunction(Register function,
304 const ParameterCount& actual,
306 const CallWrapper& call_wrapper);
308 void InvokeFunction(Register function,
309 const ParameterCount& expected,
310 const ParameterCount& actual,
312 const CallWrapper& call_wrapper);
314 void InvokeFunction(Handle<JSFunction> function,
315 const ParameterCount& expected,
316 const ParameterCount& actual,
318 const CallWrapper& call_wrapper);
320 // Invoke specified builtin JavaScript function. Adds an entry to
321 // the unresolved list if the name does not resolve.
322 void InvokeBuiltin(Builtins::JavaScript id,
324 const CallWrapper& call_wrapper = NullCallWrapper());
326 // Store the function for the given builtin in the target register.
327 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
329 // Store the code object for the given builtin in the target register.
330 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
332 // Expression support
333 // Support for constant splitting.
334 bool IsUnsafeImmediate(const Immediate& x);
335 void SafeMove(Register dst, const Immediate& x);
336 void SafePush(const Immediate& x);
338 // Compare object type for heap object.
339 // Incoming register is heap_object and outgoing register is map.
340 void CmpObjectType(Register heap_object, InstanceType type, Register map);
342 // Compare instance type for map.
343 void CmpInstanceType(Register map, InstanceType type);
345 // Check if a map for a JSObject indicates that the object has fast elements.
346 // Jump to the specified label if it does not.
347 void CheckFastElements(Register map,
349 Label::Distance distance = Label::kFar);
351 // Check if a map for a JSObject indicates that the object can have both smi
352 // and HeapObject elements. Jump to the specified label if it does not.
353 void CheckFastObjectElements(Register map,
355 Label::Distance distance = Label::kFar);
357 // Check if a map for a JSObject indicates that the object has fast smi only
358 // elements. Jump to the specified label if it does not.
359 void CheckFastSmiElements(Register map,
361 Label::Distance distance = Label::kFar);
363 // Check to see if maybe_number can be stored as a double in
364 // FastDoubleElements. If it can, store it at the index specified by key in
365 // the FastDoubleElements array elements, otherwise jump to fail.
366 void StoreNumberToDoubleElements(Register maybe_number,
373 // Compare an object's map with the specified map.
374 void CompareMap(Register obj, Handle<Map> map);
376 // Check if the map of an object is equal to a specified map and branch to
377 // label if not. Skip the smi check if not required (object is known to be a
378 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
379 // against maps that are ElementsKind transition maps of the specified map.
380 void CheckMap(Register obj,
383 SmiCheckType smi_check_type);
385 // Check if the map of an object is equal to a specified map and branch to a
386 // specified target if equal. Skip the smi check if not required (object is
387 // known to be a heap object)
388 void DispatchMap(Register obj,
391 Handle<Code> success,
392 SmiCheckType smi_check_type);
394 // Check if the object in register heap_object is a string. Afterwards the
395 // register map contains the object map and the register instance_type
396 // contains the instance_type. The registers map and instance_type can be the
397 // same in which case it contains the instance type afterwards. Either of the
398 // registers map and instance_type can be the same as heap_object.
399 Condition IsObjectStringType(Register heap_object,
401 Register instance_type);
403 // Check if the object in register heap_object is a name. Afterwards the
404 // register map contains the object map and the register instance_type
405 // contains the instance_type. The registers map and instance_type can be the
406 // same in which case it contains the instance type afterwards. Either of the
407 // registers map and instance_type can be the same as heap_object.
408 Condition IsObjectNameType(Register heap_object,
410 Register instance_type);
412 // Check if a heap object's type is in the JSObject range, not including
413 // JSFunction. The object's map will be loaded in the map register.
414 // Any or all of the three registers may be the same.
415 // The contents of the scratch register will always be overwritten.
416 void IsObjectJSObjectType(Register heap_object,
421 // The contents of the scratch register will be overwritten.
422 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
424 // FCmp is similar to integer cmp, but requires unsigned
425 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
427 void FXamMinusZero();
430 void X87SetRC(int rc);
431 void X87SetFPUCW(int cw);
433 void ClampUint8(Register reg);
434 void ClampTOSToUint8(Register result_reg);
436 void SlowTruncateToI(Register result_reg, Register input_reg,
437 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
439 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
440 void TruncateX87TOSToI(Register result_reg);
442 void X87TOSToI(Register result_reg, MinusZeroMode minus_zero_mode,
443 Label* lost_precision, Label* is_nan, Label* minus_zero,
444 Label::Distance dst = Label::kFar);
446 // Smi tagging support.
447 void SmiTag(Register reg) {
448 STATIC_ASSERT(kSmiTag == 0);
449 STATIC_ASSERT(kSmiTagSize == 1);
452 void SmiUntag(Register reg) {
453 sar(reg, kSmiTagSize);
456 // Modifies the register even if it does not contain a Smi!
457 void SmiUntag(Register reg, Label* is_smi) {
458 STATIC_ASSERT(kSmiTagSize == 1);
459 sar(reg, kSmiTagSize);
460 STATIC_ASSERT(kSmiTag == 0);
461 j(not_carry, is_smi);
464 void LoadUint32NoSSE2(Register src) {
465 LoadUint32NoSSE2(Operand(src));
467 void LoadUint32NoSSE2(const Operand& src);
469 // Jump the register contains a smi.
470 inline void JumpIfSmi(Register value,
472 Label::Distance distance = Label::kFar) {
473 test(value, Immediate(kSmiTagMask));
474 j(zero, smi_label, distance);
476 // Jump if the operand is a smi.
477 inline void JumpIfSmi(Operand value,
479 Label::Distance distance = Label::kFar) {
480 test(value, Immediate(kSmiTagMask));
481 j(zero, smi_label, distance);
483 // Jump if register contain a non-smi.
484 inline void JumpIfNotSmi(Register value,
485 Label* not_smi_label,
486 Label::Distance distance = Label::kFar) {
487 test(value, Immediate(kSmiTagMask));
488 j(not_zero, not_smi_label, distance);
491 void LoadInstanceDescriptors(Register map, Register descriptors);
492 void EnumLength(Register dst, Register map);
493 void NumberOfOwnDescriptors(Register dst, Register map);
495 template<typename Field>
496 void DecodeField(Register reg) {
497 static const int shift = Field::kShift;
498 static const int mask = Field::kMask >> Field::kShift;
502 and_(reg, Immediate(mask));
505 template<typename Field>
506 void DecodeFieldToSmi(Register reg) {
507 static const int shift = Field::kShift;
508 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
509 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
510 STATIC_ASSERT(kSmiTag == 0);
511 if (shift < kSmiTagSize) {
512 shl(reg, kSmiTagSize - shift);
513 } else if (shift > kSmiTagSize) {
514 sar(reg, shift - kSmiTagSize);
516 and_(reg, Immediate(mask));
519 // Abort execution if argument is not a number, enabled via --debug-code.
520 void AssertNumber(Register object);
522 // Abort execution if argument is not a smi, enabled via --debug-code.
523 void AssertSmi(Register object);
525 // Abort execution if argument is a smi, enabled via --debug-code.
526 void AssertNotSmi(Register object);
528 // Abort execution if argument is not a string, enabled via --debug-code.
529 void AssertString(Register object);
531 // Abort execution if argument is not a name, enabled via --debug-code.
532 void AssertName(Register object);
534 // Abort execution if argument is not undefined or an AllocationSite, enabled
536 void AssertUndefinedOrAllocationSite(Register object);
538 // ---------------------------------------------------------------------------
539 // Exception handling
541 // Push a new try handler and link it into try handler chain.
542 void PushTryHandler(StackHandler::Kind kind, int handler_index);
544 // Unlink the stack handler on top of the stack from the try handler chain.
545 void PopTryHandler();
547 // Throw to the top handler in the try hander chain.
548 void Throw(Register value);
550 // Throw past all JS frames to the top JS entry frame.
551 void ThrowUncatchable(Register value);
553 // ---------------------------------------------------------------------------
554 // Inline caching support
556 // Generate code for checking access rights - used for security checks
557 // on access to global objects across environments. The holder register
558 // is left untouched, but the scratch register is clobbered.
559 void CheckAccessGlobalProxy(Register holder_reg,
564 void GetNumberHash(Register r0, Register scratch);
566 void LoadFromNumberDictionary(Label* miss,
575 // ---------------------------------------------------------------------------
576 // Allocation support
578 // Allocate an object in new space or old pointer space. If the given space
579 // is exhausted control continues at the gc_required label. The allocated
580 // object is returned in result and end of the new object is returned in
581 // result_end. The register scratch can be passed as no_reg in which case
582 // an additional object reference will be added to the reloc info. The
583 // returned pointers in result and result_end have not yet been tagged as
584 // heap objects. If result_contains_top_on_entry is true the content of
585 // result is known to be the allocation top on entry (could be result_end
586 // from a previous call). If result_contains_top_on_entry is true scratch
587 // should be no_reg as it is never used.
588 void Allocate(int object_size,
593 AllocationFlags flags);
595 void Allocate(int header_size,
596 ScaleFactor element_size,
597 Register element_count,
598 RegisterValueType element_count_type,
603 AllocationFlags flags);
605 void Allocate(Register object_size,
610 AllocationFlags flags);
612 // Undo allocation in new space. The object passed and objects allocated after
613 // it will no longer be allocated. Make sure that no pointers are left to the
614 // object(s) no longer allocated as they would be invalid when allocation is
616 void UndoAllocationInNewSpace(Register object);
618 // Allocate a heap number in new space with undefined value. The
619 // register scratch2 can be passed as no_reg; the others must be
620 // valid registers. Returns tagged pointer in result register, or
621 // jumps to gc_required if new space is full.
622 void AllocateHeapNumber(Register result,
626 MutableMode mode = IMMUTABLE);
628 // Allocate a sequential string. All the header fields of the string object
630 void AllocateTwoByteString(Register result,
636 void AllocateOneByteString(Register result, Register length,
637 Register scratch1, Register scratch2,
638 Register scratch3, Label* gc_required);
639 void AllocateOneByteString(Register result, int length, Register scratch1,
640 Register scratch2, Label* gc_required);
642 // Allocate a raw cons string object. Only the map field of the result is
644 void AllocateTwoByteConsString(Register result,
648 void AllocateOneByteConsString(Register result, Register scratch1,
649 Register scratch2, Label* gc_required);
651 // Allocate a raw sliced string object. Only the map field of the result is
653 void AllocateTwoByteSlicedString(Register result,
657 void AllocateOneByteSlicedString(Register result, Register scratch1,
658 Register scratch2, Label* gc_required);
660 // Copy memory, byte-by-byte, from source to destination. Not optimized for
661 // long or aligned copies.
662 // The contents of index and scratch are destroyed.
663 void CopyBytes(Register source,
664 Register destination,
668 // Initialize fields with filler values. Fields starting at |start_offset|
669 // not including end_offset are overwritten with the value in |filler|. At
670 // the end the loop, |start_offset| takes the value of |end_offset|.
671 void InitializeFieldsWithFiller(Register start_offset,
675 // ---------------------------------------------------------------------------
676 // Support functions.
678 // Check a boolean-bit of a Smi field.
679 void BooleanBitTest(Register object, int field_offset, int bit_index);
681 // Check if result is zero and op is negative.
682 void NegativeZeroTest(Register result, Register op, Label* then_label);
684 // Check if result is zero and any of op1 and op2 are negative.
685 // Register scratch is destroyed, and it must be different from op2.
686 void NegativeZeroTest(Register result, Register op1, Register op2,
687 Register scratch, Label* then_label);
689 // Try to get function prototype of a function and puts the value in
690 // the result register. Checks that the function really is a
691 // function and jumps to the miss label if the fast checks fail. The
692 // function register will be untouched; the other registers may be
694 void TryGetFunctionPrototype(Register function,
698 bool miss_on_bound_function = false);
700 // Picks out an array index from the hash field.
702 // hash - holds the index's hash. Clobbered.
703 // index - holds the overwritten index on exit.
704 void IndexFromHash(Register hash, Register index);
706 // ---------------------------------------------------------------------------
709 // Call a code stub. Generate the code if necessary.
710 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
712 // Tail call a code stub (jump). Generate the code if necessary.
713 void TailCallStub(CodeStub* stub);
715 // Return from a code stub after popping its arguments.
716 void StubReturn(int argc);
718 // Call a runtime routine.
719 void CallRuntime(const Runtime::Function* f, int num_arguments,
720 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
721 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
722 const Runtime::Function* function = Runtime::FunctionForId(id);
723 CallRuntime(function, function->nargs, kSaveFPRegs);
726 // Convenience function: Same as above, but takes the fid instead.
727 void CallRuntime(Runtime::FunctionId id, int num_arguments,
728 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
729 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
732 // Convenience function: call an external reference.
733 void CallExternalReference(ExternalReference ref, int num_arguments);
735 // Tail call of a runtime routine (jump).
736 // Like JumpToExternalReference, but also takes care of passing the number
738 void TailCallExternalReference(const ExternalReference& ext,
742 // Convenience function: tail call a runtime routine (jump).
743 void TailCallRuntime(Runtime::FunctionId fid,
747 // Before calling a C-function from generated code, align arguments on stack.
748 // After aligning the frame, arguments must be stored in esp[0], esp[4],
749 // etc., not pushed. The argument count assumes all arguments are word sized.
750 // Some compilers/platforms require the stack to be aligned when calling
752 // Needs a scratch register to do some arithmetic. This register will be
754 void PrepareCallCFunction(int num_arguments, Register scratch);
756 // Calls a C function and cleans up the space for arguments allocated
757 // by PrepareCallCFunction. The called function is not allowed to trigger a
758 // garbage collection, since that might move the code and invalidate the
759 // return address (unless this is somehow accounted for by the called
761 void CallCFunction(ExternalReference function, int num_arguments);
762 void CallCFunction(Register function, int num_arguments);
764 // Prepares stack to put arguments (aligns and so on). Reserves
765 // space for return value if needed (assumes the return value is a handle).
766 // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1)
767 // etc. Saves context (esi). If space was reserved for return value then
768 // stores the pointer to the reserved slot into esi.
769 void PrepareCallApiFunction(int argc);
771 // Calls an API function. Allocates HandleScope, extracts returned value
772 // from handle and propagates exceptions. Clobbers ebx, edi and
773 // caller-save registers. Restores context. On return removes
774 // stack_space * kPointerSize (GCed).
775 void CallApiFunctionAndReturn(Register function_address,
776 ExternalReference thunk_ref,
777 Operand thunk_last_arg,
779 Operand return_value_operand,
780 Operand* context_restore_operand);
782 // Jump to a runtime routine.
783 void JumpToExternalReference(const ExternalReference& ext);
785 // ---------------------------------------------------------------------------
790 // Return and drop arguments from stack, where the number of arguments
791 // may be bigger than 2^16 - 1. Requires a scratch register.
792 void Ret(int bytes_dropped, Register scratch);
794 // Emit code to discard a non-negative number of pointer-sized elements
795 // from the stack, clobbering only the esp register.
796 void Drop(int element_count);
798 void Call(Label* target) { call(target); }
799 void Push(Register src) { push(src); }
800 void Pop(Register dst) { pop(dst); }
802 // Emit call to the code we are currently generating.
804 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
805 call(self, RelocInfo::CODE_TARGET);
808 // Move if the registers are not identical.
809 void Move(Register target, Register source);
811 // Move a constant into a destination using the most efficient encoding.
812 void Move(Register dst, const Immediate& x);
813 void Move(const Operand& dst, const Immediate& x);
815 // Push a handle value.
816 void Push(Handle<Object> handle) { push(Immediate(handle)); }
817 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
819 Handle<Object> CodeObject() {
820 DCHECK(!code_object_.is_null());
824 // Insert code to verify that the x87 stack has the specified depth (0-7)
825 void VerifyX87StackDepth(uint32_t depth);
827 // Emit code for a truncating division by a constant. The dividend register is
828 // unchanged, the result is in edx, and eax gets clobbered.
829 void TruncatingDiv(Register dividend, int32_t divisor);
831 // ---------------------------------------------------------------------------
832 // StatsCounter support
834 void SetCounter(StatsCounter* counter, int value);
835 void IncrementCounter(StatsCounter* counter, int value);
836 void DecrementCounter(StatsCounter* counter, int value);
837 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
838 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
841 // ---------------------------------------------------------------------------
844 // Calls Abort(msg) if the condition cc is not satisfied.
845 // Use --debug_code to enable.
846 void Assert(Condition cc, BailoutReason reason);
848 void AssertFastElements(Register elements);
850 // Like Assert(), but always enabled.
851 void Check(Condition cc, BailoutReason reason);
853 // Print a message to stdout and abort execution.
854 void Abort(BailoutReason reason);
856 // Check that the stack is aligned.
857 void CheckStackAlignment();
859 // Verify restrictions about code generated in stubs.
860 void set_generating_stub(bool value) { generating_stub_ = value; }
861 bool generating_stub() { return generating_stub_; }
862 void set_has_frame(bool value) { has_frame_ = value; }
863 bool has_frame() { return has_frame_; }
864 inline bool AllowThisStubCall(CodeStub* stub);
866 // ---------------------------------------------------------------------------
869 // Generate code to do a lookup in the number string cache. If the number in
870 // the register object is found in the cache the generated code falls through
871 // with the result in the result register. The object and the result register
872 // can be the same. If the number is not found in the cache the code jumps to
873 // the label not_found with only the content of register object unchanged.
874 void LookupNumberStringCache(Register object,
880 // Check whether the instance type represents a flat one-byte string. Jump to
881 // the label if not. If the instance type can be scratched specify same
882 // register for both instance type and scratch.
883 void JumpIfInstanceTypeIsNotSequentialOneByte(
884 Register instance_type, Register scratch,
885 Label* on_not_flat_one_byte_string);
887 // Checks if both objects are sequential one-byte strings, and jumps to label
889 void JumpIfNotBothSequentialOneByteStrings(
890 Register object1, Register object2, Register scratch1, Register scratch2,
891 Label* on_not_flat_one_byte_strings);
893 // Checks if the given register or operand is a unique name
894 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
895 Label::Distance distance = Label::kFar) {
896 JumpIfNotUniqueNameInstanceType(Operand(reg), not_unique_name, distance);
899 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
900 Label::Distance distance = Label::kFar);
902 void EmitSeqStringSetCharCheck(Register string,
905 uint32_t encoding_mask);
907 static int SafepointRegisterStackIndex(Register reg) {
908 return SafepointRegisterStackIndex(reg.code());
911 // Activation support.
912 void EnterFrame(StackFrame::Type type);
913 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
914 void LeaveFrame(StackFrame::Type type);
916 // Expects object in eax and returns map with validated enum cache
917 // in eax. Assumes that any other register can be used as a scratch.
918 void CheckEnumCache(Label* call_runtime);
920 // AllocationMemento support. Arrays may have an associated
921 // AllocationMemento object that can be checked for in order to pretransition
923 // On entry, receiver_reg should point to the array object.
924 // scratch_reg gets clobbered.
925 // If allocation info is present, conditional code is set to equal.
926 void TestJSArrayForAllocationMemento(Register receiver_reg,
927 Register scratch_reg,
928 Label* no_memento_found);
930 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
931 Register scratch_reg,
932 Label* memento_found) {
933 Label no_memento_found;
934 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
936 j(equal, memento_found);
937 bind(&no_memento_found);
940 // Jumps to found label if a prototype map has dictionary elements.
941 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
942 Register scratch1, Label* found);
945 bool generating_stub_;
947 // This handle will be patched with the code object on installation.
948 Handle<Object> code_object_;
950 // Helper functions for generating invokes.
951 void InvokePrologue(const ParameterCount& expected,
952 const ParameterCount& actual,
953 Handle<Code> code_constant,
954 const Operand& code_operand,
956 bool* definitely_mismatches,
958 Label::Distance done_distance,
959 const CallWrapper& call_wrapper = NullCallWrapper());
961 void EnterExitFramePrologue();
962 void EnterExitFrameEpilogue(int argc, bool save_doubles);
964 void LeaveExitFrameEpilogue(bool restore_context);
966 // Allocation support helpers.
967 void LoadAllocationTopHelper(Register result,
969 AllocationFlags flags);
971 void UpdateAllocationTopHelper(Register result_end,
973 AllocationFlags flags);
975 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
976 void InNewSpace(Register object,
979 Label* condition_met,
980 Label::Distance condition_met_distance = Label::kFar);
982 // Helper for finding the mark bits for an address. Afterwards, the
983 // bitmap register points at the word with the mark bits and the mask
984 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
986 inline void GetMarkBits(Register addr_reg,
990 // Helper for throwing exceptions. Compute a handler address and jump to
991 // it. See the implementation for register usage.
992 void JumpToHandlerEntry();
994 // Compute memory operands for safepoint stack slots.
995 Operand SafepointRegisterSlot(Register reg);
996 static int SafepointRegisterStackIndex(int reg_code);
998 // Needs access to SafepointRegisterStackIndex for compiled frame
1000 friend class StandardFrame;
1004 // The code patcher is used to patch (typically) small parts of code e.g. for
1005 // debugging and other types of instrumentation. When using the code patcher
1006 // the exact number of bytes specified must be emitted. Is not legal to emit
1007 // relocation information. If any of these constraints are violated it causes
1011 CodePatcher(byte* address, int size);
1012 virtual ~CodePatcher();
1014 // Macro assembler to emit code.
1015 MacroAssembler* masm() { return &masm_; }
1018 byte* address_; // The address of the code being patched.
1019 int size_; // Number of bytes of the expected patch size.
1020 MacroAssembler masm_; // Macro assembler used to generate the code.
1024 // -----------------------------------------------------------------------------
1025 // Static helper functions.
1027 // Generate an Operand for loading a field from an object.
1028 inline Operand FieldOperand(Register object, int offset) {
1029 return Operand(object, offset - kHeapObjectTag);
1033 // Generate an Operand for loading an indexed field from an object.
1034 inline Operand FieldOperand(Register object,
1038 return Operand(object, index, scale, offset - kHeapObjectTag);
1042 inline Operand FixedArrayElementOperand(Register array,
1043 Register index_as_smi,
1044 int additional_offset = 0) {
1045 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1046 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1050 inline Operand ContextOperand(Register context, int index) {
1051 return Operand(context, Context::SlotOffset(index));
1055 inline Operand GlobalObjectOperand() {
1056 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1060 // Generates an Operand for saving parameters after PrepareCallApiFunction.
1061 Operand ApiParameterOperand(int index);
1064 #ifdef GENERATED_CODE_COVERAGE
1065 extern void LogGeneratedCodeCoverage(const char* file_line);
1066 #define CODE_COVERAGE_STRINGIFY(x) #x
1067 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1068 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1069 #define ACCESS_MASM(masm) { \
1070 byte* ia32_coverage_function = \
1071 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1074 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1075 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1082 #define ACCESS_MASM(masm) masm->
1086 } } // namespace v8::internal
1088 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_