blob: 719c8d3d99e0c7f7a250ad904e3f3c1624dcad89 [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"
32
kasperl@chromium.org71affb52009-05-26 05:44:31 +000033namespace v8 {
34namespace internal {
ager@chromium.org9085a012009-05-11 19:22:57 +000035
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +000036// Flags used for the AllocateInNewSpace functions.
37enum AllocationFlags {
38 // No special flags.
39 NO_ALLOCATION_FLAGS = 0,
40 // Return the pointer to the allocated already tagged as a heap object.
41 TAG_OBJECT = 1 << 0,
42 // The content of the result register already contains the allocation top in
43 // new space.
44 RESULT_CONTAINS_TOP = 1 << 1
45};
46
ager@chromium.orge2902be2009-06-08 12:21:35 +000047// Default scratch register used by MacroAssembler (and other code that needs
48// a spare register). The register isn't callee save, and not used by the
49// function calling convention.
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000050static const Register kScratchRegister = { 10 }; // r10.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +000051static const Register kSmiConstantRegister = { 12 }; // r12 (callee save).
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000052static const Register kRootRegister = { 13 }; // r13 (callee save).
53// Value of smi in kSmiConstantRegister.
54static const int kSmiConstantRegisterValue = 1;
karlklose@chromium.org8f806e82011-03-07 14:06:08 +000055// Actual value of root register is offset from the root array's start
56// to take advantage of negitive 8-bit displacement values.
57static const int kRootRegisterBias = 128;
ager@chromium.orge2902be2009-06-08 12:21:35 +000058
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000059// Convenience for platform-independent signatures.
60typedef Operand MemOperand;
61
ager@chromium.org9085a012009-05-11 19:22:57 +000062// Forward declaration.
63class JumpTarget;
64
ager@chromium.org4af710e2009-09-15 12:20:11 +000065struct SmiIndex {
66 SmiIndex(Register index_register, ScaleFactor scale)
67 : reg(index_register),
68 scale(scale) {}
69 Register reg;
70 ScaleFactor scale;
71};
ager@chromium.org9085a012009-05-11 19:22:57 +000072
ager@chromium.org9085a012009-05-11 19:22:57 +000073// MacroAssembler implements a collection of frequently used macros.
74class MacroAssembler: public Assembler {
75 public:
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +000076 // The isolate parameter can be NULL if the macro assembler should
77 // not use isolate-dependent functionality. In this case, it's the
78 // responsibility of the caller to never invoke such function on the
79 // macro assembler.
80 MacroAssembler(Isolate* isolate, void* buffer, int size);
ager@chromium.org9085a012009-05-11 19:22:57 +000081
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000082 // Prevent the use of the RootArray during the lifetime of this
83 // scope object.
84 class NoRootArrayScope BASE_EMBEDDED {
85 public:
86 explicit NoRootArrayScope(MacroAssembler* assembler)
87 : variable_(&assembler->root_array_available_),
88 old_value_(assembler->root_array_available_) {
89 assembler->root_array_available_ = false;
90 }
91 ~NoRootArrayScope() {
92 *variable_ = old_value_;
93 }
94 private:
95 bool* variable_;
96 bool old_value_;
97 };
98
99 // Operand pointing to an external reference.
100 // May emit code to set up the scratch register. The operand is
101 // only guaranteed to be correct as long as the scratch register
102 // isn't changed.
103 // If the operand is used more than once, use a scratch register
104 // that is guaranteed not to be clobbered.
105 Operand ExternalOperand(ExternalReference reference,
106 Register scratch = kScratchRegister);
107 // Loads and stores the value of an external reference.
108 // Special case code for load and store to take advantage of
109 // load_rax/store_rax if possible/necessary.
110 // For other operations, just use:
111 // Operand operand = ExternalOperand(extref);
112 // operation(operand, ..);
113 void Load(Register destination, ExternalReference source);
114 void Store(ExternalReference destination, Register source);
115 // Loads the address of the external reference into the destination
116 // register.
117 void LoadAddress(Register destination, ExternalReference source);
118 // Returns the size of the code generated by LoadAddress.
119 // Used by CallSize(ExternalReference) to find the size of a call.
120 int LoadAddressSize(ExternalReference source);
121
122 // Operations on roots in the root-array.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000123 void LoadRoot(Register destination, Heap::RootListIndex index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000124 void StoreRoot(Register source, Heap::RootListIndex index);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000125 // Load a root value where the index (or part of it) is variable.
126 // The variable_offset register is added to the fixed_offset value
127 // to get the index into the root-array.
128 void LoadRootIndexed(Register destination,
129 Register variable_offset,
130 int fixed_offset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000131 void CompareRoot(Register with, Heap::RootListIndex index);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000132 void CompareRoot(const Operand& with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000133 void PushRoot(Heap::RootListIndex index);
134
ager@chromium.org9085a012009-05-11 19:22:57 +0000135 // ---------------------------------------------------------------------------
136 // GC Support
137
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000138 // For page containing |object| mark region covering |addr| dirty.
139 // RecordWriteHelper only works if the object is not in new
ager@chromium.orgac091b72010-05-05 07:34:42 +0000140 // space.
141 void RecordWriteHelper(Register object,
142 Register addr,
143 Register scratch);
144
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000145 // Check if object is in new space. The condition cc can be equal or
146 // not_equal. If it is equal a jump will be done if the object is on new
147 // space. The register scratch can be object itself, but it will be clobbered.
148 void InNewSpace(Register object,
149 Register scratch,
150 Condition cc,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000151 Label* branch,
152 Label::Distance near_jump = Label::kFar);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000153
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000154 // For page containing |object| mark region covering [object+offset]
155 // dirty. |object| is the object being stored into, |value| is the
156 // object being stored. If |offset| is zero, then the |scratch|
157 // register contains the array index into the elements array
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000158 // represented as an untagged 32-bit integer. All registers are
159 // clobbered by the operation. RecordWrite filters out smis so it
160 // does not update the write barrier if the value is a smi.
ager@chromium.org9085a012009-05-11 19:22:57 +0000161 void RecordWrite(Register object,
162 int offset,
163 Register value,
164 Register scratch);
165
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000166 // For page containing |object| mark region covering [address]
167 // dirty. |object| is the object being stored into, |value| is the
168 // object being stored. All registers are clobbered by the
169 // operation. RecordWrite filters out smis so it does not update
170 // the write barrier if the value is a smi.
171 void RecordWrite(Register object,
172 Register address,
173 Register value);
174
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000175 // For page containing |object| mark region covering [object+offset] dirty.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000176 // The value is known to not be a smi.
177 // object is the object being stored into, value is the object being stored.
178 // If offset is zero, then the scratch register contains the array index into
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000179 // the elements array represented as an untagged 32-bit integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000180 // All registers are clobbered by the operation.
181 void RecordWriteNonSmi(Register object,
182 int offset,
183 Register value,
184 Register scratch);
185
ager@chromium.org9085a012009-05-11 19:22:57 +0000186#ifdef ENABLE_DEBUGGER_SUPPORT
187 // ---------------------------------------------------------------------------
188 // Debugger Support
189
ager@chromium.org5c838252010-02-19 08:53:10 +0000190 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000191#endif
192
193 // ---------------------------------------------------------------------------
194 // Activation frames
195
196 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
197 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
198
199 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
200 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
201
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000202 // Enter specific kind of exit frame; either in normal or
203 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000204 // sets up the number of arguments in register rdi and the pointer
205 // to the first argument in register rsi.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000206 //
207 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
208 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000209 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000210
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000211 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
212 // memory (not GCed) on the stack accessible via StackSpaceOperand.
213 void EnterApiExitFrame(int arg_stack_space);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000214
ager@chromium.orga1645e22009-09-09 19:27:10 +0000215 // Leave the current exit frame. Expects/provides the return value in
216 // register rax:rdx (untouched) and the pointer to the first
217 // argument in register rsi.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000218 void LeaveExitFrame(bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000219
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000220 // Leave the current exit frame. Expects/provides the return value in
221 // register rax (untouched).
222 void LeaveApiExitFrame();
ager@chromium.org9085a012009-05-11 19:22:57 +0000223
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000224 // Push and pop the registers that can hold pointers.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000225 void PushSafepointRegisters() { Pushad(); }
226 void PopSafepointRegisters() { Popad(); }
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000227 // Store the value in register src in the safepoint register stack
228 // slot for register dst.
229 void StoreToSafepointRegisterSlot(Register dst, Register src);
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +0000230 void LoadFromSafepointRegisterSlot(Register dst, Register src);
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000231
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000232 void InitializeRootRegister() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000233 ExternalReference roots_address =
234 ExternalReference::roots_address(isolate());
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000235 movq(kRootRegister, roots_address);
236 addq(kRootRegister, Immediate(kRootRegisterBias));
237 }
238
ager@chromium.org9085a012009-05-11 19:22:57 +0000239 // ---------------------------------------------------------------------------
240 // JavaScript invokes
241
242 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000243 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000244 const ParameterCount& expected,
245 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000246 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000247 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000248
249 void InvokeCode(Handle<Code> code,
250 const ParameterCount& expected,
251 const ParameterCount& actual,
252 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000253 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000254 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000255
256 // Invoke the JavaScript function in the given register. Changes the
257 // current context to the context in the function before invoking.
258 void InvokeFunction(Register function,
259 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000260 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000261 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000262
ager@chromium.org5c838252010-02-19 08:53:10 +0000263 void InvokeFunction(JSFunction* function,
264 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000265 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000266 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org5c838252010-02-19 08:53:10 +0000267
ager@chromium.org9085a012009-05-11 19:22:57 +0000268 // Invoke specified builtin JavaScript function. Adds an entry to
269 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000270 void InvokeBuiltin(Builtins::JavaScript id,
271 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000272 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000273
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000274 // Store the function for the given builtin in the target register.
275 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
276
ager@chromium.org9085a012009-05-11 19:22:57 +0000277 // Store the code object for the given builtin in the target register.
278 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
279
ager@chromium.org4af710e2009-09-15 12:20:11 +0000280
281 // ---------------------------------------------------------------------------
282 // Smi tagging, untagging and operations on tagged smis.
283
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000284 void InitializeSmiConstantRegister() {
285 movq(kSmiConstantRegister,
286 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
287 RelocInfo::NONE);
288 }
289
ager@chromium.org4af710e2009-09-15 12:20:11 +0000290 // Conversions between tagged smi values and non-tagged integer values.
291
292 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000293 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000294 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000295 void Integer32ToSmi(Register dst, Register src);
296
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000297 // Stores an integer32 value into a memory field that already holds a smi.
298 void Integer32ToSmiField(const Operand& dst, Register src);
299
ager@chromium.org4af710e2009-09-15 12:20:11 +0000300 // Adds constant to src and tags the result as a smi.
301 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000302 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000303
304 // Convert smi to 32-bit integer. I.e., not sign extended into
305 // high 32 bits of destination.
306 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000307 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000308
309 // Convert smi to 64-bit integer (sign extended if necessary).
310 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000311 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000312
313 // Multiply a positive smi's integer value by a power of two.
314 // Provides result as 64-bit integer value.
315 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
316 Register src,
317 int power);
318
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000319 // Divide a positive smi's integer value by a power of two.
320 // Provides result as 32-bit integer value.
321 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
322 Register src,
323 int power);
324
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000325 // Perform the logical or of two smi values and return a smi value.
326 // If either argument is not a smi, jump to on_not_smis and retain
327 // the original values of source registers. The destination register
328 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000329 void SmiOrIfSmis(Register dst,
330 Register src1,
331 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000332 Label* on_not_smis,
333 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000334
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000335
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000336 // Simple comparison of smis. Both sides must be known smis to use these,
337 // otherwise use Cmp.
338 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000339 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000340 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000341 void SmiCompare(const Operand& dst, Register src);
342 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000343 // Compare the int32 in src register to the value of the smi stored at dst.
344 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000345 // Sets sign and zero flags depending on value of smi in register.
346 void SmiTest(Register src);
347
ager@chromium.org4af710e2009-09-15 12:20:11 +0000348 // Functions performing a check on a known or potential smi. Returns
349 // a condition that is satisfied if the check is successful.
350
351 // Is the value a tagged smi.
352 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000353 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000354
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000355 // Is the value a non-negative tagged smi.
356 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000357
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000358 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000359 Condition CheckBothSmi(Register first, Register second);
360
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000361 // Are both values non-negative tagged smis.
362 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000363
364 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000365 Condition CheckEitherSmi(Register first,
366 Register second,
367 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000368
ager@chromium.org4af710e2009-09-15 12:20:11 +0000369 // Is the value the minimum smi value (since we are using
370 // two's complement numbers, negating the value is known to yield
371 // a non-smi value).
372 Condition CheckIsMinSmi(Register src);
373
ager@chromium.org4af710e2009-09-15 12:20:11 +0000374 // Checks whether an 32-bit integer value is a valid for conversion
375 // to a smi.
376 Condition CheckInteger32ValidSmiValue(Register src);
377
ager@chromium.org3811b432009-10-28 14:53:37 +0000378 // Checks whether an 32-bit unsigned integer value is a valid for
379 // conversion to a smi.
380 Condition CheckUInteger32ValidSmiValue(Register src);
381
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000382 // Check whether src is a Smi, and set dst to zero if it is a smi,
383 // and to one if it isn't.
384 void CheckSmiToIndicator(Register dst, Register src);
385 void CheckSmiToIndicator(Register dst, const Operand& src);
386
ager@chromium.org4af710e2009-09-15 12:20:11 +0000387 // Test-and-jump functions. Typically combines a check function
388 // above with a conditional jump.
389
390 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000391 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
392 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000393
ager@chromium.org3811b432009-10-28 14:53:37 +0000394 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000395 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
396 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000397
ager@chromium.org4af710e2009-09-15 12:20:11 +0000398 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000399 void JumpIfSmi(Register src,
400 Label* on_smi,
401 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000402
403 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000404 void JumpIfNotSmi(Register src,
405 Label* on_not_smi,
406 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000407
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000408 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000409 void JumpUnlessNonNegativeSmi(Register src,
410 Label* on_not_smi,
411 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000412
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000413 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000414 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000415 void JumpIfSmiEqualsConstant(Register src,
416 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000417 Label* on_equals,
418 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000419
ager@chromium.org4af710e2009-09-15 12:20:11 +0000420 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000421 void JumpIfNotBothSmi(Register src1,
422 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000423 Label* on_not_both_smi,
424 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000425
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000426 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000427 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000428 Label* on_not_both_smi,
429 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000430
ager@chromium.org4af710e2009-09-15 12:20:11 +0000431 // Operations on tagged smi values.
432
433 // Smis represent a subset of integers. The subset is always equivalent to
434 // a two's complement interpretation of a fixed number of bits.
435
436 // Optimistically adds an integer constant to a supposed smi.
437 // If the src is not a smi, or the result is not a smi, jump to
438 // the label.
439 void SmiTryAddConstant(Register dst,
440 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000441 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000442 Label* on_not_smi_result,
443 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000444
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000445 // Add an integer constant to a tagged smi, giving a tagged smi as result.
446 // No overflow testing on the result is done.
447 void SmiAddConstant(Register dst, Register src, Smi* constant);
448
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000449 // Add an integer constant to a tagged smi, giving a tagged smi as result.
450 // No overflow testing on the result is done.
451 void SmiAddConstant(const Operand& dst, Smi* constant);
452
ager@chromium.org4af710e2009-09-15 12:20:11 +0000453 // Add an integer constant to a tagged smi, giving a tagged smi as result,
454 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000455 void SmiAddConstant(Register dst,
456 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000457 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000458 Label* on_not_smi_result,
459 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000460
461 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000462 // result. No testing on the result is done. Sets the N and Z flags
463 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000464 void SmiSubConstant(Register dst, Register src, Smi* constant);
465
466 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000467 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000468 void SmiSubConstant(Register dst,
469 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000470 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000471 Label* on_not_smi_result,
472 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000473
474 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000475 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000476 void SmiNeg(Register dst,
477 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000478 Label* on_smi_result,
479 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000480
481 // Adds smi values and return the result as a smi.
482 // If dst is src1, then src1 will be destroyed, even if
483 // the operation is unsuccessful.
484 void SmiAdd(Register dst,
485 Register src1,
486 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000487 Label* on_not_smi_result,
488 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000489 void SmiAdd(Register dst,
490 Register src1,
491 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000492 Label* on_not_smi_result,
493 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000494
495 void SmiAdd(Register dst,
496 Register src1,
497 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000498
499 // Subtracts smi values and return the result as a smi.
500 // If dst is src1, then src1 will be destroyed, even if
501 // the operation is unsuccessful.
502 void SmiSub(Register dst,
503 Register src1,
504 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000505 Label* on_not_smi_result,
506 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000507
ager@chromium.orgac091b72010-05-05 07:34:42 +0000508 void SmiSub(Register dst,
509 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000510 Register src2);
511
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000512 void SmiSub(Register dst,
513 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000514 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000515 Label* on_not_smi_result,
516 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000517
518 void SmiSub(Register dst,
519 Register src1,
520 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000521
ager@chromium.org4af710e2009-09-15 12:20:11 +0000522 // Multiplies smi values and return the result as a smi,
523 // if possible.
524 // If dst is src1, then src1 will be destroyed, even if
525 // the operation is unsuccessful.
526 void SmiMul(Register dst,
527 Register src1,
528 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000529 Label* on_not_smi_result,
530 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000531
532 // Divides one smi by another and returns the quotient.
533 // Clobbers rax and rdx registers.
534 void SmiDiv(Register dst,
535 Register src1,
536 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000537 Label* on_not_smi_result,
538 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000539
540 // Divides one smi by another and returns the remainder.
541 // Clobbers rax and rdx registers.
542 void SmiMod(Register dst,
543 Register src1,
544 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000545 Label* on_not_smi_result,
546 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000547
548 // Bitwise operations.
549 void SmiNot(Register dst, Register src);
550 void SmiAnd(Register dst, Register src1, Register src2);
551 void SmiOr(Register dst, Register src1, Register src2);
552 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000553 void SmiAndConstant(Register dst, Register src1, Smi* constant);
554 void SmiOrConstant(Register dst, Register src1, Smi* constant);
555 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000556
557 void SmiShiftLeftConstant(Register dst,
558 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000559 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000560 void SmiShiftLogicalRightConstant(Register dst,
561 Register src,
562 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000563 Label* on_not_smi_result,
564 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000565 void SmiShiftArithmeticRightConstant(Register dst,
566 Register src,
567 int shift_value);
568
569 // Shifts a smi value to the left, and returns the result if that is a smi.
570 // Uses and clobbers rcx, so dst may not be rcx.
571 void SmiShiftLeft(Register dst,
572 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000573 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000574 // Shifts a smi value to the right, shifting in zero bits at the top, and
575 // returns the unsigned intepretation of the result if that is a smi.
576 // Uses and clobbers rcx, so dst may not be rcx.
577 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000578 Register src1,
579 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000580 Label* on_not_smi_result,
581 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000582 // Shifts a smi value to the right, sign extending the top, and
583 // returns the signed intepretation of the result. That will always
584 // be a valid smi value, since it's numerically smaller than the
585 // original.
586 // Uses and clobbers rcx, so dst may not be rcx.
587 void SmiShiftArithmeticRight(Register dst,
588 Register src1,
589 Register src2);
590
591 // Specialized operations
592
593 // Select the non-smi register of two registers where exactly one is a
594 // smi. If neither are smis, jump to the failure label.
595 void SelectNonSmi(Register dst,
596 Register src1,
597 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000598 Label* on_not_smis,
599 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000600
601 // Converts, if necessary, a smi to a combination of number and
602 // multiplier to be used as a scaled index.
603 // The src register contains a *positive* smi value. The shift is the
604 // power of two to multiply the index value by (e.g.
605 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
606 // The returned index register may be either src or dst, depending
607 // on what is most efficient. If src and dst are different registers,
608 // src is always unchanged.
609 SmiIndex SmiToIndex(Register dst, Register src, int shift);
610
611 // Converts a positive smi to a negative index.
612 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
613
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000614 // Add the value of a smi in memory to an int32 register.
615 // Sets flags as a normal add.
616 void AddSmiField(Register dst, const Operand& src);
617
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000618 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000619 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000620 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000621 }
622
623 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000624 Register constant = GetSmiConstant(source);
625 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000626 }
627
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000628 void Push(Smi* smi);
629 void Test(const Operand& dst, Smi* source);
630
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000631 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000632 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000633
634 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000635 void JumpIfNotString(Register object,
636 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000637 Label* not_string,
638 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000639
640
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000641 void JumpIfNotBothSequentialAsciiStrings(
642 Register first_object,
643 Register second_object,
644 Register scratch1,
645 Register scratch2,
646 Label* on_not_both_flat_ascii,
647 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000648
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000649 // Check whether the instance type represents a flat ascii string. Jump to the
650 // label if not. If the instance type can be scratched specify same register
651 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000652 void JumpIfInstanceTypeIsNotSequentialAscii(
653 Register instance_type,
654 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000655 Label*on_not_flat_ascii_string,
656 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000657
658 void JumpIfBothInstanceTypesAreNotSequentialAscii(
659 Register first_object_instance_type,
660 Register second_object_instance_type,
661 Register scratch1,
662 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000663 Label* on_fail,
664 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000665
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000666 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000667 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000668
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000669 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000670 void Set(Register dst, int64_t x);
671 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000672
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000673 // Move if the registers are not identical.
674 void Move(Register target, Register source);
675
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000676 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000677 void Move(Register dst, Handle<Object> source);
678 void Move(const Operand& dst, Handle<Object> source);
679 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000680 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000681 void Cmp(Register dst, Smi* src);
682 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000683 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000684
685 // Emit code to discard a non-negative number of pointer-sized elements
686 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000687 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000688
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000689 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000690
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000691 // Control Flow
692 void Jump(Address destination, RelocInfo::Mode rmode);
693 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000694 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
695
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000696 void Call(Address destination, RelocInfo::Mode rmode);
697 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000698 void Call(Handle<Code> code_object,
699 RelocInfo::Mode rmode,
700 unsigned ast_id = kNoASTId);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000701
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000702 // The size of the code generated for different call instructions.
703 int CallSize(Address destination, RelocInfo::Mode rmode) {
704 return kCallInstructionLength;
705 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000706 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000707 int CallSize(Handle<Code> code_object) {
708 // Code calls use 32-bit relative addressing.
709 return kShortCallInstructionLength;
710 }
711 int CallSize(Register target) {
712 // Opcode: REX_opt FF /2 m64
713 return (target.high_bit() != 0) ? 3 : 2;
714 }
715 int CallSize(const Operand& target) {
716 // Opcode: REX_opt FF /2 m64
717 return (target.requires_rex() ? 2 : 1) + target.operand_size();
718 }
719
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000720 // Emit call to the code we are currently generating.
721 void CallSelf() {
722 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
723 Call(self, RelocInfo::CODE_TARGET);
724 }
725
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000726 // Non-x64 instructions.
727 // Push/pop all general purpose registers.
728 // Does not push rsp/rbp nor any of the assembler's special purpose registers
729 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
730 void Pushad();
731 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000732 // Sets the stack as after performing Popad, without actually loading the
733 // registers.
734 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000735
ager@chromium.org9085a012009-05-11 19:22:57 +0000736 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000737 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000738 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000739 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000740 void CmpObjectType(Register heap_object, InstanceType type, Register map);
741
742 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000743 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000744 void CmpInstanceType(Register map, InstanceType type);
745
ager@chromium.org5c838252010-02-19 08:53:10 +0000746 // Check if the map of an object is equal to a specified map and
747 // branch to label if not. Skip the smi check if not required
748 // (object is known to be a heap object)
749 void CheckMap(Register obj,
750 Handle<Map> map,
751 Label* fail,
752 bool is_heap_object);
753
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000754 // Check if the object in register heap_object is a string. Afterwards the
755 // register map contains the object map and the register instance_type
756 // contains the instance_type. The registers map and instance_type can be the
757 // same in which case it contains the instance type afterwards. Either of the
758 // registers map and instance_type can be the same as heap_object.
759 Condition IsObjectStringType(Register heap_object,
760 Register map,
761 Register instance_type);
762
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000763 // FCmp compares and pops the two values on top of the FPU stack.
764 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000765 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
766 void FCmp();
767
ager@chromium.org5c838252010-02-19 08:53:10 +0000768 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000769 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000770
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000771 // Abort execution if argument is a smi. Used in debug code.
772 void AbortIfSmi(Register object);
773
lrn@chromium.org25156de2010-04-06 13:10:27 +0000774 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000775 void AbortIfNotSmi(Register object);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000776 void AbortIfNotSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000777
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000778 // Abort execution if argument is a string. Used in debug code.
779 void AbortIfNotString(Register object);
780
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000781 // Abort execution if argument is not the root value with the given index.
782 void AbortIfNotRootValue(Register src,
783 Heap::RootListIndex root_value_index,
784 const char* message);
785
ager@chromium.org9085a012009-05-11 19:22:57 +0000786 // ---------------------------------------------------------------------------
787 // Exception handling
788
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000789 // Push a new try handler and link into try handler chain. The return
790 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000791 void PushTryHandler(CodeLocation try_location, HandlerType type);
792
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000793 // Unlink the stack handler on top of the stack from the try handler chain.
794 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000795
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000796 // Activate the top handler in the try hander chain and pass the
797 // thrown value.
798 void Throw(Register value);
799
800 // Propagate an uncatchable exception out of the current JS stack.
801 void ThrowUncatchable(UncatchableExceptionType type, Register value);
802
ager@chromium.org9085a012009-05-11 19:22:57 +0000803 // ---------------------------------------------------------------------------
804 // Inline caching support
805
ager@chromium.org9085a012009-05-11 19:22:57 +0000806 // Generate code for checking access rights - used for security checks
807 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000808 // is left untouched, but the scratch register and kScratchRegister,
809 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000810 void CheckAccessGlobalProxy(Register holder_reg,
811 Register scratch,
812 Label* miss);
813
814
815 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000816 // Allocation support
817
818 // Allocate an object in new space. If the new space is exhausted control
819 // continues at the gc_required label. The allocated object is returned in
820 // result and end of the new object is returned in result_end. The register
821 // scratch can be passed as no_reg in which case an additional object
822 // reference will be added to the reloc info. The returned pointers in result
823 // and result_end have not yet been tagged as heap objects. If
824 // result_contains_top_on_entry is true the content of result is known to be
825 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000826 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000827 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000828 void AllocateInNewSpace(int object_size,
829 Register result,
830 Register result_end,
831 Register scratch,
832 Label* gc_required,
833 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000834
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000835 void AllocateInNewSpace(int header_size,
836 ScaleFactor element_size,
837 Register element_count,
838 Register result,
839 Register result_end,
840 Register scratch,
841 Label* gc_required,
842 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000843
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000844 void AllocateInNewSpace(Register object_size,
845 Register result,
846 Register result_end,
847 Register scratch,
848 Label* gc_required,
849 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000850
851 // Undo allocation in new space. The object passed and objects allocated after
852 // it will no longer be allocated. Make sure that no pointers are left to the
853 // object(s) no longer allocated as they would be invalid when allocation is
854 // un-done.
855 void UndoAllocationInNewSpace(Register object);
856
ager@chromium.org3811b432009-10-28 14:53:37 +0000857 // Allocate a heap number in new space with undefined value. Returns
858 // tagged pointer in result register, or jumps to gc_required if new
859 // space is full.
860 void AllocateHeapNumber(Register result,
861 Register scratch,
862 Label* gc_required);
863
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000864 // Allocate a sequential string. All the header fields of the string object
865 // are initialized.
866 void AllocateTwoByteString(Register result,
867 Register length,
868 Register scratch1,
869 Register scratch2,
870 Register scratch3,
871 Label* gc_required);
872 void AllocateAsciiString(Register result,
873 Register length,
874 Register scratch1,
875 Register scratch2,
876 Register scratch3,
877 Label* gc_required);
878
879 // Allocate a raw cons string object. Only the map field of the result is
880 // initialized.
881 void AllocateConsString(Register result,
882 Register scratch1,
883 Register scratch2,
884 Label* gc_required);
885 void AllocateAsciiConsString(Register result,
886 Register scratch1,
887 Register scratch2,
888 Label* gc_required);
889
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000890 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000891 // Support functions.
892
893 // Check if result is zero and op is negative.
894 void NegativeZeroTest(Register result, Register op, Label* then_label);
895
896 // Check if result is zero and op is negative in code using jump targets.
897 void NegativeZeroTest(CodeGenerator* cgen,
898 Register result,
899 Register op,
900 JumpTarget* then_target);
901
902 // Check if result is zero and any of op1 and op2 are negative.
903 // Register scratch is destroyed, and it must be different from op2.
904 void NegativeZeroTest(Register result, Register op1, Register op2,
905 Register scratch, Label* then_label);
906
907 // Try to get function prototype of a function and puts the value in
908 // the result register. Checks that the function really is a
909 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000910 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000911 // clobbered.
912 void TryGetFunctionPrototype(Register function,
913 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000914 Label* miss);
915
916 // Generates code for reporting that an illegal operation has
917 // occurred.
918 void IllegalOperation(int num_arguments);
919
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000920 // Picks out an array index from the hash field.
921 // Register use:
922 // hash - holds the index's hash. Clobbered.
923 // index - holds the overwritten index on exit.
924 void IndexFromHash(Register hash, Register index);
925
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000926 // Find the function context up the context chain.
927 void LoadContext(Register dst, int context_chain_length);
928
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000929 // Load the global function with the given index.
930 void LoadGlobalFunction(int index, Register function);
931
932 // Load the initial map from the global function. The registers
933 // function and map can be the same.
934 void LoadGlobalFunctionInitialMap(Register function, Register map);
935
ager@chromium.org9085a012009-05-11 19:22:57 +0000936 // ---------------------------------------------------------------------------
937 // Runtime calls
938
939 // Call a code stub.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000940 void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId);
ager@chromium.org9085a012009-05-11 19:22:57 +0000941
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000942 // Call a code stub and return the code object called. Try to generate
943 // the code if necessary. Do not perform a GC but instead return a retry
944 // after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000945 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000946
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000947 // Tail call a code stub (jump).
948 void TailCallStub(CodeStub* stub);
949
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000950 // Tail call a code stub (jump) and return the code object called. Try to
951 // generate the code if necessary. Do not perform a GC but instead return
952 // a retry after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000953 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000954
ager@chromium.org9085a012009-05-11 19:22:57 +0000955 // Return from a code stub after popping its arguments.
956 void StubReturn(int argc);
957
958 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000959 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000960
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000961 // Call a runtime function and save the value of XMM registers.
962 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
963
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000964 // Call a runtime function, returning the CodeStub object called.
965 // Try to generate the stub code if necessary. Do not perform a GC
966 // but instead return a retry after GC failure.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000967 MUST_USE_RESULT MaybeObject* TryCallRuntime(const Runtime::Function* f,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000968 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000969
ager@chromium.org9085a012009-05-11 19:22:57 +0000970 // Convenience function: Same as above, but takes the fid instead.
971 void CallRuntime(Runtime::FunctionId id, int num_arguments);
972
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000973 // Convenience function: Same as above, but takes the fid instead.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000974 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
975 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000976
ager@chromium.org5c838252010-02-19 08:53:10 +0000977 // Convenience function: call an external reference.
978 void CallExternalReference(const ExternalReference& ext,
979 int num_arguments);
980
ager@chromium.org9085a012009-05-11 19:22:57 +0000981 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000982 // Like JumpToExternalReference, but also takes care of passing the number
983 // of parameters.
984 void TailCallExternalReference(const ExternalReference& ext,
985 int num_arguments,
986 int result_size);
987
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000988 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
989 const ExternalReference& ext, int num_arguments, int result_size);
990
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000991 // Convenience function: tail call a runtime routine (jump).
992 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000993 int num_arguments,
994 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000995
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000996 MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid,
997 int num_arguments,
998 int result_size);
999
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001000 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001001 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001002
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001003 // Jump to a runtime routine.
1004 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext,
1005 int result_size);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001006
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001007 // Prepares stack to put arguments (aligns and so on).
1008 // WIN64 calling convention requires to put the pointer to the return value
1009 // slot into rcx (rcx must be preserverd until TryCallApiFunctionAndReturn).
1010 // Saves context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
1011 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1012 void PrepareCallApiFunction(int arg_stack_space);
1013
1014 // Calls an API function. Allocates HandleScope, extracts
1015 // returned value from handle and propagates exceptions.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001016 // Clobbers r14, r15, rbx and caller-save registers. Restores context.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001017 // On return removes stack_space * kPointerSize (GCed).
1018 MUST_USE_RESULT MaybeObject* TryCallApiFunctionAndReturn(
1019 ApiFunction* function, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001020
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001021 // Before calling a C-function from generated code, align arguments on stack.
1022 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1023 // etc., not pushed. The argument count assumes all arguments are word sized.
1024 // The number of slots reserved for arguments depends on platform. On Windows
1025 // stack slots are reserved for the arguments passed in registers. On other
1026 // platforms stack slots are only reserved for the arguments actually passed
1027 // on the stack.
1028 void PrepareCallCFunction(int num_arguments);
1029
1030 // Calls a C function and cleans up the space for arguments allocated
1031 // by PrepareCallCFunction. The called function is not allowed to trigger a
1032 // garbage collection, since that might move the code and invalidate the
1033 // return address (unless this is somehow accounted for by the called
1034 // function).
1035 void CallCFunction(ExternalReference function, int num_arguments);
1036 void CallCFunction(Register function, int num_arguments);
1037
1038 // Calculate the number of stack slots to reserve for arguments when calling a
1039 // C function.
1040 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001041
1042 // ---------------------------------------------------------------------------
1043 // Utilities
1044
1045 void Ret();
1046
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001047 // Return and drop arguments from stack, where the number of arguments
1048 // may be bigger than 2^16 - 1. Requires a scratch register.
1049 void Ret(int bytes_dropped, Register scratch);
1050
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001051 Handle<Object> CodeObject() {
1052 ASSERT(!code_object_.is_null());
1053 return code_object_;
1054 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001055
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001056 // Copy length bytes from source to destination.
1057 // Uses scratch register internally (if you have a low-eight register
1058 // free, do use it, otherwise kScratchRegister will be used).
1059 // The min_length is a minimum limit on the value that length will have.
1060 // The algorithm has some special cases that might be omitted if the string
1061 // is known to always be long.
1062 void CopyBytes(Register destination,
1063 Register source,
1064 Register length,
1065 int min_length = 0,
1066 Register scratch = kScratchRegister);
1067
ager@chromium.org9085a012009-05-11 19:22:57 +00001068
1069 // ---------------------------------------------------------------------------
1070 // StatsCounter support
1071
1072 void SetCounter(StatsCounter* counter, int value);
1073 void IncrementCounter(StatsCounter* counter, int value);
1074 void DecrementCounter(StatsCounter* counter, int value);
1075
1076
1077 // ---------------------------------------------------------------------------
1078 // Debugging
1079
1080 // Calls Abort(msg) if the condition cc is not satisfied.
1081 // Use --debug_code to enable.
1082 void Assert(Condition cc, const char* msg);
1083
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001084 void AssertFastElements(Register elements);
1085
ager@chromium.org9085a012009-05-11 19:22:57 +00001086 // Like Assert(), but always enabled.
1087 void Check(Condition cc, const char* msg);
1088
1089 // Print a message to stdout and abort execution.
1090 void Abort(const char* msg);
1091
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001092 // Check that the stack is aligned.
1093 void CheckStackAlignment();
1094
ager@chromium.org9085a012009-05-11 19:22:57 +00001095 // Verify restrictions about code generated in stubs.
1096 void set_generating_stub(bool value) { generating_stub_ = value; }
1097 bool generating_stub() { return generating_stub_; }
1098 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1099 bool allow_stub_calls() { return allow_stub_calls_; }
1100
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001101 static int SafepointRegisterStackIndex(Register reg) {
1102 return SafepointRegisterStackIndex(reg.code());
1103 }
1104
ager@chromium.org9085a012009-05-11 19:22:57 +00001105 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001106 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001107 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001108 static int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001109 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001110 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001111
ager@chromium.org9085a012009-05-11 19:22:57 +00001112 bool generating_stub_;
1113 bool allow_stub_calls_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001114 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001115
1116 // Returns a register holding the smi value. The register MUST NOT be
1117 // modified. It may be the "smi 1 constant" register.
1118 Register GetSmiConstant(Smi* value);
1119
1120 // Moves the smi value to the destination register.
1121 void LoadSmiConstant(Register dst, Smi* value);
1122
ager@chromium.org5c838252010-02-19 08:53:10 +00001123 // This handle will be patched with the code object on installation.
1124 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001125
1126 // Helper functions for generating invokes.
1127 void InvokePrologue(const ParameterCount& expected,
1128 const ParameterCount& actual,
1129 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001130 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001131 Label* done,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001132 InvokeFlag flag,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001133 const CallWrapper& call_wrapper,
1134 Label::Distance near_jump = Label::kFar);
ager@chromium.org9085a012009-05-11 19:22:57 +00001135
ager@chromium.org9085a012009-05-11 19:22:57 +00001136 // Activation support.
1137 void EnterFrame(StackFrame::Type type);
1138 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001139
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001140 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001141
1142 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1143 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001144 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001145
1146 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001147
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001148 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001149 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001150 // Otherwise the address of the new-space top is loaded into scratch (if
1151 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001152 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001153 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001154 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001155 // Update allocation top with value in result_end register.
1156 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001157 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001158
1159 // Helper for PopHandleScope. Allowed to perform a GC and returns
1160 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1161 // possibly returns a failure object indicating an allocation failure.
1162 Object* PopHandleScopeHelper(Register saved,
1163 Register scratch,
1164 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001165
1166
1167 // Compute memory operands for safepoint stack slots.
1168 Operand SafepointRegisterSlot(Register reg);
1169 static int SafepointRegisterStackIndex(int reg_code) {
1170 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1171 }
1172
1173 // Needs access to SafepointRegisterStackIndex for optimized frame
1174 // traversal.
1175 friend class OptimizedFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001176};
1177
1178
ager@chromium.org4af710e2009-09-15 12:20:11 +00001179// The code patcher is used to patch (typically) small parts of code e.g. for
1180// debugging and other types of instrumentation. When using the code patcher
1181// the exact number of bytes specified must be emitted. Is not legal to emit
1182// relocation information. If any of these constraints are violated it causes
1183// an assertion.
1184class CodePatcher {
1185 public:
1186 CodePatcher(byte* address, int size);
1187 virtual ~CodePatcher();
1188
1189 // Macro assembler to emit code.
1190 MacroAssembler* masm() { return &masm_; }
1191
1192 private:
1193 byte* address_; // The address of the code being patched.
1194 int size_; // Number of bytes of the expected patch size.
1195 MacroAssembler masm_; // Macro assembler used to generate the code.
1196};
1197
1198
ager@chromium.org9085a012009-05-11 19:22:57 +00001199// -----------------------------------------------------------------------------
1200// Static helper functions.
1201
1202// Generate an Operand for loading a field from an object.
1203static inline Operand FieldOperand(Register object, int offset) {
1204 return Operand(object, offset - kHeapObjectTag);
1205}
1206
1207
1208// Generate an Operand for loading an indexed field from an object.
1209static inline Operand FieldOperand(Register object,
1210 Register index,
1211 ScaleFactor scale,
1212 int offset) {
1213 return Operand(object, index, scale, offset - kHeapObjectTag);
1214}
1215
1216
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001217static inline Operand ContextOperand(Register context, int index) {
1218 return Operand(context, Context::SlotOffset(index));
1219}
1220
1221
1222static inline Operand GlobalObjectOperand() {
1223 return ContextOperand(rsi, Context::GLOBAL_INDEX);
1224}
1225
1226
1227// Provides access to exit frame stack space (not GCed).
1228static inline Operand StackSpaceOperand(int index) {
1229#ifdef _WIN64
1230 const int kShaddowSpace = 4;
1231 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1232#else
1233 return Operand(rsp, index * kPointerSize);
1234#endif
1235}
1236
1237
1238
ager@chromium.org9085a012009-05-11 19:22:57 +00001239#ifdef GENERATED_CODE_COVERAGE
1240extern void LogGeneratedCodeCoverage(const char* file_line);
1241#define CODE_COVERAGE_STRINGIFY(x) #x
1242#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1243#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1244#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001245 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001246 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1247 masm->pushfd(); \
1248 masm->pushad(); \
1249 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001250 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001251 masm->pop(rax); \
1252 masm->popad(); \
1253 masm->popfd(); \
1254 } \
1255 masm->
1256#else
1257#define ACCESS_MASM(masm) masm->
1258#endif
1259
ager@chromium.org9085a012009-05-11 19:22:57 +00001260} } // namespace v8::internal
1261
1262#endif // V8_X64_MACRO_ASSEMBLER_X64_H_