blob: be11f662027c6f3256b1752ab38cb97a0f833f23 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_IA32_MACRO_ASSEMBLER_IA32_H_
6#define V8_IA32_MACRO_ASSEMBLER_IA32_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/assembler.h"
9#include "src/bailout-reason.h"
10#include "src/frames.h"
11#include "src/globals.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000012
13namespace v8 {
14namespace internal {
15
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016// Give alias names to registers for calling conventions.
17const Register kReturnRegister0 = {Register::kCode_eax};
18const Register kReturnRegister1 = {Register::kCode_edx};
Ben Murdoch097c5b22016-05-18 11:27:45 +010019const Register kReturnRegister2 = {Register::kCode_edi};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000020const Register kJSFunctionRegister = {Register::kCode_edi};
21const Register kContextRegister = {Register::kCode_esi};
22const Register kInterpreterAccumulatorRegister = {Register::kCode_eax};
23const Register kInterpreterRegisterFileRegister = {Register::kCode_edx};
24const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_ecx};
25const Register kInterpreterBytecodeArrayRegister = {Register::kCode_edi};
26const Register kJavaScriptCallArgCountRegister = {Register::kCode_eax};
27const Register kJavaScriptCallNewTargetRegister = {Register::kCode_edx};
28const Register kRuntimeCallFunctionRegister = {Register::kCode_ebx};
29const Register kRuntimeCallArgCountRegister = {Register::kCode_eax};
30
31// Spill slots used by interpreter dispatch calling convention.
32const int kInterpreterDispatchTableSpillSlot = -1;
33
Leon Clarkee46be812010-01-19 14:06:41 +000034// Convenience for platform-independent signatures. We do not normally
35// distinguish memory operands from other operands on ia32.
36typedef Operand MemOperand;
37
Ben Murdoch3ef787d2012-04-12 10:51:47 +010038enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
39enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040enum PointersToHereCheck {
41 kPointersToHereMaybeInteresting,
42 kPointersToHereAreAlwaysInteresting
43};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010044
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045enum RegisterValueType { REGISTER_VALUE_IS_SMI, REGISTER_VALUE_IS_INT32 };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046
Ben Murdochda12d292016-06-02 14:46:10 +010047enum class ReturnAddressState { kOnStack, kNotOnStack };
48
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049#ifdef DEBUG
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
51 Register reg4 = no_reg, Register reg5 = no_reg,
52 Register reg6 = no_reg, Register reg7 = no_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053 Register reg8 = no_reg);
54#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010055
Steve Blocka7e24c12009-10-30 11:49:00 +000056// MacroAssembler implements a collection of frequently used macros.
57class MacroAssembler: public Assembler {
58 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000059 MacroAssembler(Isolate* isolate, void* buffer, int size,
60 CodeObjectRequired create_code_object);
Steve Blocka7e24c12009-10-30 11:49:00 +000061
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 void Load(Register dst, const Operand& src, Representation r);
63 void Store(Register src, const Operand& dst, Representation r);
64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065 // Load a register with a long value as efficiently as possible.
66 void Set(Register dst, int32_t x) {
67 if (x == 0) {
68 xor_(dst, dst);
69 } else {
70 mov(dst, Immediate(x));
71 }
72 }
73 void Set(const Operand& dst, int32_t x) { mov(dst, Immediate(x)); }
74
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 // Operations on roots in the root-array.
76 void LoadRoot(Register destination, Heap::RootListIndex index);
77 void StoreRoot(Register source, Register scratch, Heap::RootListIndex index);
78 void CompareRoot(Register with, Register scratch, Heap::RootListIndex index);
79 // These methods can only be used with constant roots (i.e. non-writable
80 // and not in new space).
81 void CompareRoot(Register with, Heap::RootListIndex index);
82 void CompareRoot(const Operand& with, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083 void PushRoot(Heap::RootListIndex index);
84
85 // Compare the object in a register to a value and jump if they are equal.
86 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal,
87 Label::Distance if_equal_distance = Label::kFar) {
88 CompareRoot(with, index);
89 j(equal, if_equal, if_equal_distance);
90 }
91 void JumpIfRoot(const Operand& with, Heap::RootListIndex index,
92 Label* if_equal,
93 Label::Distance if_equal_distance = Label::kFar) {
94 CompareRoot(with, index);
95 j(equal, if_equal, if_equal_distance);
96 }
97
98 // Compare the object in a register to a value and jump if they are not equal.
99 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
100 Label* if_not_equal,
101 Label::Distance if_not_equal_distance = Label::kFar) {
102 CompareRoot(with, index);
103 j(not_equal, if_not_equal, if_not_equal_distance);
104 }
105 void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index,
106 Label* if_not_equal,
107 Label::Distance if_not_equal_distance = Label::kFar) {
108 CompareRoot(with, index);
109 j(not_equal, if_not_equal, if_not_equal_distance);
110 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111
Ben Murdoch097c5b22016-05-18 11:27:45 +0100112 // These functions do not arrange the registers in any particular order so
113 // they are not useful for calls that can cause a GC. The caller can
114 // exclude up to 3 registers that do not need to be saved and restored.
115 void PushCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg,
116 Register exclusion2 = no_reg,
117 Register exclusion3 = no_reg);
118 void PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1 = no_reg,
119 Register exclusion2 = no_reg,
120 Register exclusion3 = no_reg);
121
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 // ---------------------------------------------------------------------------
123 // GC Support
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124 enum RememberedSetFinalAction { kReturnAtEnd, kFallThroughAtEnd };
Steve Blocka7e24c12009-10-30 11:49:00 +0000125
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100126 // Record in the remembered set the fact that we have a pointer to new space
127 // at the address pointed to by the addr register. Only works if addr is not
128 // in new space.
129 void RememberedSetHelper(Register object, // Used for debug code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000130 Register addr, Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100131 SaveFPRegsMode save_fp,
132 RememberedSetFinalAction and_then);
Steve Block6ded16b2010-05-10 14:33:55 +0100133
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134 void CheckPageFlag(Register object, Register scratch, int mask, Condition cc,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100135 Label* condition_met,
136 Label::Distance condition_met_distance = Label::kFar);
Steve Block6ded16b2010-05-10 14:33:55 +0100137
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 void CheckPageFlagForMap(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000139 Handle<Map> map, int mask, Condition cc, Label* condition_met,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000140 Label::Distance condition_met_distance = Label::kFar);
141
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100142 // Check if object is in new space. Jumps if the object is not in new space.
143 // The register scratch can be object itself, but scratch will be clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144 void JumpIfNotInNewSpace(Register object, Register scratch, Label* branch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100145 Label::Distance distance = Label::kFar) {
146 InNewSpace(object, scratch, zero, branch, distance);
147 }
148
149 // Check if object is in new space. Jumps if the object is in new space.
150 // The register scratch can be object itself, but it will be clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000151 void JumpIfInNewSpace(Register object, Register scratch, Label* branch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100152 Label::Distance distance = Label::kFar) {
153 InNewSpace(object, scratch, not_zero, branch, distance);
154 }
155
156 // Check if an object has a given incremental marking color. Also uses ecx!
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157 void HasColor(Register object, Register scratch0, Register scratch1,
158 Label* has_color, Label::Distance has_color_distance,
159 int first_bit, int second_bit);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161 void JumpIfBlack(Register object, Register scratch0, Register scratch1,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100162 Label* on_black,
163 Label::Distance on_black_distance = Label::kFar);
164
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000165 // Checks the color of an object. If the object is white we jump to the
166 // incremental marker.
167 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
168 Label* value_is_white, Label::Distance distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100169
170 // Notify the garbage collector that we wrote a pointer into an object.
171 // |object| is the object being stored into, |value| is the object being
172 // stored. value and scratch registers are clobbered by the operation.
173 // The offset is the offset from the start of the object, not the offset from
174 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
175 void RecordWriteField(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000176 Register object, int offset, Register value, Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100177 SaveFPRegsMode save_fp,
178 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000179 SmiCheck smi_check = INLINE_SMI_CHECK,
180 PointersToHereCheck pointers_to_here_check_for_value =
181 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100182
183 // As above, but the offset has the tag presubtracted. For use with
184 // Operand(reg, off).
185 void RecordWriteContextSlot(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000186 Register context, int offset, Register value, Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100187 SaveFPRegsMode save_fp,
188 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000189 SmiCheck smi_check = INLINE_SMI_CHECK,
190 PointersToHereCheck pointers_to_here_check_for_value =
191 kPointersToHereMaybeInteresting) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000192 RecordWriteField(context, offset + kHeapObjectTag, value, scratch, save_fp,
193 remembered_set_action, smi_check,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100195 }
196
197 // Notify the garbage collector that we wrote a pointer into a fixed array.
198 // |array| is the array being stored into, |value| is the
199 // object being stored. |index| is the array index represented as a
200 // Smi. All registers are clobbered by the operation RecordWriteArray
Steve Block8defd9f2010-07-08 12:39:36 +0100201 // filters out smis so it does not update the write barrier if the
202 // value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100203 void RecordWriteArray(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000204 Register array, Register value, Register index, SaveFPRegsMode save_fp,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100205 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000206 SmiCheck smi_check = INLINE_SMI_CHECK,
207 PointersToHereCheck pointers_to_here_check_for_value =
208 kPointersToHereMaybeInteresting);
Steve Blocka7e24c12009-10-30 11:49:00 +0000209
Steve Block8defd9f2010-07-08 12:39:36 +0100210 // For page containing |object| mark region covering |address|
211 // dirty. |object| is the object being stored into, |value| is the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100212 // object being stored. The address and value registers are clobbered by the
Steve Block8defd9f2010-07-08 12:39:36 +0100213 // operation. RecordWrite filters out smis so it does not update the
214 // write barrier if the value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100215 void RecordWrite(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000216 Register object, Register address, Register value, SaveFPRegsMode save_fp,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100217 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 SmiCheck smi_check = INLINE_SMI_CHECK,
219 PointersToHereCheck pointers_to_here_check_for_value =
220 kPointersToHereMaybeInteresting);
Steve Block8defd9f2010-07-08 12:39:36 +0100221
Ben Murdoch097c5b22016-05-18 11:27:45 +0100222 // Notify the garbage collector that we wrote a code entry into a
223 // JSFunction. Only scratch is clobbered by the operation.
224 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
225 Register scratch);
226
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227 // For page containing |object| mark the region covering the object's map
228 // dirty. |object| is the object being stored into, |map| is the Map object
229 // that was stored.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000230 void RecordWriteForMap(Register object, Handle<Map> map, Register scratch1,
231 Register scratch2, SaveFPRegsMode save_fp);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 // ---------------------------------------------------------------------------
234 // Debugger Support
235
Andrei Popescu402d9372010-02-26 13:31:12 +0000236 void DebugBreak();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237
238 // Generates function and stub prologue code.
Ben Murdochda12d292016-06-02 14:46:10 +0100239 void StubPrologue(StackFrame::Type type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000240 void Prologue(bool code_pre_aging);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
Ben Murdochb0fe1622011-05-05 13:52:32 +0100242 // Enter specific kind of exit frame. Expects the number of
243 // arguments in register eax and sets up the number of arguments in
244 // register edi and the pointer to the first argument in register
245 // esi.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100246 void EnterExitFrame(int argc, bool save_doubles);
Steve Blockd0582a62009-12-15 09:54:21 +0000247
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800248 void EnterApiExitFrame(int argc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000249
250 // Leave the current exit frame. Expects the return value in
251 // register eax:edx (untouched) and the pointer to the first
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000252 // argument in register esi (if pop_arguments == true).
253 void LeaveExitFrame(bool save_doubles, bool pop_arguments = true);
Steve Blocka7e24c12009-10-30 11:49:00 +0000254
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800255 // Leave the current exit frame. Expects the return value in
256 // register eax (untouched).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000257 void LeaveApiExitFrame(bool restore_context);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800258
Steve Blockd0582a62009-12-15 09:54:21 +0000259 // Find the function context up the context chain.
260 void LoadContext(Register dst, int context_chain_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000261
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262 // Load the global proxy from the current context.
263 void LoadGlobalProxy(Register dst);
264
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100265 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266 // transitioned_kind from the native context if the map in register
267 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100268 // expected_kind.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000269 void LoadTransitionedArrayMapConditional(ElementsKind expected_kind,
270 ElementsKind transitioned_kind,
271 Register map_in_out,
272 Register scratch,
273 Label* no_map_match);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100274
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100275 // Load the global function with the given index.
276 void LoadGlobalFunction(int index, Register function);
277
278 // Load the initial map from the global function. The registers
279 // function and map can be the same.
280 void LoadGlobalFunctionInitialMap(Register function, Register map);
281
Ben Murdochb0fe1622011-05-05 13:52:32 +0100282 // Push and pop the registers that can hold pointers.
283 void PushSafepointRegisters() { pushad(); }
284 void PopSafepointRegisters() { popad(); }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100285 // Store the value in register/immediate src in the safepoint
286 // register stack slot for register dst.
287 void StoreToSafepointRegisterSlot(Register dst, Register src);
288 void StoreToSafepointRegisterSlot(Register dst, Immediate src);
289 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100290
Ben Murdoch097c5b22016-05-18 11:27:45 +0100291 // Nop, because ia32 does not have a root register.
292 void InitializeRootRegister() {}
293
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100294 void LoadHeapObject(Register result, Handle<HeapObject> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000295 void CmpHeapObject(Register reg, Handle<HeapObject> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100296 void PushHeapObject(Handle<HeapObject> object);
297
298 void LoadObject(Register result, Handle<Object> object) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000299 AllowDeferredHandleDereference heap_object_check;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100300 if (object->IsHeapObject()) {
301 LoadHeapObject(result, Handle<HeapObject>::cast(object));
302 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 Move(result, Immediate(object));
304 }
305 }
306
307 void CmpObject(Register reg, Handle<Object> object) {
308 AllowDeferredHandleDereference heap_object_check;
309 if (object->IsHeapObject()) {
310 CmpHeapObject(reg, Handle<HeapObject>::cast(object));
311 } else {
312 cmp(reg, Immediate(object));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100313 }
314 }
315
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400316 // Compare the given value and the value of weak cell.
317 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
318
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000319 void GetWeakValue(Register value, Handle<WeakCell> cell);
320
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400321 // Load the value of the weak cell in the value register. Branch to the given
322 // miss label if the weak cell was cleared.
323 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
324
Steve Blocka7e24c12009-10-30 11:49:00 +0000325 // ---------------------------------------------------------------------------
326 // JavaScript invokes
327
Ben Murdochda12d292016-06-02 14:46:10 +0100328 // Removes current frame and its arguments from the stack preserving
329 // the arguments and a return address pushed to the stack for the next call.
330 // |ra_state| defines whether return address is already pushed to stack or
331 // not. Both |callee_args_count| and |caller_args_count_reg| do not include
332 // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
333 // is trashed. |number_of_temp_values_after_return_address| specifies
334 // the number of words pushed to the stack after the return address. This is
335 // to allow "allocation" of scratch registers that this function requires
336 // by saving their values on the stack.
337 void PrepareForTailCall(const ParameterCount& callee_args_count,
338 Register caller_args_count_reg, Register scratch0,
339 Register scratch1, ReturnAddressState ra_state,
340 int number_of_temp_values_after_return_address);
341
Steve Blocka7e24c12009-10-30 11:49:00 +0000342 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100343
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000344 void InvokeFunctionCode(Register function, Register new_target,
345 const ParameterCount& expected,
346 const ParameterCount& actual, InvokeFlag flag,
347 const CallWrapper& call_wrapper);
348
349 void FloodFunctionIfStepping(Register fun, Register new_target,
350 const ParameterCount& expected,
351 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
353 // Invoke the JavaScript function in the given register. Changes the
354 // current context to the context in the function before invoking.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000355 void InvokeFunction(Register function, Register new_target,
356 const ParameterCount& actual, InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000357 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000358
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000359 void InvokeFunction(Register function, const ParameterCount& expected,
360 const ParameterCount& actual, InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000361 const CallWrapper& call_wrapper);
362
363 void InvokeFunction(Handle<JSFunction> function,
364 const ParameterCount& expected,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000365 const ParameterCount& actual, InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000366 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000367
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 // Expression support
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000369 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
370 // hinders register renaming and makes dependence chains longer. So we use
371 // xorps to clear the dst register before cvtsi2sd to solve this issue.
372 void Cvtsi2sd(XMMRegister dst, Register src) { Cvtsi2sd(dst, Operand(src)); }
373 void Cvtsi2sd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000374
Ben Murdoch097c5b22016-05-18 11:27:45 +0100375 void Cvtui2ss(XMMRegister dst, Register src, Register tmp);
376
Ben Murdochda12d292016-06-02 14:46:10 +0100377 void ShlPair(Register high, Register low, uint8_t imm8);
378 void ShlPair_cl(Register high, Register low);
379 void ShrPair(Register high, Register low, uint8_t imm8);
380 void ShrPair_cl(Register high, Register src);
381 void SarPair(Register high, Register low, uint8_t imm8);
382 void SarPair_cl(Register high, Register low);
383
Steve Block053d10c2011-06-13 19:13:29 +0100384 // Support for constant splitting.
385 bool IsUnsafeImmediate(const Immediate& x);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 void SafeMove(Register dst, const Immediate& x);
Steve Block053d10c2011-06-13 19:13:29 +0100387 void SafePush(const Immediate& x);
388
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 // Compare object type for heap object.
390 // Incoming register is heap_object and outgoing register is map.
391 void CmpObjectType(Register heap_object, InstanceType type, Register map);
392
393 // Compare instance type for map.
394 void CmpInstanceType(Register map, InstanceType type);
395
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000396 // Check if a map for a JSObject indicates that the object has fast elements.
397 // Jump to the specified label if it does not.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000398 void CheckFastElements(Register map, Label* fail,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000399 Label::Distance distance = Label::kFar);
400
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100401 // Check if a map for a JSObject indicates that the object can have both smi
402 // and HeapObject elements. Jump to the specified label if it does not.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000403 void CheckFastObjectElements(Register map, Label* fail,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100404 Label::Distance distance = Label::kFar);
405
406 // Check if a map for a JSObject indicates that the object has fast smi only
407 // elements. Jump to the specified label if it does not.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000408 void CheckFastSmiElements(Register map, Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409 Label::Distance distance = Label::kFar);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100410
411 // Check to see if maybe_number can be stored as a double in
412 // FastDoubleElements. If it can, store it at the index specified by key in
413 // the FastDoubleElements array elements, otherwise jump to fail.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000414 void StoreNumberToDoubleElements(Register maybe_number, Register elements,
415 Register key, Register scratch1,
416 XMMRegister scratch2, Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000417 int offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100418
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000419 // Compare an object's map with the specified map.
420 void CompareMap(Register obj, Handle<Map> map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100421
Ben Murdoch257744e2011-11-30 15:57:28 +0000422 // Check if the map of an object is equal to a specified map and branch to
423 // label if not. Skip the smi check if not required (object is known to be a
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100424 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
425 // against maps that are ElementsKind transition maps of the specified map.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000426 void CheckMap(Register obj, Handle<Map> map, Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000427 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000428
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400429 // Check if the map of an object is equal to a specified weak map and branch
430 // to a specified target if equal. Skip the smi check if not required
431 // (object is known to be a heap object)
432 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
433 Handle<WeakCell> cell, Handle<Code> success,
434 SmiCheckType smi_check_type);
Andrei Popescu31002712010-02-23 13:46:05 +0000435
Leon Clarkee46be812010-01-19 14:06:41 +0000436 // Check if the object in register heap_object is a string. Afterwards the
437 // register map contains the object map and the register instance_type
438 // contains the instance_type. The registers map and instance_type can be the
439 // same in which case it contains the instance type afterwards. Either of the
440 // registers map and instance_type can be the same as heap_object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000441 Condition IsObjectStringType(Register heap_object, Register map,
Leon Clarkee46be812010-01-19 14:06:41 +0000442 Register instance_type);
443
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444 // Check if the object in register heap_object is a name. Afterwards the
445 // register map contains the object map and the register instance_type
446 // contains the instance_type. The registers map and instance_type can be the
447 // same in which case it contains the instance type afterwards. Either of the
448 // registers map and instance_type can be the same as heap_object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000449 Condition IsObjectNameType(Register heap_object, Register map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 Register instance_type);
451
Steve Blocka7e24c12009-10-30 11:49:00 +0000452 // FCmp is similar to integer cmp, but requires unsigned
453 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
454 void FCmp();
455
Ben Murdoch257744e2011-11-30 15:57:28 +0000456 void ClampUint8(Register reg);
457
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000458 void ClampDoubleToUint8(XMMRegister input_reg, XMMRegister scratch_reg,
Ben Murdoch257744e2011-11-30 15:57:28 +0000459 Register result_reg);
460
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 void SlowTruncateToI(Register result_reg, Register input_reg,
462 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
463
464 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
465 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
466
467 void DoubleToI(Register result_reg, XMMRegister input_reg,
468 XMMRegister scratch, MinusZeroMode minus_zero_mode,
469 Label* lost_precision, Label* is_nan, Label* minus_zero,
470 Label::Distance dst = Label::kFar);
Ben Murdoch257744e2011-11-30 15:57:28 +0000471
Leon Clarkee46be812010-01-19 14:06:41 +0000472 // Smi tagging support.
473 void SmiTag(Register reg) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000474 STATIC_ASSERT(kSmiTag == 0);
475 STATIC_ASSERT(kSmiTagSize == 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100476 add(reg, reg);
Leon Clarkee46be812010-01-19 14:06:41 +0000477 }
478 void SmiUntag(Register reg) {
479 sar(reg, kSmiTagSize);
480 }
481
Iain Merrick75681382010-08-19 15:07:18 +0100482 // Modifies the register even if it does not contain a Smi!
Iain Merrick75681382010-08-19 15:07:18 +0100483 void SmiUntag(Register reg, Label* is_smi) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000484 STATIC_ASSERT(kSmiTagSize == 1);
Iain Merrick75681382010-08-19 15:07:18 +0100485 sar(reg, kSmiTagSize);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000486 STATIC_ASSERT(kSmiTag == 0);
Iain Merrick75681382010-08-19 15:07:18 +0100487 j(not_carry, is_smi);
488 }
489
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400490 void LoadUint32(XMMRegister dst, Register src) {
491 LoadUint32(dst, Operand(src));
492 }
493 void LoadUint32(XMMRegister dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000494
Steve Block1e0659c2011-05-24 12:43:12 +0100495 // Jump the register contains a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000496 inline void JumpIfSmi(Register value, Label* smi_label,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000497 Label::Distance distance = Label::kFar) {
Steve Block1e0659c2011-05-24 12:43:12 +0100498 test(value, Immediate(kSmiTagMask));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000499 j(zero, smi_label, distance);
500 }
501 // Jump if the operand is a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000502 inline void JumpIfSmi(Operand value, Label* smi_label,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000503 Label::Distance distance = Label::kFar) {
504 test(value, Immediate(kSmiTagMask));
505 j(zero, smi_label, distance);
Steve Block1e0659c2011-05-24 12:43:12 +0100506 }
507 // Jump if register contain a non-smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000508 inline void JumpIfNotSmi(Register value, Label* not_smi_label,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000509 Label::Distance distance = Label::kFar) {
Steve Block1e0659c2011-05-24 12:43:12 +0100510 test(value, Immediate(kSmiTagMask));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000511 j(not_zero, not_smi_label, distance);
Steve Block1e0659c2011-05-24 12:43:12 +0100512 }
513
Ben Murdoch257744e2011-11-30 15:57:28 +0000514 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000515 void EnumLength(Register dst, Register map);
516 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000517 void LoadAccessor(Register dst, Register holder, int accessor_index,
518 AccessorComponent accessor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519
520 template<typename Field>
521 void DecodeField(Register reg) {
522 static const int shift = Field::kShift;
523 static const int mask = Field::kMask >> Field::kShift;
524 if (shift != 0) {
525 sar(reg, shift);
526 }
527 and_(reg, Immediate(mask));
528 }
529
530 template<typename Field>
531 void DecodeFieldToSmi(Register reg) {
532 static const int shift = Field::kShift;
533 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
534 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
535 STATIC_ASSERT(kSmiTag == 0);
536 if (shift < kSmiTagSize) {
537 shl(reg, kSmiTagSize - shift);
538 } else if (shift > kSmiTagSize) {
539 sar(reg, shift - kSmiTagSize);
540 }
541 and_(reg, Immediate(mask));
542 }
Iain Merrick75681382010-08-19 15:07:18 +0100543
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100544 void LoadPowerOf2(XMMRegister dst, Register scratch, int power);
545
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 // Abort execution if argument is not a number, enabled via --debug-code.
547 void AssertNumber(Register object);
Ben Murdochda12d292016-06-02 14:46:10 +0100548 void AssertNotNumber(Register object);
Steve Block6ded16b2010-05-10 14:33:55 +0100549
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550 // Abort execution if argument is not a smi, enabled via --debug-code.
551 void AssertSmi(Register object);
Andrei Popescu402d9372010-02-26 13:31:12 +0000552
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000553 // Abort execution if argument is a smi, enabled via --debug-code.
554 void AssertNotSmi(Register object);
Iain Merrick75681382010-08-19 15:07:18 +0100555
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000556 // Abort execution if argument is not a string, enabled via --debug-code.
557 void AssertString(Register object);
558
559 // Abort execution if argument is not a name, enabled via --debug-code.
560 void AssertName(Register object);
561
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000562 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
563 void AssertFunction(Register object);
564
565 // Abort execution if argument is not a JSBoundFunction,
566 // enabled via --debug-code.
567 void AssertBoundFunction(Register object);
568
Ben Murdoch097c5b22016-05-18 11:27:45 +0100569 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
570 void AssertReceiver(Register object);
571
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000572 // Abort execution if argument is not undefined or an AllocationSite, enabled
573 // via --debug-code.
574 void AssertUndefinedOrAllocationSite(Register object);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100575
Steve Blocka7e24c12009-10-30 11:49:00 +0000576 // ---------------------------------------------------------------------------
577 // Exception handling
578
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000579 // Push a new stack handler and link it into stack handler chain.
580 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000581
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000582 // Unlink the stack handler on top of the stack from the stack handler chain.
583 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100584
Steve Blocka7e24c12009-10-30 11:49:00 +0000585 // ---------------------------------------------------------------------------
586 // Inline caching support
587
Steve Blocka7e24c12009-10-30 11:49:00 +0000588 // Generate code for checking access rights - used for security checks
589 // on access to global objects across environments. The holder register
590 // is left untouched, but the scratch register is clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000591 void CheckAccessGlobalProxy(Register holder_reg, Register scratch1,
592 Register scratch2, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
Ben Murdochc7cc0282012-03-05 14:35:55 +0000594 void GetNumberHash(Register r0, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000595
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000596 void LoadFromNumberDictionary(Label* miss, Register elements, Register key,
597 Register r0, Register r1, Register r2,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000598 Register result);
599
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 // ---------------------------------------------------------------------------
601 // Allocation support
602
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000603 // Allocate an object in new space or old space. If the given space
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000604 // is exhausted control continues at the gc_required label. The allocated
605 // object is returned in result and end of the new object is returned in
606 // result_end. The register scratch can be passed as no_reg in which case
607 // an additional object reference will be added to the reloc info. The
608 // returned pointers in result and result_end have not yet been tagged as
609 // heap objects. If result_contains_top_on_entry is true the content of
610 // result is known to be the allocation top on entry (could be result_end
611 // from a previous call). If result_contains_top_on_entry is true scratch
Steve Blocka7e24c12009-10-30 11:49:00 +0000612 // should be no_reg as it is never used.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000613 void Allocate(int object_size, Register result, Register result_end,
614 Register scratch, Label* gc_required, AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000615
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000616 void Allocate(int header_size, ScaleFactor element_size,
617 Register element_count, RegisterValueType element_count_type,
618 Register result, Register result_end, Register scratch,
619 Label* gc_required, AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000620
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000621 void Allocate(Register object_size, Register result, Register result_end,
622 Register scratch, Label* gc_required, AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000623
Steve Block3ce2e202009-11-05 08:53:23 +0000624 // Allocate a heap number in new space with undefined value. The
625 // register scratch2 can be passed as no_reg; the others must be
626 // valid registers. Returns tagged pointer in result register, or
627 // jumps to gc_required if new space is full.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000628 void AllocateHeapNumber(Register result, Register scratch1, Register scratch2,
629 Label* gc_required, MutableMode mode = IMMUTABLE);
Steve Block3ce2e202009-11-05 08:53:23 +0000630
Steve Blockd0582a62009-12-15 09:54:21 +0000631 // Allocate a sequential string. All the header fields of the string object
632 // are initialized.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000633 void AllocateTwoByteString(Register result, Register length,
634 Register scratch1, Register scratch2,
635 Register scratch3, Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000636 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);
Steve Blockd0582a62009-12-15 09:54:21 +0000641
642 // Allocate a raw cons string object. Only the map field of the result is
643 // initialized.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000644 void AllocateTwoByteConsString(Register result, Register scratch1,
645 Register scratch2, Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000646 void AllocateOneByteConsString(Register result, Register scratch1,
647 Register scratch2, Label* gc_required);
Steve Blockd0582a62009-12-15 09:54:21 +0000648
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000649 // Allocate a raw sliced string object. Only the map field of the result is
650 // initialized.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000651 void AllocateTwoByteSlicedString(Register result, Register scratch1,
652 Register scratch2, Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000653 void AllocateOneByteSlicedString(Register result, Register scratch1,
654 Register scratch2, Label* gc_required);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000655
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000656 // Allocate and initialize a JSValue wrapper with the specified {constructor}
657 // and {value}.
658 void AllocateJSValue(Register result, Register constructor, Register value,
659 Register scratch, Label* gc_required);
660
Ben Murdochb8e0da22011-05-16 14:20:40 +0100661 // Copy memory, byte-by-byte, from source to destination. Not optimized for
662 // long or aligned copies.
663 // The contents of index and scratch are destroyed.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000664 void CopyBytes(Register source, Register destination, Register length,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100665 Register scratch);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800666
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 // Initialize fields with filler values. Fields starting at |current_address|
668 // not including |end_address| are overwritten with the value in |filler|. At
669 // the end the loop, |current_address| takes the value of |end_address|.
670 void InitializeFieldsWithFiller(Register current_address,
671 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100672
Steve Blocka7e24c12009-10-30 11:49:00 +0000673 // ---------------------------------------------------------------------------
674 // Support functions.
675
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100676 // Check a boolean-bit of a Smi field.
677 void BooleanBitTest(Register object, int field_offset, int bit_index);
678
Steve Blocka7e24c12009-10-30 11:49:00 +0000679 // Check if result is zero and op is negative.
680 void NegativeZeroTest(Register result, Register op, Label* then_label);
681
Steve Blocka7e24c12009-10-30 11:49:00 +0000682 // 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);
686
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000687 // Machine code version of Map::GetConstructor().
688 // |temp| holds |result|'s map when done.
689 void GetMapConstructor(Register result, Register map, Register temp);
690
Steve Blocka7e24c12009-10-30 11:49:00 +0000691 // 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
695 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000696 void TryGetFunctionPrototype(Register function, Register result,
697 Register scratch, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000698
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100699 // Picks out an array index from the hash field.
700 // Register use:
701 // hash - holds the index's hash. Clobbered.
702 // index - holds the overwritten index on exit.
703 void IndexFromHash(Register hash, Register index);
704
Steve Blocka7e24c12009-10-30 11:49:00 +0000705 // ---------------------------------------------------------------------------
706 // Runtime calls
707
Leon Clarkee46be812010-01-19 14:06:41 +0000708 // Call a code stub. Generate the code if necessary.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000709 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000710
Leon Clarkee46be812010-01-19 14:06:41 +0000711 // Tail call a code stub (jump). Generate the code if necessary.
Steve Blockd0582a62009-12-15 09:54:21 +0000712 void TailCallStub(CodeStub* stub);
713
Steve Blocka7e24c12009-10-30 11:49:00 +0000714 // Return from a code stub after popping its arguments.
715 void StubReturn(int argc);
716
717 // Call a runtime routine.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000718 void CallRuntime(const Runtime::Function* f, int num_arguments,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000719 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000720 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
721 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000722 CallRuntime(function, function->nargs, kSaveFPRegs);
723 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000724
725 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000726 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000727 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000728 const Runtime::Function* function = Runtime::FunctionForId(fid);
729 CallRuntime(function, function->nargs, save_doubles);
730 }
731
732 // Convenience function: Same as above, but takes the fid instead.
733 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
734 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
735 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000736 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000737
Ben Murdochbb769b22010-08-11 14:56:33 +0100738 // Convenience function: call an external reference.
739 void CallExternalReference(ExternalReference ref, int num_arguments);
740
Steve Block6ded16b2010-05-10 14:33:55 +0100741 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000742 void TailCallRuntime(Runtime::FunctionId fid);
Steve Blocka7e24c12009-10-30 11:49:00 +0000743
Steve Block6ded16b2010-05-10 14:33:55 +0100744 // Before calling a C-function from generated code, align arguments on stack.
745 // After aligning the frame, arguments must be stored in esp[0], esp[4],
746 // etc., not pushed. The argument count assumes all arguments are word sized.
747 // Some compilers/platforms require the stack to be aligned when calling
748 // C++ code.
749 // Needs a scratch register to do some arithmetic. This register will be
750 // trashed.
751 void PrepareCallCFunction(int num_arguments, Register scratch);
752
753 // Calls a C function and cleans up the space for arguments allocated
754 // by PrepareCallCFunction. The called function is not allowed to trigger a
755 // garbage collection, since that might move the code and invalidate the
756 // return address (unless this is somehow accounted for by the called
757 // function).
758 void CallCFunction(ExternalReference function, int num_arguments);
759 void CallCFunction(Register function, int num_arguments);
760
Steve Blocka7e24c12009-10-30 11:49:00 +0000761 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100762 void JumpToExternalReference(const ExternalReference& ext);
Steve Blocka7e24c12009-10-30 11:49:00 +0000763
Steve Blocka7e24c12009-10-30 11:49:00 +0000764 // ---------------------------------------------------------------------------
765 // Utilities
766
767 void Ret();
768
Steve Block1e0659c2011-05-24 12:43:12 +0100769 // Return and drop arguments from stack, where the number of arguments
770 // may be bigger than 2^16 - 1. Requires a scratch register.
771 void Ret(int bytes_dropped, Register scratch);
772
Leon Clarkee46be812010-01-19 14:06:41 +0000773 // Emit code to discard a non-negative number of pointer-sized elements
774 // from the stack, clobbering only the esp register.
775 void Drop(int element_count);
776
777 void Call(Label* target) { call(target); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000778 void Call(Handle<Code> target, RelocInfo::Mode rmode) { call(target, rmode); }
779 void Jump(Handle<Code> target, RelocInfo::Mode rmode) { jmp(target, rmode); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000780 void Push(Register src) { push(src); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000781 void Push(const Operand& src) { push(src); }
782 void Push(Immediate value) { push(value); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000783 void Pop(Register dst) { pop(dst); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000784 void Pop(const Operand& dst) { pop(dst); }
785 void PushReturnAddressFrom(Register src) { push(src); }
786 void PopReturnAddressTo(Register dst) { pop(dst); }
787
788 // Non-SSE2 instructions.
789 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
790 void Pinsrd(XMMRegister dst, Register src, int8_t imm8) {
791 Pinsrd(dst, Operand(src), imm8);
792 }
793 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
794
795 void Lzcnt(Register dst, Register src) { Lzcnt(dst, Operand(src)); }
796 void Lzcnt(Register dst, const Operand& src);
797
798 void Tzcnt(Register dst, Register src) { Tzcnt(dst, Operand(src)); }
799 void Tzcnt(Register dst, const Operand& src);
800
801 void Popcnt(Register dst, Register src) { Popcnt(dst, Operand(src)); }
802 void Popcnt(Register dst, const Operand& src);
Leon Clarkee46be812010-01-19 14:06:41 +0000803
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100804 // Move if the registers are not identical.
805 void Move(Register target, Register source);
806
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000807 // Move a constant into a destination using the most efficient encoding.
808 void Move(Register dst, const Immediate& x);
809 void Move(const Operand& dst, const Immediate& x);
810
811 // Move an immediate into an XMM register.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400812 void Move(XMMRegister dst, uint32_t src);
813 void Move(XMMRegister dst, uint64_t src);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100814 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400815 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000816
Ben Murdochda12d292016-06-02 14:46:10 +0100817 void Move(Register dst, Handle<Object> handle) { LoadObject(dst, handle); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000818 void Move(Register dst, Smi* source) { Move(dst, Immediate(source)); }
819
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000820 // Push a handle value.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100821 void Push(Handle<Object> handle) { push(Immediate(handle)); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000822 void Push(Smi* smi) { Push(Immediate(smi)); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000823
Ben Murdoch8b112d22011-06-08 16:22:53 +0100824 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000825 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100826 return code_object_;
827 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000828
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000829 // Emit code for a truncating division by a constant. The dividend register is
830 // unchanged, the result is in edx, and eax gets clobbered.
831 void TruncatingDiv(Register dividend, int32_t divisor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000832
833 // ---------------------------------------------------------------------------
834 // StatsCounter support
835
836 void SetCounter(StatsCounter* counter, int value);
837 void IncrementCounter(StatsCounter* counter, int value);
838 void DecrementCounter(StatsCounter* counter, int value);
Leon Clarked91b9f72010-01-27 17:25:45 +0000839 void IncrementCounter(Condition cc, StatsCounter* counter, int value);
840 void DecrementCounter(Condition cc, StatsCounter* counter, int value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000841
Steve Blocka7e24c12009-10-30 11:49:00 +0000842 // ---------------------------------------------------------------------------
843 // Debugging
844
845 // Calls Abort(msg) if the condition cc is not satisfied.
846 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000847 void Assert(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000848
Iain Merrick75681382010-08-19 15:07:18 +0100849 void AssertFastElements(Register elements);
850
Steve Blocka7e24c12009-10-30 11:49:00 +0000851 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000852 void Check(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000853
854 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000855 void Abort(BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +0000856
Steve Block6ded16b2010-05-10 14:33:55 +0100857 // Check that the stack is aligned.
858 void CheckStackAlignment();
859
Steve Blocka7e24c12009-10-30 11:49:00 +0000860 // Verify restrictions about code generated in stubs.
861 void set_generating_stub(bool value) { generating_stub_ = value; }
862 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100863 void set_has_frame(bool value) { has_frame_ = value; }
864 bool has_frame() { return has_frame_; }
865 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +0000866
Leon Clarked91b9f72010-01-27 17:25:45 +0000867 // ---------------------------------------------------------------------------
868 // String utilities.
869
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870 // Check whether the instance type represents a flat one-byte string. Jump to
871 // the label if not. If the instance type can be scratched specify same
872 // register for both instance type and scratch.
873 void JumpIfInstanceTypeIsNotSequentialOneByte(
874 Register instance_type, Register scratch,
875 Label* on_not_flat_one_byte_string);
876
877 // Checks if both objects are sequential one-byte strings, and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +0000878 // if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000879 void JumpIfNotBothSequentialOneByteStrings(
880 Register object1, Register object2, Register scratch1, Register scratch2,
881 Label* on_not_flat_one_byte_strings);
882
883 // Checks if the given register or operand is a unique name
884 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
885 Label::Distance distance = Label::kFar) {
886 JumpIfNotUniqueNameInstanceType(Operand(reg), not_unique_name, distance);
887 }
888
889 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
890 Label::Distance distance = Label::kFar);
891
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000892 void EmitSeqStringSetCharCheck(Register string, Register index,
893 Register value, uint32_t encoding_mask);
Leon Clarked91b9f72010-01-27 17:25:45 +0000894
Ben Murdoch8b112d22011-06-08 16:22:53 +0100895 static int SafepointRegisterStackIndex(Register reg) {
896 return SafepointRegisterStackIndex(reg.code());
897 }
898
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000899 // Load the type feedback vector from a JavaScript frame.
900 void EmitLoadTypeFeedbackVector(Register vector);
901
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100902 // Activation support.
903 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400904 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100905 void LeaveFrame(StackFrame::Type type);
906
907 // Expects object in eax and returns map with validated enum cache
908 // in eax. Assumes that any other register can be used as a scratch.
909 void CheckEnumCache(Label* call_runtime);
910
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000911 // AllocationMemento support. Arrays may have an associated
912 // AllocationMemento object that can be checked for in order to pretransition
913 // to another type.
914 // On entry, receiver_reg should point to the array object.
915 // scratch_reg gets clobbered.
916 // If allocation info is present, conditional code is set to equal.
917 void TestJSArrayForAllocationMemento(Register receiver_reg,
918 Register scratch_reg,
919 Label* no_memento_found);
920
921 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
922 Register scratch_reg,
923 Label* memento_found) {
924 Label no_memento_found;
925 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
926 &no_memento_found);
927 j(equal, memento_found);
928 bind(&no_memento_found);
929 }
930
931 // Jumps to found label if a prototype map has dictionary elements.
932 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
933 Register scratch1, Label* found);
934
Steve Blocka7e24c12009-10-30 11:49:00 +0000935 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000936 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100937 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +0000938 // This handle will be patched with the code object on installation.
939 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000940
941 // Helper functions for generating invokes.
942 void InvokePrologue(const ParameterCount& expected,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000943 const ParameterCount& actual, Label* done,
944 bool* definitely_mismatches, InvokeFlag flag,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100945 Label::Distance done_distance,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000946 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000947
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100948 void EnterExitFramePrologue();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100949 void EnterExitFrameEpilogue(int argc, bool save_doubles);
Steve Blockd0582a62009-12-15 09:54:21 +0000950
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000951 void LeaveExitFrameEpilogue(bool restore_context);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800952
Steve Blocka7e24c12009-10-30 11:49:00 +0000953 // Allocation support helpers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000954 void LoadAllocationTopHelper(Register result, Register scratch,
Steve Blocka7e24c12009-10-30 11:49:00 +0000955 AllocationFlags flags);
Leon Clarkee46be812010-01-19 14:06:41 +0000956
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000957 void UpdateAllocationTopHelper(Register result_end, Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958 AllocationFlags flags);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100959
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100960 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000961 void InNewSpace(Register object, Register scratch, Condition cc,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100962 Label* condition_met,
963 Label::Distance condition_met_distance = Label::kFar);
964
965 // Helper for finding the mark bits for an address. Afterwards, the
966 // bitmap register points at the word with the mark bits and the mask
967 // the position of the first bit. Uses ecx as scratch and leaves addr_reg
968 // unchanged.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000969 inline void GetMarkBits(Register addr_reg, Register bitmap_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100970 Register mask_reg);
971
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100972 // Compute memory operands for safepoint stack slots.
973 Operand SafepointRegisterSlot(Register reg);
974 static int SafepointRegisterStackIndex(int reg_code);
975
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100977 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000978 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +0000979};
980
Steve Blocka7e24c12009-10-30 11:49:00 +0000981// The code patcher is used to patch (typically) small parts of code e.g. for
982// debugging and other types of instrumentation. When using the code patcher
983// the exact number of bytes specified must be emitted. Is not legal to emit
984// relocation information. If any of these constraints are violated it causes
985// an assertion.
986class CodePatcher {
987 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000988 CodePatcher(Isolate* isolate, byte* address, int size);
989 ~CodePatcher();
Steve Blocka7e24c12009-10-30 11:49:00 +0000990
991 // Macro assembler to emit code.
992 MacroAssembler* masm() { return &masm_; }
993
994 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000995 byte* address_; // The address of the code being patched.
996 int size_; // Number of bytes of the expected patch size.
Steve Blocka7e24c12009-10-30 11:49:00 +0000997 MacroAssembler masm_; // Macro assembler used to generate the code.
998};
999
Steve Blocka7e24c12009-10-30 11:49:00 +00001000// -----------------------------------------------------------------------------
1001// Static helper functions.
1002
1003// Generate an Operand for loading a field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001004inline Operand FieldOperand(Register object, int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001005 return Operand(object, offset - kHeapObjectTag);
1006}
1007
Steve Blocka7e24c12009-10-30 11:49:00 +00001008// Generate an Operand for loading an indexed field from an object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001009inline Operand FieldOperand(Register object, Register index, ScaleFactor scale,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001010 int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001011 return Operand(object, index, scale, offset - kHeapObjectTag);
1012}
1013
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001014inline Operand FixedArrayElementOperand(Register array, Register index_as_smi,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001015 int additional_offset = 0) {
1016 int offset = FixedArray::kHeaderSize + additional_offset * kPointerSize;
1017 return FieldOperand(array, index_as_smi, times_half_pointer_size, offset);
1018}
1019
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001020inline Operand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001021 return Operand(context, Context::SlotOffset(index));
1022}
1023
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001024inline Operand ContextOperand(Register context, Register index) {
1025 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001026}
1027
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001028inline Operand NativeContextOperand() {
1029 return ContextOperand(esi, Context::NATIVE_CONTEXT_INDEX);
1030}
Steve Blocka7e24c12009-10-30 11:49:00 +00001031
1032#ifdef GENERATED_CODE_COVERAGE
1033extern void LogGeneratedCodeCoverage(const char* file_line);
1034#define CODE_COVERAGE_STRINGIFY(x) #x
1035#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1036#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1037#define ACCESS_MASM(masm) { \
1038 byte* ia32_coverage_function = \
1039 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1040 masm->pushfd(); \
1041 masm->pushad(); \
1042 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1043 masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \
1044 masm->pop(eax); \
1045 masm->popad(); \
1046 masm->popfd(); \
1047 } \
1048 masm->
1049#else
1050#define ACCESS_MASM(masm) masm->
1051#endif
1052
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001053} // namespace internal
1054} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001055
1056#endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_