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 // Give alias names to registers for calling conventions.
17 const Register kReturnRegister0 = {kRegister_eax_Code};
18 const Register kReturnRegister1 = {kRegister_edx_Code};
19 const Register kJSFunctionRegister = {kRegister_edi_Code};
20 const Register kContextRegister = {kRegister_esi_Code};
21 const Register kInterpreterAccumulatorRegister = {kRegister_eax_Code};
22 const Register kInterpreterRegisterFileRegister = {kRegister_edx_Code};
23 const Register kInterpreterBytecodeOffsetRegister = {kRegister_ecx_Code};
24 const Register kInterpreterBytecodeArrayRegister = {kRegister_edi_Code};
25 const Register kInterpreterDispatchTableRegister = {kRegister_ebx_Code};
26 const Register kRuntimeCallFunctionRegister = {kRegister_ebx_Code};
27 const Register kRuntimeCallArgCountRegister = {kRegister_eax_Code};
29 // Convenience for platform-independent signatures. We do not normally
30 // distinguish memory operands from other operands on ia32.
31 typedef Operand MemOperand;
33 enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
34 enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
35 enum PointersToHereCheck {
36 kPointersToHereMaybeInteresting,
37 kPointersToHereAreAlwaysInteresting
41 enum RegisterValueType {
42 REGISTER_VALUE_IS_SMI,
43 REGISTER_VALUE_IS_INT32
48 bool AreAliased(Register reg1,
50 Register reg3 = no_reg,
51 Register reg4 = no_reg,
52 Register reg5 = no_reg,
53 Register reg6 = no_reg,
54 Register reg7 = no_reg,
55 Register reg8 = no_reg);
59 // MacroAssembler implements a collection of frequently used macros.
60 class MacroAssembler: public Assembler {
62 // The isolate parameter can be NULL if the macro assembler should
63 // not use isolate-dependent functionality. In this case, it's the
64 // responsibility of the caller to never invoke such function on the
66 MacroAssembler(Isolate* isolate, void* buffer, int size);
68 void Load(Register dst, const Operand& src, Representation r);
69 void Store(Register src, const Operand& dst, Representation r);
71 // Operations on roots in the root-array.
72 void LoadRoot(Register destination, Heap::RootListIndex index);
73 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
74 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
75 // These methods can only be used with constant roots (i.e. non-writable
76 // and not in new space).
77 void CompareRoot(Register with, Heap::RootListIndex index);
78 void CompareRoot(const Operand& with, Heap::RootListIndex index);
80 // ---------------------------------------------------------------------------
82 enum RememberedSetFinalAction {
87 // Record in the remembered set the fact that we have a pointer to new space
88 // at the address pointed to by the addr register. Only works if addr is not
90 void RememberedSetHelper(Register object, // Used for debug code.
91 Register addr, Register scratch,
92 SaveFPRegsMode save_fp,
93 RememberedSetFinalAction and_then);
95 void CheckPageFlag(Register object,
100 Label::Distance condition_met_distance = Label::kFar);
102 void CheckPageFlagForMap(
106 Label* condition_met,
107 Label::Distance condition_met_distance = Label::kFar);
109 // Check if object is in new space. Jumps if the object is not in new space.
110 // The register scratch can be object itself, but scratch will be clobbered.
111 void JumpIfNotInNewSpace(Register object,
114 Label::Distance distance = Label::kFar) {
115 InNewSpace(object, scratch, zero, branch, distance);
118 // Check if object is in new space. Jumps if the object is in new space.
119 // The register scratch can be object itself, but it will be clobbered.
120 void JumpIfInNewSpace(Register object,
123 Label::Distance distance = Label::kFar) {
124 InNewSpace(object, scratch, not_zero, branch, distance);
127 // Check if an object has a given incremental marking color. Also uses ecx!
128 void HasColor(Register object,
132 Label::Distance has_color_distance,
136 void JumpIfBlack(Register object,
140 Label::Distance on_black_distance = Label::kFar);
142 // Checks the color of an object. If the object is already grey or black
143 // then we just fall through, since it is already live. If it is white and
144 // we can determine that it doesn't need to be scanned, then we just mark it
145 // black and fall through. For the rest we jump to the label so the
146 // incremental marker can fix its assumptions.
147 void EnsureNotWhite(Register object,
150 Label* object_is_white_and_not_data,
151 Label::Distance distance);
153 // Notify the garbage collector that we wrote a pointer into an object.
154 // |object| is the object being stored into, |value| is the object being
155 // stored. value and scratch registers are clobbered by the operation.
156 // The offset is the offset from the start of the object, not the offset from
157 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
158 void RecordWriteField(
159 Register object, int offset, Register value, Register scratch,
160 SaveFPRegsMode save_fp,
161 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
162 SmiCheck smi_check = INLINE_SMI_CHECK,
163 PointersToHereCheck pointers_to_here_check_for_value =
164 kPointersToHereMaybeInteresting);
166 // As above, but the offset has the tag presubtracted. For use with
167 // Operand(reg, off).
168 void RecordWriteContextSlot(
169 Register context, int offset, Register value, Register scratch,
170 SaveFPRegsMode save_fp,
171 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
172 SmiCheck smi_check = INLINE_SMI_CHECK,
173 PointersToHereCheck pointers_to_here_check_for_value =
174 kPointersToHereMaybeInteresting) {
175 RecordWriteField(context, offset + kHeapObjectTag, value, scratch, save_fp,
176 remembered_set_action, smi_check,
177 pointers_to_here_check_for_value);
180 // Notify the garbage collector that we wrote a pointer into a fixed array.
181 // |array| is the array being stored into, |value| is the
182 // object being stored. |index| is the array index represented as a
183 // Smi. All registers are clobbered by the operation RecordWriteArray
184 // filters out smis so it does not update the write barrier if the
186 void RecordWriteArray(
187 Register array, Register value, Register index, SaveFPRegsMode save_fp,
188 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
189 SmiCheck smi_check = INLINE_SMI_CHECK,
190 PointersToHereCheck pointers_to_here_check_for_value =
191 kPointersToHereMaybeInteresting);
193 // For page containing |object| mark region covering |address|
194 // dirty. |object| is the object being stored into, |value| is the
195 // object being stored. The address and value registers are clobbered by the
196 // operation. RecordWrite filters out smis so it does not update the
197 // write barrier if the value is a smi.
199 Register object, Register address, Register value, SaveFPRegsMode save_fp,
200 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
201 SmiCheck smi_check = INLINE_SMI_CHECK,
202 PointersToHereCheck pointers_to_here_check_for_value =
203 kPointersToHereMaybeInteresting);
205 // For page containing |object| mark the region covering the object's map
206 // dirty. |object| is the object being stored into, |map| is the Map object
208 void RecordWriteForMap(Register object, Handle<Map> map, Register scratch1,
209 Register scratch2, SaveFPRegsMode save_fp);
211 // ---------------------------------------------------------------------------
216 // Generates function and stub prologue code.
218 void Prologue(bool code_pre_aging);
220 // Enter specific kind of exit frame. Expects the number of
221 // arguments in register eax and sets up the number of arguments in
222 // register edi and the pointer to the first argument in register
224 void EnterExitFrame(bool save_doubles);
226 void EnterApiExitFrame(int argc);
228 // Leave the current exit frame. Expects the return value in
229 // register eax:edx (untouched) and the pointer to the first
230 // argument in register esi.
231 void LeaveExitFrame(bool save_doubles);
233 // Leave the current exit frame. Expects the return value in
234 // register eax (untouched).
235 void LeaveApiExitFrame(bool restore_context);
237 // Find the function context up the context chain.
238 void LoadContext(Register dst, int context_chain_length);
240 // Conditionally load the cached Array transitioned map of type
241 // transitioned_kind from the native context if the map in register
242 // map_in_out is the cached Array map in the native context of
244 void LoadTransitionedArrayMapConditional(
245 ElementsKind expected_kind,
246 ElementsKind transitioned_kind,
249 Label* no_map_match);
251 // Load the global function with the given index.
252 void LoadGlobalFunction(int index, Register function);
254 // Load the initial map from the global function. The registers
255 // function and map can be the same.
256 void LoadGlobalFunctionInitialMap(Register function, Register map);
258 // Push and pop the registers that can hold pointers.
259 void PushSafepointRegisters() { pushad(); }
260 void PopSafepointRegisters() { popad(); }
261 // Store the value in register/immediate src in the safepoint
262 // register stack slot for register dst.
263 void StoreToSafepointRegisterSlot(Register dst, Register src);
264 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
265 void LoadFromSafepointRegisterSlot(Register dst, Register src);
267 void LoadHeapObject(Register result, Handle<HeapObject> object);
268 void CmpHeapObject(Register reg, Handle<HeapObject> object);
269 void PushHeapObject(Handle<HeapObject> object);
271 void LoadObject(Register result, Handle<Object> object) {
272 AllowDeferredHandleDereference heap_object_check;
273 if (object->IsHeapObject()) {
274 LoadHeapObject(result, Handle<HeapObject>::cast(object));
276 Move(result, Immediate(object));
280 void CmpObject(Register reg, Handle<Object> object) {
281 AllowDeferredHandleDereference heap_object_check;
282 if (object->IsHeapObject()) {
283 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
285 cmp(reg, Immediate(object));
289 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
290 void GetWeakValue(Register value, Handle<WeakCell> cell);
291 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
293 // ---------------------------------------------------------------------------
294 // JavaScript invokes
296 // Invoke the JavaScript function code by either calling or jumping.
297 void InvokeCode(Register code,
298 const ParameterCount& expected,
299 const ParameterCount& actual,
301 const CallWrapper& call_wrapper) {
302 InvokeCode(Operand(code), expected, actual, flag, call_wrapper);
305 void InvokeCode(const Operand& code,
306 const ParameterCount& expected,
307 const ParameterCount& actual,
309 const CallWrapper& call_wrapper);
311 // Invoke the JavaScript function in the given register. Changes the
312 // current context to the context in the function before invoking.
313 void InvokeFunction(Register function,
314 const ParameterCount& actual,
316 const CallWrapper& call_wrapper);
318 void InvokeFunction(Register function,
319 const ParameterCount& expected,
320 const ParameterCount& actual,
322 const CallWrapper& call_wrapper);
324 void InvokeFunction(Handle<JSFunction> function,
325 const ParameterCount& expected,
326 const ParameterCount& actual,
328 const CallWrapper& call_wrapper);
330 // Invoke specified builtin JavaScript function. Adds an entry to
331 // the unresolved list if the name does not resolve.
332 void InvokeBuiltin(Builtins::JavaScript id,
334 const CallWrapper& call_wrapper = NullCallWrapper());
336 // Store the function for the given builtin in the target register.
337 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
339 // Store the code object for the given builtin in the target register.
340 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
342 // Expression support
343 // Support for constant splitting.
344 bool IsUnsafeImmediate(const Immediate& x);
345 void SafeMove(Register dst, const Immediate& x);
346 void SafePush(const Immediate& x);
348 // Compare object type for heap object.
349 // Incoming register is heap_object and outgoing register is map.
350 void CmpObjectType(Register heap_object, InstanceType type, Register map);
352 // Compare instance type for map.
353 void CmpInstanceType(Register map, InstanceType type);
355 // Check if a map for a JSObject indicates that the object has fast elements.
356 // Jump to the specified label if it does not.
357 void CheckFastElements(Register map,
359 Label::Distance distance = Label::kFar);
361 // Check if a map for a JSObject indicates that the object can have both smi
362 // and HeapObject elements. Jump to the specified label if it does not.
363 void CheckFastObjectElements(Register map,
365 Label::Distance distance = Label::kFar);
367 // Check if a map for a JSObject indicates that the object has fast smi only
368 // elements. Jump to the specified label if it does not.
369 void CheckFastSmiElements(Register map,
371 Label::Distance distance = Label::kFar);
373 // Check to see if maybe_number can be stored as a double in
374 // FastDoubleElements. If it can, store it at the index specified by key in
375 // the FastDoubleElements array elements, otherwise jump to fail.
376 void StoreNumberToDoubleElements(Register maybe_number,
383 // Compare an object's map with the specified map.
384 void CompareMap(Register obj, Handle<Map> map);
386 // Check if the map of an object is equal to a specified map and branch to
387 // label if not. Skip the smi check if not required (object is known to be a
388 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
389 // against maps that are ElementsKind transition maps of the specified map.
390 void CheckMap(Register obj,
393 SmiCheckType smi_check_type);
395 // Check if the map of an object is equal to a specified weak map and branch
396 // to a specified target if equal. Skip the smi check if not required
397 // (object is known to be a heap object)
398 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
399 Handle<WeakCell> cell, Handle<Code> success,
400 SmiCheckType smi_check_type);
402 // Check if the object in register heap_object is a string. Afterwards the
403 // register map contains the object map and the register instance_type
404 // contains the instance_type. The registers map and instance_type can be the
405 // same in which case it contains the instance type afterwards. Either of the
406 // registers map and instance_type can be the same as heap_object.
407 Condition IsObjectStringType(Register heap_object,
409 Register instance_type);
411 // Check if the object in register heap_object is a name. Afterwards the
412 // register map contains the object map and the register instance_type
413 // contains the instance_type. The registers map and instance_type can be the
414 // same in which case it contains the instance type afterwards. Either of the
415 // registers map and instance_type can be the same as heap_object.
416 Condition IsObjectNameType(Register heap_object,
418 Register instance_type);
420 // Check if a heap object's type is in the JSObject range, not including
421 // JSFunction. The object's map will be loaded in the map register.
422 // Any or all of the three registers may be the same.
423 // The contents of the scratch register will always be overwritten.
424 void IsObjectJSObjectType(Register heap_object,
429 // The contents of the scratch register will be overwritten.
430 void IsInstanceJSObjectType(Register map, Register scratch, Label* fail);
432 // FCmp is similar to integer cmp, but requires unsigned
433 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
435 void FXamMinusZero();
438 void X87SetRC(int rc);
439 void X87SetFPUCW(int cw);
441 void ClampUint8(Register reg);
442 void ClampTOSToUint8(Register result_reg);
444 void SlowTruncateToI(Register result_reg, Register input_reg,
445 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
447 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
448 void TruncateX87TOSToI(Register result_reg);
450 void X87TOSToI(Register result_reg, MinusZeroMode minus_zero_mode,
451 Label* lost_precision, Label* is_nan, Label* minus_zero,
452 Label::Distance dst = Label::kFar);
454 // Smi tagging support.
455 void SmiTag(Register reg) {
456 STATIC_ASSERT(kSmiTag == 0);
457 STATIC_ASSERT(kSmiTagSize == 1);
460 void SmiUntag(Register reg) {
461 sar(reg, kSmiTagSize);
464 // Modifies the register even if it does not contain a Smi!
465 void SmiUntag(Register reg, Label* is_smi) {
466 STATIC_ASSERT(kSmiTagSize == 1);
467 sar(reg, kSmiTagSize);
468 STATIC_ASSERT(kSmiTag == 0);
469 j(not_carry, is_smi);
472 void LoadUint32NoSSE2(Register src) {
473 LoadUint32NoSSE2(Operand(src));
475 void LoadUint32NoSSE2(const Operand& src);
477 // Jump the register contains a smi.
478 inline void JumpIfSmi(Register value,
480 Label::Distance distance = Label::kFar) {
481 test(value, Immediate(kSmiTagMask));
482 j(zero, smi_label, distance);
484 // Jump if the operand is a smi.
485 inline void JumpIfSmi(Operand value,
487 Label::Distance distance = Label::kFar) {
488 test(value, Immediate(kSmiTagMask));
489 j(zero, smi_label, distance);
491 // Jump if register contain a non-smi.
492 inline void JumpIfNotSmi(Register value,
493 Label* not_smi_label,
494 Label::Distance distance = Label::kFar) {
495 test(value, Immediate(kSmiTagMask));
496 j(not_zero, not_smi_label, distance);
499 void LoadInstanceDescriptors(Register map, Register descriptors);
500 void EnumLength(Register dst, Register map);
501 void NumberOfOwnDescriptors(Register dst, Register map);
502 void LoadAccessor(Register dst, Register holder, int accessor_index,
503 AccessorComponent accessor);
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;
512 and_(reg, Immediate(mask));
515 template<typename Field>
516 void DecodeFieldToSmi(Register reg) {
517 static const int shift = Field::kShift;
518 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
519 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
520 STATIC_ASSERT(kSmiTag == 0);
521 if (shift < kSmiTagSize) {
522 shl(reg, kSmiTagSize - shift);
523 } else if (shift > kSmiTagSize) {
524 sar(reg, shift - kSmiTagSize);
526 and_(reg, Immediate(mask));
529 // Abort execution if argument is not a number, enabled via --debug-code.
530 void AssertNumber(Register object);
532 // Abort execution if argument is not a smi, enabled via --debug-code.
533 void AssertSmi(Register object);
535 // Abort execution if argument is a smi, enabled via --debug-code.
536 void AssertNotSmi(Register object);
538 // Abort execution if argument is not a string, enabled via --debug-code.
539 void AssertString(Register object);
541 // Abort execution if argument is not a name, enabled via --debug-code.
542 void AssertName(Register object);
544 // Abort execution if argument is not undefined or an AllocationSite, enabled
546 void AssertUndefinedOrAllocationSite(Register object);
548 // ---------------------------------------------------------------------------
549 // Exception handling
551 // Push a new stack handler and link it into stack handler chain.
552 void PushStackHandler();
554 // Unlink the stack handler on top of the stack from the stack handler chain.
555 void PopStackHandler();
557 // ---------------------------------------------------------------------------
558 // Inline caching support
560 // Generate code for checking access rights - used for security checks
561 // on access to global objects across environments. The holder register
562 // is left untouched, but the scratch register is clobbered.
563 void CheckAccessGlobalProxy(Register holder_reg,
568 void GetNumberHash(Register r0, Register scratch);
570 void LoadFromNumberDictionary(Label* miss,
579 // ---------------------------------------------------------------------------
580 // Allocation support
582 // Allocate an object in new space or old space. If the given space
583 // is exhausted control continues at the gc_required label. The allocated
584 // object is returned in result and end of the new object is returned in
585 // result_end. The register scratch can be passed as no_reg in which case
586 // an additional object reference will be added to the reloc info. The
587 // returned pointers in result and result_end have not yet been tagged as
588 // heap objects. If result_contains_top_on_entry is true the content of
589 // result is known to be the allocation top on entry (could be result_end
590 // from a previous call). If result_contains_top_on_entry is true scratch
591 // should be no_reg as it is never used.
592 void Allocate(int object_size,
597 AllocationFlags flags);
599 void Allocate(int header_size,
600 ScaleFactor element_size,
601 Register element_count,
602 RegisterValueType element_count_type,
607 AllocationFlags flags);
609 void Allocate(Register object_size,
614 AllocationFlags flags);
616 // Allocate a heap number in new space with undefined value. The
617 // register scratch2 can be passed as no_reg; the others must be
618 // valid registers. Returns tagged pointer in result register, or
619 // jumps to gc_required if new space is full.
620 void AllocateHeapNumber(Register result,
624 MutableMode mode = IMMUTABLE);
626 // Allocate a sequential string. All the header fields of the string object
628 void AllocateTwoByteString(Register result,
634 void AllocateOneByteString(Register result, Register length,
635 Register scratch1, Register scratch2,
636 Register scratch3, Label* gc_required);
637 void AllocateOneByteString(Register result, int length, Register scratch1,
638 Register scratch2, Label* gc_required);
640 // Allocate a raw cons string object. Only the map field of the result is
642 void AllocateTwoByteConsString(Register result,
646 void AllocateOneByteConsString(Register result, Register scratch1,
647 Register scratch2, Label* gc_required);
649 // Allocate a raw sliced string object. Only the map field of the result is
651 void AllocateTwoByteSlicedString(Register result,
655 void AllocateOneByteSlicedString(Register result, Register scratch1,
656 Register scratch2, Label* gc_required);
658 // Copy memory, byte-by-byte, from source to destination. Not optimized for
659 // long or aligned copies.
660 // The contents of index and scratch are destroyed.
661 void CopyBytes(Register source,
662 Register destination,
666 // Initialize fields with filler values. Fields starting at |start_offset|
667 // not including end_offset are overwritten with the value in |filler|. At
668 // the end the loop, |start_offset| takes the value of |end_offset|.
669 void InitializeFieldsWithFiller(Register start_offset,
673 // ---------------------------------------------------------------------------
674 // Support functions.
676 // Check a boolean-bit of a Smi field.
677 void BooleanBitTest(Register object, int field_offset, int bit_index);
679 // Check if result is zero and op is negative.
680 void NegativeZeroTest(Register result, Register op, Label* then_label);
682 // Check if result is zero and any of op1 and op2 are negative.
683 // Register scratch is destroyed, and it must be different from op2.
684 void NegativeZeroTest(Register result, Register op1, Register op2,
685 Register scratch, Label* then_label);
687 // Machine code version of Map::GetConstructor().
688 // |temp| holds |result|'s map when done.
689 void GetMapConstructor(Register result, Register map, Register temp);
691 // Try to get function prototype of a function and puts the value in
692 // the result register. Checks that the function really is a
693 // function and jumps to the miss label if the fast checks fail. The
694 // function register will be untouched; the other registers may be
696 void TryGetFunctionPrototype(Register function,
700 bool miss_on_bound_function = false);
702 // Picks out an array index from the hash field.
704 // hash - holds the index's hash. Clobbered.
705 // index - holds the overwritten index on exit.
706 void IndexFromHash(Register hash, Register index);
708 // ---------------------------------------------------------------------------
711 // Call a code stub. Generate the code if necessary.
712 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
714 // Tail call a code stub (jump). Generate the code if necessary.
715 void TailCallStub(CodeStub* stub);
717 // Return from a code stub after popping its arguments.
718 void StubReturn(int argc);
720 // Call a runtime routine.
721 void CallRuntime(const Runtime::Function* f, int num_arguments,
722 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
723 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
724 const Runtime::Function* function = Runtime::FunctionForId(id);
725 CallRuntime(function, function->nargs, kSaveFPRegs);
728 // Convenience function: Same as above, but takes the fid instead.
729 void CallRuntime(Runtime::FunctionId id, int num_arguments,
730 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
731 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
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 // Jump to a runtime routine.
767 void JumpToExternalReference(const ExternalReference& ext);
769 // ---------------------------------------------------------------------------
774 // Return and drop arguments from stack, where the number of arguments
775 // may be bigger than 2^16 - 1. Requires a scratch register.
776 void Ret(int bytes_dropped, Register scratch);
778 // Emit code to discard a non-negative number of pointer-sized elements
779 // from the stack, clobbering only the esp register.
780 void Drop(int element_count);
782 void Call(Label* target) { call(target); }
783 void Push(Register src) { push(src); }
784 void Pop(Register dst) { pop(dst); }
786 void Lzcnt(Register dst, Register src) { Lzcnt(dst, Operand(src)); }
787 void Lzcnt(Register dst, const Operand& src);
789 // Emit call to the code we are currently generating.
791 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
792 call(self, RelocInfo::CODE_TARGET);
795 // Move if the registers are not identical.
796 void Move(Register target, Register source);
798 // Move a constant into a destination using the most efficient encoding.
799 void Move(Register dst, const Immediate& x);
800 void Move(const Operand& dst, const Immediate& x);
802 // Push a handle value.
803 void Push(Handle<Object> handle) { push(Immediate(handle)); }
804 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
806 Handle<Object> CodeObject() {
807 DCHECK(!code_object_.is_null());
811 // Insert code to verify that the x87 stack has the specified depth (0-7)
812 void VerifyX87StackDepth(uint32_t depth);
814 // Emit code for a truncating division by a constant. The dividend register is
815 // unchanged, the result is in edx, and eax gets clobbered.
816 void TruncatingDiv(Register dividend, int32_t divisor);
818 // ---------------------------------------------------------------------------
819 // StatsCounter support
821 void SetCounter(StatsCounter* counter, int value);
822 void IncrementCounter(StatsCounter* counter, int value);
823 void DecrementCounter(StatsCounter* counter, int value);
824 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
825 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
828 // ---------------------------------------------------------------------------
831 // Calls Abort(msg) if the condition cc is not satisfied.
832 // Use --debug_code to enable.
833 void Assert(Condition cc, BailoutReason reason);
835 void AssertFastElements(Register elements);
837 // Like Assert(), but always enabled.
838 void Check(Condition cc, BailoutReason reason);
840 // Print a message to stdout and abort execution.
841 void Abort(BailoutReason reason);
843 // Check that the stack is aligned.
844 void CheckStackAlignment();
846 // Verify restrictions about code generated in stubs.
847 void set_generating_stub(bool value) { generating_stub_ = value; }
848 bool generating_stub() { return generating_stub_; }
849 void set_has_frame(bool value) { has_frame_ = value; }
850 bool has_frame() { return has_frame_; }
851 inline bool AllowThisStubCall(CodeStub* stub);
853 // ---------------------------------------------------------------------------
856 // Generate code to do a lookup in the number string cache. If the number in
857 // the register object is found in the cache the generated code falls through
858 // with the result in the result register. The object and the result register
859 // can be the same. If the number is not found in the cache the code jumps to
860 // the label not_found with only the content of register object unchanged.
861 void LookupNumberStringCache(Register object,
867 // Check whether the instance type represents a flat one-byte string. Jump to
868 // the label if not. If the instance type can be scratched specify same
869 // register for both instance type and scratch.
870 void JumpIfInstanceTypeIsNotSequentialOneByte(
871 Register instance_type, Register scratch,
872 Label* on_not_flat_one_byte_string);
874 // Checks if both objects are sequential one-byte strings, and jumps to label
876 void JumpIfNotBothSequentialOneByteStrings(
877 Register object1, Register object2, Register scratch1, Register scratch2,
878 Label* on_not_flat_one_byte_strings);
880 // Checks if the given register or operand is a unique name
881 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
882 Label::Distance distance = Label::kFar) {
883 JumpIfNotUniqueNameInstanceType(Operand(reg), not_unique_name, distance);
886 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
887 Label::Distance distance = Label::kFar);
889 void EmitSeqStringSetCharCheck(Register string,
892 uint32_t encoding_mask);
894 static int SafepointRegisterStackIndex(Register reg) {
895 return SafepointRegisterStackIndex(reg.code());
898 // Activation support.
899 void EnterFrame(StackFrame::Type type);
900 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
901 void LeaveFrame(StackFrame::Type type);
903 // Expects object in eax and returns map with validated enum cache
904 // in eax. Assumes that any other register can be used as a scratch.
905 void CheckEnumCache(Label* call_runtime);
907 // AllocationMemento support. Arrays may have an associated
908 // AllocationMemento object that can be checked for in order to pretransition
910 // On entry, receiver_reg should point to the array object.
911 // scratch_reg gets clobbered.
912 // If allocation info is present, conditional code is set to equal.
913 void TestJSArrayForAllocationMemento(Register receiver_reg,
914 Register scratch_reg,
915 Label* no_memento_found);
917 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
918 Register scratch_reg,
919 Label* memento_found) {
920 Label no_memento_found;
921 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
923 j(equal, memento_found);
924 bind(&no_memento_found);
927 // Jumps to found label if a prototype map has dictionary elements.
928 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
929 Register scratch1, Label* found);
932 bool generating_stub_;
934 // This handle will be patched with the code object on installation.
935 Handle<Object> code_object_;
937 // Helper functions for generating invokes.
938 void InvokePrologue(const ParameterCount& expected,
939 const ParameterCount& actual,
940 Handle<Code> code_constant,
941 const Operand& code_operand,
943 bool* definitely_mismatches,
945 Label::Distance done_distance,
946 const CallWrapper& call_wrapper = NullCallWrapper());
948 void EnterExitFramePrologue();
949 void EnterExitFrameEpilogue(int argc, bool save_doubles);
951 void LeaveExitFrameEpilogue(bool restore_context);
953 // Allocation support helpers.
954 void LoadAllocationTopHelper(Register result,
956 AllocationFlags flags);
958 void UpdateAllocationTopHelper(Register result_end,
960 AllocationFlags flags);
962 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
963 void InNewSpace(Register object,
966 Label* condition_met,
967 Label::Distance condition_met_distance = Label::kFar);
969 // Helper for finding the mark bits for an address. Afterwards, the
970 // bitmap register points at the word with the mark bits and the mask
971 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
973 inline void GetMarkBits(Register addr_reg,
977 // Compute memory operands for safepoint stack slots.
978 Operand SafepointRegisterSlot(Register reg);
979 static int SafepointRegisterStackIndex(int reg_code);
981 // Needs access to SafepointRegisterStackIndex for compiled frame
983 friend class StandardFrame;
987 // The code patcher is used to patch (typically) small parts of code e.g. for
988 // debugging and other types of instrumentation. When using the code patcher
989 // the exact number of bytes specified must be emitted. Is not legal to emit
990 // relocation information. If any of these constraints are violated it causes
994 CodePatcher(byte* address, int size);
997 // Macro assembler to emit code.
998 MacroAssembler* masm() { return &masm_; }
1001 byte* address_; // The address of the code being patched.
1002 int size_; // Number of bytes of the expected patch size.
1003 MacroAssembler masm_; // Macro assembler used to generate the code.
1007 // -----------------------------------------------------------------------------
1008 // Static helper functions.
1010 // Generate an Operand for loading a field from an object.
1011 inline Operand FieldOperand(Register object, int offset) {
1012 return Operand(object, offset - kHeapObjectTag);
1016 // Generate an Operand for loading an indexed field from an object.
1017 inline Operand FieldOperand(Register object,
1021 return Operand(object, index, scale, offset - kHeapObjectTag);
1025 inline Operand FixedArrayElementOperand(Register array,
1026 Register index_as_smi,
1027 int additional_offset = 0) {
1028 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1029 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1033 inline Operand ContextOperand(Register context, int index) {
1034 return Operand(context, Context::SlotOffset(index));
1038 inline Operand ContextOperand(Register context, Register index) {
1039 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1043 inline Operand GlobalObjectOperand() {
1044 return ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX);
1048 #ifdef GENERATED_CODE_COVERAGE
1049 extern void LogGeneratedCodeCoverage(const char* file_line);
1050 #define CODE_COVERAGE_STRINGIFY(x) #x
1051 #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1052 #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1053 #define ACCESS_MASM(masm) { \
1054 byte* ia32_coverage_function = \
1055 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1058 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1059 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1066 #define ACCESS_MASM(masm) masm->
1070 } } // namespace v8::internal
1072 #endif // V8_X87_MACRO_ASSEMBLER_X87_H_