blob: 716a591f2e4079cd75b8627e0556c30d2923a3d9 [file] [log] [blame]
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001// Copyright 2012 the V8 project authors. All rights reserved.
ager@chromium.org5ec48922009-05-05 07:25:34 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
ager@chromium.org9085a012009-05-11 19:22:57 +000028#ifndef V8_X64_MACRO_ASSEMBLER_X64_H_
29#define V8_X64_MACRO_ASSEMBLER_X64_H_
30
31#include "assembler.h"
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000032#include "frames.h"
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000033#include "v8globals.h"
ager@chromium.org9085a012009-05-11 19:22:57 +000034
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
ager@chromium.org9085a012009-05-11 19:22:57 +000037
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +000038// Flags used for the AllocateInNewSpace functions.
39enum AllocationFlags {
40 // No special flags.
41 NO_ALLOCATION_FLAGS = 0,
42 // Return the pointer to the allocated already tagged as a heap object.
43 TAG_OBJECT = 1 << 0,
44 // The content of the result register already contains the allocation top in
45 // new space.
46 RESULT_CONTAINS_TOP = 1 << 1
47};
48
ager@chromium.orgea91cc52011-05-23 06:06:11 +000049
ager@chromium.orge2902be2009-06-08 12:21:35 +000050// Default scratch register used by MacroAssembler (and other code that needs
51// a spare register). The register isn't callee save, and not used by the
52// function calling convention.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +000053const Register kScratchRegister = { 10 }; // r10.
54const Register kSmiConstantRegister = { 12 }; // r12 (callee save).
55const Register kRootRegister = { 13 }; // r13 (callee save).
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000056// Value of smi in kSmiConstantRegister.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +000057const int kSmiConstantRegisterValue = 1;
karlklose@chromium.org8f806e82011-03-07 14:06:08 +000058// Actual value of root register is offset from the root array's start
59// to take advantage of negitive 8-bit displacement values.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +000060const int kRootRegisterBias = 128;
ager@chromium.orge2902be2009-06-08 12:21:35 +000061
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000062// Convenience for platform-independent signatures.
63typedef Operand MemOperand;
64
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000065enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
66enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
67
68bool AreAliased(Register r1, Register r2, Register r3, Register r4);
69
ager@chromium.org9085a012009-05-11 19:22:57 +000070// Forward declaration.
71class JumpTarget;
72
ager@chromium.org4af710e2009-09-15 12:20:11 +000073struct SmiIndex {
74 SmiIndex(Register index_register, ScaleFactor scale)
75 : reg(index_register),
76 scale(scale) {}
77 Register reg;
78 ScaleFactor scale;
79};
ager@chromium.org9085a012009-05-11 19:22:57 +000080
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000081
ager@chromium.org9085a012009-05-11 19:22:57 +000082// MacroAssembler implements a collection of frequently used macros.
83class MacroAssembler: public Assembler {
84 public:
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +000085 // The isolate parameter can be NULL if the macro assembler should
86 // not use isolate-dependent functionality. In this case, it's the
87 // responsibility of the caller to never invoke such function on the
88 // macro assembler.
89 MacroAssembler(Isolate* isolate, void* buffer, int size);
ager@chromium.org9085a012009-05-11 19:22:57 +000090
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000091 // 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);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000130 // Pushes the address of the external reference onto the stack.
131 void PushAddress(ExternalReference source);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000132
133 // Operations on roots in the root-array.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000134 void LoadRoot(Register destination, Heap::RootListIndex index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000135 void StoreRoot(Register source, Heap::RootListIndex index);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000136 // Load a root value where the index (or part of it) is variable.
137 // The variable_offset register is added to the fixed_offset value
138 // to get the index into the root-array.
139 void LoadRootIndexed(Register destination,
140 Register variable_offset,
141 int fixed_offset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000142 void CompareRoot(Register with, Heap::RootListIndex index);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000143 void CompareRoot(const Operand& with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000144 void PushRoot(Heap::RootListIndex index);
145
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000146 // These functions do not arrange the registers in any particular order so
147 // they are not useful for calls that can cause a GC. The caller can
148 // exclude up to 3 registers that do not need to be saved and restored.
149 void PushCallerSaved(SaveFPRegsMode fp_mode,
150 Register exclusion1 = no_reg,
151 Register exclusion2 = no_reg,
152 Register exclusion3 = no_reg);
153 void PopCallerSaved(SaveFPRegsMode fp_mode,
154 Register exclusion1 = no_reg,
155 Register exclusion2 = no_reg,
156 Register exclusion3 = no_reg);
ager@chromium.org9085a012009-05-11 19:22:57 +0000157
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000158// ---------------------------------------------------------------------------
159// GC Support
ager@chromium.orgac091b72010-05-05 07:34:42 +0000160
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000161
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000162 enum RememberedSetFinalAction {
163 kReturnAtEnd,
164 kFallThroughAtEnd
165 };
166
167 // Record in the remembered set the fact that we have a pointer to new space
168 // at the address pointed to by the addr register. Only works if addr is not
169 // in new space.
170 void RememberedSetHelper(Register object, // Used for debug code.
171 Register addr,
172 Register scratch,
173 SaveFPRegsMode save_fp,
174 RememberedSetFinalAction and_then);
175
176 void CheckPageFlag(Register object,
177 Register scratch,
178 int mask,
179 Condition cc,
180 Label* condition_met,
181 Label::Distance condition_met_distance = Label::kFar);
182
183 // Check if object is in new space. Jumps if the object is not in new space.
184 // The register scratch can be object itself, but scratch will be clobbered.
185 void JumpIfNotInNewSpace(Register object,
186 Register scratch,
187 Label* branch,
188 Label::Distance distance = Label::kFar) {
189 InNewSpace(object, scratch, not_equal, branch, distance);
190 }
191
192 // Check if object is in new space. Jumps if the object is in new space.
193 // The register scratch can be object itself, but it will be clobbered.
194 void JumpIfInNewSpace(Register object,
195 Register scratch,
196 Label* branch,
197 Label::Distance distance = Label::kFar) {
198 InNewSpace(object, scratch, equal, branch, distance);
199 }
200
201 // Check if an object has the black incremental marking color. Also uses rcx!
202 void JumpIfBlack(Register object,
203 Register scratch0,
204 Register scratch1,
205 Label* on_black,
206 Label::Distance on_black_distance = Label::kFar);
207
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000208 // Detects conservatively whether an object is data-only, i.e. it does need to
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000209 // be scanned by the garbage collector.
210 void JumpIfDataObject(Register value,
211 Register scratch,
212 Label* not_data_object,
213 Label::Distance not_data_object_distance);
214
215 // Checks the color of an object. If the object is already grey or black
216 // then we just fall through, since it is already live. If it is white and
217 // we can determine that it doesn't need to be scanned, then we just mark it
218 // black and fall through. For the rest we jump to the label so the
219 // incremental marker can fix its assumptions.
220 void EnsureNotWhite(Register object,
221 Register scratch1,
222 Register scratch2,
223 Label* object_is_white_and_not_data,
224 Label::Distance distance);
225
226 // Notify the garbage collector that we wrote a pointer into an object.
227 // |object| is the object being stored into, |value| is the object being
228 // stored. value and scratch registers are clobbered by the operation.
229 // The offset is the offset from the start of the object, not the offset from
230 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
231 void RecordWriteField(
232 Register object,
233 int offset,
234 Register value,
235 Register scratch,
236 SaveFPRegsMode save_fp,
237 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
238 SmiCheck smi_check = INLINE_SMI_CHECK);
239
240 // As above, but the offset has the tag presubtracted. For use with
241 // Operand(reg, off).
242 void RecordWriteContextSlot(
243 Register context,
244 int offset,
245 Register value,
246 Register scratch,
247 SaveFPRegsMode save_fp,
248 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
249 SmiCheck smi_check = INLINE_SMI_CHECK) {
250 RecordWriteField(context,
251 offset + kHeapObjectTag,
252 value,
253 scratch,
254 save_fp,
255 remembered_set_action,
256 smi_check);
257 }
258
259 // Notify the garbage collector that we wrote a pointer into a fixed array.
260 // |array| is the array being stored into, |value| is the
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000261 // object being stored. |index| is the array index represented as a non-smi.
262 // All registers are clobbered by the operation RecordWriteArray
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000263 // filters out smis so it does not update the write barrier if the
264 // value is a smi.
265 void RecordWriteArray(
266 Register array,
267 Register value,
268 Register index,
269 SaveFPRegsMode save_fp,
270 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
271 SmiCheck smi_check = INLINE_SMI_CHECK);
272
273 // For page containing |object| mark region covering |address|
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000274 // dirty. |object| is the object being stored into, |value| is the
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000275 // object being stored. The address and value registers are clobbered by the
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000276 // operation. RecordWrite filters out smis so it does not update
277 // the write barrier if the value is a smi.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000278 void RecordWrite(
279 Register object,
280 Register address,
281 Register value,
282 SaveFPRegsMode save_fp,
283 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
284 SmiCheck smi_check = INLINE_SMI_CHECK);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000285
ager@chromium.org9085a012009-05-11 19:22:57 +0000286#ifdef ENABLE_DEBUGGER_SUPPORT
287 // ---------------------------------------------------------------------------
288 // Debugger Support
289
ager@chromium.org5c838252010-02-19 08:53:10 +0000290 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000291#endif
292
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000293 // Enter specific kind of exit frame; either in normal or
294 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000295 // sets up the number of arguments in register rdi and the pointer
296 // to the first argument in register rsi.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000297 //
298 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
299 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000300 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000301
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000302 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
303 // memory (not GCed) on the stack accessible via StackSpaceOperand.
304 void EnterApiExitFrame(int arg_stack_space);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000305
ager@chromium.orga1645e22009-09-09 19:27:10 +0000306 // Leave the current exit frame. Expects/provides the return value in
307 // register rax:rdx (untouched) and the pointer to the first
308 // argument in register rsi.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000309 void LeaveExitFrame(bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000310
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000311 // Leave the current exit frame. Expects/provides the return value in
312 // register rax (untouched).
313 void LeaveApiExitFrame();
ager@chromium.org9085a012009-05-11 19:22:57 +0000314
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000315 // Push and pop the registers that can hold pointers.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000316 void PushSafepointRegisters() { Pushad(); }
317 void PopSafepointRegisters() { Popad(); }
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000318 // Store the value in register src in the safepoint register stack
319 // slot for register dst.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000320 void StoreToSafepointRegisterSlot(Register dst, const Immediate& imm);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000321 void StoreToSafepointRegisterSlot(Register dst, Register src);
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +0000322 void LoadFromSafepointRegisterSlot(Register dst, Register src);
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000323
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000324 void InitializeRootRegister() {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000325 ExternalReference roots_array_start =
326 ExternalReference::roots_array_start(isolate());
327 movq(kRootRegister, roots_array_start);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000328 addq(kRootRegister, Immediate(kRootRegisterBias));
329 }
330
ager@chromium.org9085a012009-05-11 19:22:57 +0000331 // ---------------------------------------------------------------------------
332 // JavaScript invokes
333
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000334 // Set up call kind marking in rcx. The method takes rcx as an
danno@chromium.org40cb8782011-05-25 07:58:50 +0000335 // explicit first parameter to make the code more readable at the
336 // call sites.
337 void SetCallKind(Register dst, CallKind kind);
338
ager@chromium.org9085a012009-05-11 19:22:57 +0000339 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000340 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000341 const ParameterCount& expected,
342 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000343 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000344 const CallWrapper& call_wrapper,
345 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000346
347 void InvokeCode(Handle<Code> code,
348 const ParameterCount& expected,
349 const ParameterCount& actual,
350 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000351 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000352 const CallWrapper& call_wrapper,
353 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000354
355 // Invoke the JavaScript function in the given register. Changes the
356 // current context to the context in the function before invoking.
357 void InvokeFunction(Register function,
358 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000359 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000360 const CallWrapper& call_wrapper,
361 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000362
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000363 void InvokeFunction(Handle<JSFunction> function,
ager@chromium.org5c838252010-02-19 08:53:10 +0000364 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000365 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000366 const CallWrapper& call_wrapper,
367 CallKind call_kind);
ager@chromium.org5c838252010-02-19 08:53:10 +0000368
ager@chromium.org9085a012009-05-11 19:22:57 +0000369 // Invoke specified builtin JavaScript function. Adds an entry to
370 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000371 void InvokeBuiltin(Builtins::JavaScript id,
372 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000373 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000374
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000375 // Store the function for the given builtin in the target register.
376 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
377
ager@chromium.org9085a012009-05-11 19:22:57 +0000378 // Store the code object for the given builtin in the target register.
379 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
380
ager@chromium.org4af710e2009-09-15 12:20:11 +0000381
382 // ---------------------------------------------------------------------------
383 // Smi tagging, untagging and operations on tagged smis.
384
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000385 void InitializeSmiConstantRegister() {
386 movq(kSmiConstantRegister,
387 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
388 RelocInfo::NONE);
389 }
390
ager@chromium.org4af710e2009-09-15 12:20:11 +0000391 // Conversions between tagged smi values and non-tagged integer values.
392
393 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000394 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000395 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000396 void Integer32ToSmi(Register dst, Register src);
397
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000398 // Stores an integer32 value into a memory field that already holds a smi.
399 void Integer32ToSmiField(const Operand& dst, Register src);
400
ager@chromium.org4af710e2009-09-15 12:20:11 +0000401 // Adds constant to src and tags the result as a smi.
402 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000403 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000404
405 // Convert smi to 32-bit integer. I.e., not sign extended into
406 // high 32 bits of destination.
407 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000408 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000409
410 // Convert smi to 64-bit integer (sign extended if necessary).
411 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000412 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000413
414 // Multiply a positive smi's integer value by a power of two.
415 // Provides result as 64-bit integer value.
416 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
417 Register src,
418 int power);
419
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000420 // Divide a positive smi's integer value by a power of two.
421 // Provides result as 32-bit integer value.
422 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
423 Register src,
424 int power);
425
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000426 // Perform the logical or of two smi values and return a smi value.
427 // If either argument is not a smi, jump to on_not_smis and retain
428 // the original values of source registers. The destination register
429 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000430 void SmiOrIfSmis(Register dst,
431 Register src1,
432 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000433 Label* on_not_smis,
434 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000435
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000436
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000437 // Simple comparison of smis. Both sides must be known smis to use these,
438 // otherwise use Cmp.
439 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000440 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000441 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000442 void SmiCompare(const Operand& dst, Register src);
443 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000444 // Compare the int32 in src register to the value of the smi stored at dst.
445 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000446 // Sets sign and zero flags depending on value of smi in register.
447 void SmiTest(Register src);
448
ager@chromium.org4af710e2009-09-15 12:20:11 +0000449 // Functions performing a check on a known or potential smi. Returns
450 // a condition that is satisfied if the check is successful.
451
452 // Is the value a tagged smi.
453 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000454 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000455
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000456 // Is the value a non-negative tagged smi.
457 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000458
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000459 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000460 Condition CheckBothSmi(Register first, Register second);
461
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000462 // Are both values non-negative tagged smis.
463 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000464
465 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000466 Condition CheckEitherSmi(Register first,
467 Register second,
468 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000469
ager@chromium.org4af710e2009-09-15 12:20:11 +0000470 // Is the value the minimum smi value (since we are using
471 // two's complement numbers, negating the value is known to yield
472 // a non-smi value).
473 Condition CheckIsMinSmi(Register src);
474
ager@chromium.org4af710e2009-09-15 12:20:11 +0000475 // Checks whether an 32-bit integer value is a valid for conversion
476 // to a smi.
477 Condition CheckInteger32ValidSmiValue(Register src);
478
ager@chromium.org3811b432009-10-28 14:53:37 +0000479 // Checks whether an 32-bit unsigned integer value is a valid for
480 // conversion to a smi.
481 Condition CheckUInteger32ValidSmiValue(Register src);
482
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000483 // Check whether src is a Smi, and set dst to zero if it is a smi,
484 // and to one if it isn't.
485 void CheckSmiToIndicator(Register dst, Register src);
486 void CheckSmiToIndicator(Register dst, const Operand& src);
487
ager@chromium.org4af710e2009-09-15 12:20:11 +0000488 // Test-and-jump functions. Typically combines a check function
489 // above with a conditional jump.
490
491 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000492 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
493 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000494
ager@chromium.org3811b432009-10-28 14:53:37 +0000495 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000496 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
497 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000498
ager@chromium.org4af710e2009-09-15 12:20:11 +0000499 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000500 void JumpIfSmi(Register src,
501 Label* on_smi,
502 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000503
504 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000505 void JumpIfNotSmi(Register src,
506 Label* on_not_smi,
507 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000508
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000509 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000510 void JumpUnlessNonNegativeSmi(Register src,
511 Label* on_not_smi,
512 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000513
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000514 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000515 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000516 void JumpIfSmiEqualsConstant(Register src,
517 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000518 Label* on_equals,
519 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000520
ager@chromium.org4af710e2009-09-15 12:20:11 +0000521 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000522 void JumpIfNotBothSmi(Register src1,
523 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000524 Label* on_not_both_smi,
525 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000526
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000527 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000528 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000529 Label* on_not_both_smi,
530 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000531
ager@chromium.org4af710e2009-09-15 12:20:11 +0000532 // Operations on tagged smi values.
533
534 // Smis represent a subset of integers. The subset is always equivalent to
535 // a two's complement interpretation of a fixed number of bits.
536
537 // Optimistically adds an integer constant to a supposed smi.
538 // If the src is not a smi, or the result is not a smi, jump to
539 // the label.
540 void SmiTryAddConstant(Register dst,
541 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000542 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000543 Label* on_not_smi_result,
544 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000545
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000546 // Add an integer constant to a tagged smi, giving a tagged smi as result.
547 // No overflow testing on the result is done.
548 void SmiAddConstant(Register dst, Register src, Smi* constant);
549
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000550 // Add an integer constant to a tagged smi, giving a tagged smi as result.
551 // No overflow testing on the result is done.
552 void SmiAddConstant(const Operand& dst, Smi* constant);
553
ager@chromium.org4af710e2009-09-15 12:20:11 +0000554 // Add an integer constant to a tagged smi, giving a tagged smi as result,
555 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000556 void SmiAddConstant(Register dst,
557 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000558 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000559 Label* on_not_smi_result,
560 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000561
562 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000563 // result. No testing on the result is done. Sets the N and Z flags
564 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000565 void SmiSubConstant(Register dst, Register src, Smi* constant);
566
567 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000568 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000569 void SmiSubConstant(Register dst,
570 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000571 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000572 Label* on_not_smi_result,
573 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000574
575 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000576 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000577 void SmiNeg(Register dst,
578 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000579 Label* on_smi_result,
580 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000581
582 // Adds smi values and return the result as a smi.
583 // If dst is src1, then src1 will be destroyed, even if
584 // the operation is unsuccessful.
585 void SmiAdd(Register dst,
586 Register src1,
587 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000588 Label* on_not_smi_result,
589 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000590 void SmiAdd(Register dst,
591 Register src1,
592 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000593 Label* on_not_smi_result,
594 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000595
596 void SmiAdd(Register dst,
597 Register src1,
598 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000599
600 // Subtracts smi values and return the result as a smi.
601 // If dst is src1, then src1 will be destroyed, even if
602 // the operation is unsuccessful.
603 void SmiSub(Register dst,
604 Register src1,
605 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000606 Label* on_not_smi_result,
607 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000608
ager@chromium.orgac091b72010-05-05 07:34:42 +0000609 void SmiSub(Register dst,
610 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000611 Register src2);
612
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000613 void SmiSub(Register dst,
614 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000615 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000616 Label* on_not_smi_result,
617 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000618
619 void SmiSub(Register dst,
620 Register src1,
621 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000622
ager@chromium.org4af710e2009-09-15 12:20:11 +0000623 // Multiplies smi values and return the result as a smi,
624 // if possible.
625 // If dst is src1, then src1 will be destroyed, even if
626 // the operation is unsuccessful.
627 void SmiMul(Register dst,
628 Register src1,
629 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000630 Label* on_not_smi_result,
631 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000632
633 // Divides one smi by another and returns the quotient.
634 // Clobbers rax and rdx registers.
635 void SmiDiv(Register dst,
636 Register src1,
637 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000638 Label* on_not_smi_result,
639 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000640
641 // Divides one smi by another and returns the remainder.
642 // Clobbers rax and rdx registers.
643 void SmiMod(Register dst,
644 Register src1,
645 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000646 Label* on_not_smi_result,
647 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000648
649 // Bitwise operations.
650 void SmiNot(Register dst, Register src);
651 void SmiAnd(Register dst, Register src1, Register src2);
652 void SmiOr(Register dst, Register src1, Register src2);
653 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000654 void SmiAndConstant(Register dst, Register src1, Smi* constant);
655 void SmiOrConstant(Register dst, Register src1, Smi* constant);
656 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000657
658 void SmiShiftLeftConstant(Register dst,
659 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000660 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000661 void SmiShiftLogicalRightConstant(Register dst,
662 Register src,
663 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000664 Label* on_not_smi_result,
665 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000666 void SmiShiftArithmeticRightConstant(Register dst,
667 Register src,
668 int shift_value);
669
670 // Shifts a smi value to the left, and returns the result if that is a smi.
671 // Uses and clobbers rcx, so dst may not be rcx.
672 void SmiShiftLeft(Register dst,
673 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000674 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000675 // Shifts a smi value to the right, shifting in zero bits at the top, and
676 // returns the unsigned intepretation of the result if that is a smi.
677 // Uses and clobbers rcx, so dst may not be rcx.
678 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000679 Register src1,
680 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000681 Label* on_not_smi_result,
682 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000683 // Shifts a smi value to the right, sign extending the top, and
684 // returns the signed intepretation of the result. That will always
685 // be a valid smi value, since it's numerically smaller than the
686 // original.
687 // Uses and clobbers rcx, so dst may not be rcx.
688 void SmiShiftArithmeticRight(Register dst,
689 Register src1,
690 Register src2);
691
692 // Specialized operations
693
694 // Select the non-smi register of two registers where exactly one is a
695 // smi. If neither are smis, jump to the failure label.
696 void SelectNonSmi(Register dst,
697 Register src1,
698 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000699 Label* on_not_smis,
700 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000701
702 // Converts, if necessary, a smi to a combination of number and
703 // multiplier to be used as a scaled index.
704 // The src register contains a *positive* smi value. The shift is the
705 // power of two to multiply the index value by (e.g.
706 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
707 // The returned index register may be either src or dst, depending
708 // on what is most efficient. If src and dst are different registers,
709 // src is always unchanged.
710 SmiIndex SmiToIndex(Register dst, Register src, int shift);
711
712 // Converts a positive smi to a negative index.
713 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
714
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000715 // Add the value of a smi in memory to an int32 register.
716 // Sets flags as a normal add.
717 void AddSmiField(Register dst, const Operand& src);
718
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000719 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000720 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000721 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000722 }
723
724 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000725 Register constant = GetSmiConstant(source);
726 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000727 }
728
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000729 void Push(Smi* smi);
730 void Test(const Operand& dst, Smi* source);
731
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000732
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000733 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000734 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000735
736 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000737 void JumpIfNotString(Register object,
738 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000739 Label* not_string,
740 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000741
742
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000743 void JumpIfNotBothSequentialAsciiStrings(
744 Register first_object,
745 Register second_object,
746 Register scratch1,
747 Register scratch2,
748 Label* on_not_both_flat_ascii,
749 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000750
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000751 // Check whether the instance type represents a flat ASCII string. Jump to the
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000752 // label if not. If the instance type can be scratched specify same register
753 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000754 void JumpIfInstanceTypeIsNotSequentialAscii(
755 Register instance_type,
756 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000757 Label*on_not_flat_ascii_string,
758 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000759
760 void JumpIfBothInstanceTypesAreNotSequentialAscii(
761 Register first_object_instance_type,
762 Register second_object_instance_type,
763 Register scratch1,
764 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000765 Label* on_fail,
766 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000767
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000768 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000769 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000770
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000771 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000772 void Set(Register dst, int64_t x);
773 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000774
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000775 // Move if the registers are not identical.
776 void Move(Register target, Register source);
777
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +0000778 // Support for constant splitting.
779 bool IsUnsafeInt(const int x);
780 void SafeMove(Register dst, Smi* src);
781 void SafePush(Smi* src);
782
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000783 // Bit-field support.
784 void TestBit(const Operand& dst, int bit_index);
785
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000786 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000787 void Move(Register dst, Handle<Object> source);
788 void Move(const Operand& dst, Handle<Object> source);
789 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000790 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000791 void Cmp(Register dst, Smi* src);
792 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000793 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000794
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000795 // Load a heap object and handle the case of new-space objects by
796 // indirecting via a global cell.
797 void LoadHeapObject(Register result, Handle<HeapObject> object);
798 void PushHeapObject(Handle<HeapObject> object);
799
danno@chromium.orgbf0c8202011-12-27 10:09:42 +0000800 void LoadObject(Register result, Handle<Object> object) {
801 if (object->IsHeapObject()) {
802 LoadHeapObject(result, Handle<HeapObject>::cast(object));
803 } else {
804 Move(result, object);
805 }
806 }
807
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000808 // Load a global cell into a register.
809 void LoadGlobalCell(Register dst, Handle<JSGlobalPropertyCell> cell);
810
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000811 // Emit code to discard a non-negative number of pointer-sized elements
812 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000813 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000814
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000815 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000816
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000817 // Control Flow
818 void Jump(Address destination, RelocInfo::Mode rmode);
819 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000820 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
821
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000822 void Call(Address destination, RelocInfo::Mode rmode);
823 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000824 void Call(Handle<Code> code_object,
825 RelocInfo::Mode rmode,
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000826 TypeFeedbackId ast_id = TypeFeedbackId::None());
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000827
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000828 // The size of the code generated for different call instructions.
829 int CallSize(Address destination, RelocInfo::Mode rmode) {
830 return kCallInstructionLength;
831 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000832 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000833 int CallSize(Handle<Code> code_object) {
834 // Code calls use 32-bit relative addressing.
835 return kShortCallInstructionLength;
836 }
837 int CallSize(Register target) {
838 // Opcode: REX_opt FF /2 m64
839 return (target.high_bit() != 0) ? 3 : 2;
840 }
841 int CallSize(const Operand& target) {
842 // Opcode: REX_opt FF /2 m64
843 return (target.requires_rex() ? 2 : 1) + target.operand_size();
844 }
845
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000846 // Emit call to the code we are currently generating.
847 void CallSelf() {
848 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
849 Call(self, RelocInfo::CODE_TARGET);
850 }
851
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000852 // Non-x64 instructions.
853 // Push/pop all general purpose registers.
854 // Does not push rsp/rbp nor any of the assembler's special purpose registers
855 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
856 void Pushad();
857 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000858 // Sets the stack as after performing Popad, without actually loading the
859 // registers.
860 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000861
ager@chromium.org9085a012009-05-11 19:22:57 +0000862 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000863 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000864 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000865 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000866 void CmpObjectType(Register heap_object, InstanceType type, Register map);
867
868 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000869 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000870 void CmpInstanceType(Register map, InstanceType type);
871
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000872 // Check if a map for a JSObject indicates that the object has fast elements.
873 // Jump to the specified label if it does not.
874 void CheckFastElements(Register map,
875 Label* fail,
876 Label::Distance distance = Label::kFar);
877
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000878 // Check if a map for a JSObject indicates that the object can have both smi
879 // and HeapObject elements. Jump to the specified label if it does not.
880 void CheckFastObjectElements(Register map,
881 Label* fail,
882 Label::Distance distance = Label::kFar);
883
884 // Check if a map for a JSObject indicates that the object has fast smi only
885 // elements. Jump to the specified label if it does not.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000886 void CheckFastSmiElements(Register map,
887 Label* fail,
888 Label::Distance distance = Label::kFar);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000889
890 // Check to see if maybe_number can be stored as a double in
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000891 // FastDoubleElements. If it can, store it at the index specified by index in
892 // the FastDoubleElements array elements, otherwise jump to fail. Note that
893 // index must not be smi-tagged.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000894 void StoreNumberToDoubleElements(Register maybe_number,
895 Register elements,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000896 Register index,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000897 XMMRegister xmm_scratch,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000898 Label* fail,
899 int elements_offset = 0);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000900
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000901 // Compare an object's map with the specified map and its transitioned
902 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. FLAGS are set with
903 // result of map compare. If multiple map compares are required, the compare
904 // sequences branches to early_success.
905 void CompareMap(Register obj,
906 Handle<Map> map,
907 Label* early_success,
908 CompareMapMode mode = REQUIRE_EXACT_MAP);
909
910 // Check if the map of an object is equal to a specified map and branch to
911 // label if not. Skip the smi check if not required (object is known to be a
912 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000913 // against maps that are ElementsKind transition maps of the specified map.
ager@chromium.org5c838252010-02-19 08:53:10 +0000914 void CheckMap(Register obj,
915 Handle<Map> map,
916 Label* fail,
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000917 SmiCheckType smi_check_type,
918 CompareMapMode mode = REQUIRE_EXACT_MAP);
ager@chromium.org5c838252010-02-19 08:53:10 +0000919
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000920 // Check if the map of an object is equal to a specified map and branch to a
921 // specified target if equal. Skip the smi check if not required (object is
922 // known to be a heap object)
923 void DispatchMap(Register obj,
924 Handle<Map> map,
925 Handle<Code> success,
926 SmiCheckType smi_check_type);
927
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000928 // Check if the object in register heap_object is a string. Afterwards the
929 // register map contains the object map and the register instance_type
930 // contains the instance_type. The registers map and instance_type can be the
931 // same in which case it contains the instance type afterwards. Either of the
932 // registers map and instance_type can be the same as heap_object.
933 Condition IsObjectStringType(Register heap_object,
934 Register map,
935 Register instance_type);
936
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000937 // FCmp compares and pops the two values on top of the FPU stack.
938 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000939 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
940 void FCmp();
941
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000942 void ClampUint8(Register reg);
943
944 void ClampDoubleToUint8(XMMRegister input_reg,
945 XMMRegister temp_xmm_reg,
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000946 Register result_reg);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000947
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000948 void LoadUint32(XMMRegister dst, Register src, XMMRegister scratch);
949
danno@chromium.org40cb8782011-05-25 07:58:50 +0000950 void LoadInstanceDescriptors(Register map, Register descriptors);
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000951 void EnumLength(Register dst, Register map);
verwaest@chromium.org06ab2ec2012-10-09 17:00:13 +0000952 void NumberOfOwnDescriptors(Register dst, Register map);
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000953
954 template<typename Field>
955 void DecodeField(Register reg) {
verwaest@chromium.org06ab2ec2012-10-09 17:00:13 +0000956 static const int shift = Field::kShift + kSmiShift;
957 static const int mask = Field::kMask >> Field::kShift;
958 shr(reg, Immediate(shift));
959 and_(reg, Immediate(mask));
960 shl(reg, Immediate(kSmiShift));
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000961 }
danno@chromium.org40cb8782011-05-25 07:58:50 +0000962
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000963 // Abort execution if argument is not a number, enabled via --debug-code.
964 void AssertNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000965
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000966 // Abort execution if argument is a smi, enabled via --debug-code.
967 void AssertNotSmi(Register object);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000968
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000969 // Abort execution if argument is not a smi, enabled via --debug-code.
970 void AssertSmi(Register object);
971 void AssertSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000972
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000973 // Abort execution if a 64 bit register containing a 32 bit payload does not
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000974 // have zeros in the top 32 bits, enabled via --debug-code.
975 void AssertZeroExtended(Register reg);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000976
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000977 // Abort execution if argument is not a string, enabled via --debug-code.
978 void AssertString(Register object);
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000979
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +0000980 // Abort execution if argument is not the root value with the given index,
981 // enabled via --debug-code.
982 void AssertRootValue(Register src,
983 Heap::RootListIndex root_value_index,
984 const char* message);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000985
ager@chromium.org9085a012009-05-11 19:22:57 +0000986 // ---------------------------------------------------------------------------
987 // Exception handling
988
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000989 // Push a new try handler and link it into try handler chain.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000990 void PushTryHandler(StackHandler::Kind kind, int handler_index);
ager@chromium.org9085a012009-05-11 19:22:57 +0000991
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000992 // Unlink the stack handler on top of the stack from the try handler chain.
993 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000994
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000995 // Activate the top handler in the try hander chain and pass the
996 // thrown value.
997 void Throw(Register value);
998
999 // Propagate an uncatchable exception out of the current JS stack.
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001000 void ThrowUncatchable(Register value);
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001001
ager@chromium.org9085a012009-05-11 19:22:57 +00001002 // ---------------------------------------------------------------------------
1003 // Inline caching support
1004
ager@chromium.org9085a012009-05-11 19:22:57 +00001005 // Generate code for checking access rights - used for security checks
1006 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001007 // is left untouched, but the scratch register and kScratchRegister,
1008 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +00001009 void CheckAccessGlobalProxy(Register holder_reg,
1010 Register scratch,
1011 Label* miss);
1012
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001013 void GetNumberHash(Register r0, Register scratch);
ager@chromium.org9085a012009-05-11 19:22:57 +00001014
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00001015 void LoadFromNumberDictionary(Label* miss,
1016 Register elements,
1017 Register key,
1018 Register r0,
1019 Register r1,
1020 Register r2,
1021 Register result);
1022
1023
ager@chromium.org9085a012009-05-11 19:22:57 +00001024 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001025 // Allocation support
1026
1027 // Allocate an object in new space. If the new space is exhausted control
1028 // continues at the gc_required label. The allocated object is returned in
1029 // result and end of the new object is returned in result_end. The register
1030 // scratch can be passed as no_reg in which case an additional object
1031 // reference will be added to the reloc info. The returned pointers in result
1032 // and result_end have not yet been tagged as heap objects. If
1033 // result_contains_top_on_entry is true the content of result is known to be
1034 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001035 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001036 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001037 void AllocateInNewSpace(int object_size,
1038 Register result,
1039 Register result_end,
1040 Register scratch,
1041 Label* gc_required,
1042 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001043
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001044 void AllocateInNewSpace(int header_size,
1045 ScaleFactor element_size,
1046 Register element_count,
1047 Register result,
1048 Register result_end,
1049 Register scratch,
1050 Label* gc_required,
1051 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001052
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001053 void AllocateInNewSpace(Register object_size,
1054 Register result,
1055 Register result_end,
1056 Register scratch,
1057 Label* gc_required,
1058 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001059
1060 // Undo allocation in new space. The object passed and objects allocated after
1061 // it will no longer be allocated. Make sure that no pointers are left to the
1062 // object(s) no longer allocated as they would be invalid when allocation is
1063 // un-done.
1064 void UndoAllocationInNewSpace(Register object);
1065
ager@chromium.org3811b432009-10-28 14:53:37 +00001066 // Allocate a heap number in new space with undefined value. Returns
1067 // tagged pointer in result register, or jumps to gc_required if new
1068 // space is full.
1069 void AllocateHeapNumber(Register result,
1070 Register scratch,
1071 Label* gc_required);
1072
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001073 // Allocate a sequential string. All the header fields of the string object
1074 // are initialized.
1075 void AllocateTwoByteString(Register result,
1076 Register length,
1077 Register scratch1,
1078 Register scratch2,
1079 Register scratch3,
1080 Label* gc_required);
1081 void AllocateAsciiString(Register result,
1082 Register length,
1083 Register scratch1,
1084 Register scratch2,
1085 Register scratch3,
1086 Label* gc_required);
1087
1088 // Allocate a raw cons string object. Only the map field of the result is
1089 // initialized.
fschneider@chromium.org1805e212011-09-05 10:49:12 +00001090 void AllocateTwoByteConsString(Register result,
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001091 Register scratch1,
1092 Register scratch2,
1093 Label* gc_required);
1094 void AllocateAsciiConsString(Register result,
1095 Register scratch1,
1096 Register scratch2,
1097 Label* gc_required);
1098
fschneider@chromium.org1805e212011-09-05 10:49:12 +00001099 // Allocate a raw sliced string object. Only the map field of the result is
1100 // initialized.
1101 void AllocateTwoByteSlicedString(Register result,
1102 Register scratch1,
1103 Register scratch2,
1104 Label* gc_required);
1105 void AllocateAsciiSlicedString(Register result,
1106 Register scratch1,
1107 Register scratch2,
1108 Label* gc_required);
1109
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001110 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +00001111 // Support functions.
1112
1113 // Check if result is zero and op is negative.
1114 void NegativeZeroTest(Register result, Register op, Label* then_label);
1115
1116 // Check if result is zero and op is negative in code using jump targets.
1117 void NegativeZeroTest(CodeGenerator* cgen,
1118 Register result,
1119 Register op,
1120 JumpTarget* then_target);
1121
1122 // Check if result is zero and any of op1 and op2 are negative.
1123 // Register scratch is destroyed, and it must be different from op2.
1124 void NegativeZeroTest(Register result, Register op1, Register op2,
1125 Register scratch, Label* then_label);
1126
1127 // Try to get function prototype of a function and puts the value in
1128 // the result register. Checks that the function really is a
1129 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001130 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +00001131 // clobbered.
1132 void TryGetFunctionPrototype(Register function,
1133 Register result,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001134 Label* miss,
1135 bool miss_on_bound_function = false);
ager@chromium.org9085a012009-05-11 19:22:57 +00001136
1137 // Generates code for reporting that an illegal operation has
1138 // occurred.
1139 void IllegalOperation(int num_arguments);
1140
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001141 // Picks out an array index from the hash field.
1142 // Register use:
1143 // hash - holds the index's hash. Clobbered.
1144 // index - holds the overwritten index on exit.
1145 void IndexFromHash(Register hash, Register index);
1146
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00001147 // Find the function context up the context chain.
1148 void LoadContext(Register dst, int context_chain_length);
1149
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00001150 // Conditionally load the cached Array transitioned map of type
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001151 // transitioned_kind from the native context if the map in register
1152 // map_in_out is the cached Array map in the native context of
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00001153 // expected_kind.
1154 void LoadTransitionedArrayMapConditional(
1155 ElementsKind expected_kind,
1156 ElementsKind transitioned_kind,
1157 Register map_in_out,
1158 Register scratch,
1159 Label* no_map_match);
1160
1161 // Load the initial map for new Arrays from a JSFunction.
1162 void LoadInitialArrayMap(Register function_in,
1163 Register scratch,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001164 Register map_out,
1165 bool can_have_holes);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001166
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001167 // Load the global function with the given index.
1168 void LoadGlobalFunction(int index, Register function);
1169
1170 // Load the initial map from the global function. The registers
1171 // function and map can be the same.
1172 void LoadGlobalFunctionInitialMap(Register function, Register map);
1173
ager@chromium.org9085a012009-05-11 19:22:57 +00001174 // ---------------------------------------------------------------------------
1175 // Runtime calls
1176
1177 // Call a code stub.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001178 void CallStub(CodeStub* stub, TypeFeedbackId ast_id = TypeFeedbackId::None());
ager@chromium.org9085a012009-05-11 19:22:57 +00001179
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001180 // Tail call a code stub (jump).
1181 void TailCallStub(CodeStub* stub);
1182
ager@chromium.org9085a012009-05-11 19:22:57 +00001183 // Return from a code stub after popping its arguments.
1184 void StubReturn(int argc);
1185
1186 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001187 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001188
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001189 // Call a runtime function and save the value of XMM registers.
1190 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
1191
ager@chromium.org9085a012009-05-11 19:22:57 +00001192 // Convenience function: Same as above, but takes the fid instead.
1193 void CallRuntime(Runtime::FunctionId id, int num_arguments);
1194
ager@chromium.org5c838252010-02-19 08:53:10 +00001195 // Convenience function: call an external reference.
1196 void CallExternalReference(const ExternalReference& ext,
1197 int num_arguments);
1198
ager@chromium.org9085a012009-05-11 19:22:57 +00001199 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001200 // Like JumpToExternalReference, but also takes care of passing the number
1201 // of parameters.
1202 void TailCallExternalReference(const ExternalReference& ext,
1203 int num_arguments,
1204 int result_size);
1205
1206 // Convenience function: tail call a runtime routine (jump).
1207 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001208 int num_arguments,
1209 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001210
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001211 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001212 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001213
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001214 // Prepares stack to put arguments (aligns and so on). WIN64 calling
1215 // convention requires to put the pointer to the return value slot into
1216 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
1217 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001218 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1219 void PrepareCallApiFunction(int arg_stack_space);
1220
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001221 // Calls an API function. Allocates HandleScope, extracts returned value
1222 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
1223 // caller-save registers. Restores context. On return removes
1224 // stack_space * kPointerSize (GCed).
1225 void CallApiFunctionAndReturn(Address function_address, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001226
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001227 // Before calling a C-function from generated code, align arguments on stack.
1228 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1229 // etc., not pushed. The argument count assumes all arguments are word sized.
1230 // The number of slots reserved for arguments depends on platform. On Windows
1231 // stack slots are reserved for the arguments passed in registers. On other
1232 // platforms stack slots are only reserved for the arguments actually passed
1233 // on the stack.
1234 void PrepareCallCFunction(int num_arguments);
1235
1236 // Calls a C function and cleans up the space for arguments allocated
1237 // by PrepareCallCFunction. The called function is not allowed to trigger a
1238 // garbage collection, since that might move the code and invalidate the
1239 // return address (unless this is somehow accounted for by the called
1240 // function).
1241 void CallCFunction(ExternalReference function, int num_arguments);
1242 void CallCFunction(Register function, int num_arguments);
1243
1244 // Calculate the number of stack slots to reserve for arguments when calling a
1245 // C function.
1246 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001247
1248 // ---------------------------------------------------------------------------
1249 // Utilities
1250
1251 void Ret();
1252
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001253 // Return and drop arguments from stack, where the number of arguments
1254 // may be bigger than 2^16 - 1. Requires a scratch register.
1255 void Ret(int bytes_dropped, Register scratch);
1256
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001257 Handle<Object> CodeObject() {
1258 ASSERT(!code_object_.is_null());
1259 return code_object_;
1260 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001261
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001262 // Copy length bytes from source to destination.
1263 // Uses scratch register internally (if you have a low-eight register
1264 // free, do use it, otherwise kScratchRegister will be used).
1265 // The min_length is a minimum limit on the value that length will have.
1266 // The algorithm has some special cases that might be omitted if the string
1267 // is known to always be long.
1268 void CopyBytes(Register destination,
1269 Register source,
1270 Register length,
1271 int min_length = 0,
1272 Register scratch = kScratchRegister);
1273
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001274 // Initialize fields with filler values. Fields starting at |start_offset|
1275 // not including end_offset are overwritten with the value in |filler|. At
1276 // the end the loop, |start_offset| takes the value of |end_offset|.
1277 void InitializeFieldsWithFiller(Register start_offset,
1278 Register end_offset,
1279 Register filler);
1280
ager@chromium.org9085a012009-05-11 19:22:57 +00001281
1282 // ---------------------------------------------------------------------------
1283 // StatsCounter support
1284
1285 void SetCounter(StatsCounter* counter, int value);
1286 void IncrementCounter(StatsCounter* counter, int value);
1287 void DecrementCounter(StatsCounter* counter, int value);
1288
1289
1290 // ---------------------------------------------------------------------------
1291 // Debugging
1292
1293 // Calls Abort(msg) if the condition cc is not satisfied.
1294 // Use --debug_code to enable.
1295 void Assert(Condition cc, const char* msg);
1296
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001297 void AssertFastElements(Register elements);
1298
ager@chromium.org9085a012009-05-11 19:22:57 +00001299 // Like Assert(), but always enabled.
1300 void Check(Condition cc, const char* msg);
1301
1302 // Print a message to stdout and abort execution.
1303 void Abort(const char* msg);
1304
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001305 // Check that the stack is aligned.
1306 void CheckStackAlignment();
1307
ager@chromium.org9085a012009-05-11 19:22:57 +00001308 // Verify restrictions about code generated in stubs.
1309 void set_generating_stub(bool value) { generating_stub_ = value; }
1310 bool generating_stub() { return generating_stub_; }
1311 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1312 bool allow_stub_calls() { return allow_stub_calls_; }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001313 void set_has_frame(bool value) { has_frame_ = value; }
1314 bool has_frame() { return has_frame_; }
1315 inline bool AllowThisStubCall(CodeStub* stub);
ager@chromium.org9085a012009-05-11 19:22:57 +00001316
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001317 static int SafepointRegisterStackIndex(Register reg) {
1318 return SafepointRegisterStackIndex(reg.code());
1319 }
1320
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001321 // Activation support.
1322 void EnterFrame(StackFrame::Type type);
1323 void LeaveFrame(StackFrame::Type type);
1324
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00001325 // Expects object in rax and returns map with validated enum cache
1326 // in rax. Assumes that any other register can be used as a scratch.
1327 void CheckEnumCache(Register null_value,
1328 Label* call_runtime);
1329
ager@chromium.org9085a012009-05-11 19:22:57 +00001330 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001331 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001332 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001333 static const int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001334 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001335 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001336
ager@chromium.org9085a012009-05-11 19:22:57 +00001337 bool generating_stub_;
1338 bool allow_stub_calls_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001339 bool has_frame_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001340 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001341
1342 // Returns a register holding the smi value. The register MUST NOT be
1343 // modified. It may be the "smi 1 constant" register.
1344 Register GetSmiConstant(Smi* value);
1345
jkummerow@chromium.org000f7fb2012-08-01 11:14:42 +00001346 intptr_t RootRegisterDelta(ExternalReference other);
1347
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001348 // Moves the smi value to the destination register.
1349 void LoadSmiConstant(Register dst, Smi* value);
1350
ager@chromium.org5c838252010-02-19 08:53:10 +00001351 // This handle will be patched with the code object on installation.
1352 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001353
1354 // Helper functions for generating invokes.
1355 void InvokePrologue(const ParameterCount& expected,
1356 const ParameterCount& actual,
1357 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001358 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001359 Label* done,
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001360 bool* definitely_mismatches,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001361 InvokeFlag flag,
danno@chromium.org40cb8782011-05-25 07:58:50 +00001362 Label::Distance near_jump = Label::kFar,
1363 const CallWrapper& call_wrapper = NullCallWrapper(),
1364 CallKind call_kind = CALL_AS_METHOD);
ager@chromium.org9085a012009-05-11 19:22:57 +00001365
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001366 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001367
1368 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1369 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001370 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001371
1372 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001373
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001374 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001375 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001376 // Otherwise the address of the new-space top is loaded into scratch (if
1377 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001378 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001379 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001380 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001381 // Update allocation top with value in result_end register.
1382 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001383 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001384
1385 // Helper for PopHandleScope. Allowed to perform a GC and returns
1386 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1387 // possibly returns a failure object indicating an allocation failure.
1388 Object* PopHandleScopeHelper(Register saved,
1389 Register scratch,
1390 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001391
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001392 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1393 void InNewSpace(Register object,
1394 Register scratch,
1395 Condition cc,
1396 Label* branch,
1397 Label::Distance distance = Label::kFar);
1398
1399 // Helper for finding the mark bits for an address. Afterwards, the
1400 // bitmap register points at the word with the mark bits and the mask
1401 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1402 // unchanged.
1403 inline void GetMarkBits(Register addr_reg,
1404 Register bitmap_reg,
1405 Register mask_reg);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001406
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001407 // Helper for throwing exceptions. Compute a handler address and jump to
1408 // it. See the implementation for register usage.
1409 void JumpToHandlerEntry();
1410
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001411 // Compute memory operands for safepoint stack slots.
1412 Operand SafepointRegisterSlot(Register reg);
1413 static int SafepointRegisterStackIndex(int reg_code) {
1414 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1415 }
1416
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001417 // Needs access to SafepointRegisterStackIndex for compiled frame
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001418 // traversal.
mstarzinger@chromium.org32280cf2012-12-06 17:32:37 +00001419 friend class CompiledFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001420};
1421
1422
ager@chromium.org4af710e2009-09-15 12:20:11 +00001423// The code patcher is used to patch (typically) small parts of code e.g. for
1424// debugging and other types of instrumentation. When using the code patcher
1425// the exact number of bytes specified must be emitted. Is not legal to emit
1426// relocation information. If any of these constraints are violated it causes
1427// an assertion.
1428class CodePatcher {
1429 public:
1430 CodePatcher(byte* address, int size);
1431 virtual ~CodePatcher();
1432
1433 // Macro assembler to emit code.
1434 MacroAssembler* masm() { return &masm_; }
1435
1436 private:
1437 byte* address_; // The address of the code being patched.
1438 int size_; // Number of bytes of the expected patch size.
1439 MacroAssembler masm_; // Macro assembler used to generate the code.
1440};
1441
1442
ager@chromium.org9085a012009-05-11 19:22:57 +00001443// -----------------------------------------------------------------------------
1444// Static helper functions.
1445
1446// Generate an Operand for loading a field from an object.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001447inline Operand FieldOperand(Register object, int offset) {
ager@chromium.org9085a012009-05-11 19:22:57 +00001448 return Operand(object, offset - kHeapObjectTag);
1449}
1450
1451
1452// Generate an Operand for loading an indexed field from an object.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001453inline Operand FieldOperand(Register object,
1454 Register index,
1455 ScaleFactor scale,
1456 int offset) {
ager@chromium.org9085a012009-05-11 19:22:57 +00001457 return Operand(object, index, scale, offset - kHeapObjectTag);
1458}
1459
1460
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001461inline Operand ContextOperand(Register context, int index) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001462 return Operand(context, Context::SlotOffset(index));
1463}
1464
1465
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001466inline Operand GlobalObjectOperand() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001467 return ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001468}
1469
1470
1471// Provides access to exit frame stack space (not GCed).
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001472inline Operand StackSpaceOperand(int index) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001473#ifdef _WIN64
1474 const int kShaddowSpace = 4;
1475 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1476#else
1477 return Operand(rsp, index * kPointerSize);
1478#endif
1479}
1480
1481
1482
ager@chromium.org9085a012009-05-11 19:22:57 +00001483#ifdef GENERATED_CODE_COVERAGE
1484extern void LogGeneratedCodeCoverage(const char* file_line);
1485#define CODE_COVERAGE_STRINGIFY(x) #x
1486#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1487#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1488#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001489 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001490 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1491 masm->pushfd(); \
1492 masm->pushad(); \
1493 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001494 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001495 masm->pop(rax); \
1496 masm->popad(); \
1497 masm->popfd(); \
1498 } \
1499 masm->
1500#else
1501#define ACCESS_MASM(masm) masm->
1502#endif
1503
ager@chromium.org9085a012009-05-11 19:22:57 +00001504} } // namespace v8::internal
1505
1506#endif // V8_X64_MACRO_ASSEMBLER_X64_H_