blob: 16f6d8d3774e716e1e9a0f8c2dbfb371f78924d9 [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
danno@chromium.org40cb8782011-05-25 07:58:50 +0000244 // Setup call kind marking in rcx. The method takes rcx as an
245 // explicit first parameter to make the code more readable at the
246 // call sites.
247 void SetCallKind(Register dst, CallKind kind);
248
ager@chromium.org9085a012009-05-11 19:22:57 +0000249 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000250 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000251 const ParameterCount& expected,
252 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000253 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000254 const CallWrapper& call_wrapper,
255 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000256
257 void InvokeCode(Handle<Code> code,
258 const ParameterCount& expected,
259 const ParameterCount& actual,
260 RelocInfo::Mode rmode,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000261 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000262 const CallWrapper& call_wrapper,
263 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000264
265 // Invoke the JavaScript function in the given register. Changes the
266 // current context to the context in the function before invoking.
267 void InvokeFunction(Register function,
268 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000269 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000270 const CallWrapper& call_wrapper,
271 CallKind call_kind);
ager@chromium.org9085a012009-05-11 19:22:57 +0000272
ager@chromium.org5c838252010-02-19 08:53:10 +0000273 void InvokeFunction(JSFunction* function,
274 const ParameterCount& actual,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000275 InvokeFlag flag,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000276 const CallWrapper& call_wrapper,
277 CallKind call_kind);
ager@chromium.org5c838252010-02-19 08:53:10 +0000278
ager@chromium.org9085a012009-05-11 19:22:57 +0000279 // Invoke specified builtin JavaScript function. Adds an entry to
280 // the unresolved list if the name does not resolve.
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000281 void InvokeBuiltin(Builtins::JavaScript id,
282 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +0000283 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org9085a012009-05-11 19:22:57 +0000284
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000285 // Store the function for the given builtin in the target register.
286 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
287
ager@chromium.org9085a012009-05-11 19:22:57 +0000288 // Store the code object for the given builtin in the target register.
289 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
290
ager@chromium.org4af710e2009-09-15 12:20:11 +0000291
292 // ---------------------------------------------------------------------------
293 // Smi tagging, untagging and operations on tagged smis.
294
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000295 void InitializeSmiConstantRegister() {
296 movq(kSmiConstantRegister,
297 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
298 RelocInfo::NONE);
299 }
300
ager@chromium.org4af710e2009-09-15 12:20:11 +0000301 // Conversions between tagged smi values and non-tagged integer values.
302
303 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000304 // Only uses the low 32 bits of the src register. Sets the N and Z flags
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000305 // based on the value of the resulting smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000306 void Integer32ToSmi(Register dst, Register src);
307
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000308 // Stores an integer32 value into a memory field that already holds a smi.
309 void Integer32ToSmiField(const Operand& dst, Register src);
310
ager@chromium.org4af710e2009-09-15 12:20:11 +0000311 // Adds constant to src and tags the result as a smi.
312 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000313 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000314
315 // Convert smi to 32-bit integer. I.e., not sign extended into
316 // high 32 bits of destination.
317 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000318 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000319
320 // Convert smi to 64-bit integer (sign extended if necessary).
321 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000322 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000323
324 // Multiply a positive smi's integer value by a power of two.
325 // Provides result as 64-bit integer value.
326 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
327 Register src,
328 int power);
329
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000330 // Divide a positive smi's integer value by a power of two.
331 // Provides result as 32-bit integer value.
332 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
333 Register src,
334 int power);
335
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000336 // Perform the logical or of two smi values and return a smi value.
337 // If either argument is not a smi, jump to on_not_smis and retain
338 // the original values of source registers. The destination register
339 // may be changed if it's not one of the source registers.
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000340 void SmiOrIfSmis(Register dst,
341 Register src1,
342 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000343 Label* on_not_smis,
344 Label::Distance near_jump = Label::kFar);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000345
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000346
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000347 // Simple comparison of smis. Both sides must be known smis to use these,
348 // otherwise use Cmp.
349 void SmiCompare(Register smi1, Register smi2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000350 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000351 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000352 void SmiCompare(const Operand& dst, Register src);
353 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000354 // Compare the int32 in src register to the value of the smi stored at dst.
355 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000356 // Sets sign and zero flags depending on value of smi in register.
357 void SmiTest(Register src);
358
ager@chromium.org4af710e2009-09-15 12:20:11 +0000359 // Functions performing a check on a known or potential smi. Returns
360 // a condition that is satisfied if the check is successful.
361
362 // Is the value a tagged smi.
363 Condition CheckSmi(Register src);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000364 Condition CheckSmi(const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000365
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000366 // Is the value a non-negative tagged smi.
367 Condition CheckNonNegativeSmi(Register src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000368
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000369 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000370 Condition CheckBothSmi(Register first, Register second);
371
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000372 // Are both values non-negative tagged smis.
373 Condition CheckBothNonNegativeSmi(Register first, Register second);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000374
375 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000376 Condition CheckEitherSmi(Register first,
377 Register second,
378 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000379
ager@chromium.org4af710e2009-09-15 12:20:11 +0000380 // Is the value the minimum smi value (since we are using
381 // two's complement numbers, negating the value is known to yield
382 // a non-smi value).
383 Condition CheckIsMinSmi(Register src);
384
ager@chromium.org4af710e2009-09-15 12:20:11 +0000385 // Checks whether an 32-bit integer value is a valid for conversion
386 // to a smi.
387 Condition CheckInteger32ValidSmiValue(Register src);
388
ager@chromium.org3811b432009-10-28 14:53:37 +0000389 // Checks whether an 32-bit unsigned integer value is a valid for
390 // conversion to a smi.
391 Condition CheckUInteger32ValidSmiValue(Register src);
392
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000393 // Check whether src is a Smi, and set dst to zero if it is a smi,
394 // and to one if it isn't.
395 void CheckSmiToIndicator(Register dst, Register src);
396 void CheckSmiToIndicator(Register dst, const Operand& src);
397
ager@chromium.org4af710e2009-09-15 12:20:11 +0000398 // Test-and-jump functions. Typically combines a check function
399 // above with a conditional jump.
400
401 // Jump if the value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000402 void JumpIfNotValidSmiValue(Register src, Label* on_invalid,
403 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000404
ager@chromium.org3811b432009-10-28 14:53:37 +0000405 // Jump if the unsigned integer value cannot be represented by a smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000406 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid,
407 Label::Distance near_jump = Label::kFar);
ager@chromium.org3811b432009-10-28 14:53:37 +0000408
ager@chromium.org4af710e2009-09-15 12:20:11 +0000409 // Jump to label if the value is a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000410 void JumpIfSmi(Register src,
411 Label* on_smi,
412 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000413
414 // Jump to label if the value is not a tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000415 void JumpIfNotSmi(Register src,
416 Label* on_not_smi,
417 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000418
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000419 // Jump to label if the value is not a non-negative tagged smi.
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000420 void JumpUnlessNonNegativeSmi(Register src,
421 Label* on_not_smi,
422 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000423
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000424 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000425 // to the constant.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000426 void JumpIfSmiEqualsConstant(Register src,
427 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000428 Label* on_equals,
429 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000430
ager@chromium.org4af710e2009-09-15 12:20:11 +0000431 // Jump if either or both register are not smi values.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000432 void JumpIfNotBothSmi(Register src1,
433 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000434 Label* on_not_both_smi,
435 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000436
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000437 // Jump if either or both register are not non-negative smi values.
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000438 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000439 Label* on_not_both_smi,
440 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000441
ager@chromium.org4af710e2009-09-15 12:20:11 +0000442 // Operations on tagged smi values.
443
444 // Smis represent a subset of integers. The subset is always equivalent to
445 // a two's complement interpretation of a fixed number of bits.
446
447 // Optimistically adds an integer constant to a supposed smi.
448 // If the src is not a smi, or the result is not a smi, jump to
449 // the label.
450 void SmiTryAddConstant(Register dst,
451 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000452 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000453 Label* on_not_smi_result,
454 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000455
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000456 // Add an integer constant to a tagged smi, giving a tagged smi as result.
457 // No overflow testing on the result is done.
458 void SmiAddConstant(Register dst, Register src, Smi* constant);
459
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000460 // Add an integer constant to a tagged smi, giving a tagged smi as result.
461 // No overflow testing on the result is done.
462 void SmiAddConstant(const Operand& dst, Smi* constant);
463
ager@chromium.org4af710e2009-09-15 12:20:11 +0000464 // Add an integer constant to a tagged smi, giving a tagged smi as result,
465 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000466 void SmiAddConstant(Register dst,
467 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000468 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000469 Label* on_not_smi_result,
470 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000471
472 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000473 // result. No testing on the result is done. Sets the N and Z flags
474 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000475 void SmiSubConstant(Register dst, Register src, Smi* constant);
476
477 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000478 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000479 void SmiSubConstant(Register dst,
480 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000481 Smi* constant,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000482 Label* on_not_smi_result,
483 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000484
485 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000486 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000487 void SmiNeg(Register dst,
488 Register src,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000489 Label* on_smi_result,
490 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000491
492 // Adds smi values and return the result as a smi.
493 // If dst is src1, then src1 will be destroyed, even if
494 // the operation is unsuccessful.
495 void SmiAdd(Register dst,
496 Register src1,
497 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000498 Label* on_not_smi_result,
499 Label::Distance near_jump = Label::kFar);
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000500 void SmiAdd(Register dst,
501 Register src1,
502 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000503 Label* on_not_smi_result,
504 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000505
506 void SmiAdd(Register dst,
507 Register src1,
508 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000509
510 // Subtracts smi values and return the result as a smi.
511 // If dst is src1, then src1 will be destroyed, even if
512 // the operation is unsuccessful.
513 void SmiSub(Register dst,
514 Register src1,
515 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000516 Label* on_not_smi_result,
517 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000518
ager@chromium.orgac091b72010-05-05 07:34:42 +0000519 void SmiSub(Register dst,
520 Register src1,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000521 Register src2);
522
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000523 void SmiSub(Register dst,
524 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000525 const Operand& src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000526 Label* on_not_smi_result,
527 Label::Distance near_jump = Label::kFar);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000528
529 void SmiSub(Register dst,
530 Register src1,
531 const Operand& src2);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000532
ager@chromium.org4af710e2009-09-15 12:20:11 +0000533 // Multiplies smi values and return the result as a smi,
534 // if possible.
535 // If dst is src1, then src1 will be destroyed, even if
536 // the operation is unsuccessful.
537 void SmiMul(Register dst,
538 Register src1,
539 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000540 Label* on_not_smi_result,
541 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000542
543 // Divides one smi by another and returns the quotient.
544 // Clobbers rax and rdx registers.
545 void SmiDiv(Register dst,
546 Register src1,
547 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000548 Label* on_not_smi_result,
549 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000550
551 // Divides one smi by another and returns the remainder.
552 // Clobbers rax and rdx registers.
553 void SmiMod(Register dst,
554 Register src1,
555 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000556 Label* on_not_smi_result,
557 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000558
559 // Bitwise operations.
560 void SmiNot(Register dst, Register src);
561 void SmiAnd(Register dst, Register src1, Register src2);
562 void SmiOr(Register dst, Register src1, Register src2);
563 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000564 void SmiAndConstant(Register dst, Register src1, Smi* constant);
565 void SmiOrConstant(Register dst, Register src1, Smi* constant);
566 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000567
568 void SmiShiftLeftConstant(Register dst,
569 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000570 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000571 void SmiShiftLogicalRightConstant(Register dst,
572 Register src,
573 int shift_value,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000574 Label* on_not_smi_result,
575 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000576 void SmiShiftArithmeticRightConstant(Register dst,
577 Register src,
578 int shift_value);
579
580 // Shifts a smi value to the left, and returns the result if that is a smi.
581 // Uses and clobbers rcx, so dst may not be rcx.
582 void SmiShiftLeft(Register dst,
583 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000584 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000585 // Shifts a smi value to the right, shifting in zero bits at the top, and
586 // returns the unsigned intepretation of the result if that is a smi.
587 // Uses and clobbers rcx, so dst may not be rcx.
588 void SmiShiftLogicalRight(Register dst,
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000589 Register src1,
590 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000591 Label* on_not_smi_result,
592 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000593 // Shifts a smi value to the right, sign extending the top, and
594 // returns the signed intepretation of the result. That will always
595 // be a valid smi value, since it's numerically smaller than the
596 // original.
597 // Uses and clobbers rcx, so dst may not be rcx.
598 void SmiShiftArithmeticRight(Register dst,
599 Register src1,
600 Register src2);
601
602 // Specialized operations
603
604 // Select the non-smi register of two registers where exactly one is a
605 // smi. If neither are smis, jump to the failure label.
606 void SelectNonSmi(Register dst,
607 Register src1,
608 Register src2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000609 Label* on_not_smis,
610 Label::Distance near_jump = Label::kFar);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000611
612 // Converts, if necessary, a smi to a combination of number and
613 // multiplier to be used as a scaled index.
614 // The src register contains a *positive* smi value. The shift is the
615 // power of two to multiply the index value by (e.g.
616 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
617 // The returned index register may be either src or dst, depending
618 // on what is most efficient. If src and dst are different registers,
619 // src is always unchanged.
620 SmiIndex SmiToIndex(Register dst, Register src, int shift);
621
622 // Converts a positive smi to a negative index.
623 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
624
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000625 // Add the value of a smi in memory to an int32 register.
626 // Sets flags as a normal add.
627 void AddSmiField(Register dst, const Operand& src);
628
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000629 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000630 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000631 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000632 }
633
634 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000635 Register constant = GetSmiConstant(source);
636 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000637 }
638
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000639 void Push(Smi* smi);
640 void Test(const Operand& dst, Smi* source);
641
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000642 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000643 // String macros.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000644
645 // If object is a string, its map is loaded into object_map.
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000646 void JumpIfNotString(Register object,
647 Register object_map,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000648 Label* not_string,
649 Label::Distance near_jump = Label::kFar);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000650
651
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000652 void JumpIfNotBothSequentialAsciiStrings(
653 Register first_object,
654 Register second_object,
655 Register scratch1,
656 Register scratch2,
657 Label* on_not_both_flat_ascii,
658 Label::Distance near_jump = Label::kFar);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000659
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000660 // Check whether the instance type represents a flat ascii string. Jump to the
661 // label if not. If the instance type can be scratched specify same register
662 // for both instance type and scratch.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000663 void JumpIfInstanceTypeIsNotSequentialAscii(
664 Register instance_type,
665 Register scratch,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000666 Label*on_not_flat_ascii_string,
667 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000668
669 void JumpIfBothInstanceTypesAreNotSequentialAscii(
670 Register first_object_instance_type,
671 Register second_object_instance_type,
672 Register scratch1,
673 Register scratch2,
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000674 Label* on_fail,
675 Label::Distance near_jump = Label::kFar);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000676
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000677 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000678 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000679
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000680 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000681 void Set(Register dst, int64_t x);
682 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000683
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000684 // Move if the registers are not identical.
685 void Move(Register target, Register source);
686
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000687 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000688 void Move(Register dst, Handle<Object> source);
689 void Move(const Operand& dst, Handle<Object> source);
690 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000691 void Cmp(const Operand& dst, Handle<Object> source);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000692 void Cmp(Register dst, Smi* src);
693 void Cmp(const Operand& dst, Smi* src);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000694 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000695
696 // Emit code to discard a non-negative number of pointer-sized elements
697 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000698 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000699
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000700 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000701
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000702 // Control Flow
703 void Jump(Address destination, RelocInfo::Mode rmode);
704 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000705 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
706
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000707 void Call(Address destination, RelocInfo::Mode rmode);
708 void Call(ExternalReference ext);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000709 void Call(Handle<Code> code_object,
710 RelocInfo::Mode rmode,
711 unsigned ast_id = kNoASTId);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000712
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000713 // The size of the code generated for different call instructions.
714 int CallSize(Address destination, RelocInfo::Mode rmode) {
715 return kCallInstructionLength;
716 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000717 int CallSize(ExternalReference ext);
ricow@chromium.orgeb96f4f2011-03-09 13:41:48 +0000718 int CallSize(Handle<Code> code_object) {
719 // Code calls use 32-bit relative addressing.
720 return kShortCallInstructionLength;
721 }
722 int CallSize(Register target) {
723 // Opcode: REX_opt FF /2 m64
724 return (target.high_bit() != 0) ? 3 : 2;
725 }
726 int CallSize(const Operand& target) {
727 // Opcode: REX_opt FF /2 m64
728 return (target.requires_rex() ? 2 : 1) + target.operand_size();
729 }
730
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000731 // Emit call to the code we are currently generating.
732 void CallSelf() {
733 Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location()));
734 Call(self, RelocInfo::CODE_TARGET);
735 }
736
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000737 // Non-x64 instructions.
738 // Push/pop all general purpose registers.
739 // Does not push rsp/rbp nor any of the assembler's special purpose registers
740 // (kScratchRegister, kSmiConstantRegister, kRootRegister).
741 void Pushad();
742 void Popad();
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000743 // Sets the stack as after performing Popad, without actually loading the
744 // registers.
745 void Dropad();
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000746
ager@chromium.org9085a012009-05-11 19:22:57 +0000747 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000748 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000749 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000750 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000751 void CmpObjectType(Register heap_object, InstanceType type, Register map);
752
753 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000754 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000755 void CmpInstanceType(Register map, InstanceType type);
756
ager@chromium.org5c838252010-02-19 08:53:10 +0000757 // Check if the map of an object is equal to a specified map and
758 // branch to label if not. Skip the smi check if not required
759 // (object is known to be a heap object)
760 void CheckMap(Register obj,
761 Handle<Map> map,
762 Label* fail,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000763 SmiCheckType smi_check_type);
ager@chromium.org5c838252010-02-19 08:53:10 +0000764
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000765 // Check if the map of an object is equal to a specified map and branch to a
766 // specified target if equal. Skip the smi check if not required (object is
767 // known to be a heap object)
768 void DispatchMap(Register obj,
769 Handle<Map> map,
770 Handle<Code> success,
771 SmiCheckType smi_check_type);
772
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000773 // Check if the object in register heap_object is a string. Afterwards the
774 // register map contains the object map and the register instance_type
775 // contains the instance_type. The registers map and instance_type can be the
776 // same in which case it contains the instance type afterwards. Either of the
777 // registers map and instance_type can be the same as heap_object.
778 Condition IsObjectStringType(Register heap_object,
779 Register map,
780 Register instance_type);
781
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000782 // FCmp compares and pops the two values on top of the FPU stack.
783 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000784 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
785 void FCmp();
786
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000787 void ClampUint8(Register reg);
788
789 void ClampDoubleToUint8(XMMRegister input_reg,
790 XMMRegister temp_xmm_reg,
791 Register result_reg,
792 Register temp_reg);
793
danno@chromium.org40cb8782011-05-25 07:58:50 +0000794 void LoadInstanceDescriptors(Register map, Register descriptors);
795
ager@chromium.org5c838252010-02-19 08:53:10 +0000796 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000797 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000798
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000799 // Abort execution if argument is a smi. Used in debug code.
800 void AbortIfSmi(Register object);
801
lrn@chromium.org25156de2010-04-06 13:10:27 +0000802 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000803 void AbortIfNotSmi(Register object);
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000804 void AbortIfNotSmi(const Operand& object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000805
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000806 // Abort execution if argument is a string. Used in debug code.
807 void AbortIfNotString(Register object);
808
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000809 // Abort execution if argument is not the root value with the given index.
810 void AbortIfNotRootValue(Register src,
811 Heap::RootListIndex root_value_index,
812 const char* message);
813
ager@chromium.org9085a012009-05-11 19:22:57 +0000814 // ---------------------------------------------------------------------------
815 // Exception handling
816
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000817 // Push a new try handler and link into try handler chain. The return
818 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000819 void PushTryHandler(CodeLocation try_location, HandlerType type);
820
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000821 // Unlink the stack handler on top of the stack from the try handler chain.
822 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000823
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000824 // Activate the top handler in the try hander chain and pass the
825 // thrown value.
826 void Throw(Register value);
827
828 // Propagate an uncatchable exception out of the current JS stack.
829 void ThrowUncatchable(UncatchableExceptionType type, Register value);
830
ager@chromium.org9085a012009-05-11 19:22:57 +0000831 // ---------------------------------------------------------------------------
832 // Inline caching support
833
ager@chromium.org9085a012009-05-11 19:22:57 +0000834 // Generate code for checking access rights - used for security checks
835 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000836 // is left untouched, but the scratch register and kScratchRegister,
837 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000838 void CheckAccessGlobalProxy(Register holder_reg,
839 Register scratch,
840 Label* miss);
841
842
843 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000844 // Allocation support
845
846 // Allocate an object in new space. If the new space is exhausted control
847 // continues at the gc_required label. The allocated object is returned in
848 // result and end of the new object is returned in result_end. The register
849 // scratch can be passed as no_reg in which case an additional object
850 // reference will be added to the reloc info. The returned pointers in result
851 // and result_end have not yet been tagged as heap objects. If
852 // result_contains_top_on_entry is true the content of result is known to be
853 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000854 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000855 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000856 void AllocateInNewSpace(int object_size,
857 Register result,
858 Register result_end,
859 Register scratch,
860 Label* gc_required,
861 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000862
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000863 void AllocateInNewSpace(int header_size,
864 ScaleFactor element_size,
865 Register element_count,
866 Register result,
867 Register result_end,
868 Register scratch,
869 Label* gc_required,
870 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000871
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000872 void AllocateInNewSpace(Register object_size,
873 Register result,
874 Register result_end,
875 Register scratch,
876 Label* gc_required,
877 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000878
879 // Undo allocation in new space. The object passed and objects allocated after
880 // it will no longer be allocated. Make sure that no pointers are left to the
881 // object(s) no longer allocated as they would be invalid when allocation is
882 // un-done.
883 void UndoAllocationInNewSpace(Register object);
884
ager@chromium.org3811b432009-10-28 14:53:37 +0000885 // Allocate a heap number in new space with undefined value. Returns
886 // tagged pointer in result register, or jumps to gc_required if new
887 // space is full.
888 void AllocateHeapNumber(Register result,
889 Register scratch,
890 Label* gc_required);
891
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000892 // Allocate a sequential string. All the header fields of the string object
893 // are initialized.
894 void AllocateTwoByteString(Register result,
895 Register length,
896 Register scratch1,
897 Register scratch2,
898 Register scratch3,
899 Label* gc_required);
900 void AllocateAsciiString(Register result,
901 Register length,
902 Register scratch1,
903 Register scratch2,
904 Register scratch3,
905 Label* gc_required);
906
907 // Allocate a raw cons string object. Only the map field of the result is
908 // initialized.
909 void AllocateConsString(Register result,
910 Register scratch1,
911 Register scratch2,
912 Label* gc_required);
913 void AllocateAsciiConsString(Register result,
914 Register scratch1,
915 Register scratch2,
916 Label* gc_required);
917
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000918 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000919 // Support functions.
920
921 // Check if result is zero and op is negative.
922 void NegativeZeroTest(Register result, Register op, Label* then_label);
923
924 // Check if result is zero and op is negative in code using jump targets.
925 void NegativeZeroTest(CodeGenerator* cgen,
926 Register result,
927 Register op,
928 JumpTarget* then_target);
929
930 // Check if result is zero and any of op1 and op2 are negative.
931 // Register scratch is destroyed, and it must be different from op2.
932 void NegativeZeroTest(Register result, Register op1, Register op2,
933 Register scratch, Label* then_label);
934
935 // Try to get function prototype of a function and puts the value in
936 // the result register. Checks that the function really is a
937 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000938 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000939 // clobbered.
940 void TryGetFunctionPrototype(Register function,
941 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000942 Label* miss);
943
944 // Generates code for reporting that an illegal operation has
945 // occurred.
946 void IllegalOperation(int num_arguments);
947
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000948 // Picks out an array index from the hash field.
949 // Register use:
950 // hash - holds the index's hash. Clobbered.
951 // index - holds the overwritten index on exit.
952 void IndexFromHash(Register hash, Register index);
953
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000954 // Find the function context up the context chain.
955 void LoadContext(Register dst, int context_chain_length);
956
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000957 // Load the global function with the given index.
958 void LoadGlobalFunction(int index, Register function);
959
960 // Load the initial map from the global function. The registers
961 // function and map can be the same.
962 void LoadGlobalFunctionInitialMap(Register function, Register map);
963
ager@chromium.org9085a012009-05-11 19:22:57 +0000964 // ---------------------------------------------------------------------------
965 // Runtime calls
966
967 // Call a code stub.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000968 void CallStub(CodeStub* stub, unsigned ast_id = kNoASTId);
ager@chromium.org9085a012009-05-11 19:22:57 +0000969
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000970 // Call a code stub and return the code object called. Try to generate
971 // the code if necessary. Do not perform a GC but instead return a retry
972 // after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000973 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000974
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000975 // Tail call a code stub (jump).
976 void TailCallStub(CodeStub* stub);
977
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000978 // Tail call a code stub (jump) and return the code object called. Try to
979 // generate the code if necessary. Do not perform a GC but instead return
980 // a retry after GC failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000981 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000982
ager@chromium.org9085a012009-05-11 19:22:57 +0000983 // Return from a code stub after popping its arguments.
984 void StubReturn(int argc);
985
986 // Call a runtime routine.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000987 void CallRuntime(const Runtime::Function* f, int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000988
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000989 // Call a runtime function and save the value of XMM registers.
990 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
991
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000992 // Call a runtime function, returning the CodeStub object called.
993 // Try to generate the stub code if necessary. Do not perform a GC
994 // but instead return a retry after GC failure.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000995 MUST_USE_RESULT MaybeObject* TryCallRuntime(const Runtime::Function* f,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000996 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000997
ager@chromium.org9085a012009-05-11 19:22:57 +0000998 // Convenience function: Same as above, but takes the fid instead.
999 void CallRuntime(Runtime::FunctionId id, int num_arguments);
1000
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001001 // Convenience function: Same as above, but takes the fid instead.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001002 MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id,
1003 int num_arguments);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001004
ager@chromium.org5c838252010-02-19 08:53:10 +00001005 // Convenience function: call an external reference.
1006 void CallExternalReference(const ExternalReference& ext,
1007 int num_arguments);
1008
ager@chromium.org9085a012009-05-11 19:22:57 +00001009 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001010 // Like JumpToExternalReference, but also takes care of passing the number
1011 // of parameters.
1012 void TailCallExternalReference(const ExternalReference& ext,
1013 int num_arguments,
1014 int result_size);
1015
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001016 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
1017 const ExternalReference& ext, int num_arguments, int result_size);
1018
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001019 // Convenience function: tail call a runtime routine (jump).
1020 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001021 int num_arguments,
1022 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001023
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001024 MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid,
1025 int num_arguments,
1026 int result_size);
1027
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001028 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001029 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +00001030
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001031 // Jump to a runtime routine.
1032 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext,
1033 int result_size);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001034
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001035 // Prepares stack to put arguments (aligns and so on).
1036 // WIN64 calling convention requires to put the pointer to the return value
1037 // slot into rcx (rcx must be preserverd until TryCallApiFunctionAndReturn).
1038 // Saves context (rsi). Clobbers rax. Allocates arg_stack_space * kPointerSize
1039 // inside the exit frame (not GCed) accessible via StackSpaceOperand.
1040 void PrepareCallApiFunction(int arg_stack_space);
1041
1042 // Calls an API function. Allocates HandleScope, extracts
1043 // returned value from handle and propagates exceptions.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001044 // Clobbers r14, r15, rbx and caller-save registers. Restores context.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001045 // On return removes stack_space * kPointerSize (GCed).
1046 MUST_USE_RESULT MaybeObject* TryCallApiFunctionAndReturn(
1047 ApiFunction* function, int stack_space);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001048
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001049 // Before calling a C-function from generated code, align arguments on stack.
1050 // After aligning the frame, arguments must be stored in esp[0], esp[4],
1051 // etc., not pushed. The argument count assumes all arguments are word sized.
1052 // The number of slots reserved for arguments depends on platform. On Windows
1053 // stack slots are reserved for the arguments passed in registers. On other
1054 // platforms stack slots are only reserved for the arguments actually passed
1055 // on the stack.
1056 void PrepareCallCFunction(int num_arguments);
1057
1058 // Calls a C function and cleans up the space for arguments allocated
1059 // by PrepareCallCFunction. The called function is not allowed to trigger a
1060 // garbage collection, since that might move the code and invalidate the
1061 // return address (unless this is somehow accounted for by the called
1062 // function).
1063 void CallCFunction(ExternalReference function, int num_arguments);
1064 void CallCFunction(Register function, int num_arguments);
1065
1066 // Calculate the number of stack slots to reserve for arguments when calling a
1067 // C function.
1068 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +00001069
1070 // ---------------------------------------------------------------------------
1071 // Utilities
1072
1073 void Ret();
1074
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001075 // Return and drop arguments from stack, where the number of arguments
1076 // may be bigger than 2^16 - 1. Requires a scratch register.
1077 void Ret(int bytes_dropped, Register scratch);
1078
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001079 Handle<Object> CodeObject() {
1080 ASSERT(!code_object_.is_null());
1081 return code_object_;
1082 }
ager@chromium.org9085a012009-05-11 19:22:57 +00001083
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001084 // Copy length bytes from source to destination.
1085 // Uses scratch register internally (if you have a low-eight register
1086 // free, do use it, otherwise kScratchRegister will be used).
1087 // The min_length is a minimum limit on the value that length will have.
1088 // The algorithm has some special cases that might be omitted if the string
1089 // is known to always be long.
1090 void CopyBytes(Register destination,
1091 Register source,
1092 Register length,
1093 int min_length = 0,
1094 Register scratch = kScratchRegister);
1095
ager@chromium.org9085a012009-05-11 19:22:57 +00001096
1097 // ---------------------------------------------------------------------------
1098 // StatsCounter support
1099
1100 void SetCounter(StatsCounter* counter, int value);
1101 void IncrementCounter(StatsCounter* counter, int value);
1102 void DecrementCounter(StatsCounter* counter, int value);
1103
1104
1105 // ---------------------------------------------------------------------------
1106 // Debugging
1107
1108 // Calls Abort(msg) if the condition cc is not satisfied.
1109 // Use --debug_code to enable.
1110 void Assert(Condition cc, const char* msg);
1111
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001112 void AssertFastElements(Register elements);
1113
ager@chromium.org9085a012009-05-11 19:22:57 +00001114 // Like Assert(), but always enabled.
1115 void Check(Condition cc, const char* msg);
1116
1117 // Print a message to stdout and abort execution.
1118 void Abort(const char* msg);
1119
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00001120 // Check that the stack is aligned.
1121 void CheckStackAlignment();
1122
ager@chromium.org9085a012009-05-11 19:22:57 +00001123 // Verify restrictions about code generated in stubs.
1124 void set_generating_stub(bool value) { generating_stub_ = value; }
1125 bool generating_stub() { return generating_stub_; }
1126 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1127 bool allow_stub_calls() { return allow_stub_calls_; }
1128
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001129 static int SafepointRegisterStackIndex(Register reg) {
1130 return SafepointRegisterStackIndex(reg.code());
1131 }
1132
ager@chromium.org9085a012009-05-11 19:22:57 +00001133 private:
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001134 // Order general registers are pushed by Pushad.
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001135 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001136 static int kSafepointPushRegisterIndices[Register::kNumRegisters];
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001137 static const int kNumSafepointSavedRegisters = 11;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001138 static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00001139
ager@chromium.org9085a012009-05-11 19:22:57 +00001140 bool generating_stub_;
1141 bool allow_stub_calls_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001142 bool root_array_available_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001143
1144 // Returns a register holding the smi value. The register MUST NOT be
1145 // modified. It may be the "smi 1 constant" register.
1146 Register GetSmiConstant(Smi* value);
1147
1148 // Moves the smi value to the destination register.
1149 void LoadSmiConstant(Register dst, Smi* value);
1150
ager@chromium.org5c838252010-02-19 08:53:10 +00001151 // This handle will be patched with the code object on installation.
1152 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +00001153
1154 // Helper functions for generating invokes.
1155 void InvokePrologue(const ParameterCount& expected,
1156 const ParameterCount& actual,
1157 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001158 Register code_register,
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001159 Label* done,
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001160 InvokeFlag flag,
danno@chromium.org40cb8782011-05-25 07:58:50 +00001161 Label::Distance near_jump = Label::kFar,
1162 const CallWrapper& call_wrapper = NullCallWrapper(),
1163 CallKind call_kind = CALL_AS_METHOD);
ager@chromium.org9085a012009-05-11 19:22:57 +00001164
ager@chromium.org9085a012009-05-11 19:22:57 +00001165 // Activation support.
1166 void EnterFrame(StackFrame::Type type);
1167 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001168
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00001169 void EnterExitFramePrologue(bool save_rax);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001170
1171 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack
1172 // accessible via StackSpaceOperand.
ager@chromium.org0ee099b2011-01-25 14:06:47 +00001173 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001174
1175 void LeaveExitFrameEpilogue();
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001176
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001177 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001178 // Loads the top of new-space into the result register.
ager@chromium.orgac091b72010-05-05 07:34:42 +00001179 // Otherwise the address of the new-space top is loaded into scratch (if
1180 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001181 void LoadAllocationTopHelper(Register result,
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001182 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +00001183 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +00001184 // Update allocation top with value in result_end register.
1185 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001186 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +00001187
1188 // Helper for PopHandleScope. Allowed to perform a GC and returns
1189 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
1190 // possibly returns a failure object indicating an allocation failure.
1191 Object* PopHandleScopeHelper(Register saved,
1192 Register scratch,
1193 bool gc_allowed);
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +00001194
1195
1196 // Compute memory operands for safepoint stack slots.
1197 Operand SafepointRegisterSlot(Register reg);
1198 static int SafepointRegisterStackIndex(int reg_code) {
1199 return kNumSafepointRegisters - kSafepointPushRegisterIndices[reg_code] - 1;
1200 }
1201
1202 // Needs access to SafepointRegisterStackIndex for optimized frame
1203 // traversal.
1204 friend class OptimizedFrame;
ager@chromium.org9085a012009-05-11 19:22:57 +00001205};
1206
1207
ager@chromium.org4af710e2009-09-15 12:20:11 +00001208// The code patcher is used to patch (typically) small parts of code e.g. for
1209// debugging and other types of instrumentation. When using the code patcher
1210// the exact number of bytes specified must be emitted. Is not legal to emit
1211// relocation information. If any of these constraints are violated it causes
1212// an assertion.
1213class CodePatcher {
1214 public:
1215 CodePatcher(byte* address, int size);
1216 virtual ~CodePatcher();
1217
1218 // Macro assembler to emit code.
1219 MacroAssembler* masm() { return &masm_; }
1220
1221 private:
1222 byte* address_; // The address of the code being patched.
1223 int size_; // Number of bytes of the expected patch size.
1224 MacroAssembler masm_; // Macro assembler used to generate the code.
1225};
1226
1227
ager@chromium.org9085a012009-05-11 19:22:57 +00001228// -----------------------------------------------------------------------------
1229// Static helper functions.
1230
1231// Generate an Operand for loading a field from an object.
1232static inline Operand FieldOperand(Register object, int offset) {
1233 return Operand(object, offset - kHeapObjectTag);
1234}
1235
1236
1237// Generate an Operand for loading an indexed field from an object.
1238static inline Operand FieldOperand(Register object,
1239 Register index,
1240 ScaleFactor scale,
1241 int offset) {
1242 return Operand(object, index, scale, offset - kHeapObjectTag);
1243}
1244
1245
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00001246static inline Operand ContextOperand(Register context, int index) {
1247 return Operand(context, Context::SlotOffset(index));
1248}
1249
1250
1251static inline Operand GlobalObjectOperand() {
1252 return ContextOperand(rsi, Context::GLOBAL_INDEX);
1253}
1254
1255
1256// Provides access to exit frame stack space (not GCed).
1257static inline Operand StackSpaceOperand(int index) {
1258#ifdef _WIN64
1259 const int kShaddowSpace = 4;
1260 return Operand(rsp, (index + kShaddowSpace) * kPointerSize);
1261#else
1262 return Operand(rsp, index * kPointerSize);
1263#endif
1264}
1265
1266
1267
ager@chromium.org9085a012009-05-11 19:22:57 +00001268#ifdef GENERATED_CODE_COVERAGE
1269extern void LogGeneratedCodeCoverage(const char* file_line);
1270#define CODE_COVERAGE_STRINGIFY(x) #x
1271#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1272#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1273#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001274 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +00001275 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
1276 masm->pushfd(); \
1277 masm->pushad(); \
1278 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001279 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +00001280 masm->pop(rax); \
1281 masm->popad(); \
1282 masm->popfd(); \
1283 } \
1284 masm->
1285#else
1286#define ACCESS_MASM(masm) masm->
1287#endif
1288
ager@chromium.org9085a012009-05-11 19:22:57 +00001289} } // namespace v8::internal
1290
1291#endif // V8_X64_MACRO_ASSEMBLER_X64_H_