blob: b088c7d19c44a1d2301af08c19fb2f689b56df2c [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_X64_MACRO_ASSEMBLER_X64_H_
6#define V8_X64_MACRO_ASSEMBLER_X64_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/assembler.h"
9#include "src/bailout-reason.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/base/flags.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/frames.h"
12#include "src/globals.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/x64/frames-x64.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000014
15namespace v8 {
16namespace internal {
17
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018// Give alias names to registers for calling conventions.
19const Register kReturnRegister0 = {Register::kCode_rax};
20const Register kReturnRegister1 = {Register::kCode_rdx};
Ben Murdoch097c5b22016-05-18 11:27:45 +010021const Register kReturnRegister2 = {Register::kCode_r8};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022const Register kJSFunctionRegister = {Register::kCode_rdi};
23const Register kContextRegister = {Register::kCode_rsi};
Ben Murdochc5610432016-08-08 18:44:38 +010024const Register kAllocateSizeRegister = {Register::kCode_rdx};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025const Register kInterpreterAccumulatorRegister = {Register::kCode_rax};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r12};
27const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r14};
28const Register kInterpreterDispatchTableRegister = {Register::kCode_r15};
29const Register kJavaScriptCallArgCountRegister = {Register::kCode_rax};
30const Register kJavaScriptCallNewTargetRegister = {Register::kCode_rdx};
31const Register kRuntimeCallFunctionRegister = {Register::kCode_rbx};
32const Register kRuntimeCallArgCountRegister = {Register::kCode_rax};
33
Steve Blocka7e24c12009-10-30 11:49:00 +000034// Default scratch register used by MacroAssembler (and other code that needs
35// a spare register). The register isn't callee save, and not used by the
36// function calling convention.
Ben Murdoch61f157c2016-09-16 13:49:30 +010037const Register kScratchRegister = {10}; // r10.
38const XMMRegister kScratchDoubleReg = {15}; // xmm15.
39const Register kRootRegister = {13}; // r13 (callee save).
Ben Murdoche0cee9b2011-05-25 10:26:03 +010040// Actual value of root register is offset from the root array's start
41// to take advantage of negitive 8-bit displacement values.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010042const int kRootRegisterBias = 128;
Steve Blocka7e24c12009-10-30 11:49:00 +000043
Leon Clarkee46be812010-01-19 14:06:41 +000044// Convenience for platform-independent signatures.
45typedef Operand MemOperand;
46
Ben Murdoch3ef787d2012-04-12 10:51:47 +010047enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
48enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049enum PointersToHereCheck {
50 kPointersToHereMaybeInteresting,
51 kPointersToHereAreAlwaysInteresting
52};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010053
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054enum class SmiOperationConstraint {
55 kPreserveSourceRegister = 1 << 0,
56 kBailoutOnNoOverflow = 1 << 1,
57 kBailoutOnOverflow = 1 << 2
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058};
59
Ben Murdochda12d292016-06-02 14:46:10 +010060enum class ReturnAddressState { kOnStack, kNotOnStack };
61
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062typedef base::Flags<SmiOperationConstraint> SmiOperationConstraints;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064DEFINE_OPERATORS_FOR_FLAGS(SmiOperationConstraints)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065
66#ifdef DEBUG
67bool AreAliased(Register reg1,
68 Register reg2,
69 Register reg3 = no_reg,
70 Register reg4 = no_reg,
71 Register reg5 = no_reg,
72 Register reg6 = no_reg,
73 Register reg7 = no_reg,
74 Register reg8 = no_reg);
75#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076
Steve Blocka7e24c12009-10-30 11:49:00 +000077// Forward declaration.
78class JumpTarget;
79
80struct SmiIndex {
81 SmiIndex(Register index_register, ScaleFactor scale)
82 : reg(index_register),
83 scale(scale) {}
84 Register reg;
85 ScaleFactor scale;
86};
87
Ben Murdoch3ef787d2012-04-12 10:51:47 +010088
Steve Blocka7e24c12009-10-30 11:49:00 +000089// MacroAssembler implements a collection of frequently used macros.
90class MacroAssembler: public Assembler {
91 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 MacroAssembler(Isolate* isolate, void* buffer, int size,
93 CodeObjectRequired create_code_object);
Steve Blocka7e24c12009-10-30 11:49:00 +000094
Steve Block44f0eee2011-05-26 01:26:41 +010095 // Prevent the use of the RootArray during the lifetime of this
96 // scope object.
97 class NoRootArrayScope BASE_EMBEDDED {
98 public:
99 explicit NoRootArrayScope(MacroAssembler* assembler)
100 : variable_(&assembler->root_array_available_),
101 old_value_(assembler->root_array_available_) {
102 assembler->root_array_available_ = false;
103 }
104 ~NoRootArrayScope() {
105 *variable_ = old_value_;
106 }
107 private:
108 bool* variable_;
109 bool old_value_;
110 };
111
112 // Operand pointing to an external reference.
113 // May emit code to set up the scratch register. The operand is
114 // only guaranteed to be correct as long as the scratch register
115 // isn't changed.
116 // If the operand is used more than once, use a scratch register
117 // that is guaranteed not to be clobbered.
118 Operand ExternalOperand(ExternalReference reference,
119 Register scratch = kScratchRegister);
120 // Loads and stores the value of an external reference.
121 // Special case code for load and store to take advantage of
122 // load_rax/store_rax if possible/necessary.
123 // For other operations, just use:
124 // Operand operand = ExternalOperand(extref);
125 // operation(operand, ..);
126 void Load(Register destination, ExternalReference source);
127 void Store(ExternalReference destination, Register source);
128 // Loads the address of the external reference into the destination
129 // register.
130 void LoadAddress(Register destination, ExternalReference source);
131 // Returns the size of the code generated by LoadAddress.
132 // Used by CallSize(ExternalReference) to find the size of a call.
133 int LoadAddressSize(ExternalReference source);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134 // Pushes the address of the external reference onto the stack.
135 void PushAddress(ExternalReference source);
Steve Block44f0eee2011-05-26 01:26:41 +0100136
137 // Operations on roots in the root-array.
Steve Blocka7e24c12009-10-30 11:49:00 +0000138 void LoadRoot(Register destination, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000139 void LoadRoot(const Operand& destination, Heap::RootListIndex index) {
140 LoadRoot(kScratchRegister, index);
141 movp(destination, kScratchRegister);
142 }
Steve Block44f0eee2011-05-26 01:26:41 +0100143 void StoreRoot(Register source, Heap::RootListIndex index);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100144 // Load a root value where the index (or part of it) is variable.
145 // The variable_offset register is added to the fixed_offset value
146 // to get the index into the root-array.
147 void LoadRootIndexed(Register destination,
148 Register variable_offset,
149 int fixed_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000150 void CompareRoot(Register with, Heap::RootListIndex index);
Steve Block1e0659c2011-05-24 12:43:12 +0100151 void CompareRoot(const Operand& with, Heap::RootListIndex index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000152 void PushRoot(Heap::RootListIndex index);
153
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154 // Compare the object in a register to a value and jump if they are equal.
155 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal,
156 Label::Distance if_equal_distance = Label::kFar) {
157 CompareRoot(with, index);
158 j(equal, if_equal, if_equal_distance);
159 }
160 void JumpIfRoot(const Operand& with, Heap::RootListIndex index,
161 Label* if_equal,
162 Label::Distance if_equal_distance = Label::kFar) {
163 CompareRoot(with, index);
164 j(equal, if_equal, if_equal_distance);
165 }
166
167 // Compare the object in a register to a value and jump if they are not equal.
168 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
169 Label* if_not_equal,
170 Label::Distance if_not_equal_distance = Label::kFar) {
171 CompareRoot(with, index);
172 j(not_equal, if_not_equal, if_not_equal_distance);
173 }
174 void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index,
175 Label* if_not_equal,
176 Label::Distance if_not_equal_distance = Label::kFar) {
177 CompareRoot(with, index);
178 j(not_equal, if_not_equal, if_not_equal_distance);
179 }
180
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100181 // These functions do not arrange the registers in any particular order so
182 // they are not useful for calls that can cause a GC. The caller can
183 // exclude up to 3 registers that do not need to be saved and restored.
184 void PushCallerSaved(SaveFPRegsMode fp_mode,
185 Register exclusion1 = no_reg,
186 Register exclusion2 = no_reg,
187 Register exclusion3 = no_reg);
188 void PopCallerSaved(SaveFPRegsMode fp_mode,
189 Register exclusion1 = no_reg,
190 Register exclusion2 = no_reg,
191 Register exclusion3 = no_reg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000192
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100193// ---------------------------------------------------------------------------
194// GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100195
Steve Block6ded16b2010-05-10 14:33:55 +0100196
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100197 enum RememberedSetFinalAction {
198 kReturnAtEnd,
199 kFallThroughAtEnd
200 };
201
202 // Record in the remembered set the fact that we have a pointer to new space
203 // at the address pointed to by the addr register. Only works if addr is not
204 // in new space.
205 void RememberedSetHelper(Register object, // Used for debug code.
206 Register addr,
207 Register scratch,
208 SaveFPRegsMode save_fp,
209 RememberedSetFinalAction and_then);
210
211 void CheckPageFlag(Register object,
212 Register scratch,
213 int mask,
214 Condition cc,
215 Label* condition_met,
216 Label::Distance condition_met_distance = Label::kFar);
217
218 // Check if object is in new space. Jumps if the object is not in new space.
219 // The register scratch can be object itself, but scratch will be clobbered.
220 void JumpIfNotInNewSpace(Register object,
221 Register scratch,
222 Label* branch,
223 Label::Distance distance = Label::kFar) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100224 InNewSpace(object, scratch, zero, branch, distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100225 }
226
227 // Check if object is in new space. Jumps if the object is in new space.
228 // The register scratch can be object itself, but it will be clobbered.
229 void JumpIfInNewSpace(Register object,
230 Register scratch,
231 Label* branch,
232 Label::Distance distance = Label::kFar) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100233 InNewSpace(object, scratch, not_zero, branch, distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100234 }
235
236 // Check if an object has the black incremental marking color. Also uses rcx!
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 void JumpIfBlack(Register object, Register bitmap_scratch,
238 Register mask_scratch, Label* on_black,
239 Label::Distance on_black_distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100240
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000241 // Checks the color of an object. If the object is white we jump to the
242 // incremental marker.
243 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
244 Label* value_is_white, Label::Distance distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100245
246 // Notify the garbage collector that we wrote a pointer into an object.
247 // |object| is the object being stored into, |value| is the object being
248 // stored. value and scratch registers are clobbered by the operation.
249 // The offset is the offset from the start of the object, not the offset from
250 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
251 void RecordWriteField(
252 Register object,
253 int offset,
254 Register value,
255 Register scratch,
256 SaveFPRegsMode save_fp,
257 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000258 SmiCheck smi_check = INLINE_SMI_CHECK,
259 PointersToHereCheck pointers_to_here_check_for_value =
260 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100261
262 // As above, but the offset has the tag presubtracted. For use with
263 // Operand(reg, off).
264 void RecordWriteContextSlot(
265 Register context,
266 int offset,
267 Register value,
268 Register scratch,
269 SaveFPRegsMode save_fp,
270 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000271 SmiCheck smi_check = INLINE_SMI_CHECK,
272 PointersToHereCheck pointers_to_here_check_for_value =
273 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100274 RecordWriteField(context,
275 offset + kHeapObjectTag,
276 value,
277 scratch,
278 save_fp,
279 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280 smi_check,
281 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100282 }
283
284 // Notify the garbage collector that we wrote a pointer into a fixed array.
285 // |array| is the array being stored into, |value| is the
286 // object being stored. |index| is the array index represented as a non-smi.
287 // All registers are clobbered by the operation RecordWriteArray
288 // filters out smis so it does not update the write barrier if the
289 // value is a smi.
290 void RecordWriteArray(
291 Register array,
292 Register value,
293 Register index,
294 SaveFPRegsMode save_fp,
295 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296 SmiCheck smi_check = INLINE_SMI_CHECK,
297 PointersToHereCheck pointers_to_here_check_for_value =
298 kPointersToHereMaybeInteresting);
299
Ben Murdoch097c5b22016-05-18 11:27:45 +0100300 // Notify the garbage collector that we wrote a code entry into a
301 // JSFunction. Only scratch is clobbered by the operation.
302 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
303 Register scratch);
304
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000305 void RecordWriteForMap(
306 Register object,
307 Register map,
308 Register dst,
309 SaveFPRegsMode save_fp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100310
311 // For page containing |object| mark region covering |address|
Steve Block8defd9f2010-07-08 12:39:36 +0100312 // dirty. |object| is the object being stored into, |value| is the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100313 // object being stored. The address and value registers are clobbered by the
Steve Block8defd9f2010-07-08 12:39:36 +0100314 // operation. RecordWrite filters out smis so it does not update
315 // the write barrier if the value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100316 void RecordWrite(
317 Register object,
318 Register address,
319 Register value,
320 SaveFPRegsMode save_fp,
321 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000322 SmiCheck smi_check = INLINE_SMI_CHECK,
323 PointersToHereCheck pointers_to_here_check_for_value =
324 kPointersToHereMaybeInteresting);
Steve Block3ce2e202009-11-05 08:53:23 +0000325
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 // ---------------------------------------------------------------------------
327 // Debugger Support
328
Andrei Popescu402d9372010-02-26 13:31:12 +0000329 void DebugBreak();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000330
331 // Generates function and stub prologue code.
Ben Murdochda12d292016-06-02 14:46:10 +0100332 void StubPrologue(StackFrame::Type type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333 void Prologue(bool code_pre_aging);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
Steve Blockd0582a62009-12-15 09:54:21 +0000335 // Enter specific kind of exit frame; either in normal or
336 // debug mode. Expects the number of arguments in register rax and
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 // sets up the number of arguments in register rdi and the pointer
338 // to the first argument in register rsi.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800339 //
340 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
341 // accessible via StackSpaceOperand.
Steve Block1e0659c2011-05-24 12:43:12 +0100342 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800344 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
345 // memory (not GCed) on the stack accessible via StackSpaceOperand.
346 void EnterApiExitFrame(int arg_stack_space);
Ben Murdochbb769b22010-08-11 14:56:33 +0100347
Steve Blocka7e24c12009-10-30 11:49:00 +0000348 // Leave the current exit frame. Expects/provides the return value in
349 // register rax:rdx (untouched) and the pointer to the first
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000350 // argument in register rsi (if pop_arguments == true).
351 void LeaveExitFrame(bool save_doubles = false, bool pop_arguments = true);
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800353 // Leave the current exit frame. Expects/provides the return value in
354 // register rax (untouched).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000355 void LeaveApiExitFrame(bool restore_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000356
Ben Murdochb0fe1622011-05-05 13:52:32 +0100357 // Push and pop the registers that can hold pointers.
Steve Block1e0659c2011-05-24 12:43:12 +0100358 void PushSafepointRegisters() { Pushad(); }
359 void PopSafepointRegisters() { Popad(); }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100360 // Store the value in register src in the safepoint register stack
361 // slot for register dst.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000362 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100363 void StoreToSafepointRegisterSlot(Register dst, Register src);
364 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100365
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100366 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100367 ExternalReference roots_array_start =
368 ExternalReference::roots_array_start(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000369 Move(kRootRegister, roots_array_start);
370 addp(kRootRegister, Immediate(kRootRegisterBias));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100371 }
Steve Block1e0659c2011-05-24 12:43:12 +0100372
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 // ---------------------------------------------------------------------------
374 // JavaScript invokes
375
Ben Murdochda12d292016-06-02 14:46:10 +0100376 // Removes current frame and its arguments from the stack preserving
377 // the arguments and a return address pushed to the stack for the next call.
378 // |ra_state| defines whether return address is already pushed to stack or
379 // not. Both |callee_args_count| and |caller_args_count_reg| do not include
380 // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
381 // is trashed.
382 void PrepareForTailCall(const ParameterCount& callee_args_count,
383 Register caller_args_count_reg, Register scratch0,
384 Register scratch1, ReturnAddressState ra_state);
385
Steve Blocka7e24c12009-10-30 11:49:00 +0000386 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000387 void InvokeFunctionCode(Register function, Register new_target,
388 const ParameterCount& expected,
389 const ParameterCount& actual, InvokeFlag flag,
390 const CallWrapper& call_wrapper);
391
392 void FloodFunctionIfStepping(Register fun, Register new_target,
393 const ParameterCount& expected,
394 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000395
396 // Invoke the JavaScript function in the given register. Changes the
397 // current context to the context in the function before invoking.
398 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000399 Register new_target,
Steve Blocka7e24c12009-10-30 11:49:00 +0000400 const ParameterCount& actual,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100401 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000402 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000403
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000404 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405 Register new_target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000407 const ParameterCount& actual,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100408 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409 const CallWrapper& call_wrapper);
410
411 void InvokeFunction(Handle<JSFunction> function,
412 const ParameterCount& expected,
413 const ParameterCount& actual,
414 InvokeFlag flag,
415 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000416
Steve Blocka7e24c12009-10-30 11:49:00 +0000417 // ---------------------------------------------------------------------------
418 // Smi tagging, untagging and operations on tagged smis.
419
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000420 // Support for constant splitting.
421 bool IsUnsafeInt(const int32_t x);
422 void SafeMove(Register dst, Smi* src);
423 void SafePush(Smi* src);
424
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 // Conversions between tagged smi values and non-tagged integer values.
426
427 // Tag an integer value. The result must be known to be a valid smi value.
Leon Clarke4515c472010-02-03 11:58:03 +0000428 // Only uses the low 32 bits of the src register. Sets the N and Z flags
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100429 // based on the value of the resulting smi.
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 void Integer32ToSmi(Register dst, Register src);
431
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100432 // Stores an integer32 value into a memory field that already holds a smi.
433 void Integer32ToSmiField(const Operand& dst, Register src);
434
Steve Blocka7e24c12009-10-30 11:49:00 +0000435 // Adds constant to src and tags the result as a smi.
436 // Result must be a valid smi.
Steve Block3ce2e202009-11-05 08:53:23 +0000437 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
Steve Blocka7e24c12009-10-30 11:49:00 +0000438
439 // Convert smi to 32-bit integer. I.e., not sign extended into
440 // high 32 bits of destination.
441 void SmiToInteger32(Register dst, Register src);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100442 void SmiToInteger32(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000443
444 // Convert smi to 64-bit integer (sign extended if necessary).
445 void SmiToInteger64(Register dst, Register src);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100446 void SmiToInteger64(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000447
Ben Murdoch097c5b22016-05-18 11:27:45 +0100448 // Convert smi to double.
449 void SmiToDouble(XMMRegister dst, Register src) {
450 SmiToInteger32(kScratchRegister, src);
451 Cvtlsi2sd(dst, kScratchRegister);
452 }
453
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 // Multiply a positive smi's integer value by a power of two.
455 // Provides result as 64-bit integer value.
456 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
457 Register src,
458 int power);
459
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100460 // Divide a positive smi's integer value by a power of two.
461 // Provides result as 32-bit integer value.
462 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
463 Register src,
464 int power);
465
Ben Murdoch8b112d22011-06-08 16:22:53 +0100466 // Perform the logical or of two smi values and return a smi value.
467 // If either argument is not a smi, jump to on_not_smis and retain
468 // the original values of source registers. The destination register
469 // may be changed if it's not one of the source registers.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100470 void SmiOrIfSmis(Register dst,
471 Register src1,
472 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000473 Label* on_not_smis,
474 Label::Distance near_jump = Label::kFar);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100475
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100476
Steve Block44f0eee2011-05-26 01:26:41 +0100477 // Simple comparison of smis. Both sides must be known smis to use these,
478 // otherwise use Cmp.
479 void SmiCompare(Register smi1, Register smi2);
Steve Block3ce2e202009-11-05 08:53:23 +0000480 void SmiCompare(Register dst, Smi* src);
Steve Block6ded16b2010-05-10 14:33:55 +0100481 void SmiCompare(Register dst, const Operand& src);
Steve Block3ce2e202009-11-05 08:53:23 +0000482 void SmiCompare(const Operand& dst, Register src);
483 void SmiCompare(const Operand& dst, Smi* src);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100484 // Compare the int32 in src register to the value of the smi stored at dst.
485 void SmiCompareInteger32(const Operand& dst, Register src);
Steve Block3ce2e202009-11-05 08:53:23 +0000486 // Sets sign and zero flags depending on value of smi in register.
487 void SmiTest(Register src);
488
Steve Blocka7e24c12009-10-30 11:49:00 +0000489 // Functions performing a check on a known or potential smi. Returns
490 // a condition that is satisfied if the check is successful.
491
492 // Is the value a tagged smi.
493 Condition CheckSmi(Register src);
Steve Block1e0659c2011-05-24 12:43:12 +0100494 Condition CheckSmi(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000495
Ben Murdochf87a2032010-10-22 12:50:53 +0100496 // Is the value a non-negative tagged smi.
497 Condition CheckNonNegativeSmi(Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000498
Leon Clarkee46be812010-01-19 14:06:41 +0000499 // Are both values tagged smis.
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 Condition CheckBothSmi(Register first, Register second);
501
Ben Murdochf87a2032010-10-22 12:50:53 +0100502 // Are both values non-negative tagged smis.
503 Condition CheckBothNonNegativeSmi(Register first, Register second);
Leon Clarked91b9f72010-01-27 17:25:45 +0000504
Leon Clarkee46be812010-01-19 14:06:41 +0000505 // Are either value a tagged smi.
Ben Murdochbb769b22010-08-11 14:56:33 +0100506 Condition CheckEitherSmi(Register first,
507 Register second,
508 Register scratch = kScratchRegister);
Leon Clarkee46be812010-01-19 14:06:41 +0000509
Steve Blocka7e24c12009-10-30 11:49:00 +0000510 // Checks whether an 32-bit integer value is a valid for conversion
511 // to a smi.
512 Condition CheckInteger32ValidSmiValue(Register src);
513
Steve Block3ce2e202009-11-05 08:53:23 +0000514 // Checks whether an 32-bit unsigned integer value is a valid for
515 // conversion to a smi.
516 Condition CheckUInteger32ValidSmiValue(Register src);
517
Steve Block1e0659c2011-05-24 12:43:12 +0100518 // Check whether src is a Smi, and set dst to zero if it is a smi,
519 // and to one if it isn't.
520 void CheckSmiToIndicator(Register dst, Register src);
521 void CheckSmiToIndicator(Register dst, const Operand& src);
522
Steve Blocka7e24c12009-10-30 11:49:00 +0000523 // Test-and-jump functions. Typically combines a check function
524 // above with a conditional jump.
525
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000526 // Jump if the value can be represented by a smi.
527 void JumpIfValidSmiValue(Register src, Label* on_valid,
528 Label::Distance near_jump = Label::kFar);
529
Steve Blocka7e24c12009-10-30 11:49:00 +0000530 // Jump if the value cannot be represented by a smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000531 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
532 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000533
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000534 // Jump if the unsigned integer value can be represented by a smi.
535 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
536 Label::Distance near_jump = Label::kFar);
537
Steve Block3ce2e202009-11-05 08:53:23 +0000538 // Jump if the unsigned integer value cannot be represented by a smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000539 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
540 Label::Distance near_jump = Label::kFar);
Steve Block3ce2e202009-11-05 08:53:23 +0000541
Steve Blocka7e24c12009-10-30 11:49:00 +0000542 // Jump to label if the value is a tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000543 void JumpIfSmi(Register src,
544 Label* on_smi,
545 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000546
547 // Jump to label if the value is not a tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000548 void JumpIfNotSmi(Register src,
549 Label* on_not_smi,
550 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000551
Ben Murdochf87a2032010-10-22 12:50:53 +0100552 // Jump to label if the value is not a non-negative tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000553 void JumpUnlessNonNegativeSmi(Register src,
554 Label* on_not_smi,
555 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000556
Steve Block3ce2e202009-11-05 08:53:23 +0000557 // Jump to label if the value, which must be a tagged smi, has value equal
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 // to the constant.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100559 void JumpIfSmiEqualsConstant(Register src,
560 Smi* constant,
Ben Murdoch257744e2011-11-30 15:57:28 +0000561 Label* on_equals,
562 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000563
564 // Jump if either or both register are not smi values.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100565 void JumpIfNotBothSmi(Register src1,
566 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000567 Label* on_not_both_smi,
568 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000569
Ben Murdochf87a2032010-10-22 12:50:53 +0100570 // Jump if either or both register are not non-negative smi values.
Ben Murdochf87a2032010-10-22 12:50:53 +0100571 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000572 Label* on_not_both_smi,
573 Label::Distance near_jump = Label::kFar);
Leon Clarked91b9f72010-01-27 17:25:45 +0000574
Steve Blocka7e24c12009-10-30 11:49:00 +0000575 // Operations on tagged smi values.
576
577 // Smis represent a subset of integers. The subset is always equivalent to
578 // a two's complement interpretation of a fixed number of bits.
579
Steve Block3ce2e202009-11-05 08:53:23 +0000580 // Add an integer constant to a tagged smi, giving a tagged smi as result.
581 // No overflow testing on the result is done.
582 void SmiAddConstant(Register dst, Register src, Smi* constant);
583
Leon Clarkef7060e22010-06-03 12:02:55 +0100584 // Add an integer constant to a tagged smi, giving a tagged smi as result.
585 // No overflow testing on the result is done.
586 void SmiAddConstant(const Operand& dst, Smi* constant);
587
Steve Blocka7e24c12009-10-30 11:49:00 +0000588 // Add an integer constant to a tagged smi, giving a tagged smi as result,
589 // or jumping to a label if the result cannot be represented by a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 void SmiAddConstant(Register dst, Register src, Smi* constant,
591 SmiOperationConstraints constraints, Label* bailout_label,
Ben Murdoch257744e2011-11-30 15:57:28 +0000592 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
594 // Subtract an integer constant from a tagged smi, giving a tagged smi as
Steve Block6ded16b2010-05-10 14:33:55 +0100595 // result. No testing on the result is done. Sets the N and Z flags
596 // based on the value of the resulting integer.
Steve Block3ce2e202009-11-05 08:53:23 +0000597 void SmiSubConstant(Register dst, Register src, Smi* constant);
598
599 // Subtract an integer constant from a tagged smi, giving a tagged smi as
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 // result, or jumping to a label if the result cannot be represented by a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000601 void SmiSubConstant(Register dst, Register src, Smi* constant,
602 SmiOperationConstraints constraints, Label* bailout_label,
Ben Murdoch257744e2011-11-30 15:57:28 +0000603 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000604
605 // Negating a smi can give a negative zero or too large positive value.
Steve Block3ce2e202009-11-05 08:53:23 +0000606 // NOTICE: This operation jumps on success, not failure!
Steve Blocka7e24c12009-10-30 11:49:00 +0000607 void SmiNeg(Register dst,
608 Register src,
Ben Murdoch257744e2011-11-30 15:57:28 +0000609 Label* on_smi_result,
610 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000611
612 // Adds smi values and return the result as a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000613 // If dst is src1, then src1 will be destroyed if the operation is
614 // successful, otherwise kept intact.
Steve Blocka7e24c12009-10-30 11:49:00 +0000615 void SmiAdd(Register dst,
616 Register src1,
617 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000618 Label* on_not_smi_result,
619 Label::Distance near_jump = Label::kFar);
Steve Block44f0eee2011-05-26 01:26:41 +0100620 void SmiAdd(Register dst,
621 Register src1,
622 const Operand& src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000623 Label* on_not_smi_result,
624 Label::Distance near_jump = Label::kFar);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100625
626 void SmiAdd(Register dst,
627 Register src1,
628 Register src2);
Steve Blocka7e24c12009-10-30 11:49:00 +0000629
630 // Subtracts smi values and return the result as a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000631 // If dst is src1, then src1 will be destroyed if the operation is
632 // successful, otherwise kept intact.
Steve Blocka7e24c12009-10-30 11:49:00 +0000633 void SmiSub(Register dst,
634 Register src1,
635 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000636 Label* on_not_smi_result,
637 Label::Distance near_jump = Label::kFar);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000638 void SmiSub(Register dst,
639 Register src1,
640 const Operand& src2,
641 Label* on_not_smi_result,
642 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000643
Steve Block6ded16b2010-05-10 14:33:55 +0100644 void SmiSub(Register dst,
645 Register src1,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100646 Register src2);
647
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100648 void SmiSub(Register dst,
649 Register src1,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100650 const Operand& src2);
Steve Block6ded16b2010-05-10 14:33:55 +0100651
Steve Blocka7e24c12009-10-30 11:49:00 +0000652 // Multiplies smi values and return the result as a smi,
653 // if possible.
654 // If dst is src1, then src1 will be destroyed, even if
655 // the operation is unsuccessful.
656 void SmiMul(Register dst,
657 Register src1,
658 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000659 Label* on_not_smi_result,
660 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000661
662 // Divides one smi by another and returns the quotient.
663 // Clobbers rax and rdx registers.
664 void SmiDiv(Register dst,
665 Register src1,
666 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000667 Label* on_not_smi_result,
668 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000669
670 // Divides one smi by another and returns the remainder.
671 // Clobbers rax and rdx registers.
672 void SmiMod(Register dst,
673 Register src1,
674 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000675 Label* on_not_smi_result,
676 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000677
678 // Bitwise operations.
679 void SmiNot(Register dst, Register src);
680 void SmiAnd(Register dst, Register src1, Register src2);
681 void SmiOr(Register dst, Register src1, Register src2);
682 void SmiXor(Register dst, Register src1, Register src2);
Steve Block3ce2e202009-11-05 08:53:23 +0000683 void SmiAndConstant(Register dst, Register src1, Smi* constant);
684 void SmiOrConstant(Register dst, Register src1, Smi* constant);
685 void SmiXorConstant(Register dst, Register src1, Smi* constant);
Steve Blocka7e24c12009-10-30 11:49:00 +0000686
687 void SmiShiftLeftConstant(Register dst,
688 Register src,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000689 int shift_value,
690 Label* on_not_smi_result = NULL,
691 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000692 void SmiShiftLogicalRightConstant(Register dst,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000693 Register src,
694 int shift_value,
695 Label* on_not_smi_result,
696 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000697 void SmiShiftArithmeticRightConstant(Register dst,
698 Register src,
699 int shift_value);
700
701 // Shifts a smi value to the left, and returns the result if that is a smi.
702 // Uses and clobbers rcx, so dst may not be rcx.
703 void SmiShiftLeft(Register dst,
704 Register src1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000705 Register src2,
706 Label* on_not_smi_result = NULL,
707 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000708 // Shifts a smi value to the right, shifting in zero bits at the top, and
709 // returns the unsigned intepretation of the result if that is a smi.
710 // Uses and clobbers rcx, so dst may not be rcx.
711 void SmiShiftLogicalRight(Register dst,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100712 Register src1,
713 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000714 Label* on_not_smi_result,
715 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000716 // Shifts a smi value to the right, sign extending the top, and
717 // returns the signed intepretation of the result. That will always
718 // be a valid smi value, since it's numerically smaller than the
719 // original.
720 // Uses and clobbers rcx, so dst may not be rcx.
721 void SmiShiftArithmeticRight(Register dst,
722 Register src1,
723 Register src2);
724
725 // Specialized operations
726
727 // Select the non-smi register of two registers where exactly one is a
728 // smi. If neither are smis, jump to the failure label.
729 void SelectNonSmi(Register dst,
730 Register src1,
731 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000732 Label* on_not_smis,
733 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000734
735 // Converts, if necessary, a smi to a combination of number and
736 // multiplier to be used as a scaled index.
737 // The src register contains a *positive* smi value. The shift is the
738 // power of two to multiply the index value by (e.g.
739 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
740 // The returned index register may be either src or dst, depending
741 // on what is most efficient. If src and dst are different registers,
742 // src is always unchanged.
743 SmiIndex SmiToIndex(Register dst, Register src, int shift);
744
745 // Converts a positive smi to a negative index.
746 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
747
Steve Block44f0eee2011-05-26 01:26:41 +0100748 // Add the value of a smi in memory to an int32 register.
749 // Sets flags as a normal add.
750 void AddSmiField(Register dst, const Operand& src);
751
Steve Block3ce2e202009-11-05 08:53:23 +0000752 // Basic Smi operations.
753 void Move(Register dst, Smi* source) {
Steve Block8defd9f2010-07-08 12:39:36 +0100754 LoadSmiConstant(dst, source);
Steve Block3ce2e202009-11-05 08:53:23 +0000755 }
756
757 void Move(const Operand& dst, Smi* source) {
Steve Block8defd9f2010-07-08 12:39:36 +0100758 Register constant = GetSmiConstant(source);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759 movp(dst, constant);
Steve Block3ce2e202009-11-05 08:53:23 +0000760 }
761
762 void Push(Smi* smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000763
764 // Save away a raw integer with pointer size on the stack as two integers
765 // masquerading as smis so that the garbage collector skips visiting them.
766 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
767 // Reconstruct a raw integer with pointer size from two integers masquerading
768 // as smis on the top of stack.
769 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
770
Steve Block3ce2e202009-11-05 08:53:23 +0000771 void Test(const Operand& dst, Smi* source);
772
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100773
Steve Blocka7e24c12009-10-30 11:49:00 +0000774 // ---------------------------------------------------------------------------
Leon Clarkee46be812010-01-19 14:06:41 +0000775 // String macros.
Steve Block1e0659c2011-05-24 12:43:12 +0100776
777 // If object is a string, its map is loaded into object_map.
Steve Block1e0659c2011-05-24 12:43:12 +0100778 void JumpIfNotString(Register object,
779 Register object_map,
Ben Murdoch257744e2011-11-30 15:57:28 +0000780 Label* not_string,
781 Label::Distance near_jump = Label::kFar);
Steve Block1e0659c2011-05-24 12:43:12 +0100782
783
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784 void JumpIfNotBothSequentialOneByteStrings(
785 Register first_object, Register second_object, Register scratch1,
786 Register scratch2, Label* on_not_both_flat_one_byte,
Ben Murdoch257744e2011-11-30 15:57:28 +0000787 Label::Distance near_jump = Label::kFar);
Leon Clarkee46be812010-01-19 14:06:41 +0000788
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000789 // Check whether the instance type represents a flat one-byte string. Jump
790 // to the label if not. If the instance type can be scratched specify same
791 // register for both instance type and scratch.
792 void JumpIfInstanceTypeIsNotSequentialOneByte(
793 Register instance_type, Register scratch,
794 Label* on_not_flat_one_byte_string,
Ben Murdoch257744e2011-11-30 15:57:28 +0000795 Label::Distance near_jump = Label::kFar);
Steve Block6ded16b2010-05-10 14:33:55 +0100796
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
798 Register first_object_instance_type, Register second_object_instance_type,
799 Register scratch1, Register scratch2, Label* on_fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000800 Label::Distance near_jump = Label::kFar);
Steve Block6ded16b2010-05-10 14:33:55 +0100801
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 void EmitSeqStringSetCharCheck(Register string,
803 Register index,
804 Register value,
805 uint32_t encoding_mask);
806
807 // Checks if the given register or operand is a unique name
808 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
809 Label::Distance distance = Label::kFar);
810 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
811 Label::Distance distance = Label::kFar);
812
Leon Clarkee46be812010-01-19 14:06:41 +0000813 // ---------------------------------------------------------------------------
814 // Macro instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +0000815
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000816 // Load/store with specific representation.
817 void Load(Register dst, const Operand& src, Representation r);
818 void Store(const Operand& dst, Register src, Representation r);
819
Steve Block3ce2e202009-11-05 08:53:23 +0000820 // Load a register with a long value as efficiently as possible.
Steve Blocka7e24c12009-10-30 11:49:00 +0000821 void Set(Register dst, int64_t x);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000822 void Set(const Operand& dst, intptr_t x);
823
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000824 void Cvtss2sd(XMMRegister dst, XMMRegister src);
825 void Cvtss2sd(XMMRegister dst, const Operand& src);
826 void Cvtsd2ss(XMMRegister dst, XMMRegister src);
827 void Cvtsd2ss(XMMRegister dst, const Operand& src);
828
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000829 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
830 // hinders register renaming and makes dependence chains longer. So we use
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000831 // xorpd to clear the dst register before cvtsi2sd to solve this issue.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000832 void Cvtlsi2sd(XMMRegister dst, Register src);
833 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000834
Ben Murdoch097c5b22016-05-18 11:27:45 +0100835 void Cvtlsi2ss(XMMRegister dst, Register src);
836 void Cvtlsi2ss(XMMRegister dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000837 void Cvtqsi2ss(XMMRegister dst, Register src);
838 void Cvtqsi2ss(XMMRegister dst, const Operand& src);
839
840 void Cvtqsi2sd(XMMRegister dst, Register src);
841 void Cvtqsi2sd(XMMRegister dst, const Operand& src);
842
843 void Cvtqui2ss(XMMRegister dst, Register src, Register tmp);
844 void Cvtqui2sd(XMMRegister dst, Register src, Register tmp);
845
846 void Cvtsd2si(Register dst, XMMRegister src);
847
Ben Murdoch097c5b22016-05-18 11:27:45 +0100848 void Cvttss2si(Register dst, XMMRegister src);
849 void Cvttss2si(Register dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000850 void Cvttsd2si(Register dst, XMMRegister src);
851 void Cvttsd2si(Register dst, const Operand& src);
852 void Cvttss2siq(Register dst, XMMRegister src);
853 void Cvttss2siq(Register dst, const Operand& src);
854 void Cvttsd2siq(Register dst, XMMRegister src);
855 void Cvttsd2siq(Register dst, const Operand& src);
856
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100857 // Move if the registers are not identical.
858 void Move(Register target, Register source);
859
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000860 // TestBit and Load SharedFunctionInfo special field.
861 void TestBitSharedFunctionInfoSpecialField(Register base,
862 int offset,
863 int bit_index);
864 void LoadSharedFunctionInfoSpecialField(Register dst,
865 Register base,
866 int offset);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100867
Steve Blocka7e24c12009-10-30 11:49:00 +0000868 // Handle support
Steve Blocka7e24c12009-10-30 11:49:00 +0000869 void Move(Register dst, Handle<Object> source);
870 void Move(const Operand& dst, Handle<Object> source);
871 void Cmp(Register dst, Handle<Object> source);
872 void Cmp(const Operand& dst, Handle<Object> source);
Steve Block44f0eee2011-05-26 01:26:41 +0100873 void Cmp(Register dst, Smi* src);
874 void Cmp(const Operand& dst, Smi* src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000875 void Push(Handle<Object> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000876
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100877 // Load a heap object and handle the case of new-space objects by
878 // indirecting via a global cell.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000879 void MoveHeapObject(Register result, Handle<Object> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100880
881 // Load a global cell into a register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000882 void LoadGlobalCell(Register dst, Handle<Cell> cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100883
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400884 // Compare the given value and the value of weak cell.
885 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
886
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000887 void GetWeakValue(Register value, Handle<WeakCell> cell);
888
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400889 // Load the value of the weak cell in the value register. Branch to the given
890 // miss label if the weak cell was cleared.
891 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
892
Leon Clarkee46be812010-01-19 14:06:41 +0000893 // Emit code to discard a non-negative number of pointer-sized elements
894 // from the stack, clobbering only the rsp register.
895 void Drop(int stack_elements);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000896 // Emit code to discard a positive number of pointer-sized elements
897 // from the stack under the return address which remains on the top,
898 // clobbering the rsp register.
899 void DropUnderReturnAddress(int stack_elements,
900 Register scratch = kScratchRegister);
Leon Clarkee46be812010-01-19 14:06:41 +0000901
902 void Call(Label* target) { call(target); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000903 void Push(Register src);
904 void Push(const Operand& src);
905 void PushQuad(const Operand& src);
906 void Push(Immediate value);
907 void PushImm32(int32_t imm32);
908 void Pop(Register dst);
909 void Pop(const Operand& dst);
910 void PopQuad(const Operand& dst);
911 void PushReturnAddressFrom(Register src) { pushq(src); }
912 void PopReturnAddressTo(Register dst) { popq(dst); }
913 void Move(Register dst, ExternalReference ext) {
914 movp(dst, reinterpret_cast<void*>(ext.address()),
915 RelocInfo::EXTERNAL_REFERENCE);
916 }
917
918 // Loads a pointer into a register with a relocation mode.
919 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
920 // This method must not be used with heap object references. The stored
921 // address is not GC safe. Use the handle version instead.
922 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
923 movp(dst, ptr, rmode);
924 }
925
926 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
927 AllowDeferredHandleDereference using_raw_address;
928 DCHECK(!RelocInfo::IsNone(rmode));
929 DCHECK(value->IsHeapObject());
930 DCHECK(!isolate()->heap()->InNewSpace(*value));
931 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
932 }
Leon Clarkee46be812010-01-19 14:06:41 +0000933
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400934 void Move(XMMRegister dst, uint32_t src);
935 void Move(XMMRegister dst, uint64_t src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000936 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
937 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
938
939#define AVX_OP2_WITH_TYPE(macro_name, name, src_type) \
940 void macro_name(XMMRegister dst, src_type src) { \
941 if (CpuFeatures::IsSupported(AVX)) { \
942 CpuFeatureScope scope(this, AVX); \
943 v##name(dst, dst, src); \
944 } else { \
945 name(dst, src); \
946 } \
947 }
948#define AVX_OP2_X(macro_name, name) \
949 AVX_OP2_WITH_TYPE(macro_name, name, XMMRegister)
950#define AVX_OP2_O(macro_name, name) \
951 AVX_OP2_WITH_TYPE(macro_name, name, const Operand&)
952#define AVX_OP2_XO(macro_name, name) \
953 AVX_OP2_X(macro_name, name) \
954 AVX_OP2_O(macro_name, name)
955
956 AVX_OP2_XO(Addsd, addsd)
957 AVX_OP2_XO(Subsd, subsd)
958 AVX_OP2_XO(Mulsd, mulsd)
959 AVX_OP2_XO(Divsd, divsd)
960 AVX_OP2_X(Andpd, andpd)
961 AVX_OP2_X(Orpd, orpd)
962 AVX_OP2_X(Xorpd, xorpd)
963 AVX_OP2_X(Pcmpeqd, pcmpeqd)
964 AVX_OP2_WITH_TYPE(Psllq, psllq, byte)
965 AVX_OP2_WITH_TYPE(Psrlq, psrlq, byte)
966
967#undef AVX_OP2_O
968#undef AVX_OP2_X
969#undef AVX_OP2_XO
970#undef AVX_OP2_WITH_TYPE
971
972 void Movsd(XMMRegister dst, XMMRegister src);
973 void Movsd(XMMRegister dst, const Operand& src);
974 void Movsd(const Operand& dst, XMMRegister src);
975 void Movss(XMMRegister dst, XMMRegister src);
976 void Movss(XMMRegister dst, const Operand& src);
977 void Movss(const Operand& dst, XMMRegister src);
978
979 void Movd(XMMRegister dst, Register src);
980 void Movd(XMMRegister dst, const Operand& src);
981 void Movd(Register dst, XMMRegister src);
982 void Movq(XMMRegister dst, Register src);
983 void Movq(Register dst, XMMRegister src);
984
985 void Movaps(XMMRegister dst, XMMRegister src);
986 void Movapd(XMMRegister dst, XMMRegister src);
987 void Movmskpd(Register dst, XMMRegister src);
988
989 void Roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
990 void Roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
991 void Sqrtsd(XMMRegister dst, XMMRegister src);
992 void Sqrtsd(XMMRegister dst, const Operand& src);
993
994 void Ucomiss(XMMRegister src1, XMMRegister src2);
995 void Ucomiss(XMMRegister src1, const Operand& src2);
996 void Ucomisd(XMMRegister src1, XMMRegister src2);
997 void Ucomisd(XMMRegister src1, const Operand& src2);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400998
Steve Blocka7e24c12009-10-30 11:49:00 +0000999 // Control Flow
1000 void Jump(Address destination, RelocInfo::Mode rmode);
1001 void Jump(ExternalReference ext);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001002 void Jump(const Operand& op);
Steve Blocka7e24c12009-10-30 11:49:00 +00001003 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
1004
1005 void Call(Address destination, RelocInfo::Mode rmode);
1006 void Call(ExternalReference ext);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001007 void Call(const Operand& op);
Ben Murdoch257744e2011-11-30 15:57:28 +00001008 void Call(Handle<Code> code_object,
1009 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001010 TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001011
Steve Block44f0eee2011-05-26 01:26:41 +01001012 // The size of the code generated for different call instructions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001013 int CallSize(Address destination) {
1014 return kCallSequenceLength;
Steve Block44f0eee2011-05-26 01:26:41 +01001015 }
1016 int CallSize(ExternalReference ext);
1017 int CallSize(Handle<Code> code_object) {
1018 // Code calls use 32-bit relative addressing.
1019 return kShortCallInstructionLength;
1020 }
1021 int CallSize(Register target) {
1022 // Opcode: REX_opt FF /2 m64
1023 return (target.high_bit() != 0) ? 3 : 2;
1024 }
1025 int CallSize(const Operand& target) {
1026 // Opcode: REX_opt FF /2 m64
1027 return (target.requires_rex() ? 2 : 1) + target.operand_size();
1028 }
1029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001030 // Non-SSE2 instructions.
1031 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
1032 void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
1033 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
1034
1035 void Lzcntq(Register dst, Register src);
1036 void Lzcntq(Register dst, const Operand& src);
1037
1038 void Lzcntl(Register dst, Register src);
1039 void Lzcntl(Register dst, const Operand& src);
1040
1041 void Tzcntq(Register dst, Register src);
1042 void Tzcntq(Register dst, const Operand& src);
1043
1044 void Tzcntl(Register dst, Register src);
1045 void Tzcntl(Register dst, const Operand& src);
1046
1047 void Popcntl(Register dst, Register src);
1048 void Popcntl(Register dst, const Operand& src);
1049
1050 void Popcntq(Register dst, Register src);
1051 void Popcntq(Register dst, const Operand& src);
1052
Steve Block1e0659c2011-05-24 12:43:12 +01001053 // Non-x64 instructions.
1054 // Push/pop all general purpose registers.
1055 // Does not push rsp/rbp nor any of the assembler's special purpose registers
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001056 // (kScratchRegister, kRootRegister).
Steve Block1e0659c2011-05-24 12:43:12 +01001057 void Pushad();
1058 void Popad();
1059 // Sets the stack as after performing Popad, without actually loading the
1060 // registers.
1061 void Dropad();
1062
Steve Blocka7e24c12009-10-30 11:49:00 +00001063 // Compare object type for heap object.
1064 // Always use unsigned comparisons: above and below, not less and greater.
1065 // Incoming register is heap_object and outgoing register is map.
1066 // They may be the same register, and may be kScratchRegister.
1067 void CmpObjectType(Register heap_object, InstanceType type, Register map);
1068
1069 // Compare instance type for map.
1070 // Always use unsigned comparisons: above and below, not less and greater.
1071 void CmpInstanceType(Register map, InstanceType type);
1072
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001073 // Check if a map for a JSObject indicates that the object has fast elements.
1074 // Jump to the specified label if it does not.
1075 void CheckFastElements(Register map,
1076 Label* fail,
1077 Label::Distance distance = Label::kFar);
1078
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001079 // Check if a map for a JSObject indicates that the object can have both smi
1080 // and HeapObject elements. Jump to the specified label if it does not.
1081 void CheckFastObjectElements(Register map,
1082 Label* fail,
1083 Label::Distance distance = Label::kFar);
1084
1085 // Check if a map for a JSObject indicates that the object has fast smi only
1086 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001087 void CheckFastSmiElements(Register map,
1088 Label* fail,
1089 Label::Distance distance = Label::kFar);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001090
1091 // Check to see if maybe_number can be stored as a double in
1092 // FastDoubleElements. If it can, store it at the index specified by index in
1093 // the FastDoubleElements array elements, otherwise jump to fail. Note that
1094 // index must not be smi-tagged.
1095 void StoreNumberToDoubleElements(Register maybe_number,
1096 Register elements,
1097 Register index,
1098 XMMRegister xmm_scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001099 Label* fail,
1100 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001101
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001102 // Compare an object's map with the specified map.
1103 void CompareMap(Register obj, Handle<Map> map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001104
1105 // Check if the map of an object is equal to a specified map and branch to
1106 // label if not. Skip the smi check if not required (object is known to be a
1107 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1108 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +00001109 void CheckMap(Register obj,
1110 Handle<Map> map,
1111 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001112 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +00001113
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001114 // Check if the map of an object is equal to a specified weak map and branch
1115 // to a specified target if equal. Skip the smi check if not required
1116 // (object is known to be a heap object)
1117 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1118 Handle<WeakCell> cell, Handle<Code> success,
1119 SmiCheckType smi_check_type);
Andrei Popescu31002712010-02-23 13:46:05 +00001120
Leon Clarked91b9f72010-01-27 17:25:45 +00001121 // Check if the object in register heap_object is a string. Afterwards the
1122 // register map contains the object map and the register instance_type
1123 // contains the instance_type. The registers map and instance_type can be the
1124 // same in which case it contains the instance type afterwards. Either of the
1125 // registers map and instance_type can be the same as heap_object.
1126 Condition IsObjectStringType(Register heap_object,
1127 Register map,
1128 Register instance_type);
1129
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001130 // Check if the object in register heap_object is a name. Afterwards the
1131 // register map contains the object map and the register instance_type
1132 // contains the instance_type. The registers map and instance_type can be the
1133 // same in which case it contains the instance type afterwards. Either of the
1134 // registers map and instance_type can be the same as heap_object.
1135 Condition IsObjectNameType(Register heap_object,
1136 Register map,
1137 Register instance_type);
1138
Steve Block8defd9f2010-07-08 12:39:36 +01001139 // FCmp compares and pops the two values on top of the FPU stack.
1140 // The flag results are similar to integer cmp, but requires unsigned
Steve Blocka7e24c12009-10-30 11:49:00 +00001141 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1142 void FCmp();
1143
Ben Murdoch257744e2011-11-30 15:57:28 +00001144 void ClampUint8(Register reg);
1145
1146 void ClampDoubleToUint8(XMMRegister input_reg,
1147 XMMRegister temp_xmm_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001148 Register result_reg);
1149
1150 void SlowTruncateToI(Register result_reg, Register input_reg,
1151 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1152
1153 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1154 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1155
1156 void DoubleToI(Register result_reg, XMMRegister input_reg,
1157 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1158 Label* lost_precision, Label* is_nan, Label* minus_zero,
1159 Label::Distance dst = Label::kFar);
1160
1161 void LoadUint32(XMMRegister dst, Register src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001162
1163 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001164 void EnumLength(Register dst, Register map);
1165 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001166 void LoadAccessor(Register dst, Register holder, int accessor_index,
1167 AccessorComponent accessor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001168
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001169 template<typename Field>
1170 void DecodeField(Register reg) {
1171 static const int shift = Field::kShift;
1172 static const int mask = Field::kMask >> Field::kShift;
1173 if (shift != 0) {
1174 shrp(reg, Immediate(shift));
1175 }
1176 andp(reg, Immediate(mask));
1177 }
Andrei Popescu402d9372010-02-26 13:31:12 +00001178
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001179 template<typename Field>
1180 void DecodeFieldToSmi(Register reg) {
1181 if (SmiValuesAre32Bits()) {
1182 andp(reg, Immediate(Field::kMask));
1183 shlp(reg, Immediate(kSmiShift - Field::kShift));
1184 } else {
1185 static const int shift = Field::kShift;
1186 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1187 DCHECK(SmiValuesAre31Bits());
1188 DCHECK(kSmiShift == kSmiTagSize);
1189 DCHECK((mask & 0x80000000u) == 0);
1190 if (shift < kSmiShift) {
1191 shlp(reg, Immediate(kSmiShift - shift));
1192 } else if (shift > kSmiShift) {
1193 sarp(reg, Immediate(shift - kSmiShift));
1194 }
1195 andp(reg, Immediate(mask));
1196 }
1197 }
Iain Merrick75681382010-08-19 15:07:18 +01001198
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001199 // Abort execution if argument is not a number, enabled via --debug-code.
1200 void AssertNumber(Register object);
Ben Murdochda12d292016-06-02 14:46:10 +01001201 void AssertNotNumber(Register object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001202
1203 // Abort execution if argument is a smi, enabled via --debug-code.
1204 void AssertNotSmi(Register object);
1205
1206 // Abort execution if argument is not a smi, enabled via --debug-code.
1207 void AssertSmi(Register object);
1208 void AssertSmi(const Operand& object);
Steve Block6ded16b2010-05-10 14:33:55 +01001209
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001210 // Abort execution if a 64 bit register containing a 32 bit payload does not
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001211 // have zeros in the top 32 bits, enabled via --debug-code.
1212 void AssertZeroExtended(Register reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001213
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001214 // Abort execution if argument is not a string, enabled via --debug-code.
1215 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001216
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001217 // Abort execution if argument is not a name, enabled via --debug-code.
1218 void AssertName(Register object);
1219
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001220 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1221 void AssertFunction(Register object);
1222
1223 // Abort execution if argument is not a JSBoundFunction,
1224 // enabled via --debug-code.
1225 void AssertBoundFunction(Register object);
1226
Ben Murdochc5610432016-08-08 18:44:38 +01001227 // Abort execution if argument is not a JSGeneratorObject,
1228 // enabled via --debug-code.
1229 void AssertGeneratorObject(Register object);
1230
Ben Murdoch097c5b22016-05-18 11:27:45 +01001231 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1232 void AssertReceiver(Register object);
1233
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001234 // Abort execution if argument is not undefined or an AllocationSite, enabled
1235 // via --debug-code.
1236 void AssertUndefinedOrAllocationSite(Register object);
1237
1238 // Abort execution if argument is not the root value with the given index,
1239 // enabled via --debug-code.
1240 void AssertRootValue(Register src,
1241 Heap::RootListIndex root_value_index,
1242 BailoutReason reason);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01001243
Steve Blocka7e24c12009-10-30 11:49:00 +00001244 // ---------------------------------------------------------------------------
1245 // Exception handling
1246
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001247 // Push a new stack handler and link it into stack handler chain.
1248 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +00001249
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001250 // Unlink the stack handler on top of the stack from the stack handler chain.
1251 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001252
Steve Blocka7e24c12009-10-30 11:49:00 +00001253 // ---------------------------------------------------------------------------
1254 // Inline caching support
1255
Steve Blocka7e24c12009-10-30 11:49:00 +00001256 // Generate code for checking access rights - used for security checks
1257 // on access to global objects across environments. The holder register
1258 // is left untouched, but the scratch register and kScratchRegister,
1259 // which must be different, are clobbered.
1260 void CheckAccessGlobalProxy(Register holder_reg,
1261 Register scratch,
1262 Label* miss);
1263
Ben Murdochc7cc0282012-03-05 14:35:55 +00001264 void GetNumberHash(Register r0, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001265
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001266 void LoadFromNumberDictionary(Label* miss,
1267 Register elements,
1268 Register key,
1269 Register r0,
1270 Register r1,
1271 Register r2,
1272 Register result);
1273
1274
Steve Blocka7e24c12009-10-30 11:49:00 +00001275 // ---------------------------------------------------------------------------
1276 // Allocation support
1277
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001278 // Allocate an object in new space or old space. If the given space
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001279 // is exhausted control continues at the gc_required label. The allocated
1280 // object is returned in result and end of the new object is returned in
1281 // result_end. The register scratch can be passed as no_reg in which case
1282 // an additional object reference will be added to the reloc info. The
1283 // returned pointers in result and result_end have not yet been tagged as
1284 // heap objects. If result_contains_top_on_entry is true the content of
1285 // result is known to be the allocation top on entry (could be result_end
1286 // from a previous call). If result_contains_top_on_entry is true scratch
Steve Blocka7e24c12009-10-30 11:49:00 +00001287 // should be no_reg as it is never used.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001288 void Allocate(int object_size,
1289 Register result,
1290 Register result_end,
1291 Register scratch,
1292 Label* gc_required,
1293 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001294
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001295 void Allocate(int header_size,
1296 ScaleFactor element_size,
1297 Register element_count,
1298 Register result,
1299 Register result_end,
1300 Register scratch,
1301 Label* gc_required,
1302 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001303
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001304 void Allocate(Register object_size,
1305 Register result,
1306 Register result_end,
1307 Register scratch,
1308 Label* gc_required,
1309 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001310
Ben Murdochc5610432016-08-08 18:44:38 +01001311 // FastAllocate is right now only used for folded allocations. It just
1312 // increments the top pointer without checking against limit. This can only
1313 // be done if it was proved earlier that the allocation will succeed.
1314 void FastAllocate(int object_size, Register result, Register result_end,
1315 AllocationFlags flags);
1316
1317 void FastAllocate(Register object_size, Register result, Register result_end,
1318 AllocationFlags flags);
1319
Steve Block3ce2e202009-11-05 08:53:23 +00001320 // Allocate a heap number in new space with undefined value. Returns
1321 // tagged pointer in result register, or jumps to gc_required if new
1322 // space is full.
1323 void AllocateHeapNumber(Register result,
1324 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001325 Label* gc_required,
1326 MutableMode mode = IMMUTABLE);
Steve Block3ce2e202009-11-05 08:53:23 +00001327
Leon Clarkee46be812010-01-19 14:06:41 +00001328 // Allocate a sequential string. All the header fields of the string object
1329 // are initialized.
1330 void AllocateTwoByteString(Register result,
1331 Register length,
1332 Register scratch1,
1333 Register scratch2,
1334 Register scratch3,
1335 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001336 void AllocateOneByteString(Register result, Register length,
1337 Register scratch1, Register scratch2,
1338 Register scratch3, Label* gc_required);
Leon Clarkee46be812010-01-19 14:06:41 +00001339
1340 // Allocate a raw cons string object. Only the map field of the result is
1341 // initialized.
Ben Murdoch589d6972011-11-30 16:04:58 +00001342 void AllocateTwoByteConsString(Register result,
Leon Clarkee46be812010-01-19 14:06:41 +00001343 Register scratch1,
1344 Register scratch2,
1345 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001346 void AllocateOneByteConsString(Register result, Register scratch1,
1347 Register scratch2, Label* gc_required);
Leon Clarkee46be812010-01-19 14:06:41 +00001348
Ben Murdoch589d6972011-11-30 16:04:58 +00001349 // Allocate a raw sliced string object. Only the map field of the result is
1350 // initialized.
1351 void AllocateTwoByteSlicedString(Register result,
1352 Register scratch1,
1353 Register scratch2,
1354 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001355 void AllocateOneByteSlicedString(Register result, Register scratch1,
1356 Register scratch2, Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +00001357
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001358 // Allocate and initialize a JSValue wrapper with the specified {constructor}
1359 // and {value}.
1360 void AllocateJSValue(Register result, Register constructor, Register value,
1361 Register scratch, Label* gc_required);
1362
Steve Blocka7e24c12009-10-30 11:49:00 +00001363 // ---------------------------------------------------------------------------
1364 // Support functions.
1365
1366 // Check if result is zero and op is negative.
1367 void NegativeZeroTest(Register result, Register op, Label* then_label);
1368
1369 // Check if result is zero and op is negative in code using jump targets.
1370 void NegativeZeroTest(CodeGenerator* cgen,
1371 Register result,
1372 Register op,
1373 JumpTarget* then_target);
1374
1375 // Check if result is zero and any of op1 and op2 are negative.
1376 // Register scratch is destroyed, and it must be different from op2.
1377 void NegativeZeroTest(Register result, Register op1, Register op2,
1378 Register scratch, Label* then_label);
1379
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001380 // Machine code version of Map::GetConstructor().
1381 // |temp| holds |result|'s map when done.
1382 void GetMapConstructor(Register result, Register map, Register temp);
1383
Steve Blocka7e24c12009-10-30 11:49:00 +00001384 // Try to get function prototype of a function and puts the value in
1385 // the result register. Checks that the function really is a
1386 // function and jumps to the miss label if the fast checks fail. The
1387 // function register will be untouched; the other register may be
1388 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001389 void TryGetFunctionPrototype(Register function, Register result, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +00001390
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001391 // Picks out an array index from the hash field.
1392 // Register use:
1393 // hash - holds the index's hash. Clobbered.
1394 // index - holds the overwritten index on exit.
1395 void IndexFromHash(Register hash, Register index);
1396
Steve Blockd0582a62009-12-15 09:54:21 +00001397 // Find the function context up the context chain.
1398 void LoadContext(Register dst, int context_chain_length);
1399
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001400 // Load the global object from the current context.
1401 void LoadGlobalObject(Register dst) {
1402 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
1403 }
1404
1405 // Load the global proxy from the current context.
1406 void LoadGlobalProxy(Register dst) {
1407 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
1408 }
1409
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001410 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001411 // transitioned_kind from the native context if the map in register
1412 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001413 // expected_kind.
1414 void LoadTransitionedArrayMapConditional(
1415 ElementsKind expected_kind,
1416 ElementsKind transitioned_kind,
1417 Register map_in_out,
1418 Register scratch,
1419 Label* no_map_match);
1420
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001421 // Load the native context slot with the current index.
1422 void LoadNativeContextSlot(int index, Register dst);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001423
1424 // Load the initial map from the global function. The registers
1425 // function and map can be the same.
1426 void LoadGlobalFunctionInitialMap(Register function, Register map);
1427
Steve Blocka7e24c12009-10-30 11:49:00 +00001428 // ---------------------------------------------------------------------------
1429 // Runtime calls
1430
1431 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001432 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001433
Leon Clarkee46be812010-01-19 14:06:41 +00001434 // Tail call a code stub (jump).
1435 void TailCallStub(CodeStub* stub);
1436
Steve Blocka7e24c12009-10-30 11:49:00 +00001437 // Return from a code stub after popping its arguments.
1438 void StubReturn(int argc);
1439
1440 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001441 void CallRuntime(const Runtime::Function* f,
1442 int num_arguments,
1443 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Steve Blocka7e24c12009-10-30 11:49:00 +00001444
Steve Block1e0659c2011-05-24 12:43:12 +01001445 // Call a runtime function and save the value of XMM registers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001446 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1447 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001448 CallRuntime(function, function->nargs, kSaveFPRegs);
1449 }
Steve Block1e0659c2011-05-24 12:43:12 +01001450
Steve Blocka7e24c12009-10-30 11:49:00 +00001451 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001452 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001453 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001454 const Runtime::Function* function = Runtime::FunctionForId(fid);
1455 CallRuntime(function, function->nargs, save_doubles);
1456 }
1457
1458 // Convenience function: Same as above, but takes the fid instead.
1459 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1460 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1461 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001462 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001463
Andrei Popescu402d9372010-02-26 13:31:12 +00001464 // Convenience function: call an external reference.
1465 void CallExternalReference(const ExternalReference& ext,
1466 int num_arguments);
1467
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001468 // Convenience function: tail call a runtime routine (jump)
1469 void TailCallRuntime(Runtime::FunctionId fid);
Steve Block6ded16b2010-05-10 14:33:55 +01001470
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001471 // Jump to a runtime routines
1472 void JumpToExternalReference(const ExternalReference& ext);
John Reck59135872010-11-02 12:39:01 -07001473
Leon Clarke4515c472010-02-03 11:58:03 +00001474 // Before calling a C-function from generated code, align arguments on stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001475 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
Leon Clarke4515c472010-02-03 11:58:03 +00001476 // etc., not pushed. The argument count assumes all arguments are word sized.
1477 // The number of slots reserved for arguments depends on platform. On Windows
1478 // stack slots are reserved for the arguments passed in registers. On other
1479 // platforms stack slots are only reserved for the arguments actually passed
1480 // on the stack.
1481 void PrepareCallCFunction(int num_arguments);
1482
1483 // Calls a C function and cleans up the space for arguments allocated
1484 // by PrepareCallCFunction. The called function is not allowed to trigger a
1485 // garbage collection, since that might move the code and invalidate the
1486 // return address (unless this is somehow accounted for by the called
1487 // function).
1488 void CallCFunction(ExternalReference function, int num_arguments);
1489 void CallCFunction(Register function, int num_arguments);
1490
1491 // Calculate the number of stack slots to reserve for arguments when calling a
1492 // C function.
1493 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
Steve Blocka7e24c12009-10-30 11:49:00 +00001494
1495 // ---------------------------------------------------------------------------
1496 // Utilities
1497
1498 void Ret();
1499
Steve Block1e0659c2011-05-24 12:43:12 +01001500 // Return and drop arguments from stack, where the number of arguments
1501 // may be bigger than 2^16 - 1. Requires a scratch register.
1502 void Ret(int bytes_dropped, Register scratch);
1503
Ben Murdoch8b112d22011-06-08 16:22:53 +01001504 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001505 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001506 return code_object_;
1507 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001508
Steve Block44f0eee2011-05-26 01:26:41 +01001509 // Copy length bytes from source to destination.
1510 // Uses scratch register internally (if you have a low-eight register
1511 // free, do use it, otherwise kScratchRegister will be used).
1512 // The min_length is a minimum limit on the value that length will have.
1513 // The algorithm has some special cases that might be omitted if the string
1514 // is known to always be long.
1515 void CopyBytes(Register destination,
1516 Register source,
1517 Register length,
1518 int min_length = 0,
1519 Register scratch = kScratchRegister);
1520
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001521 // Initialize fields with filler values. Fields starting at |current_address|
1522 // not including |end_address| are overwritten with the value in |filler|. At
1523 // the end the loop, |current_address| takes the value of |end_address|.
1524 void InitializeFieldsWithFiller(Register current_address,
1525 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001526
Steve Blocka7e24c12009-10-30 11:49:00 +00001527
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528 // Emit code for a truncating division by a constant. The dividend register is
1529 // unchanged, the result is in rdx, and rax gets clobbered.
1530 void TruncatingDiv(Register dividend, int32_t divisor);
1531
Steve Blocka7e24c12009-10-30 11:49:00 +00001532 // ---------------------------------------------------------------------------
1533 // StatsCounter support
1534
1535 void SetCounter(StatsCounter* counter, int value);
1536 void IncrementCounter(StatsCounter* counter, int value);
1537 void DecrementCounter(StatsCounter* counter, int value);
1538
1539
1540 // ---------------------------------------------------------------------------
1541 // Debugging
1542
1543 // Calls Abort(msg) if the condition cc is not satisfied.
1544 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001545 void Assert(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001546
Iain Merrick75681382010-08-19 15:07:18 +01001547 void AssertFastElements(Register elements);
1548
Steve Blocka7e24c12009-10-30 11:49:00 +00001549 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001550 void Check(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001551
1552 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001553 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001554
Steve Block6ded16b2010-05-10 14:33:55 +01001555 // Check that the stack is aligned.
1556 void CheckStackAlignment();
1557
Steve Blocka7e24c12009-10-30 11:49:00 +00001558 // Verify restrictions about code generated in stubs.
1559 void set_generating_stub(bool value) { generating_stub_ = value; }
1560 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001561 void set_has_frame(bool value) { has_frame_ = value; }
1562 bool has_frame() { return has_frame_; }
1563 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001564
Ben Murdoch8b112d22011-06-08 16:22:53 +01001565 static int SafepointRegisterStackIndex(Register reg) {
1566 return SafepointRegisterStackIndex(reg.code());
1567 }
1568
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001569 // Load the type feedback vector from a JavaScript frame.
1570 void EmitLoadTypeFeedbackVector(Register vector);
1571
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001572 // Activation support.
1573 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001574 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001575 void LeaveFrame(StackFrame::Type type);
1576
1577 // Expects object in rax and returns map with validated enum cache
1578 // in rax. Assumes that any other register can be used as a scratch.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001579 void CheckEnumCache(Label* call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001580
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001581 // AllocationMemento support. Arrays may have an associated
1582 // AllocationMemento object that can be checked for in order to pretransition
1583 // to another type.
1584 // On entry, receiver_reg should point to the array object.
1585 // scratch_reg gets clobbered.
1586 // If allocation info is present, condition flags are set to equal.
1587 void TestJSArrayForAllocationMemento(Register receiver_reg,
1588 Register scratch_reg,
1589 Label* no_memento_found);
1590
1591 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1592 Register scratch_reg,
1593 Label* memento_found) {
1594 Label no_memento_found;
1595 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1596 &no_memento_found);
1597 j(equal, memento_found);
1598 bind(&no_memento_found);
1599 }
1600
1601 // Jumps to found label if a prototype map has dictionary elements.
1602 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1603 Register scratch1, Label* found);
1604
Steve Blocka7e24c12009-10-30 11:49:00 +00001605 private:
Steve Block1e0659c2011-05-24 12:43:12 +01001606 // Order general registers are pushed by Pushad.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001607 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001608 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001609 static const int kNumSafepointSavedRegisters = 12;
Ben Murdoch257744e2011-11-30 15:57:28 +00001610 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001611
Steve Blocka7e24c12009-10-30 11:49:00 +00001612 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001613 bool has_frame_;
Steve Block44f0eee2011-05-26 01:26:41 +01001614 bool root_array_available_;
Steve Block8defd9f2010-07-08 12:39:36 +01001615
1616 // Returns a register holding the smi value. The register MUST NOT be
1617 // modified. It may be the "smi 1 constant" register.
1618 Register GetSmiConstant(Smi* value);
1619
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001620 int64_t RootRegisterDelta(ExternalReference other);
1621
Steve Block8defd9f2010-07-08 12:39:36 +01001622 // Moves the smi value to the destination register.
1623 void LoadSmiConstant(Register dst, Smi* value);
1624
Andrei Popescu31002712010-02-23 13:46:05 +00001625 // This handle will be patched with the code object on installation.
1626 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001627
1628 // Helper functions for generating invokes.
1629 void InvokePrologue(const ParameterCount& expected,
1630 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +00001631 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001632 bool* definitely_mismatches,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001633 InvokeFlag flag,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001634 Label::Distance near_jump,
1635 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001636
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001637 void EnterExitFramePrologue(bool save_rax);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001638
1639 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1640 // accessible via StackSpaceOperand.
Steve Block1e0659c2011-05-24 12:43:12 +01001641 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001642
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001643 void LeaveExitFrameEpilogue(bool restore_context);
Ben Murdochbb769b22010-08-11 14:56:33 +01001644
Steve Blocka7e24c12009-10-30 11:49:00 +00001645 // Allocation support helpers.
Steve Block6ded16b2010-05-10 14:33:55 +01001646 // Loads the top of new-space into the result register.
Steve Block6ded16b2010-05-10 14:33:55 +01001647 // Otherwise the address of the new-space top is loaded into scratch (if
1648 // scratch is valid), and the new-space top is loaded into result.
Steve Blocka7e24c12009-10-30 11:49:00 +00001649 void LoadAllocationTopHelper(Register result,
Steve Blocka7e24c12009-10-30 11:49:00 +00001650 Register scratch,
1651 AllocationFlags flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001652
1653 void MakeSureDoubleAlignedHelper(Register result,
1654 Register scratch,
1655 Label* gc_required,
1656 AllocationFlags flags);
1657
Steve Block6ded16b2010-05-10 14:33:55 +01001658 // Update allocation top with value in result_end register.
1659 // If scratch is valid, it contains the address of the allocation top.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001660 void UpdateAllocationTopHelper(Register result_end,
1661 Register scratch,
1662 AllocationFlags flags);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001663
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001664 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1665 void InNewSpace(Register object,
1666 Register scratch,
1667 Condition cc,
1668 Label* branch,
1669 Label::Distance distance = Label::kFar);
1670
1671 // Helper for finding the mark bits for an address. Afterwards, the
1672 // bitmap register points at the word with the mark bits and the mask
1673 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1674 // unchanged.
1675 inline void GetMarkBits(Register addr_reg,
1676 Register bitmap_reg,
1677 Register mask_reg);
1678
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001679 // Compute memory operands for safepoint stack slots.
1680 Operand SafepointRegisterSlot(Register reg);
1681 static int SafepointRegisterStackIndex(int reg_code) {
1682 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1683 }
1684
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001685 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001686 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001687 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001688};
1689
1690
1691// The code patcher is used to patch (typically) small parts of code e.g. for
1692// debugging and other types of instrumentation. When using the code patcher
1693// the exact number of bytes specified must be emitted. Is not legal to emit
1694// relocation information. If any of these constraints are violated it causes
1695// an assertion.
1696class CodePatcher {
1697 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001698 CodePatcher(Isolate* isolate, byte* address, int size);
1699 ~CodePatcher();
Steve Blocka7e24c12009-10-30 11:49:00 +00001700
1701 // Macro assembler to emit code.
1702 MacroAssembler* masm() { return &masm_; }
1703
1704 private:
1705 byte* address_; // The address of the code being patched.
1706 int size_; // Number of bytes of the expected patch size.
1707 MacroAssembler masm_; // Macro assembler used to generate the code.
1708};
1709
1710
1711// -----------------------------------------------------------------------------
1712// Static helper functions.
1713
1714// Generate an Operand for loading a field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001715inline Operand FieldOperand(Register object, int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001716 return Operand(object, offset - kHeapObjectTag);
1717}
1718
1719
1720// Generate an Operand for loading an indexed field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001721inline Operand FieldOperand(Register object,
1722 Register index,
1723 ScaleFactor scale,
1724 int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001725 return Operand(object, index, scale, offset - kHeapObjectTag);
1726}
1727
1728
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001729inline Operand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001730 return Operand(context, Context::SlotOffset(index));
1731}
1732
1733
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001734inline Operand ContextOperand(Register context, Register index) {
1735 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1736}
1737
1738
1739inline Operand NativeContextOperand() {
1740 return ContextOperand(rsi, Context::NATIVE_CONTEXT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001741}
1742
1743
1744// Provides access to exit frame stack space (not GCed).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001745inline Operand StackSpaceOperand(int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001746#ifdef _WIN64
1747 const int kShaddowSpace = 4;
1748 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1749#else
1750 return Operand(rsp, index * kPointerSize);
1751#endif
1752}
1753
1754
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001755inline Operand StackOperandForReturnAddress(int32_t disp) {
1756 return Operand(rsp, disp);
1757}
1758
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001759
Steve Blocka7e24c12009-10-30 11:49:00 +00001760#ifdef GENERATED_CODE_COVERAGE
1761extern void LogGeneratedCodeCoverage(const char* file_line);
1762#define CODE_COVERAGE_STRINGIFY(x) #x
1763#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1764#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001765#define ACCESS_MASM(masm) { \
1766 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1767 masm->pushfq(); \
1768 masm->Pushad(); \
1769 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1770 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1771 masm->Pop(rax); \
1772 masm->Popad(); \
1773 masm->popfq(); \
1774 } \
Steve Blocka7e24c12009-10-30 11:49:00 +00001775 masm->
1776#else
1777#define ACCESS_MASM(masm) masm->
1778#endif
1779
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001780} // namespace internal
1781} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001782
1783#endif // V8_X64_MACRO_ASSEMBLER_X64_H_