blob: d7d5af3bd33e704bc2c07291c33edef6d8b0fa70 [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.orgea91cc52011-05-23 06:06:11 +000048
ager@chromium.orge2902be2009-06-08 12:21:35 +000049// Default scratch register used by MacroAssembler (and other code that needs
50// a spare register). The register isn't callee save, and not used by the
51// function calling convention.
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000052static const Register kScratchRegister = { 10 }; // r10.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +000053static const Register kSmiConstantRegister = { 12 }; // r12 (callee save).
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000054static const Register kRootRegister = { 13 }; // r13 (callee save).
55// Value of smi in kSmiConstantRegister.
56static const int kSmiConstantRegisterValue = 1;
karlklose@chromium.org8f806e82011-03-07 14:06:08 +000057// Actual value of root register is offset from the root array's start
58// to take advantage of negitive 8-bit displacement values.
59static const int kRootRegisterBias = 128;
ager@chromium.orge2902be2009-06-08 12:21:35 +000060
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000061// Convenience for platform-independent signatures.
62typedef Operand MemOperand;
63
ager@chromium.org9085a012009-05-11 19:22:57 +000064// Forward declaration.
65class JumpTarget;
66
ager@chromium.org4af710e2009-09-15 12:20:11 +000067struct SmiIndex {
68 SmiIndex(Register index_register, ScaleFactor scale)
69 : reg(index_register),
70 scale(scale) {}
71 Register reg;
72 ScaleFactor scale;
73};
ager@chromium.org9085a012009-05-11 19:22:57 +000074
ager@chromium.org9085a012009-05-11 19:22:57 +000075// MacroAssembler implements a collection of frequently used macros.
76class MacroAssembler: public Assembler {
77 public:
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +000078 // The isolate parameter can be NULL if the macro assembler should
79 // not use isolate-dependent functionality. In this case, it's the
80 // responsibility of the caller to never invoke such function on the
81 // macro assembler.
82 MacroAssembler(Isolate* isolate, void* buffer, int size);
ager@chromium.org9085a012009-05-11 19:22:57 +000083
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000084 // Prevent the use of the RootArray during the lifetime of this
85 // scope object.
86 class NoRootArrayScope BASE_EMBEDDED {
87 public:
88 explicit NoRootArrayScope(MacroAssembler* assembler)
89 : variable_(&assembler->root_array_available_),
90 old_value_(assembler->root_array_available_) {
91 assembler->root_array_available_ = false;
92 }
93 ~NoRootArrayScope() {
94 *variable_ = old_value_;
95 }
96 private:
97 bool* variable_;
98 bool old_value_;
99 };
100
101 // Operand pointing to an external reference.
102 // May emit code to set up the scratch register. The operand is
103 // only guaranteed to be correct as long as the scratch register
104 // isn't changed.
105 // If the operand is used more than once, use a scratch register
106 // that is guaranteed not to be clobbered.
107 Operand ExternalOperand(ExternalReference reference,
108 Register scratch = kScratchRegister);
109 // Loads and stores the value of an external reference.
110 // Special case code for load and store to take advantage of
111 // load_rax/store_rax if possible/necessary.
112 // For other operations, just use:
113 // Operand operand = ExternalOperand(extref);
114 // operation(operand, ..);
115 void Load(Register destination, ExternalReference source);
116 void Store(ExternalReference destination, Register source);
117 // Loads the address of the external reference into the destination
118 // register.
119 void LoadAddress(Register destination, ExternalReference source);
120 // Returns the size of the code generated by LoadAddress.
121 // Used by CallSize(ExternalReference) to find the size of a call.
122 int LoadAddressSize(ExternalReference source);
123
124 // Operations on roots in the root-array.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000125 void LoadRoot(Register destination, Heap::RootListIndex index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000126 void StoreRoot(Register source, Heap::RootListIndex index);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000127 // Load a root value where the index (or part of it) is variable.
128 // The variable_offset register is added to the fixed_offset value
129 // to get the index into the root-array.
130 void LoadRootIndexed(Register destination,
131 Register variable_offset,
132 int fixed_offset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000133 void CompareRoot(Register with, Heap::RootListIndex index);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000134 void CompareRoot(const Operand& with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000135 void PushRoot(Heap::RootListIndex index);
136
ager@chromium.org9085a012009-05-11 19:22:57 +0000137 // ---------------------------------------------------------------------------
138 // GC Support
139
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000140 // For page containing |object| mark region covering |addr| dirty.
141 // RecordWriteHelper only works if the object is not in new
ager@chromium.orgac091b72010-05-05 07:34:42 +0000142 // space.
143 void RecordWriteHelper(Register object,
144 Register addr,
145 Register scratch);
146
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000147 // Check if object is in new space. The condition cc can be equal or
148 // not_equal. If it is equal a jump will be done if the object is on new
149 // space. The register scratch can be object itself, but it will be clobbered.
150 void InNewSpace(Register object,
151 Register scratch,
152 Condition cc,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000153 Label* branch,
154 Label::Distance near_jump = Label::kFar);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000155
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000156 // For page containing |object| mark region covering [object+offset]
157 // dirty. |object| is the object being stored into, |value| is the
158 // object being stored. If |offset| is zero, then the |scratch|
159 // register contains the array index into the elements array
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000160 // represented as an untagged 32-bit integer. All registers are
161 // clobbered by the operation. RecordWrite filters out smis so it
162 // does not update the write barrier if the value is a smi.
ager@chromium.org9085a012009-05-11 19:22:57 +0000163 void RecordWrite(Register object,
164 int offset,
165 Register value,
166 Register scratch);
167
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000168 // For page containing |object| mark region covering [address]
169 // dirty. |object| is the object being stored into, |value| is the
170 // object being stored. All registers are clobbered by the
171 // operation. RecordWrite filters out smis so it does not update
172 // the write barrier if the value is a smi.
173 void RecordWrite(Register object,
174 Register address,
175 Register value);
176
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000177 // For page containing |object| mark region covering [object+offset] dirty.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000178 // The value is known to not be a smi.
179 // object is the object being stored into, value is the object being stored.
180 // If offset is zero, then the scratch register contains the array index into
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000181 // the elements array represented as an untagged 32-bit integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000182 // All registers are clobbered by the operation.
183 void RecordWriteNonSmi(Register object,
184 int offset,
185 Register value,
186 Register scratch);
187
ager@chromium.org9085a012009-05-11 19:22:57 +0000188#ifdef ENABLE_DEBUGGER_SUPPORT
189 // ---------------------------------------------------------------------------
190 // Debugger Support
191
ager@chromium.org5c838252010-02-19 08:53:10 +0000192 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000193#endif
194
195 // ---------------------------------------------------------------------------
196 // Activation frames
197
198 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
199 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
200
201 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
202 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
203
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000204 // Enter specific kind of exit frame; either in normal or
205 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000206 // sets up the number of arguments in register rdi and the pointer
207 // to the first argument in register rsi.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000208 //
209 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
210 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000211 void EnterExitFrame(int arg_stack_space = 0, bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000212
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000213 // Enter specific kind of exit frame. Allocates arg_stack_space * kPointerSize
214 // memory (not GCed) on the stack accessible via StackSpaceOperand.
215 void EnterApiExitFrame(int arg_stack_space);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000216
ager@chromium.orga1645e22009-09-09 19:27:10 +0000217 // Leave the current exit frame. Expects/provides the return value in
218 // register rax:rdx (untouched) and the pointer to the first
219 // argument in register rsi.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000220 void LeaveExitFrame(bool save_doubles = false);
ager@chromium.org9085a012009-05-11 19:22:57 +0000221
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000222 // Leave the current exit frame. Expects/provides the return value in
223 // register rax (untouched).
224 void LeaveApiExitFrame();
ager@chromium.org9085a012009-05-11 19:22:57 +0000225
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000226 // Push and pop the registers that can hold pointers.
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000227 void PushSafepointRegisters() { Pushad(); }
228 void PopSafepointRegisters() { Popad(); }
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000229 // Store the value in register src in the safepoint register stack
230 // slot for register dst.
231 void StoreToSafepointRegisterSlot(Register dst, Register src);
vegorov@chromium.org5d6c1f52011-02-28 13:13:38 +0000232 void LoadFromSafepointRegisterSlot(Register dst, Register src);
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000233
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000234 void InitializeRootRegister() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000235 ExternalReference roots_address =
236 ExternalReference::roots_address(isolate());
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000237 movq(kRootRegister, roots_address);
238 addq(kRootRegister, Immediate(kRootRegisterBias));
239 }
240
ager@chromium.org9085a012009-05-11 19:22:57 +0000241 // ---------------------------------------------------------------------------
242 // JavaScript invokes
243
244 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000245 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000246 const ParameterCount& expected,
247 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000248 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000249 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000250
251 void InvokeCode(Handle<Code> code,
252 const ParameterCount& expected,
253 const ParameterCount& actual,
254 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000255 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000256 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000257
258 // Invoke the JavaScript function in the given register. Changes the
259 // current context to the context in the function before invoking.
260 void InvokeFunction(Register function,
261 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000262 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000263 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000264
ager@chromium.org5c838252010-02-19 08:53:10 +0000265 void InvokeFunction(JSFunction* function,
266 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000267 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000268 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org5c838252010-02-19 08:53:10 +0000269
ager@chromium.org9085a012009-05-11 19:22:57 +0000270 // Invoke specified builtin JavaScript function. Adds an entry to
271 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000272 void InvokeBuiltin(Builtins::JavaScript id,
273 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000274 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000275
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000276 // Store the function for the given builtin in the target register.
277 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
278
ager@chromium.org9085a012009-05-11 19:22:57 +0000279 // Store the code object for the given builtin in the target register.
280 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
281
ager@chromium.org4af710e2009-09-15 12:20:11 +0000282
283 // ---------------------------------------------------------------------------
284 // Smi tagging, untagging and operations on tagged smis.
285
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000286 void InitializeSmiConstantRegister() {
287 movq(kSmiConstantRegister,
288 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
289 RelocInfo::NONE);
290 }
291
ager@chromium.org4af710e2009-09-15 12:20:11 +0000292 // Conversions between tagged smi values and non-tagged integer values.
293
294 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000295 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000296 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000297 void Integer32ToSmi(Register dst, Register src);
298
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000299 // Stores an integer32 value into a memory field that already holds a smi.
300 void Integer32ToSmiField(const Operand& dst, Register src);
301
ager@chromium.org4af710e2009-09-15 12:20:11 +0000302 // Adds constant to src and tags the result as a smi.
303 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000304 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000305
306 // Convert smi to 32-bit integer. I.e., not sign extended into
307 // high 32 bits of destination.
308 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000309 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000310
311 // Convert smi to 64-bit integer (sign extended if necessary).
312 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000313 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000314
315 // Multiply a positive smi's integer value by a power of two.
316 // Provides result as 64-bit integer value.
317 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
318 Register src,
319 int power);
320
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000321 // Divide a positive smi's integer value by a power of two.
322 // Provides result as 32-bit integer value.
323 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
324 Register src,
325 int power);
326
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000327 // Perform the logical or of two smi values and return a smi value.
328 // If either argument is not a smi, jump to on_not_smis and retain
329 // the original values of source registers. The destination register
330 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000331 void SmiOrIfSmis(Register dst,
332 Register src1,
333 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000334 Label* on_not_smis,
335 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000336
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000337
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000338 // Simple comparison of smis. Both sides must be known smis to use these,
339 // otherwise use Cmp.
340 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000341 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000342 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000343 void SmiCompare(const Operand& dst, Register src);
344 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000345 // Compare the int32 in src register to the value of the smi stored at dst.
346 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000347 // Sets sign and zero flags depending on value of smi in register.
348 void SmiTest(Register src);
349
ager@chromium.org4af710e2009-09-15 12:20:11 +0000350 // Functions performing a check on a known or potential smi. Returns
351 // a condition that is satisfied if the check is successful.
352
353 // Is the value a tagged smi.
354 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000355 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000356
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000357 // Is the value a non-negative tagged smi.
358 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000359
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000360 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000361 Condition CheckBothSmi(Register first, Register second);
362
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000363 // Are both values non-negative tagged smis.
364 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000365
366 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000367 Condition CheckEitherSmi(Register first,
368 Register second,
369 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000370
ager@chromium.org4af710e2009-09-15 12:20:11 +0000371 // Is the value the minimum smi value (since we are using
372 // two's complement numbers, negating the value is known to yield
373 // a non-smi value).
374 Condition CheckIsMinSmi(Register src);
375
ager@chromium.org4af710e2009-09-15 12:20:11 +0000376 // Checks whether an 32-bit integer value is a valid for conversion
377 // to a smi.
378 Condition CheckInteger32ValidSmiValue(Register src);
379
ager@chromium.org3811b432009-10-28 14:53:37 +0000380 // Checks whether an 32-bit unsigned integer value is a valid for
381 // conversion to a smi.
382 Condition CheckUInteger32ValidSmiValue(Register src);
383
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000384 // Check whether src is a Smi, and set dst to zero if it is a smi,
385 // and to one if it isn't.
386 void CheckSmiToIndicator(Register dst, Register src);
387 void CheckSmiToIndicator(Register dst, const Operand& src);
388
ager@chromium.org4af710e2009-09-15 12:20:11 +0000389 // Test-and-jump functions. Typically combines a check function
390 // above with a conditional jump.
391
392 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000393 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
394 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000395
ager@chromium.org3811b432009-10-28 14:53:37 +0000396 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000397 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
398 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000399
ager@chromium.org4af710e2009-09-15 12:20:11 +0000400 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000401 void JumpIfSmi(Register src,
402 Label* on_smi,
403 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000404
405 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000406 void JumpIfNotSmi(Register src,
407 Label* on_not_smi,
408 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000409
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000410 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000411 void JumpUnlessNonNegativeSmi(Register src,
412 Label* on_not_smi,
413 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000414
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000415 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000416 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000417 void JumpIfSmiEqualsConstant(Register src,
418 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000419 Label* on_equals,
420 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000421
ager@chromium.org4af710e2009-09-15 12:20:11 +0000422 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000423 void JumpIfNotBothSmi(Register src1,
424 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000425 Label* on_not_both_smi,
426 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000427
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000428 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000429 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000430 Label* on_not_both_smi,
431 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000432
ager@chromium.org4af710e2009-09-15 12:20:11 +0000433 // Operations on tagged smi values.
434
435 // Smis represent a subset of integers. The subset is always equivalent to
436 // a two's complement interpretation of a fixed number of bits.
437
438 // Optimistically adds an integer constant to a supposed smi.
439 // If the src is not a smi, or the result is not a smi, jump to
440 // the label.
441 void SmiTryAddConstant(Register dst,
442 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000443 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000444 Label* on_not_smi_result,
445 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000446
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000447 // Add an integer constant to a tagged smi, giving a tagged smi as result.
448 // No overflow testing on the result is done.
449 void SmiAddConstant(Register dst, Register src, Smi* constant);
450
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000451 // Add an integer constant to a tagged smi, giving a tagged smi as result.
452 // No overflow testing on the result is done.
453 void SmiAddConstant(const Operand& dst, Smi* constant);
454
ager@chromium.org4af710e2009-09-15 12:20:11 +0000455 // Add an integer constant to a tagged smi, giving a tagged smi as result,
456 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000457 void SmiAddConstant(Register dst,
458 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000459 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000460 Label* on_not_smi_result,
461 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000462
463 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000464 // result. No testing on the result is done. Sets the N and Z flags
465 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000466 void SmiSubConstant(Register dst, Register src, Smi* constant);
467
468 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000469 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000470 void SmiSubConstant(Register dst,
471 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000472 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000473 Label* on_not_smi_result,
474 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000475
476 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000477 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000478 void SmiNeg(Register dst,
479 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000480 Label* on_smi_result,
481 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000482
483 // Adds smi values and return the result as a smi.
484 // If dst is src1, then src1 will be destroyed, even if
485 // the operation is unsuccessful.
486 void SmiAdd(Register dst,
487 Register src1,
488 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000489 Label* on_not_smi_result,
490 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000491 void SmiAdd(Register dst,
492 Register src1,
493 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000494 Label* on_not_smi_result,
495 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000496
497 void SmiAdd(Register dst,
498 Register src1,
499 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000500
501 // Subtracts smi values and return the result as a smi.
502 // If dst is src1, then src1 will be destroyed, even if
503 // the operation is unsuccessful.
504 void SmiSub(Register dst,
505 Register src1,
506 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000507 Label* on_not_smi_result,
508 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000509
ager@chromium.orgac091b72010-05-05 07:34:42 +0000510 void SmiSub(Register dst,
511 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000512 Register src2);
513
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000514 void SmiSub(Register dst,
515 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000516 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000517 Label* on_not_smi_result,
518 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000519
520 void SmiSub(Register dst,
521 Register src1,
522 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000523
ager@chromium.org4af710e2009-09-15 12:20:11 +0000524 // Multiplies smi values and return the result as a smi,
525 // if possible.
526 // If dst is src1, then src1 will be destroyed, even if
527 // the operation is unsuccessful.
528 void SmiMul(Register dst,
529 Register src1,
530 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000531 Label* on_not_smi_result,
532 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000533
534 // Divides one smi by another and returns the quotient.
535 // Clobbers rax and rdx registers.
536 void SmiDiv(Register dst,
537 Register src1,
538 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000539 Label* on_not_smi_result,
540 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000541
542 // Divides one smi by another and returns the remainder.
543 // Clobbers rax and rdx registers.
544 void SmiMod(Register dst,
545 Register src1,
546 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000547 Label* on_not_smi_result,
548 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000549
550 // Bitwise operations.
551 void SmiNot(Register dst, Register src);
552 void SmiAnd(Register dst, Register src1, Register src2);
553 void SmiOr(Register dst, Register src1, Register src2);
554 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000555 void SmiAndConstant(Register dst, Register src1, Smi* constant);
556 void SmiOrConstant(Register dst, Register src1, Smi* constant);
557 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000558
559 void SmiShiftLeftConstant(Register dst,
560 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000561 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000562 void SmiShiftLogicalRightConstant(Register dst,
563 Register src,
564 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000565 Label* on_not_smi_result,
566 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000567 void SmiShiftArithmeticRightConstant(Register dst,
568 Register src,
569 int shift_value);
570
571 // Shifts a smi value to the left, and returns the result if that is a smi.
572 // Uses and clobbers rcx, so dst may not be rcx.
573 void SmiShiftLeft(Register dst,
574 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000575 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000576 // Shifts a smi value to the right, shifting in zero bits at the top, and
577 // returns the unsigned intepretation of the result if that is a smi.
578 // Uses and clobbers rcx, so dst may not be rcx.
579 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000580 Register src1,
581 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000582 Label* on_not_smi_result,
583 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000584 // Shifts a smi value to the right, sign extending the top, and
585 // returns the signed intepretation of the result. That will always
586 // be a valid smi value, since it's numerically smaller than the
587 // original.
588 // Uses and clobbers rcx, so dst may not be rcx.
589 void SmiShiftArithmeticRight(Register dst,
590 Register src1,
591 Register src2);
592
593 // Specialized operations
594
595 // Select the non-smi register of two registers where exactly one is a
596 // smi. If neither are smis, jump to the failure label.
597 void SelectNonSmi(Register dst,
598 Register src1,
599 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000600 Label* on_not_smis,
601 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000602
603 // Converts, if necessary, a smi to a combination of number and
604 // multiplier to be used as a scaled index.
605 // The src register contains a *positive* smi value. The shift is the
606 // power of two to multiply the index value by (e.g.
607 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
608 // The returned index register may be either src or dst, depending
609 // on what is most efficient. If src and dst are different registers,
610 // src is always unchanged.
611 SmiIndex SmiToIndex(Register dst, Register src, int shift);
612
613 // Converts a positive smi to a negative index.
614 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
615
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000616 // Add the value of a smi in memory to an int32 register.
617 // Sets flags as a normal add.
618 void AddSmiField(Register dst, const Operand& src);
619
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000620 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000621 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000622 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000623 }
624
625 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000626 Register constant = GetSmiConstant(source);
627 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000628 }
629
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000630 void Push(Smi* smi);
631 void Test(const Operand& dst, Smi* source);
632
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000633 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000634 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000635
636 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000637 void JumpIfNotString(Register object,
638 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000639 Label* not_string,
640 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000641
642
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000643 void JumpIfNotBothSequentialAsciiStrings(
644 Register first_object,
645 Register second_object,
646 Register scratch1,
647 Register scratch2,
648 Label* on_not_both_flat_ascii,
649 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000650
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000651 // Check whether the instance type represents a flat ascii string. Jump to the
652 // label if not. If the instance type can be scratched specify same register
653 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000654 void JumpIfInstanceTypeIsNotSequentialAscii(
655 Register instance_type,
656 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000657 Label*on_not_flat_ascii_string,
658 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000659
660 void JumpIfBothInstanceTypesAreNotSequentialAscii(
661 Register first_object_instance_type,
662 Register second_object_instance_type,
663 Register scratch1,
664 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000665 Label* on_fail,
666 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000667
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000668 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000669 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000670
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000671 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000672 void Set(Register dst, int64_t x);
673 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000674
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000675 // Move if the registers are not identical.
676 void Move(Register target, Register source);
677
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000678 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000679 void Move(Register dst, Handle<Object> source);
680 void Move(const Operand& dst, Handle<Object> source);
681 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000682 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000683 void Cmp(Register dst, Smi* src);
684 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000685 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000686
687 // Emit code to discard a non-negative number of pointer-sized elements
688 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000689 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000690
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000691 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000692
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000693 // Control Flow
694 void Jump(Address destination, RelocInfo::Mode rmode);
695 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000696 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
697
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000698 void Call(Address destination, RelocInfo::Mode rmode);
699 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000700 void Call(Handle<Code> code_object,
701 RelocInfo::Mode rmode,
702 unsigned ast_id = kNoASTId);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000703
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000704 // The size of the code generated for different call instructions.
705 int CallSize(Address destination, RelocInfo::Mode rmode) {
706 return kCallInstructionLength;
707 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000708 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000709 int CallSize(Handle<Code> code_object) {
710 // Code calls use 32-bit relative addressing.
711 return kShortCallInstructionLength;
712 }
713 int CallSize(Register target) {
714 // Opcode: REX_opt FF /2 m64
715 return (target.high_bit() != 0) ? 3 : 2;
716 }
717 int CallSize(const Operand& target) {
718 // Opcode: REX_opt FF /2 m64
719 return (target.requires_rex() ? 2 : 1) + target.operand_size();
720 }
721
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000722 // Emit call to the code we are currently generating.
723 void CallSelf() {
724 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
725 Call(self, RelocInfo::CODE_TARGET);
726 }
727
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000728 // Non-x64 instructions.
729 // Push/pop all general purpose registers.
730 // Does not push rsp/rbp nor any of the assembler's special purpose registers
731 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
732 void Pushad();
733 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000734 // Sets the stack as after performing Popad, without actually loading the
735 // registers.
736 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000737
ager@chromium.org9085a012009-05-11 19:22:57 +0000738 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000739 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000740 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000741 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000742 void CmpObjectType(Register heap_object, InstanceType type, Register map);
743
744 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000745 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000746 void CmpInstanceType(Register map, InstanceType type);
747
ager@chromium.org5c838252010-02-19 08:53:10 +0000748 // Check if the map of an object is equal to a specified map and
749 // branch to label if not. Skip the smi check if not required
750 // (object is known to be a heap object)
751 void CheckMap(Register obj,
752 Handle<Map> map,
753 Label* fail,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000754 SmiCheckType smi_check_type);
ager@chromium.org5c838252010-02-19 08:53:10 +0000755
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000756 // Check if the map of an object is equal to a specified map and branch to a
757 // specified target if equal. Skip the smi check if not required (object is
758 // known to be a heap object)
759 void DispatchMap(Register obj,
760 Handle<Map> map,
761 Handle<Code> success,
762 SmiCheckType smi_check_type);
763
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000764 // Check if the object in register heap_object is a string. Afterwards the
765 // register map contains the object map and the register instance_type
766 // contains the instance_type. The registers map and instance_type can be the
767 // same in which case it contains the instance type afterwards. Either of the
768 // registers map and instance_type can be the same as heap_object.
769 Condition IsObjectStringType(Register heap_object,
770 Register map,
771 Register instance_type);
772
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000773 // FCmp compares and pops the two values on top of the FPU stack.
774 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000775 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
776 void FCmp();
777
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000778 void ClampUint8(Register reg);
779
780 void ClampDoubleToUint8(XMMRegister input_reg,
781 XMMRegister temp_xmm_reg,
782 Register result_reg,
783 Register temp_reg);
784
ager@chromium.org5c838252010-02-19 08:53:10 +0000785 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000786 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000787
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000788 // Abort execution if argument is a smi. Used in debug code.
789 void AbortIfSmi(Register object);
790
lrn@chromium.org25156de2010-04-06 13:10:27 +0000791 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000792 void AbortIfNotSmi(Register object);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000793 void AbortIfNotSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000794
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000795 // Abort execution if argument is a string. Used in debug code.
796 void AbortIfNotString(Register object);
797
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000798 // Abort execution if argument is not the root value with the given index.
799 void AbortIfNotRootValue(Register src,
800 Heap::RootListIndex root_value_index,
801 const char* message);
802
ager@chromium.org9085a012009-05-11 19:22:57 +0000803 // ---------------------------------------------------------------------------
804 // Exception handling
805
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000806 // Push a new try handler and link into try handler chain. The return
807 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000808 void PushTryHandler(CodeLocation try_location, HandlerType type);
809
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000810 // Unlink the stack handler on top of the stack from the try handler chain.
811 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000812
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000813 // Activate the top handler in the try hander chain and pass the
814 // thrown value.
815 void Throw(Register value);
816
817 // Propagate an uncatchable exception out of the current JS stack.
818 void ThrowUncatchable(UncatchableExceptionType type, Register value);
819
ager@chromium.org9085a012009-05-11 19:22:57 +0000820 // ---------------------------------------------------------------------------
821 // Inline caching support
822
ager@chromium.org9085a012009-05-11 19:22:57 +0000823 // Generate code for checking access rights - used for security checks
824 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000825 // is left untouched, but the scratch register and kScratchRegister,
826 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000827 void CheckAccessGlobalProxy(Register holder_reg,
828 Register scratch,
829 Label* miss);
830
831
832 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000833 // Allocation support
834
835 // Allocate an object in new space. If the new space is exhausted control
836 // continues at the gc_required label. The allocated object is returned in
837 // result and end of the new object is returned in result_end. The register
838 // scratch can be passed as no_reg in which case an additional object
839 // reference will be added to the reloc info. The returned pointers in result
840 // and result_end have not yet been tagged as heap objects. If
841 // result_contains_top_on_entry is true the content of result is known to be
842 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000843 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000844 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000845 void AllocateInNewSpace(int object_size,
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(int header_size,
853 ScaleFactor element_size,
854 Register element_count,
855 Register result,
856 Register result_end,
857 Register scratch,
858 Label* gc_required,
859 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000860
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000861 void AllocateInNewSpace(Register object_size,
862 Register result,
863 Register result_end,
864 Register scratch,
865 Label* gc_required,
866 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000867
868 // Undo allocation in new space. The object passed and objects allocated after
869 // it will no longer be allocated. Make sure that no pointers are left to the
870 // object(s) no longer allocated as they would be invalid when allocation is
871 // un-done.
872 void UndoAllocationInNewSpace(Register object);
873
ager@chromium.org3811b432009-10-28 14:53:37 +0000874 // Allocate a heap number in new space with undefined value. Returns
875 // tagged pointer in result register, or jumps to gc_required if new
876 // space is full.
877 void AllocateHeapNumber(Register result,
878 Register scratch,
879 Label* gc_required);
880
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000881 // Allocate a sequential string. All the header fields of the string object
882 // are initialized.
883 void AllocateTwoByteString(Register result,
884 Register length,
885 Register scratch1,
886 Register scratch2,
887 Register scratch3,
888 Label* gc_required);
889 void AllocateAsciiString(Register result,
890 Register length,
891 Register scratch1,
892 Register scratch2,
893 Register scratch3,
894 Label* gc_required);
895
896 // Allocate a raw cons string object. Only the map field of the result is
897 // initialized.
898 void AllocateConsString(Register result,
899 Register scratch1,
900 Register scratch2,
901 Label* gc_required);
902 void AllocateAsciiConsString(Register result,
903 Register scratch1,
904 Register scratch2,
905 Label* gc_required);
906
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000907 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000908 // Support functions.
909
910 // Check if result is zero and op is negative.
911 void NegativeZeroTest(Register result, Register op, Label* then_label);
912
913 // Check if result is zero and op is negative in code using jump targets.
914 void NegativeZeroTest(CodeGenerator* cgen,
915 Register result,
916 Register op,
917 JumpTarget* then_target);
918
919 // Check if result is zero and any of op1 and op2 are negative.
920 // Register scratch is destroyed, and it must be different from op2.
921 void NegativeZeroTest(Register result, Register op1, Register op2,
922 Register scratch, Label* then_label);
923
924 // Try to get function prototype of a function and puts the value in
925 // the result register. Checks that the function really is a
926 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000927 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000928 // clobbered.
929 void TryGetFunctionPrototype(Register function,
930 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000931 Label* miss);
932
933 // Generates code for reporting that an illegal operation has
934 // occurred.
935 void IllegalOperation(int num_arguments);
936
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000937 // Picks out an array index from the hash field.
938 // Register use:
939 // hash - holds the index's hash. Clobbered.
940 // index - holds the overwritten index on exit.
941 void IndexFromHash(Register hash, Register index);
942
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000943 // Find the function context up the context chain.
944 void LoadContext(Register dst, int context_chain_length);
945
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000946 // Load the global function with the given index.
947 void LoadGlobalFunction(int index, Register function);
948
949 // Load the initial map from the global function. The registers
950 // function and map can be the same.
951 void LoadGlobalFunctionInitialMap(Register function, Register map);
952
ager@chromium.org9085a012009-05-11 19:22:57 +0000953 // ---------------------------------------------------------------------------
954 // Runtime calls
955
956 // Call a code stub.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000957 void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId);
ager@chromium.org9085a012009-05-11 19:22:57 +0000958
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000959 // Call a code stub and return the code object called. Try to generate
960 // the code if necessary. Do not perform a GC but instead return a retry
961 // after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000962 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000963
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000964 // Tail call a code stub (jump).
965 void TailCallStub(CodeStub* stub);
966
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000967 // Tail call a code stub (jump) and return the code object called. Try to
968 // generate the code if necessary. Do not perform a GC but instead return
969 // a retry after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000970 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000971
ager@chromium.org9085a012009-05-11 19:22:57 +0000972 // Return from a code stub after popping its arguments.
973 void StubReturn(int argc);
974
975 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000976 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000977
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000978 // Call a runtime function and save the value of XMM registers.
979 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
980
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000981 // Call a runtime function, returning the CodeStub object called.
982 // Try to generate the stub code if necessary. Do not perform a GC
983 // but instead return a retry after GC failure.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000984 MUST_USE_RESULT MaybeObject* TryCallRuntime(const Runtime::Function* f,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000985 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000986
ager@chromium.org9085a012009-05-11 19:22:57 +0000987 // Convenience function: Same as above, but takes the fid instead.
988 void CallRuntime(Runtime::FunctionId id, int num_arguments);
989
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000990 // Convenience function: Same as above, but takes the fid instead.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000991 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
992 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000993
ager@chromium.org5c838252010-02-19 08:53:10 +0000994 // Convenience function: call an external reference.
995 void CallExternalReference(const ExternalReference& ext,
996 int num_arguments);
997
ager@chromium.org9085a012009-05-11 19:22:57 +0000998 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000999 // Like JumpToExternalReference, but also takes care of passing the number
1000 // of parameters.
1001 void TailCallExternalReference(const ExternalReference& ext,
1002 int num_arguments,
1003 int result_size);
1004
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001005 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
1006 const ExternalReference& ext, int num_arguments, int result_size);
1007
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001008 // Convenience function: tail call a runtime routine (jump).
1009 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001010 int num_arguments,
1011 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001012
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001013 MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid,
1014 int num_arguments,
1015 int result_size);
1016
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001017 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001018 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001019
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001020 // Jump to a runtime routine.
1021 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext,
1022 int result_size);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001023
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001024 // Prepares stack to put arguments (aligns and so on).
1025 // WIN64 calling convention requires to put the pointer to the return value
1026 // slot into rcx (rcx must be preserverd until TryCallApiFunctionAndReturn).
1027 // Saves context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
1028 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1029 void PrepareCallApiFunction(int arg_stack_space);
1030
1031 // Calls an API function. Allocates HandleScope, extracts
1032 // returned value from handle and propagates exceptions.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001033 // Clobbers r14, r15, rbx and caller-save registers. Restores context.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001034 // On return removes stack_space * kPointerSize (GCed).
1035 MUST_USE_RESULT MaybeObject* TryCallApiFunctionAndReturn(
1036 ApiFunction* function, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001037
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001038 // Before calling a C-function from generated code, align arguments on stack.
1039 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1040 // etc., not pushed. The argument count assumes all arguments are word sized.
1041 // The number of slots reserved for arguments depends on platform. On Windows
1042 // stack slots are reserved for the arguments passed in registers. On other
1043 // platforms stack slots are only reserved for the arguments actually passed
1044 // on the stack.
1045 void PrepareCallCFunction(int num_arguments);
1046
1047 // Calls a C function and cleans up the space for arguments allocated
1048 // by PrepareCallCFunction. The called function is not allowed to trigger a
1049 // garbage collection, since that might move the code and invalidate the
1050 // return address (unless this is somehow accounted for by the called
1051 // function).
1052 void CallCFunction(ExternalReference function, int num_arguments);
1053 void CallCFunction(Register function, int num_arguments);
1054
1055 // Calculate the number of stack slots to reserve for arguments when calling a
1056 // C function.
1057 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001058
1059 // ---------------------------------------------------------------------------
1060 // Utilities
1061
1062 void Ret();
1063
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001064 // Return and drop arguments from stack, where the number of arguments
1065 // may be bigger than 2^16 - 1. Requires a scratch register.
1066 void Ret(int bytes_dropped, Register scratch);
1067
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001068 Handle<Object> CodeObject() {
1069 ASSERT(!code_object_.is_null());
1070 return code_object_;
1071 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001072
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001073 // Copy length bytes from source to destination.
1074 // Uses scratch register internally (if you have a low-eight register
1075 // free, do use it, otherwise kScratchRegister will be used).
1076 // The min_length is a minimum limit on the value that length will have.
1077 // The algorithm has some special cases that might be omitted if the string
1078 // is known to always be long.
1079 void CopyBytes(Register destination,
1080 Register source,
1081 Register length,
1082 int min_length = 0,
1083 Register scratch = kScratchRegister);
1084
ager@chromium.org9085a012009-05-11 19:22:57 +00001085
1086 // ---------------------------------------------------------------------------
1087 // StatsCounter support
1088
1089 void SetCounter(StatsCounter* counter, int value);
1090 void IncrementCounter(StatsCounter* counter, int value);
1091 void DecrementCounter(StatsCounter* counter, int value);
1092
1093
1094 // ---------------------------------------------------------------------------
1095 // Debugging
1096
1097 // Calls Abort(msg) if the condition cc is not satisfied.
1098 // Use --debug_code to enable.
1099 void Assert(Condition cc, const char* msg);
1100
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001101 void AssertFastElements(Register elements);
1102
ager@chromium.org9085a012009-05-11 19:22:57 +00001103 // Like Assert(), but always enabled.
1104 void Check(Condition cc, const char* msg);
1105
1106 // Print a message to stdout and abort execution.
1107 void Abort(const char* msg);
1108
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001109 // Check that the stack is aligned.
1110 void CheckStackAlignment();
1111
ager@chromium.org9085a012009-05-11 19:22:57 +00001112 // Verify restrictions about code generated in stubs.
1113 void set_generating_stub(bool value) { generating_stub_ = value; }
1114 bool generating_stub() { return generating_stub_; }
1115 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1116 bool allow_stub_calls() { return allow_stub_calls_; }
1117
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001118 static int SafepointRegisterStackIndex(Register reg) {
1119 return SafepointRegisterStackIndex(reg.code());
1120 }
1121
ager@chromium.org9085a012009-05-11 19:22:57 +00001122 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001123 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001124 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001125 static int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001126 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001127 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001128
ager@chromium.org9085a012009-05-11 19:22:57 +00001129 bool generating_stub_;
1130 bool allow_stub_calls_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001131 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001132
1133 // Returns a register holding the smi value. The register MUST NOT be
1134 // modified. It may be the "smi 1 constant" register.
1135 Register GetSmiConstant(Smi* value);
1136
1137 // Moves the smi value to the destination register.
1138 void LoadSmiConstant(Register dst, Smi* value);
1139
ager@chromium.org5c838252010-02-19 08:53:10 +00001140 // This handle will be patched with the code object on installation.
1141 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001142
1143 // Helper functions for generating invokes.
1144 void InvokePrologue(const ParameterCount& expected,
1145 const ParameterCount& actual,
1146 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001147 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001148 Label* done,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001149 InvokeFlag flag,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001150 const CallWrapper& call_wrapper,
1151 Label::Distance near_jump = Label::kFar);
ager@chromium.org9085a012009-05-11 19:22:57 +00001152
ager@chromium.org9085a012009-05-11 19:22:57 +00001153 // Activation support.
1154 void EnterFrame(StackFrame::Type type);
1155 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001156
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001157 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001158
1159 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1160 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001161 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001162
1163 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001164
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001165 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001166 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001167 // Otherwise the address of the new-space top is loaded into scratch (if
1168 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001169 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001170 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001171 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001172 // Update allocation top with value in result_end register.
1173 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001174 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001175
1176 // Helper for PopHandleScope. Allowed to perform a GC and returns
1177 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1178 // possibly returns a failure object indicating an allocation failure.
1179 Object* PopHandleScopeHelper(Register saved,
1180 Register scratch,
1181 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001182
1183
1184 // Compute memory operands for safepoint stack slots.
1185 Operand SafepointRegisterSlot(Register reg);
1186 static int SafepointRegisterStackIndex(int reg_code) {
1187 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1188 }
1189
1190 // Needs access to SafepointRegisterStackIndex for optimized frame
1191 // traversal.
1192 friend class OptimizedFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001193};
1194
1195
ager@chromium.org4af710e2009-09-15 12:20:11 +00001196// The code patcher is used to patch (typically) small parts of code e.g. for
1197// debugging and other types of instrumentation. When using the code patcher
1198// the exact number of bytes specified must be emitted. Is not legal to emit
1199// relocation information. If any of these constraints are violated it causes
1200// an assertion.
1201class CodePatcher {
1202 public:
1203 CodePatcher(byte* address, int size);
1204 virtual ~CodePatcher();
1205
1206 // Macro assembler to emit code.
1207 MacroAssembler* masm() { return &masm_; }
1208
1209 private:
1210 byte* address_; // The address of the code being patched.
1211 int size_; // Number of bytes of the expected patch size.
1212 MacroAssembler masm_; // Macro assembler used to generate the code.
1213};
1214
1215
ager@chromium.org9085a012009-05-11 19:22:57 +00001216// -----------------------------------------------------------------------------
1217// Static helper functions.
1218
1219// Generate an Operand for loading a field from an object.
1220static inline Operand FieldOperand(Register object, int offset) {
1221 return Operand(object, offset - kHeapObjectTag);
1222}
1223
1224
1225// Generate an Operand for loading an indexed field from an object.
1226static inline Operand FieldOperand(Register object,
1227 Register index,
1228 ScaleFactor scale,
1229 int offset) {
1230 return Operand(object, index, scale, offset - kHeapObjectTag);
1231}
1232
1233
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001234static inline Operand ContextOperand(Register context, int index) {
1235 return Operand(context, Context::SlotOffset(index));
1236}
1237
1238
1239static inline Operand GlobalObjectOperand() {
1240 return ContextOperand(rsi, Context::GLOBAL_INDEX);
1241}
1242
1243
1244// Provides access to exit frame stack space (not GCed).
1245static inline Operand StackSpaceOperand(int index) {
1246#ifdef _WIN64
1247 const int kShaddowSpace = 4;
1248 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1249#else
1250 return Operand(rsp, index * kPointerSize);
1251#endif
1252}
1253
1254
1255
ager@chromium.org9085a012009-05-11 19:22:57 +00001256#ifdef GENERATED_CODE_COVERAGE
1257extern void LogGeneratedCodeCoverage(const char* file_line);
1258#define CODE_COVERAGE_STRINGIFY(x) #x
1259#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1260#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1261#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001262 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001263 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1264 masm->pushfd(); \
1265 masm->pushad(); \
1266 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001267 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001268 masm->pop(rax); \
1269 masm->popad(); \
1270 masm->popfd(); \
1271 } \
1272 masm->
1273#else
1274#define ACCESS_MASM(masm) masm->
1275#endif
1276
ager@chromium.org9085a012009-05-11 19:22:57 +00001277} } // namespace v8::internal
1278
1279#endif // V8_X64_MACRO_ASSEMBLER_X64_H_