blob: 8046e5cd3bcc206949a7e758b08395955d02cda2 [file] [log] [blame]
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +00001// Copyright 2011 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);
130
131 // Operations on roots in the root-array.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000132 void LoadRoot(Register destination, Heap::RootListIndex index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000133 void StoreRoot(Register source, Heap::RootListIndex index);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000134 // Load a root value where the index (or part of it) is variable.
135 // The variable_offset register is added to the fixed_offset value
136 // to get the index into the root-array.
137 void LoadRootIndexed(Register destination,
138 Register variable_offset,
139 int fixed_offset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000140 void CompareRoot(Register with, Heap::RootListIndex index);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000141 void CompareRoot(const Operand& with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000142 void PushRoot(Heap::RootListIndex index);
143
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000144 // These functions do not arrange the registers in any particular order so
145 // they are not useful for calls that can cause a GC. The caller can
146 // exclude up to 3 registers that do not need to be saved and restored.
147 void PushCallerSaved(SaveFPRegsMode fp_mode,
148 Register exclusion1 = no_reg,
149 Register exclusion2 = no_reg,
150 Register exclusion3 = no_reg);
151 void PopCallerSaved(SaveFPRegsMode fp_mode,
152 Register exclusion1 = no_reg,
153 Register exclusion2 = no_reg,
154 Register exclusion3 = no_reg);
ager@chromium.org9085a012009-05-11 19:22:57 +0000155
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000156// ---------------------------------------------------------------------------
157// GC Support
ager@chromium.orgac091b72010-05-05 07:34:42 +0000158
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000159
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000160 enum RememberedSetFinalAction {
161 kReturnAtEnd,
162 kFallThroughAtEnd
163 };
164
165 // Record in the remembered set the fact that we have a pointer to new space
166 // at the address pointed to by the addr register. Only works if addr is not
167 // in new space.
168 void RememberedSetHelper(Register object, // Used for debug code.
169 Register addr,
170 Register scratch,
171 SaveFPRegsMode save_fp,
172 RememberedSetFinalAction and_then);
173
174 void CheckPageFlag(Register object,
175 Register scratch,
176 int mask,
177 Condition cc,
178 Label* condition_met,
179 Label::Distance condition_met_distance = Label::kFar);
180
181 // Check if object is in new space. Jumps if the object is not in new space.
182 // The register scratch can be object itself, but scratch will be clobbered.
183 void JumpIfNotInNewSpace(Register object,
184 Register scratch,
185 Label* branch,
186 Label::Distance distance = Label::kFar) {
187 InNewSpace(object, scratch, not_equal, branch, distance);
188 }
189
190 // Check if object is in new space. Jumps if the object is in new space.
191 // The register scratch can be object itself, but it will be clobbered.
192 void JumpIfInNewSpace(Register object,
193 Register scratch,
194 Label* branch,
195 Label::Distance distance = Label::kFar) {
196 InNewSpace(object, scratch, equal, branch, distance);
197 }
198
199 // Check if an object has the black incremental marking color. Also uses rcx!
200 void JumpIfBlack(Register object,
201 Register scratch0,
202 Register scratch1,
203 Label* on_black,
204 Label::Distance on_black_distance = Label::kFar);
205
206 // Detects conservatively whether an object is data-only, ie it does need to
207 // be scanned by the garbage collector.
208 void JumpIfDataObject(Register value,
209 Register scratch,
210 Label* not_data_object,
211 Label::Distance not_data_object_distance);
212
213 // Checks the color of an object. If the object is already grey or black
214 // then we just fall through, since it is already live. If it is white and
215 // we can determine that it doesn't need to be scanned, then we just mark it
216 // black and fall through. For the rest we jump to the label so the
217 // incremental marker can fix its assumptions.
218 void EnsureNotWhite(Register object,
219 Register scratch1,
220 Register scratch2,
221 Label* object_is_white_and_not_data,
222 Label::Distance distance);
223
224 // Notify the garbage collector that we wrote a pointer into an object.
225 // |object| is the object being stored into, |value| is the object being
226 // stored. value and scratch registers are clobbered by the operation.
227 // The offset is the offset from the start of the object, not the offset from
228 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
229 void RecordWriteField(
230 Register object,
231 int offset,
232 Register value,
233 Register scratch,
234 SaveFPRegsMode save_fp,
235 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
236 SmiCheck smi_check = INLINE_SMI_CHECK);
237
238 // As above, but the offset has the tag presubtracted. For use with
239 // Operand(reg, off).
240 void RecordWriteContextSlot(
241 Register context,
242 int offset,
243 Register value,
244 Register scratch,
245 SaveFPRegsMode save_fp,
246 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
247 SmiCheck smi_check = INLINE_SMI_CHECK) {
248 RecordWriteField(context,
249 offset + kHeapObjectTag,
250 value,
251 scratch,
252 save_fp,
253 remembered_set_action,
254 smi_check);
255 }
256
257 // Notify the garbage collector that we wrote a pointer into a fixed array.
258 // |array| is the array being stored into, |value| is the
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000259 // object being stored. |index| is the array index represented as a non-smi.
260 // All registers are clobbered by the operation RecordWriteArray
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000261 // filters out smis so it does not update the write barrier if the
262 // value is a smi.
263 void RecordWriteArray(
264 Register array,
265 Register value,
266 Register index,
267 SaveFPRegsMode save_fp,
268 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
269 SmiCheck smi_check = INLINE_SMI_CHECK);
270
271 // For page containing |object| mark region covering |address|
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000272 // dirty. |object| is the object being stored into, |value| is the
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000273 // object being stored. The address and value registers are clobbered by the
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000274 // operation. RecordWrite filters out smis so it does not update
275 // the write barrier if the value is a smi.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000276 void RecordWrite(
277 Register object,
278 Register address,
279 Register value,
280 SaveFPRegsMode save_fp,
281 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
282 SmiCheck smi_check = INLINE_SMI_CHECK);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000283
ager@chromium.org9085a012009-05-11 19:22:57 +0000284#ifdef ENABLE_DEBUGGER_SUPPORT
285 // ---------------------------------------------------------------------------
286 // Debugger Support
287
ager@chromium.org5c838252010-02-19 08:53:10 +0000288 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000289#endif
290
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000291 // Enter specific kind of exit frame; either in normal or
292 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000293 // sets up the number of arguments in register rdi and the pointer
294 // to the first argument in register rsi.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000295 //
296 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
297 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000298 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000299
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000300 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
301 // memory (not GCed) on the stack accessible via StackSpaceOperand.
302 void EnterApiExitFrame(int arg_stack_space);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000303
ager@chromium.orga1645e22009-09-09 19:27:10 +0000304 // Leave the current exit frame. Expects/provides the return value in
305 // register rax:rdx (untouched) and the pointer to the first
306 // argument in register rsi.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000307 void LeaveExitFrame(bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000308
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000309 // Leave the current exit frame. Expects/provides the return value in
310 // register rax (untouched).
311 void LeaveApiExitFrame();
ager@chromium.org9085a012009-05-11 19:22:57 +0000312
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000313 // Push and pop the registers that can hold pointers.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000314 void PushSafepointRegisters() { Pushad(); }
315 void PopSafepointRegisters() { Popad(); }
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000316 // Store the value in register src in the safepoint register stack
317 // slot for register dst.
318 void StoreToSafepointRegisterSlot(Register dst, Register src);
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +0000319 void LoadFromSafepointRegisterSlot(Register dst, Register src);
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000320
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000321 void InitializeRootRegister() {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000322 ExternalReference roots_array_start =
323 ExternalReference::roots_array_start(isolate());
324 movq(kRootRegister, roots_array_start);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000325 addq(kRootRegister, Immediate(kRootRegisterBias));
326 }
327
ager@chromium.org9085a012009-05-11 19:22:57 +0000328 // ---------------------------------------------------------------------------
329 // JavaScript invokes
330
danno@chromium.org40cb8782011-05-25 07:58:50 +0000331 // Setup call kind marking in rcx. The method takes rcx as an
332 // explicit first parameter to make the code more readable at the
333 // call sites.
334 void SetCallKind(Register dst, CallKind kind);
335
ager@chromium.org9085a012009-05-11 19:22:57 +0000336 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000337 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000338 const ParameterCount& expected,
339 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000340 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000341 const CallWrapper& call_wrapper,
342 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000343
344 void InvokeCode(Handle<Code> code,
345 const ParameterCount& expected,
346 const ParameterCount& actual,
347 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000348 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000349 const CallWrapper& call_wrapper,
350 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000351
352 // Invoke the JavaScript function in the given register. Changes the
353 // current context to the context in the function before invoking.
354 void InvokeFunction(Register function,
355 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000356 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000357 const CallWrapper& call_wrapper,
358 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000359
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000360 void InvokeFunction(Handle<JSFunction> function,
ager@chromium.org5c838252010-02-19 08:53:10 +0000361 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000362 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000363 const CallWrapper& call_wrapper,
364 CallKind call_kind);
ager@chromium.org5c838252010-02-19 08:53:10 +0000365
ager@chromium.org9085a012009-05-11 19:22:57 +0000366 // Invoke specified builtin JavaScript function. Adds an entry to
367 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000368 void InvokeBuiltin(Builtins::JavaScript id,
369 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000370 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000371
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000372 // Store the function for the given builtin in the target register.
373 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
374
ager@chromium.org9085a012009-05-11 19:22:57 +0000375 // Store the code object for the given builtin in the target register.
376 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
377
ager@chromium.org4af710e2009-09-15 12:20:11 +0000378
379 // ---------------------------------------------------------------------------
380 // Smi tagging, untagging and operations on tagged smis.
381
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000382 void InitializeSmiConstantRegister() {
383 movq(kSmiConstantRegister,
384 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
385 RelocInfo::NONE);
386 }
387
ager@chromium.org4af710e2009-09-15 12:20:11 +0000388 // Conversions between tagged smi values and non-tagged integer values.
389
390 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000391 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000392 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000393 void Integer32ToSmi(Register dst, Register src);
394
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000395 // Stores an integer32 value into a memory field that already holds a smi.
396 void Integer32ToSmiField(const Operand& dst, Register src);
397
ager@chromium.org4af710e2009-09-15 12:20:11 +0000398 // Adds constant to src and tags the result as a smi.
399 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000400 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000401
402 // Convert smi to 32-bit integer. I.e., not sign extended into
403 // high 32 bits of destination.
404 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000405 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000406
407 // Convert smi to 64-bit integer (sign extended if necessary).
408 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000409 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000410
411 // Multiply a positive smi's integer value by a power of two.
412 // Provides result as 64-bit integer value.
413 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
414 Register src,
415 int power);
416
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000417 // Divide a positive smi's integer value by a power of two.
418 // Provides result as 32-bit integer value.
419 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
420 Register src,
421 int power);
422
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000423 // Perform the logical or of two smi values and return a smi value.
424 // If either argument is not a smi, jump to on_not_smis and retain
425 // the original values of source registers. The destination register
426 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000427 void SmiOrIfSmis(Register dst,
428 Register src1,
429 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000430 Label* on_not_smis,
431 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000432
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000433
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000434 // Simple comparison of smis. Both sides must be known smis to use these,
435 // otherwise use Cmp.
436 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000437 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000438 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000439 void SmiCompare(const Operand& dst, Register src);
440 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000441 // Compare the int32 in src register to the value of the smi stored at dst.
442 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000443 // Sets sign and zero flags depending on value of smi in register.
444 void SmiTest(Register src);
445
ager@chromium.org4af710e2009-09-15 12:20:11 +0000446 // Functions performing a check on a known or potential smi. Returns
447 // a condition that is satisfied if the check is successful.
448
449 // Is the value a tagged smi.
450 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000451 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000452
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000453 // Is the value a non-negative tagged smi.
454 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000455
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000456 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000457 Condition CheckBothSmi(Register first, Register second);
458
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000459 // Are both values non-negative tagged smis.
460 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000461
462 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000463 Condition CheckEitherSmi(Register first,
464 Register second,
465 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000466
ager@chromium.org4af710e2009-09-15 12:20:11 +0000467 // Is the value the minimum smi value (since we are using
468 // two's complement numbers, negating the value is known to yield
469 // a non-smi value).
470 Condition CheckIsMinSmi(Register src);
471
ager@chromium.org4af710e2009-09-15 12:20:11 +0000472 // Checks whether an 32-bit integer value is a valid for conversion
473 // to a smi.
474 Condition CheckInteger32ValidSmiValue(Register src);
475
ager@chromium.org3811b432009-10-28 14:53:37 +0000476 // Checks whether an 32-bit unsigned integer value is a valid for
477 // conversion to a smi.
478 Condition CheckUInteger32ValidSmiValue(Register src);
479
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000480 // Check whether src is a Smi, and set dst to zero if it is a smi,
481 // and to one if it isn't.
482 void CheckSmiToIndicator(Register dst, Register src);
483 void CheckSmiToIndicator(Register dst, const Operand& src);
484
ager@chromium.org4af710e2009-09-15 12:20:11 +0000485 // Test-and-jump functions. Typically combines a check function
486 // above with a conditional jump.
487
488 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000489 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
490 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000491
ager@chromium.org3811b432009-10-28 14:53:37 +0000492 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000493 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
494 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000495
ager@chromium.org4af710e2009-09-15 12:20:11 +0000496 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000497 void JumpIfSmi(Register src,
498 Label* on_smi,
499 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000500
501 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000502 void JumpIfNotSmi(Register src,
503 Label* on_not_smi,
504 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000505
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000506 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000507 void JumpUnlessNonNegativeSmi(Register src,
508 Label* on_not_smi,
509 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000510
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000511 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000512 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000513 void JumpIfSmiEqualsConstant(Register src,
514 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000515 Label* on_equals,
516 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000517
ager@chromium.org4af710e2009-09-15 12:20:11 +0000518 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000519 void JumpIfNotBothSmi(Register src1,
520 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000521 Label* on_not_both_smi,
522 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000523
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000524 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000525 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000526 Label* on_not_both_smi,
527 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000528
ager@chromium.org4af710e2009-09-15 12:20:11 +0000529 // Operations on tagged smi values.
530
531 // Smis represent a subset of integers. The subset is always equivalent to
532 // a two's complement interpretation of a fixed number of bits.
533
534 // Optimistically adds an integer constant to a supposed smi.
535 // If the src is not a smi, or the result is not a smi, jump to
536 // the label.
537 void SmiTryAddConstant(Register dst,
538 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000539 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000540 Label* on_not_smi_result,
541 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000542
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000543 // Add an integer constant to a tagged smi, giving a tagged smi as result.
544 // No overflow testing on the result is done.
545 void SmiAddConstant(Register dst, Register src, Smi* constant);
546
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000547 // Add an integer constant to a tagged smi, giving a tagged smi as result.
548 // No overflow testing on the result is done.
549 void SmiAddConstant(const Operand& dst, Smi* constant);
550
ager@chromium.org4af710e2009-09-15 12:20:11 +0000551 // Add an integer constant to a tagged smi, giving a tagged smi as result,
552 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000553 void SmiAddConstant(Register dst,
554 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000555 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000556 Label* on_not_smi_result,
557 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000558
559 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000560 // result. No testing on the result is done. Sets the N and Z flags
561 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000562 void SmiSubConstant(Register dst, Register src, Smi* constant);
563
564 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000565 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000566 void SmiSubConstant(Register dst,
567 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000568 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000569 Label* on_not_smi_result,
570 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000571
572 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000573 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000574 void SmiNeg(Register dst,
575 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000576 Label* on_smi_result,
577 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000578
579 // Adds smi values and return the result as a smi.
580 // If dst is src1, then src1 will be destroyed, even if
581 // the operation is unsuccessful.
582 void SmiAdd(Register dst,
583 Register src1,
584 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000585 Label* on_not_smi_result,
586 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000587 void SmiAdd(Register dst,
588 Register src1,
589 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000590 Label* on_not_smi_result,
591 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000592
593 void SmiAdd(Register dst,
594 Register src1,
595 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000596
597 // Subtracts smi values and return the result as a smi.
598 // If dst is src1, then src1 will be destroyed, even if
599 // the operation is unsuccessful.
600 void SmiSub(Register dst,
601 Register src1,
602 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000603 Label* on_not_smi_result,
604 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000605
ager@chromium.orgac091b72010-05-05 07:34:42 +0000606 void SmiSub(Register dst,
607 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000608 Register src2);
609
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000610 void SmiSub(Register dst,
611 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000612 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000613 Label* on_not_smi_result,
614 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000615
616 void SmiSub(Register dst,
617 Register src1,
618 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000619
ager@chromium.org4af710e2009-09-15 12:20:11 +0000620 // Multiplies smi values and return the result as a smi,
621 // if possible.
622 // If dst is src1, then src1 will be destroyed, even if
623 // the operation is unsuccessful.
624 void SmiMul(Register dst,
625 Register src1,
626 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000627 Label* on_not_smi_result,
628 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000629
630 // Divides one smi by another and returns the quotient.
631 // Clobbers rax and rdx registers.
632 void SmiDiv(Register dst,
633 Register src1,
634 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000635 Label* on_not_smi_result,
636 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000637
638 // Divides one smi by another and returns the remainder.
639 // Clobbers rax and rdx registers.
640 void SmiMod(Register dst,
641 Register src1,
642 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000643 Label* on_not_smi_result,
644 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000645
646 // Bitwise operations.
647 void SmiNot(Register dst, Register src);
648 void SmiAnd(Register dst, Register src1, Register src2);
649 void SmiOr(Register dst, Register src1, Register src2);
650 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000651 void SmiAndConstant(Register dst, Register src1, Smi* constant);
652 void SmiOrConstant(Register dst, Register src1, Smi* constant);
653 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000654
655 void SmiShiftLeftConstant(Register dst,
656 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000657 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000658 void SmiShiftLogicalRightConstant(Register dst,
659 Register src,
660 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000661 Label* on_not_smi_result,
662 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000663 void SmiShiftArithmeticRightConstant(Register dst,
664 Register src,
665 int shift_value);
666
667 // Shifts a smi value to the left, and returns the result if that is a smi.
668 // Uses and clobbers rcx, so dst may not be rcx.
669 void SmiShiftLeft(Register dst,
670 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000671 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000672 // Shifts a smi value to the right, shifting in zero bits at the top, and
673 // returns the unsigned intepretation of the result if that is a smi.
674 // Uses and clobbers rcx, so dst may not be rcx.
675 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000676 Register src1,
677 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000678 Label* on_not_smi_result,
679 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000680 // Shifts a smi value to the right, sign extending the top, and
681 // returns the signed intepretation of the result. That will always
682 // be a valid smi value, since it's numerically smaller than the
683 // original.
684 // Uses and clobbers rcx, so dst may not be rcx.
685 void SmiShiftArithmeticRight(Register dst,
686 Register src1,
687 Register src2);
688
689 // Specialized operations
690
691 // Select the non-smi register of two registers where exactly one is a
692 // smi. If neither are smis, jump to the failure label.
693 void SelectNonSmi(Register dst,
694 Register src1,
695 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000696 Label* on_not_smis,
697 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000698
699 // Converts, if necessary, a smi to a combination of number and
700 // multiplier to be used as a scaled index.
701 // The src register contains a *positive* smi value. The shift is the
702 // power of two to multiply the index value by (e.g.
703 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
704 // The returned index register may be either src or dst, depending
705 // on what is most efficient. If src and dst are different registers,
706 // src is always unchanged.
707 SmiIndex SmiToIndex(Register dst, Register src, int shift);
708
709 // Converts a positive smi to a negative index.
710 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
711
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000712 // Add the value of a smi in memory to an int32 register.
713 // Sets flags as a normal add.
714 void AddSmiField(Register dst, const Operand& src);
715
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000716 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000717 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000718 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000719 }
720
721 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000722 Register constant = GetSmiConstant(source);
723 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000724 }
725
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000726 void Push(Smi* smi);
727 void Test(const Operand& dst, Smi* source);
728
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000729
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000730 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000731 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000732
733 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000734 void JumpIfNotString(Register object,
735 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000736 Label* not_string,
737 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000738
739
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000740 void JumpIfNotBothSequentialAsciiStrings(
741 Register first_object,
742 Register second_object,
743 Register scratch1,
744 Register scratch2,
745 Label* on_not_both_flat_ascii,
746 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000747
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000748 // Check whether the instance type represents a flat ascii string. Jump to the
749 // label if not. If the instance type can be scratched specify same register
750 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000751 void JumpIfInstanceTypeIsNotSequentialAscii(
752 Register instance_type,
753 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000754 Label*on_not_flat_ascii_string,
755 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000756
757 void JumpIfBothInstanceTypesAreNotSequentialAscii(
758 Register first_object_instance_type,
759 Register second_object_instance_type,
760 Register scratch1,
761 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000762 Label* on_fail,
763 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000764
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000765 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000766 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000767
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000768 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000769 void Set(Register dst, int64_t x);
770 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000771
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000772 // Move if the registers are not identical.
773 void Move(Register target, Register source);
774
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000775 // Bit-field support.
776 void TestBit(const Operand& dst, int bit_index);
777
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000778 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000779 void Move(Register dst, Handle<Object> source);
780 void Move(const Operand& dst, Handle<Object> source);
781 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000782 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000783 void Cmp(Register dst, Smi* src);
784 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000785 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000786
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000787 // Load a heap object and handle the case of new-space objects by
788 // indirecting via a global cell.
789 void LoadHeapObject(Register result, Handle<HeapObject> object);
790 void PushHeapObject(Handle<HeapObject> object);
791
792 // Load a global cell into a register.
793 void LoadGlobalCell(Register dst, Handle<JSGlobalPropertyCell> cell);
794
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000795 // Emit code to discard a non-negative number of pointer-sized elements
796 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000797 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000798
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000799 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000800
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000801 // Control Flow
802 void Jump(Address destination, RelocInfo::Mode rmode);
803 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000804 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
805
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000806 void Call(Address destination, RelocInfo::Mode rmode);
807 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000808 void Call(Handle<Code> code_object,
809 RelocInfo::Mode rmode,
810 unsigned ast_id = kNoASTId);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000811
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000812 // The size of the code generated for different call instructions.
813 int CallSize(Address destination, RelocInfo::Mode rmode) {
814 return kCallInstructionLength;
815 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000816 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000817 int CallSize(Handle<Code> code_object) {
818 // Code calls use 32-bit relative addressing.
819 return kShortCallInstructionLength;
820 }
821 int CallSize(Register target) {
822 // Opcode: REX_opt FF /2 m64
823 return (target.high_bit() != 0) ? 3 : 2;
824 }
825 int CallSize(const Operand& target) {
826 // Opcode: REX_opt FF /2 m64
827 return (target.requires_rex() ? 2 : 1) + target.operand_size();
828 }
829
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000830 // Emit call to the code we are currently generating.
831 void CallSelf() {
832 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
833 Call(self, RelocInfo::CODE_TARGET);
834 }
835
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000836 // Non-x64 instructions.
837 // Push/pop all general purpose registers.
838 // Does not push rsp/rbp nor any of the assembler's special purpose registers
839 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
840 void Pushad();
841 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000842 // Sets the stack as after performing Popad, without actually loading the
843 // registers.
844 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000845
ager@chromium.org9085a012009-05-11 19:22:57 +0000846 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000847 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000848 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000849 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000850 void CmpObjectType(Register heap_object, InstanceType type, Register map);
851
852 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000853 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000854 void CmpInstanceType(Register map, InstanceType type);
855
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000856 // Check if a map for a JSObject indicates that the object has fast elements.
857 // Jump to the specified label if it does not.
858 void CheckFastElements(Register map,
859 Label* fail,
860 Label::Distance distance = Label::kFar);
861
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000862 // Check if a map for a JSObject indicates that the object can have both smi
863 // and HeapObject elements. Jump to the specified label if it does not.
864 void CheckFastObjectElements(Register map,
865 Label* fail,
866 Label::Distance distance = Label::kFar);
867
868 // Check if a map for a JSObject indicates that the object has fast smi only
869 // elements. Jump to the specified label if it does not.
870 void CheckFastSmiOnlyElements(Register map,
871 Label* fail,
872 Label::Distance distance = Label::kFar);
873
874 // Check to see if maybe_number can be stored as a double in
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000875 // FastDoubleElements. If it can, store it at the index specified by index in
876 // the FastDoubleElements array elements, otherwise jump to fail. Note that
877 // index must not be smi-tagged.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000878 void StoreNumberToDoubleElements(Register maybe_number,
879 Register elements,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000880 Register index,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000881 XMMRegister xmm_scratch,
882 Label* fail);
883
ager@chromium.org5c838252010-02-19 08:53:10 +0000884 // Check if the map of an object is equal to a specified map and
885 // branch to label if not. Skip the smi check if not required
886 // (object is known to be a heap object)
887 void CheckMap(Register obj,
888 Handle<Map> map,
889 Label* fail,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000890 SmiCheckType smi_check_type);
ager@chromium.org5c838252010-02-19 08:53:10 +0000891
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000892 // Check if the map of an object is equal to a specified map and branch to a
893 // specified target if equal. Skip the smi check if not required (object is
894 // known to be a heap object)
895 void DispatchMap(Register obj,
896 Handle<Map> map,
897 Handle<Code> success,
898 SmiCheckType smi_check_type);
899
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000900 // Check if the object in register heap_object is a string. Afterwards the
901 // register map contains the object map and the register instance_type
902 // contains the instance_type. The registers map and instance_type can be the
903 // same in which case it contains the instance type afterwards. Either of the
904 // registers map and instance_type can be the same as heap_object.
905 Condition IsObjectStringType(Register heap_object,
906 Register map,
907 Register instance_type);
908
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000909 // FCmp compares and pops the two values on top of the FPU stack.
910 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000911 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
912 void FCmp();
913
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000914 void ClampUint8(Register reg);
915
916 void ClampDoubleToUint8(XMMRegister input_reg,
917 XMMRegister temp_xmm_reg,
918 Register result_reg,
919 Register temp_reg);
920
danno@chromium.org40cb8782011-05-25 07:58:50 +0000921 void LoadInstanceDescriptors(Register map, Register descriptors);
922
ager@chromium.org5c838252010-02-19 08:53:10 +0000923 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000924 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000925
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000926 // Abort execution if argument is a smi. Used in debug code.
927 void AbortIfSmi(Register object);
928
lrn@chromium.org25156de2010-04-06 13:10:27 +0000929 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000930 void AbortIfNotSmi(Register object);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000931 void AbortIfNotSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000932
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000933 // Abort execution if argument is a string. Used in debug code.
934 void AbortIfNotString(Register object);
935
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000936 // Abort execution if argument is not the root value with the given index.
937 void AbortIfNotRootValue(Register src,
938 Heap::RootListIndex root_value_index,
939 const char* message);
940
ager@chromium.org9085a012009-05-11 19:22:57 +0000941 // ---------------------------------------------------------------------------
942 // Exception handling
943
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000944 // Push a new try handler and link it into try handler chain.
945 void PushTryHandler(CodeLocation try_location,
946 HandlerType type,
947 int handler_index);
ager@chromium.org9085a012009-05-11 19:22:57 +0000948
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000949 // Unlink the stack handler on top of the stack from the try handler chain.
950 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000951
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000952 // Activate the top handler in the try hander chain and pass the
953 // thrown value.
954 void Throw(Register value);
955
956 // Propagate an uncatchable exception out of the current JS stack.
957 void ThrowUncatchable(UncatchableExceptionType type, Register value);
958
ager@chromium.org9085a012009-05-11 19:22:57 +0000959 // ---------------------------------------------------------------------------
960 // Inline caching support
961
ager@chromium.org9085a012009-05-11 19:22:57 +0000962 // Generate code for checking access rights - used for security checks
963 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000964 // is left untouched, but the scratch register and kScratchRegister,
965 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000966 void CheckAccessGlobalProxy(Register holder_reg,
967 Register scratch,
968 Label* miss);
969
970
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000971 void LoadFromNumberDictionary(Label* miss,
972 Register elements,
973 Register key,
974 Register r0,
975 Register r1,
976 Register r2,
977 Register result);
978
979
ager@chromium.org9085a012009-05-11 19:22:57 +0000980 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000981 // Allocation support
982
983 // Allocate an object in new space. If the new space is exhausted control
984 // continues at the gc_required label. The allocated object is returned in
985 // result and end of the new object is returned in result_end. The register
986 // scratch can be passed as no_reg in which case an additional object
987 // reference will be added to the reloc info. The returned pointers in result
988 // and result_end have not yet been tagged as heap objects. If
989 // result_contains_top_on_entry is true the content of result is known to be
990 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000991 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000992 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000993 void AllocateInNewSpace(int object_size,
994 Register result,
995 Register result_end,
996 Register scratch,
997 Label* gc_required,
998 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000999
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001000 void AllocateInNewSpace(int header_size,
1001 ScaleFactor element_size,
1002 Register element_count,
1003 Register result,
1004 Register result_end,
1005 Register scratch,
1006 Label* gc_required,
1007 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001008
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001009 void AllocateInNewSpace(Register object_size,
1010 Register result,
1011 Register result_end,
1012 Register scratch,
1013 Label* gc_required,
1014 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001015
1016 // Undo allocation in new space. The object passed and objects allocated after
1017 // it will no longer be allocated. Make sure that no pointers are left to the
1018 // object(s) no longer allocated as they would be invalid when allocation is
1019 // un-done.
1020 void UndoAllocationInNewSpace(Register object);
1021
ager@chromium.org3811b432009-10-28 14:53:37 +00001022 // Allocate a heap number in new space with undefined value. Returns
1023 // tagged pointer in result register, or jumps to gc_required if new
1024 // space is full.
1025 void AllocateHeapNumber(Register result,
1026 Register scratch,
1027 Label* gc_required);
1028
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001029 // Allocate a sequential string. All the header fields of the string object
1030 // are initialized.
1031 void AllocateTwoByteString(Register result,
1032 Register length,
1033 Register scratch1,
1034 Register scratch2,
1035 Register scratch3,
1036 Label* gc_required);
1037 void AllocateAsciiString(Register result,
1038 Register length,
1039 Register scratch1,
1040 Register scratch2,
1041 Register scratch3,
1042 Label* gc_required);
1043
1044 // Allocate a raw cons string object. Only the map field of the result is
1045 // initialized.
fschneider@chromium.org1805e212011-09-05 10:49:12 +00001046 void AllocateTwoByteConsString(Register result,
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001047 Register scratch1,
1048 Register scratch2,
1049 Label* gc_required);
1050 void AllocateAsciiConsString(Register result,
1051 Register scratch1,
1052 Register scratch2,
1053 Label* gc_required);
1054
fschneider@chromium.org1805e212011-09-05 10:49:12 +00001055 // Allocate a raw sliced string object. Only the map field of the result is
1056 // initialized.
1057 void AllocateTwoByteSlicedString(Register result,
1058 Register scratch1,
1059 Register scratch2,
1060 Label* gc_required);
1061 void AllocateAsciiSlicedString(Register result,
1062 Register scratch1,
1063 Register scratch2,
1064 Label* gc_required);
1065
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001066 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +00001067 // Support functions.
1068
1069 // Check if result is zero and op is negative.
1070 void NegativeZeroTest(Register result, Register op, Label* then_label);
1071
1072 // Check if result is zero and op is negative in code using jump targets.
1073 void NegativeZeroTest(CodeGenerator* cgen,
1074 Register result,
1075 Register op,
1076 JumpTarget* then_target);
1077
1078 // Check if result is zero and any of op1 and op2 are negative.
1079 // Register scratch is destroyed, and it must be different from op2.
1080 void NegativeZeroTest(Register result, Register op1, Register op2,
1081 Register scratch, Label* then_label);
1082
1083 // Try to get function prototype of a function and puts the value in
1084 // the result register. Checks that the function really is a
1085 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001086 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +00001087 // clobbered.
1088 void TryGetFunctionPrototype(Register function,
1089 Register result,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001090 Label* miss,
1091 bool miss_on_bound_function = false);
ager@chromium.org9085a012009-05-11 19:22:57 +00001092
1093 // Generates code for reporting that an illegal operation has
1094 // occurred.
1095 void IllegalOperation(int num_arguments);
1096
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001097 // Picks out an array index from the hash field.
1098 // Register use:
1099 // hash - holds the index's hash. Clobbered.
1100 // index - holds the overwritten index on exit.
1101 void IndexFromHash(Register hash, Register index);
1102
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00001103 // Find the function context up the context chain.
1104 void LoadContext(Register dst, int context_chain_length);
1105
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001106 // Load the global function with the given index.
1107 void LoadGlobalFunction(int index, Register function);
1108
1109 // Load the initial map from the global function. The registers
1110 // function and map can be the same.
1111 void LoadGlobalFunctionInitialMap(Register function, Register map);
1112
ager@chromium.org9085a012009-05-11 19:22:57 +00001113 // ---------------------------------------------------------------------------
1114 // Runtime calls
1115
1116 // Call a code stub.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00001117 void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId);
ager@chromium.org9085a012009-05-11 19:22:57 +00001118
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001119 // Tail call a code stub (jump).
1120 void TailCallStub(CodeStub* stub);
1121
ager@chromium.org9085a012009-05-11 19:22:57 +00001122 // Return from a code stub after popping its arguments.
1123 void StubReturn(int argc);
1124
1125 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001126 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001127
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001128 // Call a runtime function and save the value of XMM registers.
1129 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
1130
ager@chromium.org9085a012009-05-11 19:22:57 +00001131 // Convenience function: Same as above, but takes the fid instead.
1132 void CallRuntime(Runtime::FunctionId id, int num_arguments);
1133
ager@chromium.org5c838252010-02-19 08:53:10 +00001134 // Convenience function: call an external reference.
1135 void CallExternalReference(const ExternalReference& ext,
1136 int num_arguments);
1137
ager@chromium.org9085a012009-05-11 19:22:57 +00001138 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001139 // Like JumpToExternalReference, but also takes care of passing the number
1140 // of parameters.
1141 void TailCallExternalReference(const ExternalReference& ext,
1142 int num_arguments,
1143 int result_size);
1144
1145 // Convenience function: tail call a runtime routine (jump).
1146 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001147 int num_arguments,
1148 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001149
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001150 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001151 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001152
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001153 // Prepares stack to put arguments (aligns and so on). WIN64 calling
1154 // convention requires to put the pointer to the return value slot into
1155 // rcx (rcx must be preserverd until CallApiFunctionAndReturn). Saves
1156 // context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001157 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1158 void PrepareCallApiFunction(int arg_stack_space);
1159
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001160 // Calls an API function. Allocates HandleScope, extracts returned value
1161 // from handle and propagates exceptions. Clobbers r14, r15, rbx and
1162 // caller-save registers. Restores context. On return removes
1163 // stack_space * kPointerSize (GCed).
1164 void CallApiFunctionAndReturn(Address function_address, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001165
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001166 // Before calling a C-function from generated code, align arguments on stack.
1167 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1168 // etc., not pushed. The argument count assumes all arguments are word sized.
1169 // The number of slots reserved for arguments depends on platform. On Windows
1170 // stack slots are reserved for the arguments passed in registers. On other
1171 // platforms stack slots are only reserved for the arguments actually passed
1172 // on the stack.
1173 void PrepareCallCFunction(int num_arguments);
1174
1175 // Calls a C function and cleans up the space for arguments allocated
1176 // by PrepareCallCFunction. The called function is not allowed to trigger a
1177 // garbage collection, since that might move the code and invalidate the
1178 // return address (unless this is somehow accounted for by the called
1179 // function).
1180 void CallCFunction(ExternalReference function, int num_arguments);
1181 void CallCFunction(Register function, int num_arguments);
1182
1183 // Calculate the number of stack slots to reserve for arguments when calling a
1184 // C function.
1185 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001186
1187 // ---------------------------------------------------------------------------
1188 // Utilities
1189
1190 void Ret();
1191
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001192 // Return and drop arguments from stack, where the number of arguments
1193 // may be bigger than 2^16 - 1. Requires a scratch register.
1194 void Ret(int bytes_dropped, Register scratch);
1195
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001196 Handle<Object> CodeObject() {
1197 ASSERT(!code_object_.is_null());
1198 return code_object_;
1199 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001200
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001201 // Copy length bytes from source to destination.
1202 // Uses scratch register internally (if you have a low-eight register
1203 // free, do use it, otherwise kScratchRegister will be used).
1204 // The min_length is a minimum limit on the value that length will have.
1205 // The algorithm has some special cases that might be omitted if the string
1206 // is known to always be long.
1207 void CopyBytes(Register destination,
1208 Register source,
1209 Register length,
1210 int min_length = 0,
1211 Register scratch = kScratchRegister);
1212
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001213 // Initialize fields with filler values. Fields starting at |start_offset|
1214 // not including end_offset are overwritten with the value in |filler|. At
1215 // the end the loop, |start_offset| takes the value of |end_offset|.
1216 void InitializeFieldsWithFiller(Register start_offset,
1217 Register end_offset,
1218 Register filler);
1219
ager@chromium.org9085a012009-05-11 19:22:57 +00001220
1221 // ---------------------------------------------------------------------------
1222 // StatsCounter support
1223
1224 void SetCounter(StatsCounter* counter, int value);
1225 void IncrementCounter(StatsCounter* counter, int value);
1226 void DecrementCounter(StatsCounter* counter, int value);
1227
1228
1229 // ---------------------------------------------------------------------------
1230 // Debugging
1231
1232 // Calls Abort(msg) if the condition cc is not satisfied.
1233 // Use --debug_code to enable.
1234 void Assert(Condition cc, const char* msg);
1235
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001236 void AssertFastElements(Register elements);
1237
ager@chromium.org9085a012009-05-11 19:22:57 +00001238 // Like Assert(), but always enabled.
1239 void Check(Condition cc, const char* msg);
1240
1241 // Print a message to stdout and abort execution.
1242 void Abort(const char* msg);
1243
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001244 // Check that the stack is aligned.
1245 void CheckStackAlignment();
1246
ager@chromium.org9085a012009-05-11 19:22:57 +00001247 // Verify restrictions about code generated in stubs.
1248 void set_generating_stub(bool value) { generating_stub_ = value; }
1249 bool generating_stub() { return generating_stub_; }
1250 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1251 bool allow_stub_calls() { return allow_stub_calls_; }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001252 void set_has_frame(bool value) { has_frame_ = value; }
1253 bool has_frame() { return has_frame_; }
1254 inline bool AllowThisStubCall(CodeStub* stub);
ager@chromium.org9085a012009-05-11 19:22:57 +00001255
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001256 static int SafepointRegisterStackIndex(Register reg) {
1257 return SafepointRegisterStackIndex(reg.code());
1258 }
1259
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001260 // Activation support.
1261 void EnterFrame(StackFrame::Type type);
1262 void LeaveFrame(StackFrame::Type type);
1263
ager@chromium.org9085a012009-05-11 19:22:57 +00001264 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001265 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001266 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001267 static int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001268 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001269 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001270
ager@chromium.org9085a012009-05-11 19:22:57 +00001271 bool generating_stub_;
1272 bool allow_stub_calls_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001273 bool has_frame_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001274 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001275
1276 // Returns a register holding the smi value. The register MUST NOT be
1277 // modified. It may be the "smi 1 constant" register.
1278 Register GetSmiConstant(Smi* value);
1279
1280 // Moves the smi value to the destination register.
1281 void LoadSmiConstant(Register dst, Smi* value);
1282
ager@chromium.org5c838252010-02-19 08:53:10 +00001283 // This handle will be patched with the code object on installation.
1284 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001285
1286 // Helper functions for generating invokes.
1287 void InvokePrologue(const ParameterCount& expected,
1288 const ParameterCount& actual,
1289 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001290 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001291 Label* done,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001292 InvokeFlag flag,
danno@chromium.org40cb8782011-05-25 07:58:50 +00001293 Label::Distance near_jump = Label::kFar,
1294 const CallWrapper& call_wrapper = NullCallWrapper(),
1295 CallKind call_kind = CALL_AS_METHOD);
ager@chromium.org9085a012009-05-11 19:22:57 +00001296
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001297 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001298
1299 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1300 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001301 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001302
1303 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001304
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001305 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001306 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001307 // Otherwise the address of the new-space top is loaded into scratch (if
1308 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001309 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001310 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001311 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001312 // Update allocation top with value in result_end register.
1313 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001314 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001315
1316 // Helper for PopHandleScope. Allowed to perform a GC and returns
1317 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1318 // possibly returns a failure object indicating an allocation failure.
1319 Object* PopHandleScopeHelper(Register saved,
1320 Register scratch,
1321 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001322
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001323 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1324 void InNewSpace(Register object,
1325 Register scratch,
1326 Condition cc,
1327 Label* branch,
1328 Label::Distance distance = Label::kFar);
1329
1330 // Helper for finding the mark bits for an address. Afterwards, the
1331 // bitmap register points at the word with the mark bits and the mask
1332 // the position of the first bit. Uses rcx as scratch and leaves addr_reg
1333 // unchanged.
1334 inline void GetMarkBits(Register addr_reg,
1335 Register bitmap_reg,
1336 Register mask_reg);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001337
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001338 // Helper for throwing exceptions. Compute a handler address and jump to
1339 // it. See the implementation for register usage.
1340 void JumpToHandlerEntry();
1341
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001342 // Compute memory operands for safepoint stack slots.
1343 Operand SafepointRegisterSlot(Register reg);
1344 static int SafepointRegisterStackIndex(int reg_code) {
1345 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1346 }
1347
1348 // Needs access to SafepointRegisterStackIndex for optimized frame
1349 // traversal.
1350 friend class OptimizedFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001351};
1352
1353
ager@chromium.org4af710e2009-09-15 12:20:11 +00001354// The code patcher is used to patch (typically) small parts of code e.g. for
1355// debugging and other types of instrumentation. When using the code patcher
1356// the exact number of bytes specified must be emitted. Is not legal to emit
1357// relocation information. If any of these constraints are violated it causes
1358// an assertion.
1359class CodePatcher {
1360 public:
1361 CodePatcher(byte* address, int size);
1362 virtual ~CodePatcher();
1363
1364 // Macro assembler to emit code.
1365 MacroAssembler* masm() { return &masm_; }
1366
1367 private:
1368 byte* address_; // The address of the code being patched.
1369 int size_; // Number of bytes of the expected patch size.
1370 MacroAssembler masm_; // Macro assembler used to generate the code.
1371};
1372
1373
ager@chromium.org9085a012009-05-11 19:22:57 +00001374// -----------------------------------------------------------------------------
1375// Static helper functions.
1376
1377// Generate an Operand for loading a field from an object.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001378inline Operand FieldOperand(Register object, int offset) {
ager@chromium.org9085a012009-05-11 19:22:57 +00001379 return Operand(object, offset - kHeapObjectTag);
1380}
1381
1382
1383// Generate an Operand for loading an indexed field from an object.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001384inline Operand FieldOperand(Register object,
1385 Register index,
1386 ScaleFactor scale,
1387 int offset) {
ager@chromium.org9085a012009-05-11 19:22:57 +00001388 return Operand(object, index, scale, offset - kHeapObjectTag);
1389}
1390
1391
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001392inline Operand ContextOperand(Register context, int index) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001393 return Operand(context, Context::SlotOffset(index));
1394}
1395
1396
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001397inline Operand GlobalObjectOperand() {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001398 return ContextOperand(rsi, Context::GLOBAL_INDEX);
1399}
1400
1401
1402// Provides access to exit frame stack space (not GCed).
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001403inline Operand StackSpaceOperand(int index) {
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001404#ifdef _WIN64
1405 const int kShaddowSpace = 4;
1406 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1407#else
1408 return Operand(rsp, index * kPointerSize);
1409#endif
1410}
1411
1412
1413
ager@chromium.org9085a012009-05-11 19:22:57 +00001414#ifdef GENERATED_CODE_COVERAGE
1415extern void LogGeneratedCodeCoverage(const char* file_line);
1416#define CODE_COVERAGE_STRINGIFY(x) #x
1417#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1418#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1419#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001420 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001421 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1422 masm->pushfd(); \
1423 masm->pushad(); \
1424 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001425 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001426 masm->pop(rax); \
1427 masm->popad(); \
1428 masm->popfd(); \
1429 } \
1430 masm->
1431#else
1432#define ACCESS_MASM(masm) masm->
1433#endif
1434
ager@chromium.org9085a012009-05-11 19:22:57 +00001435} } // namespace v8::internal
1436
1437#endif // V8_X64_MACRO_ASSEMBLER_X64_H_