blob: 1aa2c74f228984b8db91d3e5decb970b2bc4d727 [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};
21const Register kJSFunctionRegister = {Register::kCode_rdi};
22const Register kContextRegister = {Register::kCode_rsi};
23const Register kInterpreterAccumulatorRegister = {Register::kCode_rax};
24const Register kInterpreterRegisterFileRegister = {Register::kCode_r11};
25const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r12};
26const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r14};
27const Register kInterpreterDispatchTableRegister = {Register::kCode_r15};
28const Register kJavaScriptCallArgCountRegister = {Register::kCode_rax};
29const Register kJavaScriptCallNewTargetRegister = {Register::kCode_rdx};
30const Register kRuntimeCallFunctionRegister = {Register::kCode_rbx};
31const Register kRuntimeCallArgCountRegister = {Register::kCode_rax};
32
Steve Blocka7e24c12009-10-30 11:49:00 +000033// Default scratch register used by MacroAssembler (and other code that needs
34// a spare register). The register isn't callee save, and not used by the
35// function calling convention.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010036const Register kScratchRegister = { 10 }; // r10.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010037const Register kRootRegister = { 13 }; // r13 (callee save).
Ben Murdoche0cee9b2011-05-25 10:26:03 +010038// Actual value of root register is offset from the root array's start
39// to take advantage of negitive 8-bit displacement values.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010040const int kRootRegisterBias = 128;
Steve Blocka7e24c12009-10-30 11:49:00 +000041
Leon Clarkee46be812010-01-19 14:06:41 +000042// Convenience for platform-independent signatures.
43typedef Operand MemOperand;
44
Ben Murdoch3ef787d2012-04-12 10:51:47 +010045enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
46enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047enum PointersToHereCheck {
48 kPointersToHereMaybeInteresting,
49 kPointersToHereAreAlwaysInteresting
50};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010051
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052enum class SmiOperationConstraint {
53 kPreserveSourceRegister = 1 << 0,
54 kBailoutOnNoOverflow = 1 << 1,
55 kBailoutOnOverflow = 1 << 2
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056};
57
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058typedef base::Flags<SmiOperationConstraint> SmiOperationConstraints;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060DEFINE_OPERATORS_FOR_FLAGS(SmiOperationConstraints)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061
62#ifdef DEBUG
63bool AreAliased(Register reg1,
64 Register reg2,
65 Register reg3 = no_reg,
66 Register reg4 = no_reg,
67 Register reg5 = no_reg,
68 Register reg6 = no_reg,
69 Register reg7 = no_reg,
70 Register reg8 = no_reg);
71#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010072
Steve Blocka7e24c12009-10-30 11:49:00 +000073// Forward declaration.
74class JumpTarget;
75
76struct SmiIndex {
77 SmiIndex(Register index_register, ScaleFactor scale)
78 : reg(index_register),
79 scale(scale) {}
80 Register reg;
81 ScaleFactor scale;
82};
83
Ben Murdoch3ef787d2012-04-12 10:51:47 +010084
Steve Blocka7e24c12009-10-30 11:49:00 +000085// MacroAssembler implements a collection of frequently used macros.
86class MacroAssembler: public Assembler {
87 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000088 MacroAssembler(Isolate* isolate, void* buffer, int size,
89 CodeObjectRequired create_code_object);
Steve Blocka7e24c12009-10-30 11:49:00 +000090
Steve Block44f0eee2011-05-26 01:26:41 +010091 // Prevent the use of the RootArray during the lifetime of this
92 // scope object.
93 class NoRootArrayScope BASE_EMBEDDED {
94 public:
95 explicit NoRootArrayScope(MacroAssembler* assembler)
96 : variable_(&assembler->root_array_available_),
97 old_value_(assembler->root_array_available_) {
98 assembler->root_array_available_ = false;
99 }
100 ~NoRootArrayScope() {
101 *variable_ = old_value_;
102 }
103 private:
104 bool* variable_;
105 bool old_value_;
106 };
107
108 // Operand pointing to an external reference.
109 // May emit code to set up the scratch register. The operand is
110 // only guaranteed to be correct as long as the scratch register
111 // isn't changed.
112 // If the operand is used more than once, use a scratch register
113 // that is guaranteed not to be clobbered.
114 Operand ExternalOperand(ExternalReference reference,
115 Register scratch = kScratchRegister);
116 // Loads and stores the value of an external reference.
117 // Special case code for load and store to take advantage of
118 // load_rax/store_rax if possible/necessary.
119 // For other operations, just use:
120 // Operand operand = ExternalOperand(extref);
121 // operation(operand, ..);
122 void Load(Register destination, ExternalReference source);
123 void Store(ExternalReference destination, Register source);
124 // Loads the address of the external reference into the destination
125 // register.
126 void LoadAddress(Register destination, ExternalReference source);
127 // Returns the size of the code generated by LoadAddress.
128 // Used by CallSize(ExternalReference) to find the size of a call.
129 int LoadAddressSize(ExternalReference source);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130 // Pushes the address of the external reference onto the stack.
131 void PushAddress(ExternalReference source);
Steve Block44f0eee2011-05-26 01:26:41 +0100132
133 // Operations on roots in the root-array.
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 void LoadRoot(Register destination, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000135 void LoadRoot(const Operand& destination, Heap::RootListIndex index) {
136 LoadRoot(kScratchRegister, index);
137 movp(destination, kScratchRegister);
138 }
Steve Block44f0eee2011-05-26 01:26:41 +0100139 void StoreRoot(Register source, Heap::RootListIndex index);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100140 // Load a root value where the index (or part of it) is variable.
141 // The variable_offset register is added to the fixed_offset value
142 // to get the index into the root-array.
143 void LoadRootIndexed(Register destination,
144 Register variable_offset,
145 int fixed_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000146 void CompareRoot(Register with, Heap::RootListIndex index);
Steve Block1e0659c2011-05-24 12:43:12 +0100147 void CompareRoot(const Operand& with, Heap::RootListIndex index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 void PushRoot(Heap::RootListIndex index);
149
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000150 // Compare the object in a register to a value and jump if they are equal.
151 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal,
152 Label::Distance if_equal_distance = Label::kFar) {
153 CompareRoot(with, index);
154 j(equal, if_equal, if_equal_distance);
155 }
156 void JumpIfRoot(const Operand& with, Heap::RootListIndex index,
157 Label* if_equal,
158 Label::Distance if_equal_distance = Label::kFar) {
159 CompareRoot(with, index);
160 j(equal, if_equal, if_equal_distance);
161 }
162
163 // Compare the object in a register to a value and jump if they are not equal.
164 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
165 Label* if_not_equal,
166 Label::Distance if_not_equal_distance = Label::kFar) {
167 CompareRoot(with, index);
168 j(not_equal, if_not_equal, if_not_equal_distance);
169 }
170 void JumpIfNotRoot(const Operand& with, Heap::RootListIndex index,
171 Label* if_not_equal,
172 Label::Distance if_not_equal_distance = Label::kFar) {
173 CompareRoot(with, index);
174 j(not_equal, if_not_equal, if_not_equal_distance);
175 }
176
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100177 // These functions do not arrange the registers in any particular order so
178 // they are not useful for calls that can cause a GC. The caller can
179 // exclude up to 3 registers that do not need to be saved and restored.
180 void PushCallerSaved(SaveFPRegsMode fp_mode,
181 Register exclusion1 = no_reg,
182 Register exclusion2 = no_reg,
183 Register exclusion3 = no_reg);
184 void PopCallerSaved(SaveFPRegsMode fp_mode,
185 Register exclusion1 = no_reg,
186 Register exclusion2 = no_reg,
187 Register exclusion3 = no_reg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000188
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100189// ---------------------------------------------------------------------------
190// GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100191
Steve Block6ded16b2010-05-10 14:33:55 +0100192
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100193 enum RememberedSetFinalAction {
194 kReturnAtEnd,
195 kFallThroughAtEnd
196 };
197
198 // Record in the remembered set the fact that we have a pointer to new space
199 // at the address pointed to by the addr register. Only works if addr is not
200 // in new space.
201 void RememberedSetHelper(Register object, // Used for debug code.
202 Register addr,
203 Register scratch,
204 SaveFPRegsMode save_fp,
205 RememberedSetFinalAction and_then);
206
207 void CheckPageFlag(Register object,
208 Register scratch,
209 int mask,
210 Condition cc,
211 Label* condition_met,
212 Label::Distance condition_met_distance = Label::kFar);
213
214 // Check if object is in new space. Jumps if the object is not in new space.
215 // The register scratch can be object itself, but scratch will be clobbered.
216 void JumpIfNotInNewSpace(Register object,
217 Register scratch,
218 Label* branch,
219 Label::Distance distance = Label::kFar) {
220 InNewSpace(object, scratch, not_equal, branch, distance);
221 }
222
223 // Check if object is in new space. Jumps if the object is in new space.
224 // The register scratch can be object itself, but it will be clobbered.
225 void JumpIfInNewSpace(Register object,
226 Register scratch,
227 Label* branch,
228 Label::Distance distance = Label::kFar) {
229 InNewSpace(object, scratch, equal, branch, distance);
230 }
231
232 // Check if an object has the black incremental marking color. Also uses rcx!
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000233 void JumpIfBlack(Register object, Register bitmap_scratch,
234 Register mask_scratch, Label* on_black,
235 Label::Distance on_black_distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100236
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 // Checks the color of an object. If the object is white we jump to the
238 // incremental marker.
239 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
240 Label* value_is_white, Label::Distance distance);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100241
242 // Notify the garbage collector that we wrote a pointer into an object.
243 // |object| is the object being stored into, |value| is the object being
244 // stored. value and scratch registers are clobbered by the operation.
245 // The offset is the offset from the start of the object, not the offset from
246 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
247 void RecordWriteField(
248 Register object,
249 int offset,
250 Register value,
251 Register scratch,
252 SaveFPRegsMode save_fp,
253 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000254 SmiCheck smi_check = INLINE_SMI_CHECK,
255 PointersToHereCheck pointers_to_here_check_for_value =
256 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100257
258 // As above, but the offset has the tag presubtracted. For use with
259 // Operand(reg, off).
260 void RecordWriteContextSlot(
261 Register context,
262 int offset,
263 Register value,
264 Register scratch,
265 SaveFPRegsMode save_fp,
266 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267 SmiCheck smi_check = INLINE_SMI_CHECK,
268 PointersToHereCheck pointers_to_here_check_for_value =
269 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100270 RecordWriteField(context,
271 offset + kHeapObjectTag,
272 value,
273 scratch,
274 save_fp,
275 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 smi_check,
277 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100278 }
279
280 // Notify the garbage collector that we wrote a pointer into a fixed array.
281 // |array| is the array being stored into, |value| is the
282 // object being stored. |index| is the array index represented as a non-smi.
283 // All registers are clobbered by the operation RecordWriteArray
284 // filters out smis so it does not update the write barrier if the
285 // value is a smi.
286 void RecordWriteArray(
287 Register array,
288 Register value,
289 Register index,
290 SaveFPRegsMode save_fp,
291 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000292 SmiCheck smi_check = INLINE_SMI_CHECK,
293 PointersToHereCheck pointers_to_here_check_for_value =
294 kPointersToHereMaybeInteresting);
295
296 void RecordWriteForMap(
297 Register object,
298 Register map,
299 Register dst,
300 SaveFPRegsMode save_fp);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100301
302 // For page containing |object| mark region covering |address|
Steve Block8defd9f2010-07-08 12:39:36 +0100303 // dirty. |object| is the object being stored into, |value| is the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100304 // object being stored. The address and value registers are clobbered by the
Steve Block8defd9f2010-07-08 12:39:36 +0100305 // operation. RecordWrite filters out smis so it does not update
306 // the write barrier if the value is a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100307 void RecordWrite(
308 Register object,
309 Register address,
310 Register value,
311 SaveFPRegsMode save_fp,
312 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313 SmiCheck smi_check = INLINE_SMI_CHECK,
314 PointersToHereCheck pointers_to_here_check_for_value =
315 kPointersToHereMaybeInteresting);
Steve Block3ce2e202009-11-05 08:53:23 +0000316
Steve Blocka7e24c12009-10-30 11:49:00 +0000317 // ---------------------------------------------------------------------------
318 // Debugger Support
319
Andrei Popescu402d9372010-02-26 13:31:12 +0000320 void DebugBreak();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321
322 // Generates function and stub prologue code.
323 void StubPrologue();
324 void Prologue(bool code_pre_aging);
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
Steve Blockd0582a62009-12-15 09:54:21 +0000326 // Enter specific kind of exit frame; either in normal or
327 // debug mode. Expects the number of arguments in register rax and
Steve Blocka7e24c12009-10-30 11:49:00 +0000328 // sets up the number of arguments in register rdi and the pointer
329 // to the first argument in register rsi.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800330 //
331 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
332 // accessible via StackSpaceOperand.
Steve Block1e0659c2011-05-24 12:43:12 +0100333 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800335 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
336 // memory (not GCed) on the stack accessible via StackSpaceOperand.
337 void EnterApiExitFrame(int arg_stack_space);
Ben Murdochbb769b22010-08-11 14:56:33 +0100338
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 // Leave the current exit frame. Expects/provides the return value in
340 // register rax:rdx (untouched) and the pointer to the first
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000341 // argument in register rsi (if pop_arguments == true).
342 void LeaveExitFrame(bool save_doubles = false, bool pop_arguments = true);
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800344 // Leave the current exit frame. Expects/provides the return value in
345 // register rax (untouched).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000346 void LeaveApiExitFrame(bool restore_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Ben Murdochb0fe1622011-05-05 13:52:32 +0100348 // Push and pop the registers that can hold pointers.
Steve Block1e0659c2011-05-24 12:43:12 +0100349 void PushSafepointRegisters() { Pushad(); }
350 void PopSafepointRegisters() { Popad(); }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100351 // Store the value in register src in the safepoint register stack
352 // slot for register dst.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000353 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100354 void StoreToSafepointRegisterSlot(Register dst, Register src);
355 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100356
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100357 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100358 ExternalReference roots_array_start =
359 ExternalReference::roots_array_start(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000360 Move(kRootRegister, roots_array_start);
361 addp(kRootRegister, Immediate(kRootRegisterBias));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100362 }
Steve Block1e0659c2011-05-24 12:43:12 +0100363
Steve Blocka7e24c12009-10-30 11:49:00 +0000364 // ---------------------------------------------------------------------------
365 // JavaScript invokes
366
367 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000368 void InvokeFunctionCode(Register function, Register new_target,
369 const ParameterCount& expected,
370 const ParameterCount& actual, InvokeFlag flag,
371 const CallWrapper& call_wrapper);
372
373 void FloodFunctionIfStepping(Register fun, Register new_target,
374 const ParameterCount& expected,
375 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000376
377 // Invoke the JavaScript function in the given register. Changes the
378 // current context to the context in the function before invoking.
379 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000380 Register new_target,
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 const ParameterCount& actual,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100382 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000384
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000385 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000386 Register new_target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000388 const ParameterCount& actual,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100389 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000390 const CallWrapper& call_wrapper);
391
392 void InvokeFunction(Handle<JSFunction> function,
393 const ParameterCount& expected,
394 const ParameterCount& actual,
395 InvokeFlag flag,
396 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000397
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000398 // Invoke specified builtin JavaScript function.
399 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000400 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +0000401
Steve Blocka7e24c12009-10-30 11:49:00 +0000402 // ---------------------------------------------------------------------------
403 // Smi tagging, untagging and operations on tagged smis.
404
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 // Support for constant splitting.
406 bool IsUnsafeInt(const int32_t x);
407 void SafeMove(Register dst, Smi* src);
408 void SafePush(Smi* src);
409
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 // Conversions between tagged smi values and non-tagged integer values.
411
412 // Tag an integer value. The result must be known to be a valid smi value.
Leon Clarke4515c472010-02-03 11:58:03 +0000413 // Only uses the low 32 bits of the src register. Sets the N and Z flags
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100414 // based on the value of the resulting smi.
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 void Integer32ToSmi(Register dst, Register src);
416
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100417 // Stores an integer32 value into a memory field that already holds a smi.
418 void Integer32ToSmiField(const Operand& dst, Register src);
419
Steve Blocka7e24c12009-10-30 11:49:00 +0000420 // Adds constant to src and tags the result as a smi.
421 // Result must be a valid smi.
Steve Block3ce2e202009-11-05 08:53:23 +0000422 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
Steve Blocka7e24c12009-10-30 11:49:00 +0000423
424 // Convert smi to 32-bit integer. I.e., not sign extended into
425 // high 32 bits of destination.
426 void SmiToInteger32(Register dst, Register src);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100427 void SmiToInteger32(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000428
429 // Convert smi to 64-bit integer (sign extended if necessary).
430 void SmiToInteger64(Register dst, Register src);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100431 void SmiToInteger64(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000432
433 // Multiply a positive smi's integer value by a power of two.
434 // Provides result as 64-bit integer value.
435 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
436 Register src,
437 int power);
438
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100439 // Divide a positive smi's integer value by a power of two.
440 // Provides result as 32-bit integer value.
441 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
442 Register src,
443 int power);
444
Ben Murdoch8b112d22011-06-08 16:22:53 +0100445 // Perform the logical or of two smi values and return a smi value.
446 // If either argument is not a smi, jump to on_not_smis and retain
447 // the original values of source registers. The destination register
448 // may be changed if it's not one of the source registers.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100449 void SmiOrIfSmis(Register dst,
450 Register src1,
451 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000452 Label* on_not_smis,
453 Label::Distance near_jump = Label::kFar);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100454
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100455
Steve Block44f0eee2011-05-26 01:26:41 +0100456 // Simple comparison of smis. Both sides must be known smis to use these,
457 // otherwise use Cmp.
458 void SmiCompare(Register smi1, Register smi2);
Steve Block3ce2e202009-11-05 08:53:23 +0000459 void SmiCompare(Register dst, Smi* src);
Steve Block6ded16b2010-05-10 14:33:55 +0100460 void SmiCompare(Register dst, const Operand& src);
Steve Block3ce2e202009-11-05 08:53:23 +0000461 void SmiCompare(const Operand& dst, Register src);
462 void SmiCompare(const Operand& dst, Smi* src);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100463 // Compare the int32 in src register to the value of the smi stored at dst.
464 void SmiCompareInteger32(const Operand& dst, Register src);
Steve Block3ce2e202009-11-05 08:53:23 +0000465 // Sets sign and zero flags depending on value of smi in register.
466 void SmiTest(Register src);
467
Steve Blocka7e24c12009-10-30 11:49:00 +0000468 // Functions performing a check on a known or potential smi. Returns
469 // a condition that is satisfied if the check is successful.
470
471 // Is the value a tagged smi.
472 Condition CheckSmi(Register src);
Steve Block1e0659c2011-05-24 12:43:12 +0100473 Condition CheckSmi(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000474
Ben Murdochf87a2032010-10-22 12:50:53 +0100475 // Is the value a non-negative tagged smi.
476 Condition CheckNonNegativeSmi(Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000477
Leon Clarkee46be812010-01-19 14:06:41 +0000478 // Are both values tagged smis.
Steve Blocka7e24c12009-10-30 11:49:00 +0000479 Condition CheckBothSmi(Register first, Register second);
480
Ben Murdochf87a2032010-10-22 12:50:53 +0100481 // Are both values non-negative tagged smis.
482 Condition CheckBothNonNegativeSmi(Register first, Register second);
Leon Clarked91b9f72010-01-27 17:25:45 +0000483
Leon Clarkee46be812010-01-19 14:06:41 +0000484 // Are either value a tagged smi.
Ben Murdochbb769b22010-08-11 14:56:33 +0100485 Condition CheckEitherSmi(Register first,
486 Register second,
487 Register scratch = kScratchRegister);
Leon Clarkee46be812010-01-19 14:06:41 +0000488
Steve Blocka7e24c12009-10-30 11:49:00 +0000489 // Checks whether an 32-bit integer value is a valid for conversion
490 // to a smi.
491 Condition CheckInteger32ValidSmiValue(Register src);
492
Steve Block3ce2e202009-11-05 08:53:23 +0000493 // Checks whether an 32-bit unsigned integer value is a valid for
494 // conversion to a smi.
495 Condition CheckUInteger32ValidSmiValue(Register src);
496
Steve Block1e0659c2011-05-24 12:43:12 +0100497 // Check whether src is a Smi, and set dst to zero if it is a smi,
498 // and to one if it isn't.
499 void CheckSmiToIndicator(Register dst, Register src);
500 void CheckSmiToIndicator(Register dst, const Operand& src);
501
Steve Blocka7e24c12009-10-30 11:49:00 +0000502 // Test-and-jump functions. Typically combines a check function
503 // above with a conditional jump.
504
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000505 // Jump if the value can be represented by a smi.
506 void JumpIfValidSmiValue(Register src, Label* on_valid,
507 Label::Distance near_jump = Label::kFar);
508
Steve Blocka7e24c12009-10-30 11:49:00 +0000509 // Jump if the value cannot be represented by a smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000510 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
511 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000512
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513 // Jump if the unsigned integer value can be represented by a smi.
514 void JumpIfUIntValidSmiValue(Register src, Label* on_valid,
515 Label::Distance near_jump = Label::kFar);
516
Steve Block3ce2e202009-11-05 08:53:23 +0000517 // Jump if the unsigned integer value cannot be represented by a smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000518 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
519 Label::Distance near_jump = Label::kFar);
Steve Block3ce2e202009-11-05 08:53:23 +0000520
Steve Blocka7e24c12009-10-30 11:49:00 +0000521 // Jump to label if the value is a tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000522 void JumpIfSmi(Register src,
523 Label* on_smi,
524 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000525
526 // Jump to label if the value is not a tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000527 void JumpIfNotSmi(Register src,
528 Label* on_not_smi,
529 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000530
Ben Murdochf87a2032010-10-22 12:50:53 +0100531 // Jump to label if the value is not a non-negative tagged smi.
Ben Murdoch257744e2011-11-30 15:57:28 +0000532 void JumpUnlessNonNegativeSmi(Register src,
533 Label* on_not_smi,
534 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000535
Steve Block3ce2e202009-11-05 08:53:23 +0000536 // Jump to label if the value, which must be a tagged smi, has value equal
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 // to the constant.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100538 void JumpIfSmiEqualsConstant(Register src,
539 Smi* constant,
Ben Murdoch257744e2011-11-30 15:57:28 +0000540 Label* on_equals,
541 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000542
543 // Jump if either or both register are not smi values.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100544 void JumpIfNotBothSmi(Register src1,
545 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000546 Label* on_not_both_smi,
547 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000548
Ben Murdochf87a2032010-10-22 12:50:53 +0100549 // Jump if either or both register are not non-negative smi values.
Ben Murdochf87a2032010-10-22 12:50:53 +0100550 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000551 Label* on_not_both_smi,
552 Label::Distance near_jump = Label::kFar);
Leon Clarked91b9f72010-01-27 17:25:45 +0000553
Steve Blocka7e24c12009-10-30 11:49:00 +0000554 // Operations on tagged smi values.
555
556 // Smis represent a subset of integers. The subset is always equivalent to
557 // a two's complement interpretation of a fixed number of bits.
558
Steve Block3ce2e202009-11-05 08:53:23 +0000559 // Add an integer constant to a tagged smi, giving a tagged smi as result.
560 // No overflow testing on the result is done.
561 void SmiAddConstant(Register dst, Register src, Smi* constant);
562
Leon Clarkef7060e22010-06-03 12:02:55 +0100563 // Add an integer constant to a tagged smi, giving a tagged smi as result.
564 // No overflow testing on the result is done.
565 void SmiAddConstant(const Operand& dst, Smi* constant);
566
Steve Blocka7e24c12009-10-30 11:49:00 +0000567 // Add an integer constant to a tagged smi, giving a tagged smi as result,
568 // or jumping to a label if the result cannot be represented by a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000569 void SmiAddConstant(Register dst, Register src, Smi* constant,
570 SmiOperationConstraints constraints, Label* bailout_label,
Ben Murdoch257744e2011-11-30 15:57:28 +0000571 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000572
573 // Subtract an integer constant from a tagged smi, giving a tagged smi as
Steve Block6ded16b2010-05-10 14:33:55 +0100574 // result. No testing on the result is done. Sets the N and Z flags
575 // based on the value of the resulting integer.
Steve Block3ce2e202009-11-05 08:53:23 +0000576 void SmiSubConstant(Register dst, Register src, Smi* constant);
577
578 // Subtract an integer constant from a tagged smi, giving a tagged smi as
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 // result, or jumping to a label if the result cannot be represented by a smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000580 void SmiSubConstant(Register dst, Register src, Smi* constant,
581 SmiOperationConstraints constraints, Label* bailout_label,
Ben Murdoch257744e2011-11-30 15:57:28 +0000582 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000583
584 // Negating a smi can give a negative zero or too large positive value.
Steve Block3ce2e202009-11-05 08:53:23 +0000585 // NOTICE: This operation jumps on success, not failure!
Steve Blocka7e24c12009-10-30 11:49:00 +0000586 void SmiNeg(Register dst,
587 Register src,
Ben Murdoch257744e2011-11-30 15:57:28 +0000588 Label* on_smi_result,
589 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000590
591 // Adds smi values and return the result as a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000592 // If dst is src1, then src1 will be destroyed if the operation is
593 // successful, otherwise kept intact.
Steve Blocka7e24c12009-10-30 11:49:00 +0000594 void SmiAdd(Register dst,
595 Register src1,
596 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000597 Label* on_not_smi_result,
598 Label::Distance near_jump = Label::kFar);
Steve Block44f0eee2011-05-26 01:26:41 +0100599 void SmiAdd(Register dst,
600 Register src1,
601 const Operand& src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000602 Label* on_not_smi_result,
603 Label::Distance near_jump = Label::kFar);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100604
605 void SmiAdd(Register dst,
606 Register src1,
607 Register src2);
Steve Blocka7e24c12009-10-30 11:49:00 +0000608
609 // Subtracts smi values and return the result as a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000610 // If dst is src1, then src1 will be destroyed if the operation is
611 // successful, otherwise kept intact.
Steve Blocka7e24c12009-10-30 11:49:00 +0000612 void SmiSub(Register dst,
613 Register src1,
614 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000615 Label* on_not_smi_result,
616 Label::Distance near_jump = Label::kFar);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000617 void SmiSub(Register dst,
618 Register src1,
619 const Operand& src2,
620 Label* on_not_smi_result,
621 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000622
Steve Block6ded16b2010-05-10 14:33:55 +0100623 void SmiSub(Register dst,
624 Register src1,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100625 Register src2);
626
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100627 void SmiSub(Register dst,
628 Register src1,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100629 const Operand& src2);
Steve Block6ded16b2010-05-10 14:33:55 +0100630
Steve Blocka7e24c12009-10-30 11:49:00 +0000631 // Multiplies smi values and return the result as a smi,
632 // if possible.
633 // If dst is src1, then src1 will be destroyed, even if
634 // the operation is unsuccessful.
635 void SmiMul(Register dst,
636 Register src1,
637 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000638 Label* on_not_smi_result,
639 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000640
641 // Divides one smi by another and returns the quotient.
642 // Clobbers rax and rdx registers.
643 void SmiDiv(Register dst,
644 Register src1,
645 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000646 Label* on_not_smi_result,
647 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000648
649 // Divides one smi by another and returns the remainder.
650 // Clobbers rax and rdx registers.
651 void SmiMod(Register dst,
652 Register src1,
653 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 Label* on_not_smi_result,
655 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000656
657 // Bitwise operations.
658 void SmiNot(Register dst, Register src);
659 void SmiAnd(Register dst, Register src1, Register src2);
660 void SmiOr(Register dst, Register src1, Register src2);
661 void SmiXor(Register dst, Register src1, Register src2);
Steve Block3ce2e202009-11-05 08:53:23 +0000662 void SmiAndConstant(Register dst, Register src1, Smi* constant);
663 void SmiOrConstant(Register dst, Register src1, Smi* constant);
664 void SmiXorConstant(Register dst, Register src1, Smi* constant);
Steve Blocka7e24c12009-10-30 11:49:00 +0000665
666 void SmiShiftLeftConstant(Register dst,
667 Register src,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000668 int shift_value,
669 Label* on_not_smi_result = NULL,
670 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000671 void SmiShiftLogicalRightConstant(Register dst,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000672 Register src,
673 int shift_value,
674 Label* on_not_smi_result,
675 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000676 void SmiShiftArithmeticRightConstant(Register dst,
677 Register src,
678 int shift_value);
679
680 // Shifts a smi value to the left, and returns the result if that is a smi.
681 // Uses and clobbers rcx, so dst may not be rcx.
682 void SmiShiftLeft(Register dst,
683 Register src1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 Register src2,
685 Label* on_not_smi_result = NULL,
686 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000687 // Shifts a smi value to the right, shifting in zero bits at the top, and
688 // returns the unsigned intepretation of the result if that is a smi.
689 // Uses and clobbers rcx, so dst may not be rcx.
690 void SmiShiftLogicalRight(Register dst,
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100691 Register src1,
692 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000693 Label* on_not_smi_result,
694 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000695 // Shifts a smi value to the right, sign extending the top, and
696 // returns the signed intepretation of the result. That will always
697 // be a valid smi value, since it's numerically smaller than the
698 // original.
699 // Uses and clobbers rcx, so dst may not be rcx.
700 void SmiShiftArithmeticRight(Register dst,
701 Register src1,
702 Register src2);
703
704 // Specialized operations
705
706 // Select the non-smi register of two registers where exactly one is a
707 // smi. If neither are smis, jump to the failure label.
708 void SelectNonSmi(Register dst,
709 Register src1,
710 Register src2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000711 Label* on_not_smis,
712 Label::Distance near_jump = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000713
714 // Converts, if necessary, a smi to a combination of number and
715 // multiplier to be used as a scaled index.
716 // The src register contains a *positive* smi value. The shift is the
717 // power of two to multiply the index value by (e.g.
718 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
719 // The returned index register may be either src or dst, depending
720 // on what is most efficient. If src and dst are different registers,
721 // src is always unchanged.
722 SmiIndex SmiToIndex(Register dst, Register src, int shift);
723
724 // Converts a positive smi to a negative index.
725 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
726
Steve Block44f0eee2011-05-26 01:26:41 +0100727 // Add the value of a smi in memory to an int32 register.
728 // Sets flags as a normal add.
729 void AddSmiField(Register dst, const Operand& src);
730
Steve Block3ce2e202009-11-05 08:53:23 +0000731 // Basic Smi operations.
732 void Move(Register dst, Smi* source) {
Steve Block8defd9f2010-07-08 12:39:36 +0100733 LoadSmiConstant(dst, source);
Steve Block3ce2e202009-11-05 08:53:23 +0000734 }
735
736 void Move(const Operand& dst, Smi* source) {
Steve Block8defd9f2010-07-08 12:39:36 +0100737 Register constant = GetSmiConstant(source);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000738 movp(dst, constant);
Steve Block3ce2e202009-11-05 08:53:23 +0000739 }
740
741 void Push(Smi* smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000742
743 // Save away a raw integer with pointer size on the stack as two integers
744 // masquerading as smis so that the garbage collector skips visiting them.
745 void PushRegisterAsTwoSmis(Register src, Register scratch = kScratchRegister);
746 // Reconstruct a raw integer with pointer size from two integers masquerading
747 // as smis on the top of stack.
748 void PopRegisterAsTwoSmis(Register dst, Register scratch = kScratchRegister);
749
Steve Block3ce2e202009-11-05 08:53:23 +0000750 void Test(const Operand& dst, Smi* source);
751
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100752
Steve Blocka7e24c12009-10-30 11:49:00 +0000753 // ---------------------------------------------------------------------------
Leon Clarkee46be812010-01-19 14:06:41 +0000754 // String macros.
Steve Block1e0659c2011-05-24 12:43:12 +0100755
756 // If object is a string, its map is loaded into object_map.
Steve Block1e0659c2011-05-24 12:43:12 +0100757 void JumpIfNotString(Register object,
758 Register object_map,
Ben Murdoch257744e2011-11-30 15:57:28 +0000759 Label* not_string,
760 Label::Distance near_jump = Label::kFar);
Steve Block1e0659c2011-05-24 12:43:12 +0100761
762
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000763 void JumpIfNotBothSequentialOneByteStrings(
764 Register first_object, Register second_object, Register scratch1,
765 Register scratch2, Label* on_not_both_flat_one_byte,
Ben Murdoch257744e2011-11-30 15:57:28 +0000766 Label::Distance near_jump = Label::kFar);
Leon Clarkee46be812010-01-19 14:06:41 +0000767
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000768 // Check whether the instance type represents a flat one-byte string. Jump
769 // to the label if not. If the instance type can be scratched specify same
770 // register for both instance type and scratch.
771 void JumpIfInstanceTypeIsNotSequentialOneByte(
772 Register instance_type, Register scratch,
773 Label* on_not_flat_one_byte_string,
Ben Murdoch257744e2011-11-30 15:57:28 +0000774 Label::Distance near_jump = Label::kFar);
Steve Block6ded16b2010-05-10 14:33:55 +0100775
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000776 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
777 Register first_object_instance_type, Register second_object_instance_type,
778 Register scratch1, Register scratch2, Label* on_fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000779 Label::Distance near_jump = Label::kFar);
Steve Block6ded16b2010-05-10 14:33:55 +0100780
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000781 void EmitSeqStringSetCharCheck(Register string,
782 Register index,
783 Register value,
784 uint32_t encoding_mask);
785
786 // Checks if the given register or operand is a unique name
787 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name,
788 Label::Distance distance = Label::kFar);
789 void JumpIfNotUniqueNameInstanceType(Operand operand, Label* not_unique_name,
790 Label::Distance distance = Label::kFar);
791
Leon Clarkee46be812010-01-19 14:06:41 +0000792 // ---------------------------------------------------------------------------
793 // Macro instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +0000794
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000795 // Load/store with specific representation.
796 void Load(Register dst, const Operand& src, Representation r);
797 void Store(const Operand& dst, Register src, Representation r);
798
Steve Block3ce2e202009-11-05 08:53:23 +0000799 // Load a register with a long value as efficiently as possible.
Steve Blocka7e24c12009-10-30 11:49:00 +0000800 void Set(Register dst, int64_t x);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000801 void Set(const Operand& dst, intptr_t x);
802
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000803 void Cvtss2sd(XMMRegister dst, XMMRegister src);
804 void Cvtss2sd(XMMRegister dst, const Operand& src);
805 void Cvtsd2ss(XMMRegister dst, XMMRegister src);
806 void Cvtsd2ss(XMMRegister dst, const Operand& src);
807
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000808 // cvtsi2sd instruction only writes to the low 64-bit of dst register, which
809 // hinders register renaming and makes dependence chains longer. So we use
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000810 // xorpd to clear the dst register before cvtsi2sd to solve this issue.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000811 void Cvtlsi2sd(XMMRegister dst, Register src);
812 void Cvtlsi2sd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000813
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000814 void Cvtqsi2ss(XMMRegister dst, Register src);
815 void Cvtqsi2ss(XMMRegister dst, const Operand& src);
816
817 void Cvtqsi2sd(XMMRegister dst, Register src);
818 void Cvtqsi2sd(XMMRegister dst, const Operand& src);
819
820 void Cvtqui2ss(XMMRegister dst, Register src, Register tmp);
821 void Cvtqui2sd(XMMRegister dst, Register src, Register tmp);
822
823 void Cvtsd2si(Register dst, XMMRegister src);
824
825 void Cvttsd2si(Register dst, XMMRegister src);
826 void Cvttsd2si(Register dst, const Operand& src);
827 void Cvttss2siq(Register dst, XMMRegister src);
828 void Cvttss2siq(Register dst, const Operand& src);
829 void Cvttsd2siq(Register dst, XMMRegister src);
830 void Cvttsd2siq(Register dst, const Operand& src);
831
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100832 // Move if the registers are not identical.
833 void Move(Register target, Register source);
834
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000835 // TestBit and Load SharedFunctionInfo special field.
836 void TestBitSharedFunctionInfoSpecialField(Register base,
837 int offset,
838 int bit_index);
839 void LoadSharedFunctionInfoSpecialField(Register dst,
840 Register base,
841 int offset);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100842
Steve Blocka7e24c12009-10-30 11:49:00 +0000843 // Handle support
Steve Blocka7e24c12009-10-30 11:49:00 +0000844 void Move(Register dst, Handle<Object> source);
845 void Move(const Operand& dst, Handle<Object> source);
846 void Cmp(Register dst, Handle<Object> source);
847 void Cmp(const Operand& dst, Handle<Object> source);
Steve Block44f0eee2011-05-26 01:26:41 +0100848 void Cmp(Register dst, Smi* src);
849 void Cmp(const Operand& dst, Smi* src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000850 void Push(Handle<Object> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000851
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100852 // Load a heap object and handle the case of new-space objects by
853 // indirecting via a global cell.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000854 void MoveHeapObject(Register result, Handle<Object> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100855
856 // Load a global cell into a register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000857 void LoadGlobalCell(Register dst, Handle<Cell> cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100858
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400859 // Compare the given value and the value of weak cell.
860 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
861
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000862 void GetWeakValue(Register value, Handle<WeakCell> cell);
863
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400864 // Load the value of the weak cell in the value register. Branch to the given
865 // miss label if the weak cell was cleared.
866 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
867
Leon Clarkee46be812010-01-19 14:06:41 +0000868 // Emit code to discard a non-negative number of pointer-sized elements
869 // from the stack, clobbering only the rsp register.
870 void Drop(int stack_elements);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000871 // Emit code to discard a positive number of pointer-sized elements
872 // from the stack under the return address which remains on the top,
873 // clobbering the rsp register.
874 void DropUnderReturnAddress(int stack_elements,
875 Register scratch = kScratchRegister);
Leon Clarkee46be812010-01-19 14:06:41 +0000876
877 void Call(Label* target) { call(target); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000878 void Push(Register src);
879 void Push(const Operand& src);
880 void PushQuad(const Operand& src);
881 void Push(Immediate value);
882 void PushImm32(int32_t imm32);
883 void Pop(Register dst);
884 void Pop(const Operand& dst);
885 void PopQuad(const Operand& dst);
886 void PushReturnAddressFrom(Register src) { pushq(src); }
887 void PopReturnAddressTo(Register dst) { popq(dst); }
888 void Move(Register dst, ExternalReference ext) {
889 movp(dst, reinterpret_cast<void*>(ext.address()),
890 RelocInfo::EXTERNAL_REFERENCE);
891 }
892
893 // Loads a pointer into a register with a relocation mode.
894 void Move(Register dst, void* ptr, RelocInfo::Mode rmode) {
895 // This method must not be used with heap object references. The stored
896 // address is not GC safe. Use the handle version instead.
897 DCHECK(rmode > RelocInfo::LAST_GCED_ENUM);
898 movp(dst, ptr, rmode);
899 }
900
901 void Move(Register dst, Handle<Object> value, RelocInfo::Mode rmode) {
902 AllowDeferredHandleDereference using_raw_address;
903 DCHECK(!RelocInfo::IsNone(rmode));
904 DCHECK(value->IsHeapObject());
905 DCHECK(!isolate()->heap()->InNewSpace(*value));
906 movp(dst, reinterpret_cast<void*>(value.location()), rmode);
907 }
Leon Clarkee46be812010-01-19 14:06:41 +0000908
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400909 void Move(XMMRegister dst, uint32_t src);
910 void Move(XMMRegister dst, uint64_t src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000911 void Move(XMMRegister dst, float src) { Move(dst, bit_cast<uint32_t>(src)); }
912 void Move(XMMRegister dst, double src) { Move(dst, bit_cast<uint64_t>(src)); }
913
914#define AVX_OP2_WITH_TYPE(macro_name, name, src_type) \
915 void macro_name(XMMRegister dst, src_type src) { \
916 if (CpuFeatures::IsSupported(AVX)) { \
917 CpuFeatureScope scope(this, AVX); \
918 v##name(dst, dst, src); \
919 } else { \
920 name(dst, src); \
921 } \
922 }
923#define AVX_OP2_X(macro_name, name) \
924 AVX_OP2_WITH_TYPE(macro_name, name, XMMRegister)
925#define AVX_OP2_O(macro_name, name) \
926 AVX_OP2_WITH_TYPE(macro_name, name, const Operand&)
927#define AVX_OP2_XO(macro_name, name) \
928 AVX_OP2_X(macro_name, name) \
929 AVX_OP2_O(macro_name, name)
930
931 AVX_OP2_XO(Addsd, addsd)
932 AVX_OP2_XO(Subsd, subsd)
933 AVX_OP2_XO(Mulsd, mulsd)
934 AVX_OP2_XO(Divsd, divsd)
935 AVX_OP2_X(Andpd, andpd)
936 AVX_OP2_X(Orpd, orpd)
937 AVX_OP2_X(Xorpd, xorpd)
938 AVX_OP2_X(Pcmpeqd, pcmpeqd)
939 AVX_OP2_WITH_TYPE(Psllq, psllq, byte)
940 AVX_OP2_WITH_TYPE(Psrlq, psrlq, byte)
941
942#undef AVX_OP2_O
943#undef AVX_OP2_X
944#undef AVX_OP2_XO
945#undef AVX_OP2_WITH_TYPE
946
947 void Movsd(XMMRegister dst, XMMRegister src);
948 void Movsd(XMMRegister dst, const Operand& src);
949 void Movsd(const Operand& dst, XMMRegister src);
950 void Movss(XMMRegister dst, XMMRegister src);
951 void Movss(XMMRegister dst, const Operand& src);
952 void Movss(const Operand& dst, XMMRegister src);
953
954 void Movd(XMMRegister dst, Register src);
955 void Movd(XMMRegister dst, const Operand& src);
956 void Movd(Register dst, XMMRegister src);
957 void Movq(XMMRegister dst, Register src);
958 void Movq(Register dst, XMMRegister src);
959
960 void Movaps(XMMRegister dst, XMMRegister src);
961 void Movapd(XMMRegister dst, XMMRegister src);
962 void Movmskpd(Register dst, XMMRegister src);
963
964 void Roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
965 void Roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
966 void Sqrtsd(XMMRegister dst, XMMRegister src);
967 void Sqrtsd(XMMRegister dst, const Operand& src);
968
969 void Ucomiss(XMMRegister src1, XMMRegister src2);
970 void Ucomiss(XMMRegister src1, const Operand& src2);
971 void Ucomisd(XMMRegister src1, XMMRegister src2);
972 void Ucomisd(XMMRegister src1, const Operand& src2);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400973
Steve Blocka7e24c12009-10-30 11:49:00 +0000974 // Control Flow
975 void Jump(Address destination, RelocInfo::Mode rmode);
976 void Jump(ExternalReference ext);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000977 void Jump(const Operand& op);
Steve Blocka7e24c12009-10-30 11:49:00 +0000978 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
979
980 void Call(Address destination, RelocInfo::Mode rmode);
981 void Call(ExternalReference ext);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000982 void Call(const Operand& op);
Ben Murdoch257744e2011-11-30 15:57:28 +0000983 void Call(Handle<Code> code_object,
984 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000985 TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000986
Steve Block44f0eee2011-05-26 01:26:41 +0100987 // The size of the code generated for different call instructions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000988 int CallSize(Address destination) {
989 return kCallSequenceLength;
Steve Block44f0eee2011-05-26 01:26:41 +0100990 }
991 int CallSize(ExternalReference ext);
992 int CallSize(Handle<Code> code_object) {
993 // Code calls use 32-bit relative addressing.
994 return kShortCallInstructionLength;
995 }
996 int CallSize(Register target) {
997 // Opcode: REX_opt FF /2 m64
998 return (target.high_bit() != 0) ? 3 : 2;
999 }
1000 int CallSize(const Operand& target) {
1001 // Opcode: REX_opt FF /2 m64
1002 return (target.requires_rex() ? 2 : 1) + target.operand_size();
1003 }
1004
Steve Block1e0659c2011-05-24 12:43:12 +01001005 // Emit call to the code we are currently generating.
1006 void CallSelf() {
1007 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
1008 Call(self, RelocInfo::CODE_TARGET);
1009 }
1010
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001011 // Non-SSE2 instructions.
1012 void Pextrd(Register dst, XMMRegister src, int8_t imm8);
1013 void Pinsrd(XMMRegister dst, Register src, int8_t imm8);
1014 void Pinsrd(XMMRegister dst, const Operand& src, int8_t imm8);
1015
1016 void Lzcntq(Register dst, Register src);
1017 void Lzcntq(Register dst, const Operand& src);
1018
1019 void Lzcntl(Register dst, Register src);
1020 void Lzcntl(Register dst, const Operand& src);
1021
1022 void Tzcntq(Register dst, Register src);
1023 void Tzcntq(Register dst, const Operand& src);
1024
1025 void Tzcntl(Register dst, Register src);
1026 void Tzcntl(Register dst, const Operand& src);
1027
1028 void Popcntl(Register dst, Register src);
1029 void Popcntl(Register dst, const Operand& src);
1030
1031 void Popcntq(Register dst, Register src);
1032 void Popcntq(Register dst, const Operand& src);
1033
Steve Block1e0659c2011-05-24 12:43:12 +01001034 // Non-x64 instructions.
1035 // Push/pop all general purpose registers.
1036 // Does not push rsp/rbp nor any of the assembler's special purpose registers
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001037 // (kScratchRegister, kRootRegister).
Steve Block1e0659c2011-05-24 12:43:12 +01001038 void Pushad();
1039 void Popad();
1040 // Sets the stack as after performing Popad, without actually loading the
1041 // registers.
1042 void Dropad();
1043
Steve Blocka7e24c12009-10-30 11:49:00 +00001044 // Compare object type for heap object.
1045 // Always use unsigned comparisons: above and below, not less and greater.
1046 // Incoming register is heap_object and outgoing register is map.
1047 // They may be the same register, and may be kScratchRegister.
1048 void CmpObjectType(Register heap_object, InstanceType type, Register map);
1049
1050 // Compare instance type for map.
1051 // Always use unsigned comparisons: above and below, not less and greater.
1052 void CmpInstanceType(Register map, InstanceType type);
1053
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001054 // Check if a map for a JSObject indicates that the object has fast elements.
1055 // Jump to the specified label if it does not.
1056 void CheckFastElements(Register map,
1057 Label* fail,
1058 Label::Distance distance = Label::kFar);
1059
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001060 // Check if a map for a JSObject indicates that the object can have both smi
1061 // and HeapObject elements. Jump to the specified label if it does not.
1062 void CheckFastObjectElements(Register map,
1063 Label* fail,
1064 Label::Distance distance = Label::kFar);
1065
1066 // Check if a map for a JSObject indicates that the object has fast smi only
1067 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001068 void CheckFastSmiElements(Register map,
1069 Label* fail,
1070 Label::Distance distance = Label::kFar);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001071
1072 // Check to see if maybe_number can be stored as a double in
1073 // FastDoubleElements. If it can, store it at the index specified by index in
1074 // the FastDoubleElements array elements, otherwise jump to fail. Note that
1075 // index must not be smi-tagged.
1076 void StoreNumberToDoubleElements(Register maybe_number,
1077 Register elements,
1078 Register index,
1079 XMMRegister xmm_scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001080 Label* fail,
1081 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001082
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001083 // Compare an object's map with the specified map.
1084 void CompareMap(Register obj, Handle<Map> map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001085
1086 // Check if the map of an object is equal to a specified map and branch to
1087 // label if not. Skip the smi check if not required (object is known to be a
1088 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1089 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +00001090 void CheckMap(Register obj,
1091 Handle<Map> map,
1092 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001093 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +00001094
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001095 // Check if the map of an object is equal to a specified weak map and branch
1096 // to a specified target if equal. Skip the smi check if not required
1097 // (object is known to be a heap object)
1098 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1099 Handle<WeakCell> cell, Handle<Code> success,
1100 SmiCheckType smi_check_type);
Andrei Popescu31002712010-02-23 13:46:05 +00001101
Leon Clarked91b9f72010-01-27 17:25:45 +00001102 // Check if the object in register heap_object is a string. Afterwards the
1103 // register map contains the object map and the register instance_type
1104 // contains the instance_type. The registers map and instance_type can be the
1105 // same in which case it contains the instance type afterwards. Either of the
1106 // registers map and instance_type can be the same as heap_object.
1107 Condition IsObjectStringType(Register heap_object,
1108 Register map,
1109 Register instance_type);
1110
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001111 // Check if the object in register heap_object is a name. Afterwards the
1112 // register map contains the object map and the register instance_type
1113 // contains the instance_type. The registers map and instance_type can be the
1114 // same in which case it contains the instance type afterwards. Either of the
1115 // registers map and instance_type can be the same as heap_object.
1116 Condition IsObjectNameType(Register heap_object,
1117 Register map,
1118 Register instance_type);
1119
Steve Block8defd9f2010-07-08 12:39:36 +01001120 // FCmp compares and pops the two values on top of the FPU stack.
1121 // The flag results are similar to integer cmp, but requires unsigned
Steve Blocka7e24c12009-10-30 11:49:00 +00001122 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
1123 void FCmp();
1124
Ben Murdoch257744e2011-11-30 15:57:28 +00001125 void ClampUint8(Register reg);
1126
1127 void ClampDoubleToUint8(XMMRegister input_reg,
1128 XMMRegister temp_xmm_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129 Register result_reg);
1130
1131 void SlowTruncateToI(Register result_reg, Register input_reg,
1132 int offset = HeapNumber::kValueOffset - kHeapObjectTag);
1133
1134 void TruncateHeapNumberToI(Register result_reg, Register input_reg);
1135 void TruncateDoubleToI(Register result_reg, XMMRegister input_reg);
1136
1137 void DoubleToI(Register result_reg, XMMRegister input_reg,
1138 XMMRegister scratch, MinusZeroMode minus_zero_mode,
1139 Label* lost_precision, Label* is_nan, Label* minus_zero,
1140 Label::Distance dst = Label::kFar);
1141
1142 void LoadUint32(XMMRegister dst, Register src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001143
1144 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001145 void EnumLength(Register dst, Register map);
1146 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001147 void LoadAccessor(Register dst, Register holder, int accessor_index,
1148 AccessorComponent accessor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001149
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001150 template<typename Field>
1151 void DecodeField(Register reg) {
1152 static const int shift = Field::kShift;
1153 static const int mask = Field::kMask >> Field::kShift;
1154 if (shift != 0) {
1155 shrp(reg, Immediate(shift));
1156 }
1157 andp(reg, Immediate(mask));
1158 }
Andrei Popescu402d9372010-02-26 13:31:12 +00001159
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001160 template<typename Field>
1161 void DecodeFieldToSmi(Register reg) {
1162 if (SmiValuesAre32Bits()) {
1163 andp(reg, Immediate(Field::kMask));
1164 shlp(reg, Immediate(kSmiShift - Field::kShift));
1165 } else {
1166 static const int shift = Field::kShift;
1167 static const int mask = (Field::kMask >> Field::kShift) << kSmiTagSize;
1168 DCHECK(SmiValuesAre31Bits());
1169 DCHECK(kSmiShift == kSmiTagSize);
1170 DCHECK((mask & 0x80000000u) == 0);
1171 if (shift < kSmiShift) {
1172 shlp(reg, Immediate(kSmiShift - shift));
1173 } else if (shift > kSmiShift) {
1174 sarp(reg, Immediate(shift - kSmiShift));
1175 }
1176 andp(reg, Immediate(mask));
1177 }
1178 }
Iain Merrick75681382010-08-19 15:07:18 +01001179
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001180 // Abort execution if argument is not a number, enabled via --debug-code.
1181 void AssertNumber(Register object);
1182
1183 // Abort execution if argument is a smi, enabled via --debug-code.
1184 void AssertNotSmi(Register object);
1185
1186 // Abort execution if argument is not a smi, enabled via --debug-code.
1187 void AssertSmi(Register object);
1188 void AssertSmi(const Operand& object);
Steve Block6ded16b2010-05-10 14:33:55 +01001189
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001190 // Abort execution if a 64 bit register containing a 32 bit payload does not
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001191 // have zeros in the top 32 bits, enabled via --debug-code.
1192 void AssertZeroExtended(Register reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001193
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001194 // Abort execution if argument is not a string, enabled via --debug-code.
1195 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001196
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001197 // Abort execution if argument is not a name, enabled via --debug-code.
1198 void AssertName(Register object);
1199
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001200 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1201 void AssertFunction(Register object);
1202
1203 // Abort execution if argument is not a JSBoundFunction,
1204 // enabled via --debug-code.
1205 void AssertBoundFunction(Register object);
1206
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001207 // Abort execution if argument is not undefined or an AllocationSite, enabled
1208 // via --debug-code.
1209 void AssertUndefinedOrAllocationSite(Register object);
1210
1211 // Abort execution if argument is not the root value with the given index,
1212 // enabled via --debug-code.
1213 void AssertRootValue(Register src,
1214 Heap::RootListIndex root_value_index,
1215 BailoutReason reason);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01001216
Steve Blocka7e24c12009-10-30 11:49:00 +00001217 // ---------------------------------------------------------------------------
1218 // Exception handling
1219
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001220 // Push a new stack handler and link it into stack handler chain.
1221 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +00001222
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001223 // Unlink the stack handler on top of the stack from the stack handler chain.
1224 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001225
Steve Blocka7e24c12009-10-30 11:49:00 +00001226 // ---------------------------------------------------------------------------
1227 // Inline caching support
1228
Steve Blocka7e24c12009-10-30 11:49:00 +00001229 // Generate code for checking access rights - used for security checks
1230 // on access to global objects across environments. The holder register
1231 // is left untouched, but the scratch register and kScratchRegister,
1232 // which must be different, are clobbered.
1233 void CheckAccessGlobalProxy(Register holder_reg,
1234 Register scratch,
1235 Label* miss);
1236
Ben Murdochc7cc0282012-03-05 14:35:55 +00001237 void GetNumberHash(Register r0, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001238
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001239 void LoadFromNumberDictionary(Label* miss,
1240 Register elements,
1241 Register key,
1242 Register r0,
1243 Register r1,
1244 Register r2,
1245 Register result);
1246
1247
Steve Blocka7e24c12009-10-30 11:49:00 +00001248 // ---------------------------------------------------------------------------
1249 // Allocation support
1250
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001251 // Allocate an object in new space or old space. If the given space
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001252 // is exhausted control continues at the gc_required label. The allocated
1253 // object is returned in result and end of the new object is returned in
1254 // result_end. The register scratch can be passed as no_reg in which case
1255 // an additional object reference will be added to the reloc info. The
1256 // returned pointers in result and result_end have not yet been tagged as
1257 // heap objects. If result_contains_top_on_entry is true the content of
1258 // result is known to be the allocation top on entry (could be result_end
1259 // from a previous call). If result_contains_top_on_entry is true scratch
Steve Blocka7e24c12009-10-30 11:49:00 +00001260 // should be no_reg as it is never used.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001261 void Allocate(int object_size,
1262 Register result,
1263 Register result_end,
1264 Register scratch,
1265 Label* gc_required,
1266 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001267
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001268 void Allocate(int header_size,
1269 ScaleFactor element_size,
1270 Register element_count,
1271 Register result,
1272 Register result_end,
1273 Register scratch,
1274 Label* gc_required,
1275 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001276
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001277 void Allocate(Register object_size,
1278 Register result,
1279 Register result_end,
1280 Register scratch,
1281 Label* gc_required,
1282 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00001283
Steve Block3ce2e202009-11-05 08:53:23 +00001284 // Allocate a heap number in new space with undefined value. Returns
1285 // tagged pointer in result register, or jumps to gc_required if new
1286 // space is full.
1287 void AllocateHeapNumber(Register result,
1288 Register scratch,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001289 Label* gc_required,
1290 MutableMode mode = IMMUTABLE);
Steve Block3ce2e202009-11-05 08:53:23 +00001291
Leon Clarkee46be812010-01-19 14:06:41 +00001292 // Allocate a sequential string. All the header fields of the string object
1293 // are initialized.
1294 void AllocateTwoByteString(Register result,
1295 Register length,
1296 Register scratch1,
1297 Register scratch2,
1298 Register scratch3,
1299 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001300 void AllocateOneByteString(Register result, Register length,
1301 Register scratch1, Register scratch2,
1302 Register scratch3, Label* gc_required);
Leon Clarkee46be812010-01-19 14:06:41 +00001303
1304 // Allocate a raw cons string object. Only the map field of the result is
1305 // initialized.
Ben Murdoch589d6972011-11-30 16:04:58 +00001306 void AllocateTwoByteConsString(Register result,
Leon Clarkee46be812010-01-19 14:06:41 +00001307 Register scratch1,
1308 Register scratch2,
1309 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001310 void AllocateOneByteConsString(Register result, Register scratch1,
1311 Register scratch2, Label* gc_required);
Leon Clarkee46be812010-01-19 14:06:41 +00001312
Ben Murdoch589d6972011-11-30 16:04:58 +00001313 // Allocate a raw sliced string object. Only the map field of the result is
1314 // initialized.
1315 void AllocateTwoByteSlicedString(Register result,
1316 Register scratch1,
1317 Register scratch2,
1318 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001319 void AllocateOneByteSlicedString(Register result, Register scratch1,
1320 Register scratch2, Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +00001321
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001322 // Allocate and initialize a JSValue wrapper with the specified {constructor}
1323 // and {value}.
1324 void AllocateJSValue(Register result, Register constructor, Register value,
1325 Register scratch, Label* gc_required);
1326
Steve Blocka7e24c12009-10-30 11:49:00 +00001327 // ---------------------------------------------------------------------------
1328 // Support functions.
1329
1330 // Check if result is zero and op is negative.
1331 void NegativeZeroTest(Register result, Register op, Label* then_label);
1332
1333 // Check if result is zero and op is negative in code using jump targets.
1334 void NegativeZeroTest(CodeGenerator* cgen,
1335 Register result,
1336 Register op,
1337 JumpTarget* then_target);
1338
1339 // Check if result is zero and any of op1 and op2 are negative.
1340 // Register scratch is destroyed, and it must be different from op2.
1341 void NegativeZeroTest(Register result, Register op1, Register op2,
1342 Register scratch, Label* then_label);
1343
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001344 // Machine code version of Map::GetConstructor().
1345 // |temp| holds |result|'s map when done.
1346 void GetMapConstructor(Register result, Register map, Register temp);
1347
Steve Blocka7e24c12009-10-30 11:49:00 +00001348 // Try to get function prototype of a function and puts the value in
1349 // the result register. Checks that the function really is a
1350 // function and jumps to the miss label if the fast checks fail. The
1351 // function register will be untouched; the other register may be
1352 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001353 void TryGetFunctionPrototype(Register function, Register result, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +00001354
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001355 // Picks out an array index from the hash field.
1356 // Register use:
1357 // hash - holds the index's hash. Clobbered.
1358 // index - holds the overwritten index on exit.
1359 void IndexFromHash(Register hash, Register index);
1360
Steve Blockd0582a62009-12-15 09:54:21 +00001361 // Find the function context up the context chain.
1362 void LoadContext(Register dst, int context_chain_length);
1363
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001364 // Load the global object from the current context.
1365 void LoadGlobalObject(Register dst) {
1366 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
1367 }
1368
1369 // Load the global proxy from the current context.
1370 void LoadGlobalProxy(Register dst) {
1371 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
1372 }
1373
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001374 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001375 // transitioned_kind from the native context if the map in register
1376 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001377 // expected_kind.
1378 void LoadTransitionedArrayMapConditional(
1379 ElementsKind expected_kind,
1380 ElementsKind transitioned_kind,
1381 Register map_in_out,
1382 Register scratch,
1383 Label* no_map_match);
1384
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001385 // Load the native context slot with the current index.
1386 void LoadNativeContextSlot(int index, Register dst);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001387
1388 // Load the initial map from the global function. The registers
1389 // function and map can be the same.
1390 void LoadGlobalFunctionInitialMap(Register function, Register map);
1391
Steve Blocka7e24c12009-10-30 11:49:00 +00001392 // ---------------------------------------------------------------------------
1393 // Runtime calls
1394
1395 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001396 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001397
Leon Clarkee46be812010-01-19 14:06:41 +00001398 // Tail call a code stub (jump).
1399 void TailCallStub(CodeStub* stub);
1400
Steve Blocka7e24c12009-10-30 11:49:00 +00001401 // Return from a code stub after popping its arguments.
1402 void StubReturn(int argc);
1403
1404 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001405 void CallRuntime(const Runtime::Function* f,
1406 int num_arguments,
1407 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Steve Blocka7e24c12009-10-30 11:49:00 +00001408
Steve Block1e0659c2011-05-24 12:43:12 +01001409 // Call a runtime function and save the value of XMM registers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001410 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1411 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001412 CallRuntime(function, function->nargs, kSaveFPRegs);
1413 }
Steve Block1e0659c2011-05-24 12:43:12 +01001414
Steve Blocka7e24c12009-10-30 11:49:00 +00001415 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001416 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001417 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001418 const Runtime::Function* function = Runtime::FunctionForId(fid);
1419 CallRuntime(function, function->nargs, save_doubles);
1420 }
1421
1422 // Convenience function: Same as above, but takes the fid instead.
1423 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1424 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1425 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001426 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001427
Andrei Popescu402d9372010-02-26 13:31:12 +00001428 // Convenience function: call an external reference.
1429 void CallExternalReference(const ExternalReference& ext,
1430 int num_arguments);
1431
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001432 // Convenience function: tail call a runtime routine (jump)
1433 void TailCallRuntime(Runtime::FunctionId fid);
Steve Block6ded16b2010-05-10 14:33:55 +01001434
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001435 // Jump to a runtime routines
1436 void JumpToExternalReference(const ExternalReference& ext);
John Reck59135872010-11-02 12:39:01 -07001437
Leon Clarke4515c472010-02-03 11:58:03 +00001438 // Before calling a C-function from generated code, align arguments on stack.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001439 // After aligning the frame, arguments must be stored in rsp[0], rsp[8],
Leon Clarke4515c472010-02-03 11:58:03 +00001440 // etc., not pushed. The argument count assumes all arguments are word sized.
1441 // The number of slots reserved for arguments depends on platform. On Windows
1442 // stack slots are reserved for the arguments passed in registers. On other
1443 // platforms stack slots are only reserved for the arguments actually passed
1444 // on the stack.
1445 void PrepareCallCFunction(int num_arguments);
1446
1447 // Calls a C function and cleans up the space for arguments allocated
1448 // by PrepareCallCFunction. The called function is not allowed to trigger a
1449 // garbage collection, since that might move the code and invalidate the
1450 // return address (unless this is somehow accounted for by the called
1451 // function).
1452 void CallCFunction(ExternalReference function, int num_arguments);
1453 void CallCFunction(Register function, int num_arguments);
1454
1455 // Calculate the number of stack slots to reserve for arguments when calling a
1456 // C function.
1457 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
Steve Blocka7e24c12009-10-30 11:49:00 +00001458
1459 // ---------------------------------------------------------------------------
1460 // Utilities
1461
1462 void Ret();
1463
Steve Block1e0659c2011-05-24 12:43:12 +01001464 // Return and drop arguments from stack, where the number of arguments
1465 // may be bigger than 2^16 - 1. Requires a scratch register.
1466 void Ret(int bytes_dropped, Register scratch);
1467
Ben Murdoch8b112d22011-06-08 16:22:53 +01001468 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001469 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001470 return code_object_;
1471 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001472
Steve Block44f0eee2011-05-26 01:26:41 +01001473 // Copy length bytes from source to destination.
1474 // Uses scratch register internally (if you have a low-eight register
1475 // free, do use it, otherwise kScratchRegister will be used).
1476 // The min_length is a minimum limit on the value that length will have.
1477 // The algorithm has some special cases that might be omitted if the string
1478 // is known to always be long.
1479 void CopyBytes(Register destination,
1480 Register source,
1481 Register length,
1482 int min_length = 0,
1483 Register scratch = kScratchRegister);
1484
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001485 // Initialize fields with filler values. Fields starting at |current_address|
1486 // not including |end_address| are overwritten with the value in |filler|. At
1487 // the end the loop, |current_address| takes the value of |end_address|.
1488 void InitializeFieldsWithFiller(Register current_address,
1489 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001490
Steve Blocka7e24c12009-10-30 11:49:00 +00001491
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001492 // Emit code for a truncating division by a constant. The dividend register is
1493 // unchanged, the result is in rdx, and rax gets clobbered.
1494 void TruncatingDiv(Register dividend, int32_t divisor);
1495
Steve Blocka7e24c12009-10-30 11:49:00 +00001496 // ---------------------------------------------------------------------------
1497 // StatsCounter support
1498
1499 void SetCounter(StatsCounter* counter, int value);
1500 void IncrementCounter(StatsCounter* counter, int value);
1501 void DecrementCounter(StatsCounter* counter, int value);
1502
1503
1504 // ---------------------------------------------------------------------------
1505 // Debugging
1506
1507 // Calls Abort(msg) if the condition cc is not satisfied.
1508 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001509 void Assert(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001510
Iain Merrick75681382010-08-19 15:07:18 +01001511 void AssertFastElements(Register elements);
1512
Steve Blocka7e24c12009-10-30 11:49:00 +00001513 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001514 void Check(Condition cc, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001515
1516 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001517 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001518
Steve Block6ded16b2010-05-10 14:33:55 +01001519 // Check that the stack is aligned.
1520 void CheckStackAlignment();
1521
Steve Blocka7e24c12009-10-30 11:49:00 +00001522 // Verify restrictions about code generated in stubs.
1523 void set_generating_stub(bool value) { generating_stub_ = value; }
1524 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001525 void set_has_frame(bool value) { has_frame_ = value; }
1526 bool has_frame() { return has_frame_; }
1527 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001528
Ben Murdoch8b112d22011-06-08 16:22:53 +01001529 static int SafepointRegisterStackIndex(Register reg) {
1530 return SafepointRegisterStackIndex(reg.code());
1531 }
1532
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001533 // Load the type feedback vector from a JavaScript frame.
1534 void EmitLoadTypeFeedbackVector(Register vector);
1535
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001536 // Activation support.
1537 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001538 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001539 void LeaveFrame(StackFrame::Type type);
1540
1541 // Expects object in rax and returns map with validated enum cache
1542 // in rax. Assumes that any other register can be used as a scratch.
1543 void CheckEnumCache(Register null_value,
1544 Label* call_runtime);
1545
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001546 // AllocationMemento support. Arrays may have an associated
1547 // AllocationMemento object that can be checked for in order to pretransition
1548 // to another type.
1549 // On entry, receiver_reg should point to the array object.
1550 // scratch_reg gets clobbered.
1551 // If allocation info is present, condition flags are set to equal.
1552 void TestJSArrayForAllocationMemento(Register receiver_reg,
1553 Register scratch_reg,
1554 Label* no_memento_found);
1555
1556 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1557 Register scratch_reg,
1558 Label* memento_found) {
1559 Label no_memento_found;
1560 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1561 &no_memento_found);
1562 j(equal, memento_found);
1563 bind(&no_memento_found);
1564 }
1565
1566 // Jumps to found label if a prototype map has dictionary elements.
1567 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1568 Register scratch1, Label* found);
1569
Steve Blocka7e24c12009-10-30 11:49:00 +00001570 private:
Steve Block1e0659c2011-05-24 12:43:12 +01001571 // Order general registers are pushed by Pushad.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001572 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r12, r14, r15.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001573 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001574 static const int kNumSafepointSavedRegisters = 12;
Ben Murdoch257744e2011-11-30 15:57:28 +00001575 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001576
Steve Blocka7e24c12009-10-30 11:49:00 +00001577 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001578 bool has_frame_;
Steve Block44f0eee2011-05-26 01:26:41 +01001579 bool root_array_available_;
Steve Block8defd9f2010-07-08 12:39:36 +01001580
1581 // Returns a register holding the smi value. The register MUST NOT be
1582 // modified. It may be the "smi 1 constant" register.
1583 Register GetSmiConstant(Smi* value);
1584
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001585 int64_t RootRegisterDelta(ExternalReference other);
1586
Steve Block8defd9f2010-07-08 12:39:36 +01001587 // Moves the smi value to the destination register.
1588 void LoadSmiConstant(Register dst, Smi* value);
1589
Andrei Popescu31002712010-02-23 13:46:05 +00001590 // This handle will be patched with the code object on installation.
1591 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001592
1593 // Helper functions for generating invokes.
1594 void InvokePrologue(const ParameterCount& expected,
1595 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +00001596 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001597 bool* definitely_mismatches,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001598 InvokeFlag flag,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001599 Label::Distance near_jump,
1600 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001601
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001602 void EnterExitFramePrologue(bool save_rax);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001603
1604 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1605 // accessible via StackSpaceOperand.
Steve Block1e0659c2011-05-24 12:43:12 +01001606 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001607
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001608 void LeaveExitFrameEpilogue(bool restore_context);
Ben Murdochbb769b22010-08-11 14:56:33 +01001609
Steve Blocka7e24c12009-10-30 11:49:00 +00001610 // Allocation support helpers.
Steve Block6ded16b2010-05-10 14:33:55 +01001611 // Loads the top of new-space into the result register.
Steve Block6ded16b2010-05-10 14:33:55 +01001612 // Otherwise the address of the new-space top is loaded into scratch (if
1613 // scratch is valid), and the new-space top is loaded into result.
Steve Blocka7e24c12009-10-30 11:49:00 +00001614 void LoadAllocationTopHelper(Register result,
Steve Blocka7e24c12009-10-30 11:49:00 +00001615 Register scratch,
1616 AllocationFlags flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001617
1618 void MakeSureDoubleAlignedHelper(Register result,
1619 Register scratch,
1620 Label* gc_required,
1621 AllocationFlags flags);
1622
Steve Block6ded16b2010-05-10 14:33:55 +01001623 // Update allocation top with value in result_end register.
1624 // If scratch is valid, it contains the address of the allocation top.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001625 void UpdateAllocationTopHelper(Register result_end,
1626 Register scratch,
1627 AllocationFlags flags);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001628
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001629 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1630 void InNewSpace(Register object,
1631 Register scratch,
1632 Condition cc,
1633 Label* branch,
1634 Label::Distance distance = Label::kFar);
1635
1636 // Helper for finding the mark bits for an address. Afterwards, the
1637 // bitmap register points at the word with the mark bits and the mask
1638 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1639 // unchanged.
1640 inline void GetMarkBits(Register addr_reg,
1641 Register bitmap_reg,
1642 Register mask_reg);
1643
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001644 // Compute memory operands for safepoint stack slots.
1645 Operand SafepointRegisterSlot(Register reg);
1646 static int SafepointRegisterStackIndex(int reg_code) {
1647 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1648 }
1649
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001650 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001651 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001652 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001653};
1654
1655
1656// The code patcher is used to patch (typically) small parts of code e.g. for
1657// debugging and other types of instrumentation. When using the code patcher
1658// the exact number of bytes specified must be emitted. Is not legal to emit
1659// relocation information. If any of these constraints are violated it causes
1660// an assertion.
1661class CodePatcher {
1662 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001663 CodePatcher(Isolate* isolate, byte* address, int size);
1664 ~CodePatcher();
Steve Blocka7e24c12009-10-30 11:49:00 +00001665
1666 // Macro assembler to emit code.
1667 MacroAssembler* masm() { return &masm_; }
1668
1669 private:
1670 byte* address_; // The address of the code being patched.
1671 int size_; // Number of bytes of the expected patch size.
1672 MacroAssembler masm_; // Macro assembler used to generate the code.
1673};
1674
1675
1676// -----------------------------------------------------------------------------
1677// Static helper functions.
1678
1679// Generate an Operand for loading a field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001680inline Operand FieldOperand(Register object, int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001681 return Operand(object, offset - kHeapObjectTag);
1682}
1683
1684
1685// Generate an Operand for loading an indexed field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001686inline Operand FieldOperand(Register object,
1687 Register index,
1688 ScaleFactor scale,
1689 int offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001690 return Operand(object, index, scale, offset - kHeapObjectTag);
1691}
1692
1693
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001694inline Operand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001695 return Operand(context, Context::SlotOffset(index));
1696}
1697
1698
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001699inline Operand ContextOperand(Register context, Register index) {
1700 return Operand(context, index, times_pointer_size, Context::SlotOffset(0));
1701}
1702
1703
1704inline Operand NativeContextOperand() {
1705 return ContextOperand(rsi, Context::NATIVE_CONTEXT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001706}
1707
1708
1709// Provides access to exit frame stack space (not GCed).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001710inline Operand StackSpaceOperand(int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001711#ifdef _WIN64
1712 const int kShaddowSpace = 4;
1713 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1714#else
1715 return Operand(rsp, index * kPointerSize);
1716#endif
1717}
1718
1719
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001720inline Operand StackOperandForReturnAddress(int32_t disp) {
1721 return Operand(rsp, disp);
1722}
1723
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001724
Steve Blocka7e24c12009-10-30 11:49:00 +00001725#ifdef GENERATED_CODE_COVERAGE
1726extern void LogGeneratedCodeCoverage(const char* file_line);
1727#define CODE_COVERAGE_STRINGIFY(x) #x
1728#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1729#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001730#define ACCESS_MASM(masm) { \
1731 Address x64_coverage_function = FUNCTION_ADDR(LogGeneratedCodeCoverage); \
1732 masm->pushfq(); \
1733 masm->Pushad(); \
1734 masm->Push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
1735 masm->Call(x64_coverage_function, RelocInfo::EXTERNAL_REFERENCE); \
1736 masm->Pop(rax); \
1737 masm->Popad(); \
1738 masm->popfq(); \
1739 } \
Steve Blocka7e24c12009-10-30 11:49:00 +00001740 masm->
1741#else
1742#define ACCESS_MASM(masm) masm->
1743#endif
1744
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001745} // namespace internal
1746} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001747
1748#endif // V8_X64_MACRO_ASSEMBLER_X64_H_