blob: 0e46253af98e2ed67ffe80cee1548873d88fb701 [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"
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +000032#include "v8globals.h"
ager@chromium.org9085a012009-05-11 19:22:57 +000033
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
ager@chromium.org9085a012009-05-11 19:22:57 +000036
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +000037// Flags used for the AllocateInNewSpace functions.
38enum AllocationFlags {
39 // No special flags.
40 NO_ALLOCATION_FLAGS = 0,
41 // Return the pointer to the allocated already tagged as a heap object.
42 TAG_OBJECT = 1 << 0,
43 // The content of the result register already contains the allocation top in
44 // new space.
45 RESULT_CONTAINS_TOP = 1 << 1
46};
47
ager@chromium.orge2902be2009-06-08 12:21:35 +000048// Default scratch register used by MacroAssembler (and other code that needs
49// a spare register). The register isn't callee save, and not used by the
50// function calling convention.
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000051static const Register kScratchRegister = { 10 }; // r10.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +000052static const Register kSmiConstantRegister = { 12 }; // r12 (callee save).
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000053static const Register kRootRegister = { 13 }; // r13 (callee save).
54// Value of smi in kSmiConstantRegister.
55static const int kSmiConstantRegisterValue = 1;
karlklose@chromium.org8f806e82011-03-07 14:06:08 +000056// Actual value of root register is offset from the root array's start
57// to take advantage of negitive 8-bit displacement values.
58static const int kRootRegisterBias = 128;
ager@chromium.orge2902be2009-06-08 12:21:35 +000059
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000060// Convenience for platform-independent signatures.
61typedef Operand MemOperand;
62
ager@chromium.org9085a012009-05-11 19:22:57 +000063// Forward declaration.
64class JumpTarget;
65
ager@chromium.org4af710e2009-09-15 12:20:11 +000066struct SmiIndex {
67 SmiIndex(Register index_register, ScaleFactor scale)
68 : reg(index_register),
69 scale(scale) {}
70 Register reg;
71 ScaleFactor scale;
72};
ager@chromium.org9085a012009-05-11 19:22:57 +000073
ager@chromium.org9085a012009-05-11 19:22:57 +000074// MacroAssembler implements a collection of frequently used macros.
75class MacroAssembler: public Assembler {
76 public:
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +000077 // The isolate parameter can be NULL if the macro assembler should
78 // not use isolate-dependent functionality. In this case, it's the
79 // responsibility of the caller to never invoke such function on the
80 // macro assembler.
81 MacroAssembler(Isolate* isolate, void* buffer, int size);
ager@chromium.org9085a012009-05-11 19:22:57 +000082
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000083 // Prevent the use of the RootArray during the lifetime of this
84 // scope object.
85 class NoRootArrayScope BASE_EMBEDDED {
86 public:
87 explicit NoRootArrayScope(MacroAssembler* assembler)
88 : variable_(&assembler->root_array_available_),
89 old_value_(assembler->root_array_available_) {
90 assembler->root_array_available_ = false;
91 }
92 ~NoRootArrayScope() {
93 *variable_ = old_value_;
94 }
95 private:
96 bool* variable_;
97 bool old_value_;
98 };
99
100 // Operand pointing to an external reference.
101 // May emit code to set up the scratch register. The operand is
102 // only guaranteed to be correct as long as the scratch register
103 // isn't changed.
104 // If the operand is used more than once, use a scratch register
105 // that is guaranteed not to be clobbered.
106 Operand ExternalOperand(ExternalReference reference,
107 Register scratch = kScratchRegister);
108 // Loads and stores the value of an external reference.
109 // Special case code for load and store to take advantage of
110 // load_rax/store_rax if possible/necessary.
111 // For other operations, just use:
112 // Operand operand = ExternalOperand(extref);
113 // operation(operand, ..);
114 void Load(Register destination, ExternalReference source);
115 void Store(ExternalReference destination, Register source);
116 // Loads the address of the external reference into the destination
117 // register.
118 void LoadAddress(Register destination, ExternalReference source);
119 // Returns the size of the code generated by LoadAddress.
120 // Used by CallSize(ExternalReference) to find the size of a call.
121 int LoadAddressSize(ExternalReference source);
122
123 // Operations on roots in the root-array.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000124 void LoadRoot(Register destination, Heap::RootListIndex index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000125 void StoreRoot(Register source, Heap::RootListIndex index);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000126 // Load a root value where the index (or part of it) is variable.
127 // The variable_offset register is added to the fixed_offset value
128 // to get the index into the root-array.
129 void LoadRootIndexed(Register destination,
130 Register variable_offset,
131 int fixed_offset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000132 void CompareRoot(Register with, Heap::RootListIndex index);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000133 void CompareRoot(const Operand& with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000134 void PushRoot(Heap::RootListIndex index);
135
ager@chromium.org9085a012009-05-11 19:22:57 +0000136 // ---------------------------------------------------------------------------
137 // GC Support
138
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000139 // For page containing |object| mark region covering |addr| dirty.
140 // RecordWriteHelper only works if the object is not in new
ager@chromium.orgac091b72010-05-05 07:34:42 +0000141 // space.
142 void RecordWriteHelper(Register object,
143 Register addr,
144 Register scratch);
145
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000146 // Check if object is in new space. The condition cc can be equal or
147 // not_equal. If it is equal a jump will be done if the object is on new
148 // space. The register scratch can be object itself, but it will be clobbered.
149 void InNewSpace(Register object,
150 Register scratch,
151 Condition cc,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000152 Label* branch,
153 Label::Distance near_jump = Label::kFar);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000154
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000155 // For page containing |object| mark region covering [object+offset]
156 // dirty. |object| is the object being stored into, |value| is the
157 // object being stored. If |offset| is zero, then the |scratch|
158 // register contains the array index into the elements array
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000159 // represented as an untagged 32-bit integer. All registers are
160 // clobbered by the operation. RecordWrite filters out smis so it
161 // does not update the write barrier if the value is a smi.
ager@chromium.org9085a012009-05-11 19:22:57 +0000162 void RecordWrite(Register object,
163 int offset,
164 Register value,
165 Register scratch);
166
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000167 // For page containing |object| mark region covering [address]
168 // dirty. |object| is the object being stored into, |value| is the
169 // object being stored. All registers are clobbered by the
170 // operation. RecordWrite filters out smis so it does not update
171 // the write barrier if the value is a smi.
172 void RecordWrite(Register object,
173 Register address,
174 Register value);
175
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000176 // For page containing |object| mark region covering [object+offset] dirty.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000177 // The value is known to not be a smi.
178 // object is the object being stored into, value is the object being stored.
179 // If offset is zero, then the scratch register contains the array index into
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000180 // the elements array represented as an untagged 32-bit integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000181 // All registers are clobbered by the operation.
182 void RecordWriteNonSmi(Register object,
183 int offset,
184 Register value,
185 Register scratch);
186
ager@chromium.org9085a012009-05-11 19:22:57 +0000187#ifdef ENABLE_DEBUGGER_SUPPORT
188 // ---------------------------------------------------------------------------
189 // Debugger Support
190
ager@chromium.org5c838252010-02-19 08:53:10 +0000191 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000192#endif
193
194 // ---------------------------------------------------------------------------
195 // Activation frames
196
197 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
198 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
199
200 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
201 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
202
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000203 // Enter specific kind of exit frame; either in normal or
204 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000205 // sets up the number of arguments in register rdi and the pointer
206 // to the first argument in register rsi.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000207 //
208 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
209 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000210 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000211
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000212 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
213 // memory (not GCed) on the stack accessible via StackSpaceOperand.
214 void EnterApiExitFrame(int arg_stack_space);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000215
ager@chromium.orga1645e22009-09-09 19:27:10 +0000216 // Leave the current exit frame. Expects/provides the return value in
217 // register rax:rdx (untouched) and the pointer to the first
218 // argument in register rsi.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000219 void LeaveExitFrame(bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000220
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000221 // Leave the current exit frame. Expects/provides the return value in
222 // register rax (untouched).
223 void LeaveApiExitFrame();
ager@chromium.org9085a012009-05-11 19:22:57 +0000224
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000225 // Push and pop the registers that can hold pointers.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000226 void PushSafepointRegisters() { Pushad(); }
227 void PopSafepointRegisters() { Popad(); }
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000228 // Store the value in register src in the safepoint register stack
229 // slot for register dst.
230 void StoreToSafepointRegisterSlot(Register dst, Register src);
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +0000231 void LoadFromSafepointRegisterSlot(Register dst, Register src);
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000232
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000233 void InitializeRootRegister() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000234 ExternalReference roots_address =
235 ExternalReference::roots_address(isolate());
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000236 movq(kRootRegister, roots_address);
237 addq(kRootRegister, Immediate(kRootRegisterBias));
238 }
239
ager@chromium.org9085a012009-05-11 19:22:57 +0000240 // ---------------------------------------------------------------------------
241 // JavaScript invokes
242
243 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000244 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000245 const ParameterCount& expected,
246 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000247 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000248 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000249
250 void InvokeCode(Handle<Code> code,
251 const ParameterCount& expected,
252 const ParameterCount& actual,
253 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000254 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000255 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000256
257 // Invoke the JavaScript function in the given register. Changes the
258 // current context to the context in the function before invoking.
259 void InvokeFunction(Register function,
260 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000261 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000262 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000263
ager@chromium.org5c838252010-02-19 08:53:10 +0000264 void InvokeFunction(JSFunction* function,
265 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000266 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000267 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org5c838252010-02-19 08:53:10 +0000268
ager@chromium.org9085a012009-05-11 19:22:57 +0000269 // Invoke specified builtin JavaScript function. Adds an entry to
270 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000271 void InvokeBuiltin(Builtins::JavaScript id,
272 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000273 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000274
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000275 // Store the function for the given builtin in the target register.
276 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
277
ager@chromium.org9085a012009-05-11 19:22:57 +0000278 // Store the code object for the given builtin in the target register.
279 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
280
ager@chromium.org4af710e2009-09-15 12:20:11 +0000281
282 // ---------------------------------------------------------------------------
283 // Smi tagging, untagging and operations on tagged smis.
284
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000285 void InitializeSmiConstantRegister() {
286 movq(kSmiConstantRegister,
287 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
288 RelocInfo::NONE);
289 }
290
ager@chromium.org4af710e2009-09-15 12:20:11 +0000291 // Conversions between tagged smi values and non-tagged integer values.
292
293 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000294 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000295 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000296 void Integer32ToSmi(Register dst, Register src);
297
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000298 // Stores an integer32 value into a memory field that already holds a smi.
299 void Integer32ToSmiField(const Operand& dst, Register src);
300
ager@chromium.org4af710e2009-09-15 12:20:11 +0000301 // Adds constant to src and tags the result as a smi.
302 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000303 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000304
305 // Convert smi to 32-bit integer. I.e., not sign extended into
306 // high 32 bits of destination.
307 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000308 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000309
310 // Convert smi to 64-bit integer (sign extended if necessary).
311 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000312 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000313
314 // Multiply a positive smi's integer value by a power of two.
315 // Provides result as 64-bit integer value.
316 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
317 Register src,
318 int power);
319
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000320 // Divide a positive smi's integer value by a power of two.
321 // Provides result as 32-bit integer value.
322 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
323 Register src,
324 int power);
325
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000326 // Perform the logical or of two smi values and return a smi value.
327 // If either argument is not a smi, jump to on_not_smis and retain
328 // the original values of source registers. The destination register
329 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000330 void SmiOrIfSmis(Register dst,
331 Register src1,
332 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000333 Label* on_not_smis,
334 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000335
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000336
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000337 // Simple comparison of smis. Both sides must be known smis to use these,
338 // otherwise use Cmp.
339 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000340 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000341 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000342 void SmiCompare(const Operand& dst, Register src);
343 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000344 // Compare the int32 in src register to the value of the smi stored at dst.
345 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000346 // Sets sign and zero flags depending on value of smi in register.
347 void SmiTest(Register src);
348
ager@chromium.org4af710e2009-09-15 12:20:11 +0000349 // Functions performing a check on a known or potential smi. Returns
350 // a condition that is satisfied if the check is successful.
351
352 // Is the value a tagged smi.
353 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000354 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000355
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000356 // Is the value a non-negative tagged smi.
357 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000358
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000359 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000360 Condition CheckBothSmi(Register first, Register second);
361
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000362 // Are both values non-negative tagged smis.
363 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000364
365 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000366 Condition CheckEitherSmi(Register first,
367 Register second,
368 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000369
ager@chromium.org4af710e2009-09-15 12:20:11 +0000370 // Is the value the minimum smi value (since we are using
371 // two's complement numbers, negating the value is known to yield
372 // a non-smi value).
373 Condition CheckIsMinSmi(Register src);
374
ager@chromium.org4af710e2009-09-15 12:20:11 +0000375 // Checks whether an 32-bit integer value is a valid for conversion
376 // to a smi.
377 Condition CheckInteger32ValidSmiValue(Register src);
378
ager@chromium.org3811b432009-10-28 14:53:37 +0000379 // Checks whether an 32-bit unsigned integer value is a valid for
380 // conversion to a smi.
381 Condition CheckUInteger32ValidSmiValue(Register src);
382
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000383 // Check whether src is a Smi, and set dst to zero if it is a smi,
384 // and to one if it isn't.
385 void CheckSmiToIndicator(Register dst, Register src);
386 void CheckSmiToIndicator(Register dst, const Operand& src);
387
ager@chromium.org4af710e2009-09-15 12:20:11 +0000388 // Test-and-jump functions. Typically combines a check function
389 // above with a conditional jump.
390
391 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000392 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
393 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000394
ager@chromium.org3811b432009-10-28 14:53:37 +0000395 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000396 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
397 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000398
ager@chromium.org4af710e2009-09-15 12:20:11 +0000399 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000400 void JumpIfSmi(Register src,
401 Label* on_smi,
402 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000403
404 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000405 void JumpIfNotSmi(Register src,
406 Label* on_not_smi,
407 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000408
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000409 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000410 void JumpUnlessNonNegativeSmi(Register src,
411 Label* on_not_smi,
412 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000413
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000414 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000415 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000416 void JumpIfSmiEqualsConstant(Register src,
417 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000418 Label* on_equals,
419 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000420
ager@chromium.org4af710e2009-09-15 12:20:11 +0000421 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000422 void JumpIfNotBothSmi(Register src1,
423 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000424 Label* on_not_both_smi,
425 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000426
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000427 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000428 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000429 Label* on_not_both_smi,
430 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000431
ager@chromium.org4af710e2009-09-15 12:20:11 +0000432 // Operations on tagged smi values.
433
434 // Smis represent a subset of integers. The subset is always equivalent to
435 // a two's complement interpretation of a fixed number of bits.
436
437 // Optimistically adds an integer constant to a supposed smi.
438 // If the src is not a smi, or the result is not a smi, jump to
439 // the label.
440 void SmiTryAddConstant(Register dst,
441 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000442 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000443 Label* on_not_smi_result,
444 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000445
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000446 // Add an integer constant to a tagged smi, giving a tagged smi as result.
447 // No overflow testing on the result is done.
448 void SmiAddConstant(Register dst, Register src, Smi* constant);
449
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000450 // Add an integer constant to a tagged smi, giving a tagged smi as result.
451 // No overflow testing on the result is done.
452 void SmiAddConstant(const Operand& dst, Smi* constant);
453
ager@chromium.org4af710e2009-09-15 12:20:11 +0000454 // Add an integer constant to a tagged smi, giving a tagged smi as result,
455 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000456 void SmiAddConstant(Register dst,
457 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000458 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000459 Label* on_not_smi_result,
460 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000461
462 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000463 // result. No testing on the result is done. Sets the N and Z flags
464 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000465 void SmiSubConstant(Register dst, Register src, Smi* constant);
466
467 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000468 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000469 void SmiSubConstant(Register dst,
470 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000471 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000472 Label* on_not_smi_result,
473 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000474
475 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000476 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000477 void SmiNeg(Register dst,
478 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000479 Label* on_smi_result,
480 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000481
482 // Adds smi values and return the result as a smi.
483 // If dst is src1, then src1 will be destroyed, even if
484 // the operation is unsuccessful.
485 void SmiAdd(Register dst,
486 Register src1,
487 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000488 Label* on_not_smi_result,
489 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000490 void SmiAdd(Register dst,
491 Register src1,
492 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000493 Label* on_not_smi_result,
494 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000495
496 void SmiAdd(Register dst,
497 Register src1,
498 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000499
500 // Subtracts smi values and return the result as a smi.
501 // If dst is src1, then src1 will be destroyed, even if
502 // the operation is unsuccessful.
503 void SmiSub(Register dst,
504 Register src1,
505 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000506 Label* on_not_smi_result,
507 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000508
ager@chromium.orgac091b72010-05-05 07:34:42 +0000509 void SmiSub(Register dst,
510 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000511 Register src2);
512
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000513 void SmiSub(Register dst,
514 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000515 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000516 Label* on_not_smi_result,
517 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000518
519 void SmiSub(Register dst,
520 Register src1,
521 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000522
ager@chromium.org4af710e2009-09-15 12:20:11 +0000523 // Multiplies smi values and return the result as a smi,
524 // if possible.
525 // If dst is src1, then src1 will be destroyed, even if
526 // the operation is unsuccessful.
527 void SmiMul(Register dst,
528 Register src1,
529 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000530 Label* on_not_smi_result,
531 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000532
533 // Divides one smi by another and returns the quotient.
534 // Clobbers rax and rdx registers.
535 void SmiDiv(Register dst,
536 Register src1,
537 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000538 Label* on_not_smi_result,
539 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000540
541 // Divides one smi by another and returns the remainder.
542 // Clobbers rax and rdx registers.
543 void SmiMod(Register dst,
544 Register src1,
545 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000546 Label* on_not_smi_result,
547 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000548
549 // Bitwise operations.
550 void SmiNot(Register dst, Register src);
551 void SmiAnd(Register dst, Register src1, Register src2);
552 void SmiOr(Register dst, Register src1, Register src2);
553 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000554 void SmiAndConstant(Register dst, Register src1, Smi* constant);
555 void SmiOrConstant(Register dst, Register src1, Smi* constant);
556 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000557
558 void SmiShiftLeftConstant(Register dst,
559 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000560 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000561 void SmiShiftLogicalRightConstant(Register dst,
562 Register src,
563 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000564 Label* on_not_smi_result,
565 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000566 void SmiShiftArithmeticRightConstant(Register dst,
567 Register src,
568 int shift_value);
569
570 // Shifts a smi value to the left, and returns the result if that is a smi.
571 // Uses and clobbers rcx, so dst may not be rcx.
572 void SmiShiftLeft(Register dst,
573 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000574 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000575 // Shifts a smi value to the right, shifting in zero bits at the top, and
576 // returns the unsigned intepretation of the result if that is a smi.
577 // Uses and clobbers rcx, so dst may not be rcx.
578 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000579 Register src1,
580 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000581 Label* on_not_smi_result,
582 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000583 // Shifts a smi value to the right, sign extending the top, and
584 // returns the signed intepretation of the result. That will always
585 // be a valid smi value, since it's numerically smaller than the
586 // original.
587 // Uses and clobbers rcx, so dst may not be rcx.
588 void SmiShiftArithmeticRight(Register dst,
589 Register src1,
590 Register src2);
591
592 // Specialized operations
593
594 // Select the non-smi register of two registers where exactly one is a
595 // smi. If neither are smis, jump to the failure label.
596 void SelectNonSmi(Register dst,
597 Register src1,
598 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000599 Label* on_not_smis,
600 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000601
602 // Converts, if necessary, a smi to a combination of number and
603 // multiplier to be used as a scaled index.
604 // The src register contains a *positive* smi value. The shift is the
605 // power of two to multiply the index value by (e.g.
606 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
607 // The returned index register may be either src or dst, depending
608 // on what is most efficient. If src and dst are different registers,
609 // src is always unchanged.
610 SmiIndex SmiToIndex(Register dst, Register src, int shift);
611
612 // Converts a positive smi to a negative index.
613 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
614
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000615 // Add the value of a smi in memory to an int32 register.
616 // Sets flags as a normal add.
617 void AddSmiField(Register dst, const Operand& src);
618
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000619 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000620 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000621 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000622 }
623
624 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000625 Register constant = GetSmiConstant(source);
626 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000627 }
628
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000629 void Push(Smi* smi);
630 void Test(const Operand& dst, Smi* source);
631
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000632 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000633 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000634
635 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000636 void JumpIfNotString(Register object,
637 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000638 Label* not_string,
639 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000640
641
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000642 void JumpIfNotBothSequentialAsciiStrings(
643 Register first_object,
644 Register second_object,
645 Register scratch1,
646 Register scratch2,
647 Label* on_not_both_flat_ascii,
648 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000649
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000650 // Check whether the instance type represents a flat ascii string. Jump to the
651 // label if not. If the instance type can be scratched specify same register
652 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000653 void JumpIfInstanceTypeIsNotSequentialAscii(
654 Register instance_type,
655 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000656 Label*on_not_flat_ascii_string,
657 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000658
659 void JumpIfBothInstanceTypesAreNotSequentialAscii(
660 Register first_object_instance_type,
661 Register second_object_instance_type,
662 Register scratch1,
663 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000664 Label* on_fail,
665 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000666
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000667 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000668 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000669
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000670 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000671 void Set(Register dst, int64_t x);
672 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000673
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000674 // Move if the registers are not identical.
675 void Move(Register target, Register source);
676
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000677 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000678 void Move(Register dst, Handle<Object> source);
679 void Move(const Operand& dst, Handle<Object> source);
680 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000681 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000682 void Cmp(Register dst, Smi* src);
683 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000684 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000685
686 // Emit code to discard a non-negative number of pointer-sized elements
687 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000688 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000689
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000690 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000691
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000692 // Control Flow
693 void Jump(Address destination, RelocInfo::Mode rmode);
694 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000695 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
696
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000697 void Call(Address destination, RelocInfo::Mode rmode);
698 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000699 void Call(Handle<Code> code_object,
700 RelocInfo::Mode rmode,
701 unsigned ast_id = kNoASTId);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000702
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000703 // The size of the code generated for different call instructions.
704 int CallSize(Address destination, RelocInfo::Mode rmode) {
705 return kCallInstructionLength;
706 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000707 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000708 int CallSize(Handle<Code> code_object) {
709 // Code calls use 32-bit relative addressing.
710 return kShortCallInstructionLength;
711 }
712 int CallSize(Register target) {
713 // Opcode: REX_opt FF /2 m64
714 return (target.high_bit() != 0) ? 3 : 2;
715 }
716 int CallSize(const Operand& target) {
717 // Opcode: REX_opt FF /2 m64
718 return (target.requires_rex() ? 2 : 1) + target.operand_size();
719 }
720
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000721 // Emit call to the code we are currently generating.
722 void CallSelf() {
723 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
724 Call(self, RelocInfo::CODE_TARGET);
725 }
726
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000727 // Non-x64 instructions.
728 // Push/pop all general purpose registers.
729 // Does not push rsp/rbp nor any of the assembler's special purpose registers
730 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
731 void Pushad();
732 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000733 // Sets the stack as after performing Popad, without actually loading the
734 // registers.
735 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000736
ager@chromium.org9085a012009-05-11 19:22:57 +0000737 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000738 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000739 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000740 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000741 void CmpObjectType(Register heap_object, InstanceType type, Register map);
742
743 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000744 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000745 void CmpInstanceType(Register map, InstanceType type);
746
ager@chromium.org5c838252010-02-19 08:53:10 +0000747 // Check if the map of an object is equal to a specified map and
748 // branch to label if not. Skip the smi check if not required
749 // (object is known to be a heap object)
750 void CheckMap(Register obj,
751 Handle<Map> map,
752 Label* fail,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000753 SmiCheckType smi_check_type);
ager@chromium.org5c838252010-02-19 08:53:10 +0000754
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000755 // Check if the object in register heap_object is a string. Afterwards the
756 // register map contains the object map and the register instance_type
757 // contains the instance_type. The registers map and instance_type can be the
758 // same in which case it contains the instance type afterwards. Either of the
759 // registers map and instance_type can be the same as heap_object.
760 Condition IsObjectStringType(Register heap_object,
761 Register map,
762 Register instance_type);
763
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000764 // FCmp compares and pops the two values on top of the FPU stack.
765 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000766 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
767 void FCmp();
768
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000769 void ClampUint8(Register reg);
770
771 void ClampDoubleToUint8(XMMRegister input_reg,
772 XMMRegister temp_xmm_reg,
773 Register result_reg,
774 Register temp_reg);
775
ager@chromium.org5c838252010-02-19 08:53:10 +0000776 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000777 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000778
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000779 // Abort execution if argument is a smi. Used in debug code.
780 void AbortIfSmi(Register object);
781
lrn@chromium.org25156de2010-04-06 13:10:27 +0000782 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000783 void AbortIfNotSmi(Register object);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000784 void AbortIfNotSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000785
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000786 // Abort execution if argument is a string. Used in debug code.
787 void AbortIfNotString(Register object);
788
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000789 // Abort execution if argument is not the root value with the given index.
790 void AbortIfNotRootValue(Register src,
791 Heap::RootListIndex root_value_index,
792 const char* message);
793
ager@chromium.org9085a012009-05-11 19:22:57 +0000794 // ---------------------------------------------------------------------------
795 // Exception handling
796
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000797 // Push a new try handler and link into try handler chain. The return
798 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000799 void PushTryHandler(CodeLocation try_location, HandlerType type);
800
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000801 // Unlink the stack handler on top of the stack from the try handler chain.
802 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000803
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000804 // Activate the top handler in the try hander chain and pass the
805 // thrown value.
806 void Throw(Register value);
807
808 // Propagate an uncatchable exception out of the current JS stack.
809 void ThrowUncatchable(UncatchableExceptionType type, Register value);
810
ager@chromium.org9085a012009-05-11 19:22:57 +0000811 // ---------------------------------------------------------------------------
812 // Inline caching support
813
ager@chromium.org9085a012009-05-11 19:22:57 +0000814 // Generate code for checking access rights - used for security checks
815 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000816 // is left untouched, but the scratch register and kScratchRegister,
817 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000818 void CheckAccessGlobalProxy(Register holder_reg,
819 Register scratch,
820 Label* miss);
821
822
823 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000824 // Allocation support
825
826 // Allocate an object in new space. If the new space is exhausted control
827 // continues at the gc_required label. The allocated object is returned in
828 // result and end of the new object is returned in result_end. The register
829 // scratch can be passed as no_reg in which case an additional object
830 // reference will be added to the reloc info. The returned pointers in result
831 // and result_end have not yet been tagged as heap objects. If
832 // result_contains_top_on_entry is true the content of result is known to be
833 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000834 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000835 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000836 void AllocateInNewSpace(int object_size,
837 Register result,
838 Register result_end,
839 Register scratch,
840 Label* gc_required,
841 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000842
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000843 void AllocateInNewSpace(int header_size,
844 ScaleFactor element_size,
845 Register element_count,
846 Register result,
847 Register result_end,
848 Register scratch,
849 Label* gc_required,
850 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000851
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000852 void AllocateInNewSpace(Register object_size,
853 Register result,
854 Register result_end,
855 Register scratch,
856 Label* gc_required,
857 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000858
859 // Undo allocation in new space. The object passed and objects allocated after
860 // it will no longer be allocated. Make sure that no pointers are left to the
861 // object(s) no longer allocated as they would be invalid when allocation is
862 // un-done.
863 void UndoAllocationInNewSpace(Register object);
864
ager@chromium.org3811b432009-10-28 14:53:37 +0000865 // Allocate a heap number in new space with undefined value. Returns
866 // tagged pointer in result register, or jumps to gc_required if new
867 // space is full.
868 void AllocateHeapNumber(Register result,
869 Register scratch,
870 Label* gc_required);
871
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000872 // Allocate a sequential string. All the header fields of the string object
873 // are initialized.
874 void AllocateTwoByteString(Register result,
875 Register length,
876 Register scratch1,
877 Register scratch2,
878 Register scratch3,
879 Label* gc_required);
880 void AllocateAsciiString(Register result,
881 Register length,
882 Register scratch1,
883 Register scratch2,
884 Register scratch3,
885 Label* gc_required);
886
887 // Allocate a raw cons string object. Only the map field of the result is
888 // initialized.
889 void AllocateConsString(Register result,
890 Register scratch1,
891 Register scratch2,
892 Label* gc_required);
893 void AllocateAsciiConsString(Register result,
894 Register scratch1,
895 Register scratch2,
896 Label* gc_required);
897
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000898 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000899 // Support functions.
900
901 // Check if result is zero and op is negative.
902 void NegativeZeroTest(Register result, Register op, Label* then_label);
903
904 // Check if result is zero and op is negative in code using jump targets.
905 void NegativeZeroTest(CodeGenerator* cgen,
906 Register result,
907 Register op,
908 JumpTarget* then_target);
909
910 // Check if result is zero and any of op1 and op2 are negative.
911 // Register scratch is destroyed, and it must be different from op2.
912 void NegativeZeroTest(Register result, Register op1, Register op2,
913 Register scratch, Label* then_label);
914
915 // Try to get function prototype of a function and puts the value in
916 // the result register. Checks that the function really is a
917 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000918 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000919 // clobbered.
920 void TryGetFunctionPrototype(Register function,
921 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000922 Label* miss);
923
924 // Generates code for reporting that an illegal operation has
925 // occurred.
926 void IllegalOperation(int num_arguments);
927
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000928 // Picks out an array index from the hash field.
929 // Register use:
930 // hash - holds the index's hash. Clobbered.
931 // index - holds the overwritten index on exit.
932 void IndexFromHash(Register hash, Register index);
933
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000934 // Find the function context up the context chain.
935 void LoadContext(Register dst, int context_chain_length);
936
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000937 // Load the global function with the given index.
938 void LoadGlobalFunction(int index, Register function);
939
940 // Load the initial map from the global function. The registers
941 // function and map can be the same.
942 void LoadGlobalFunctionInitialMap(Register function, Register map);
943
ager@chromium.org9085a012009-05-11 19:22:57 +0000944 // ---------------------------------------------------------------------------
945 // Runtime calls
946
947 // Call a code stub.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000948 void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId);
ager@chromium.org9085a012009-05-11 19:22:57 +0000949
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000950 // Call a code stub and return the code object called. Try to generate
951 // the code if necessary. Do not perform a GC but instead return a retry
952 // after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000953 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000954
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000955 // Tail call a code stub (jump).
956 void TailCallStub(CodeStub* stub);
957
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000958 // Tail call a code stub (jump) and return the code object called. Try to
959 // generate the code if necessary. Do not perform a GC but instead return
960 // a retry after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000961 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000962
ager@chromium.org9085a012009-05-11 19:22:57 +0000963 // Return from a code stub after popping its arguments.
964 void StubReturn(int argc);
965
966 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000967 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000968
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000969 // Call a runtime function and save the value of XMM registers.
970 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
971
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000972 // Call a runtime function, returning the CodeStub object called.
973 // Try to generate the stub code if necessary. Do not perform a GC
974 // but instead return a retry after GC failure.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000975 MUST_USE_RESULT MaybeObject* TryCallRuntime(const Runtime::Function* f,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000976 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000977
ager@chromium.org9085a012009-05-11 19:22:57 +0000978 // Convenience function: Same as above, but takes the fid instead.
979 void CallRuntime(Runtime::FunctionId id, int num_arguments);
980
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000981 // Convenience function: Same as above, but takes the fid instead.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000982 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
983 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000984
ager@chromium.org5c838252010-02-19 08:53:10 +0000985 // Convenience function: call an external reference.
986 void CallExternalReference(const ExternalReference& ext,
987 int num_arguments);
988
ager@chromium.org9085a012009-05-11 19:22:57 +0000989 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000990 // Like JumpToExternalReference, but also takes care of passing the number
991 // of parameters.
992 void TailCallExternalReference(const ExternalReference& ext,
993 int num_arguments,
994 int result_size);
995
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000996 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
997 const ExternalReference& ext, int num_arguments, int result_size);
998
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000999 // Convenience function: tail call a runtime routine (jump).
1000 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001001 int num_arguments,
1002 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001003
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001004 MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid,
1005 int num_arguments,
1006 int result_size);
1007
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001008 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001009 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001010
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001011 // Jump to a runtime routine.
1012 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext,
1013 int result_size);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001014
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001015 // Prepares stack to put arguments (aligns and so on).
1016 // WIN64 calling convention requires to put the pointer to the return value
1017 // slot into rcx (rcx must be preserverd until TryCallApiFunctionAndReturn).
1018 // Saves context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
1019 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1020 void PrepareCallApiFunction(int arg_stack_space);
1021
1022 // Calls an API function. Allocates HandleScope, extracts
1023 // returned value from handle and propagates exceptions.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001024 // Clobbers r14, r15, rbx and caller-save registers. Restores context.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001025 // On return removes stack_space * kPointerSize (GCed).
1026 MUST_USE_RESULT MaybeObject* TryCallApiFunctionAndReturn(
1027 ApiFunction* function, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001028
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001029 // Before calling a C-function from generated code, align arguments on stack.
1030 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1031 // etc., not pushed. The argument count assumes all arguments are word sized.
1032 // The number of slots reserved for arguments depends on platform. On Windows
1033 // stack slots are reserved for the arguments passed in registers. On other
1034 // platforms stack slots are only reserved for the arguments actually passed
1035 // on the stack.
1036 void PrepareCallCFunction(int num_arguments);
1037
1038 // Calls a C function and cleans up the space for arguments allocated
1039 // by PrepareCallCFunction. The called function is not allowed to trigger a
1040 // garbage collection, since that might move the code and invalidate the
1041 // return address (unless this is somehow accounted for by the called
1042 // function).
1043 void CallCFunction(ExternalReference function, int num_arguments);
1044 void CallCFunction(Register function, int num_arguments);
1045
1046 // Calculate the number of stack slots to reserve for arguments when calling a
1047 // C function.
1048 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001049
1050 // ---------------------------------------------------------------------------
1051 // Utilities
1052
1053 void Ret();
1054
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001055 // Return and drop arguments from stack, where the number of arguments
1056 // may be bigger than 2^16 - 1. Requires a scratch register.
1057 void Ret(int bytes_dropped, Register scratch);
1058
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001059 Handle<Object> CodeObject() {
1060 ASSERT(!code_object_.is_null());
1061 return code_object_;
1062 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001063
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001064 // Copy length bytes from source to destination.
1065 // Uses scratch register internally (if you have a low-eight register
1066 // free, do use it, otherwise kScratchRegister will be used).
1067 // The min_length is a minimum limit on the value that length will have.
1068 // The algorithm has some special cases that might be omitted if the string
1069 // is known to always be long.
1070 void CopyBytes(Register destination,
1071 Register source,
1072 Register length,
1073 int min_length = 0,
1074 Register scratch = kScratchRegister);
1075
ager@chromium.org9085a012009-05-11 19:22:57 +00001076
1077 // ---------------------------------------------------------------------------
1078 // StatsCounter support
1079
1080 void SetCounter(StatsCounter* counter, int value);
1081 void IncrementCounter(StatsCounter* counter, int value);
1082 void DecrementCounter(StatsCounter* counter, int value);
1083
1084
1085 // ---------------------------------------------------------------------------
1086 // Debugging
1087
1088 // Calls Abort(msg) if the condition cc is not satisfied.
1089 // Use --debug_code to enable.
1090 void Assert(Condition cc, const char* msg);
1091
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001092 void AssertFastElements(Register elements);
1093
ager@chromium.org9085a012009-05-11 19:22:57 +00001094 // Like Assert(), but always enabled.
1095 void Check(Condition cc, const char* msg);
1096
1097 // Print a message to stdout and abort execution.
1098 void Abort(const char* msg);
1099
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001100 // Check that the stack is aligned.
1101 void CheckStackAlignment();
1102
ager@chromium.org9085a012009-05-11 19:22:57 +00001103 // Verify restrictions about code generated in stubs.
1104 void set_generating_stub(bool value) { generating_stub_ = value; }
1105 bool generating_stub() { return generating_stub_; }
1106 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1107 bool allow_stub_calls() { return allow_stub_calls_; }
1108
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001109 static int SafepointRegisterStackIndex(Register reg) {
1110 return SafepointRegisterStackIndex(reg.code());
1111 }
1112
ager@chromium.org9085a012009-05-11 19:22:57 +00001113 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001114 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001115 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001116 static int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001117 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001118 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001119
ager@chromium.org9085a012009-05-11 19:22:57 +00001120 bool generating_stub_;
1121 bool allow_stub_calls_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001122 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001123
1124 // Returns a register holding the smi value. The register MUST NOT be
1125 // modified. It may be the "smi 1 constant" register.
1126 Register GetSmiConstant(Smi* value);
1127
1128 // Moves the smi value to the destination register.
1129 void LoadSmiConstant(Register dst, Smi* value);
1130
ager@chromium.org5c838252010-02-19 08:53:10 +00001131 // This handle will be patched with the code object on installation.
1132 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001133
1134 // Helper functions for generating invokes.
1135 void InvokePrologue(const ParameterCount& expected,
1136 const ParameterCount& actual,
1137 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001138 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001139 Label* done,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001140 InvokeFlag flag,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001141 const CallWrapper& call_wrapper,
1142 Label::Distance near_jump = Label::kFar);
ager@chromium.org9085a012009-05-11 19:22:57 +00001143
ager@chromium.org9085a012009-05-11 19:22:57 +00001144 // Activation support.
1145 void EnterFrame(StackFrame::Type type);
1146 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001147
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001148 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001149
1150 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1151 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001152 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001153
1154 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001155
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001156 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001157 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001158 // Otherwise the address of the new-space top is loaded into scratch (if
1159 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001160 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001161 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001162 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001163 // Update allocation top with value in result_end register.
1164 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001165 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001166
1167 // Helper for PopHandleScope. Allowed to perform a GC and returns
1168 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1169 // possibly returns a failure object indicating an allocation failure.
1170 Object* PopHandleScopeHelper(Register saved,
1171 Register scratch,
1172 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001173
1174
1175 // Compute memory operands for safepoint stack slots.
1176 Operand SafepointRegisterSlot(Register reg);
1177 static int SafepointRegisterStackIndex(int reg_code) {
1178 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1179 }
1180
1181 // Needs access to SafepointRegisterStackIndex for optimized frame
1182 // traversal.
1183 friend class OptimizedFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001184};
1185
1186
ager@chromium.org4af710e2009-09-15 12:20:11 +00001187// The code patcher is used to patch (typically) small parts of code e.g. for
1188// debugging and other types of instrumentation. When using the code patcher
1189// the exact number of bytes specified must be emitted. Is not legal to emit
1190// relocation information. If any of these constraints are violated it causes
1191// an assertion.
1192class CodePatcher {
1193 public:
1194 CodePatcher(byte* address, int size);
1195 virtual ~CodePatcher();
1196
1197 // Macro assembler to emit code.
1198 MacroAssembler* masm() { return &masm_; }
1199
1200 private:
1201 byte* address_; // The address of the code being patched.
1202 int size_; // Number of bytes of the expected patch size.
1203 MacroAssembler masm_; // Macro assembler used to generate the code.
1204};
1205
1206
ager@chromium.org9085a012009-05-11 19:22:57 +00001207// -----------------------------------------------------------------------------
1208// Static helper functions.
1209
1210// Generate an Operand for loading a field from an object.
1211static inline Operand FieldOperand(Register object, int offset) {
1212 return Operand(object, offset - kHeapObjectTag);
1213}
1214
1215
1216// Generate an Operand for loading an indexed field from an object.
1217static inline Operand FieldOperand(Register object,
1218 Register index,
1219 ScaleFactor scale,
1220 int offset) {
1221 return Operand(object, index, scale, offset - kHeapObjectTag);
1222}
1223
1224
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001225static inline Operand ContextOperand(Register context, int index) {
1226 return Operand(context, Context::SlotOffset(index));
1227}
1228
1229
1230static inline Operand GlobalObjectOperand() {
1231 return ContextOperand(rsi, Context::GLOBAL_INDEX);
1232}
1233
1234
1235// Provides access to exit frame stack space (not GCed).
1236static inline Operand StackSpaceOperand(int index) {
1237#ifdef _WIN64
1238 const int kShaddowSpace = 4;
1239 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1240#else
1241 return Operand(rsp, index * kPointerSize);
1242#endif
1243}
1244
1245
1246
ager@chromium.org9085a012009-05-11 19:22:57 +00001247#ifdef GENERATED_CODE_COVERAGE
1248extern void LogGeneratedCodeCoverage(const char* file_line);
1249#define CODE_COVERAGE_STRINGIFY(x) #x
1250#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1251#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1252#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001253 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001254 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1255 masm->pushfd(); \
1256 masm->pushad(); \
1257 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001258 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001259 masm->pop(rax); \
1260 masm->popad(); \
1261 masm->popfd(); \
1262 } \
1263 masm->
1264#else
1265#define ACCESS_MASM(masm) masm->
1266#endif
1267
ager@chromium.org9085a012009-05-11 19:22:57 +00001268} } // namespace v8::internal
1269
1270#endif // V8_X64_MACRO_ASSEMBLER_X64_H_