blob: aedc3b9ced3416e8cfb83f828c88024a01cc6f53 [file] [log] [blame]
ager@chromium.orga1645e22009-09-09 19:27:10 +00001// Copyright 2009 the V8 project authors. All rights reserved.
ager@chromium.org5ec48922009-05-05 07:25:34 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
ager@chromium.org9085a012009-05-11 19:22:57 +000028#ifndef V8_X64_MACRO_ASSEMBLER_X64_H_
29#define V8_X64_MACRO_ASSEMBLER_X64_H_
30
31#include "assembler.h"
32
kasperl@chromium.org71affb52009-05-26 05:44:31 +000033namespace v8 {
34namespace internal {
ager@chromium.org9085a012009-05-11 19:22:57 +000035
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +000036// Flags used for the AllocateInNewSpace functions.
37enum AllocationFlags {
38 // No special flags.
39 NO_ALLOCATION_FLAGS = 0,
40 // Return the pointer to the allocated already tagged as a heap object.
41 TAG_OBJECT = 1 << 0,
42 // The content of the result register already contains the allocation top in
43 // new space.
44 RESULT_CONTAINS_TOP = 1 << 1
45};
46
ager@chromium.orge2902be2009-06-08 12:21:35 +000047// Default scratch register used by MacroAssembler (and other code that needs
48// a spare register). The register isn't callee save, and not used by the
49// function calling convention.
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000050static const Register kScratchRegister = { 10 }; // r10.
51static const Register kSmiConstantRegister = { 15 }; // r15 (callee save).
52static const Register kRootRegister = { 13 }; // r13 (callee save).
53// Value of smi in kSmiConstantRegister.
54static const int kSmiConstantRegisterValue = 1;
ager@chromium.orge2902be2009-06-08 12:21:35 +000055
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000056// Convenience for platform-independent signatures.
57typedef Operand MemOperand;
58
ager@chromium.org9085a012009-05-11 19:22:57 +000059// Forward declaration.
60class JumpTarget;
61
ager@chromium.org4af710e2009-09-15 12:20:11 +000062struct SmiIndex {
63 SmiIndex(Register index_register, ScaleFactor scale)
64 : reg(index_register),
65 scale(scale) {}
66 Register reg;
67 ScaleFactor scale;
68};
ager@chromium.org9085a012009-05-11 19:22:57 +000069
ager@chromium.org9085a012009-05-11 19:22:57 +000070// MacroAssembler implements a collection of frequently used macros.
71class MacroAssembler: public Assembler {
72 public:
73 MacroAssembler(void* buffer, int size);
74
ager@chromium.org18ad94b2009-09-02 08:22:29 +000075 void LoadRoot(Register destination, Heap::RootListIndex index);
76 void CompareRoot(Register with, Heap::RootListIndex index);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +000077 void CompareRoot(Operand with, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +000078 void PushRoot(Heap::RootListIndex index);
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +000079 void StoreRoot(Register source, Heap::RootListIndex index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +000080
ager@chromium.org9085a012009-05-11 19:22:57 +000081 // ---------------------------------------------------------------------------
82 // GC Support
83
ricow@chromium.org30ce4112010-05-31 10:38:25 +000084 // For page containing |object| mark region covering |addr| dirty.
85 // RecordWriteHelper only works if the object is not in new
ager@chromium.orgac091b72010-05-05 07:34:42 +000086 // space.
87 void RecordWriteHelper(Register object,
88 Register addr,
89 Register scratch);
90
kmillikin@chromium.org4111b802010-05-03 10:34:42 +000091 // Check if object is in new space. The condition cc can be equal or
92 // not_equal. If it is equal a jump will be done if the object is on new
93 // space. The register scratch can be object itself, but it will be clobbered.
94 void InNewSpace(Register object,
95 Register scratch,
96 Condition cc,
97 Label* branch);
98
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000099 // For page containing |object| mark region covering [object+offset]
100 // dirty. |object| is the object being stored into, |value| is the
101 // object being stored. If |offset| is zero, then the |scratch|
102 // register contains the array index into the elements array
103 // represented as a Smi. All registers are clobbered by the
104 // operation. RecordWrite filters out smis so it does not update the
105 // write barrier if the value is a smi.
ager@chromium.org9085a012009-05-11 19:22:57 +0000106 void RecordWrite(Register object,
107 int offset,
108 Register value,
109 Register scratch);
110
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000111 // For page containing |object| mark region covering [address]
112 // dirty. |object| is the object being stored into, |value| is the
113 // object being stored. All registers are clobbered by the
114 // operation. RecordWrite filters out smis so it does not update
115 // the write barrier if the value is a smi.
116 void RecordWrite(Register object,
117 Register address,
118 Register value);
119
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000120 // For page containing |object| mark region covering [object+offset] dirty.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000121 // The value is known to not be a smi.
122 // object is the object being stored into, value is the object being stored.
123 // If offset is zero, then the scratch register contains the array index into
124 // the elements array represented as a Smi.
125 // All registers are clobbered by the operation.
126 void RecordWriteNonSmi(Register object,
127 int offset,
128 Register value,
129 Register scratch);
130
ager@chromium.org9085a012009-05-11 19:22:57 +0000131#ifdef ENABLE_DEBUGGER_SUPPORT
132 // ---------------------------------------------------------------------------
133 // Debugger Support
134
135 void SaveRegistersToMemory(RegList regs);
136 void RestoreRegistersFromMemory(RegList regs);
137 void PushRegistersFromMemory(RegList regs);
138 void PopRegistersToMemory(RegList regs);
139 void CopyRegistersFromStackToMemory(Register base,
140 Register scratch,
141 RegList regs);
ager@chromium.org5c838252010-02-19 08:53:10 +0000142 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000143#endif
144
145 // ---------------------------------------------------------------------------
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000146 // Stack limit support
147
148 // Do simple test for stack overflow. This doesn't handle an overflow.
149 void StackLimitCheck(Label* on_stack_limit_hit);
150
151 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000152 // Activation frames
153
154 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
155 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
156
157 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
158 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
159
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000160 // Enter specific kind of exit frame; either in normal or
161 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000162 // sets up the number of arguments in register rdi and the pointer
163 // to the first argument in register rsi.
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000164 void EnterExitFrame(ExitFrame::Mode mode, int result_size = 1);
ager@chromium.org9085a012009-05-11 19:22:57 +0000165
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000166 void EnterApiExitFrame(ExitFrame::Mode mode,
167 int stack_space,
168 int argc,
169 int result_size = 1);
170
ager@chromium.orga1645e22009-09-09 19:27:10 +0000171 // Leave the current exit frame. Expects/provides the return value in
172 // register rax:rdx (untouched) and the pointer to the first
173 // argument in register rsi.
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000174 void LeaveExitFrame(ExitFrame::Mode mode, int result_size = 1);
ager@chromium.org9085a012009-05-11 19:22:57 +0000175
176
177 // ---------------------------------------------------------------------------
178 // JavaScript invokes
179
180 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000181 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000182 const ParameterCount& expected,
183 const ParameterCount& actual,
184 InvokeFlag flag);
185
186 void InvokeCode(Handle<Code> code,
187 const ParameterCount& expected,
188 const ParameterCount& actual,
189 RelocInfo::Mode rmode,
190 InvokeFlag flag);
191
192 // Invoke the JavaScript function in the given register. Changes the
193 // current context to the context in the function before invoking.
194 void InvokeFunction(Register function,
195 const ParameterCount& actual,
196 InvokeFlag flag);
197
ager@chromium.org5c838252010-02-19 08:53:10 +0000198 void InvokeFunction(JSFunction* function,
199 const ParameterCount& actual,
200 InvokeFlag flag);
201
ager@chromium.org9085a012009-05-11 19:22:57 +0000202 // Invoke specified builtin JavaScript function. Adds an entry to
203 // the unresolved list if the name does not resolve.
204 void InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag);
205
206 // Store the code object for the given builtin in the target register.
207 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
208
ager@chromium.org4af710e2009-09-15 12:20:11 +0000209
210 // ---------------------------------------------------------------------------
211 // Smi tagging, untagging and operations on tagged smis.
212
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000213 void InitializeSmiConstantRegister() {
214 movq(kSmiConstantRegister,
215 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
216 RelocInfo::NONE);
217 }
218
ager@chromium.org4af710e2009-09-15 12:20:11 +0000219 // Conversions between tagged smi values and non-tagged integer values.
220
221 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000222 // Only uses the low 32 bits of the src register. Sets the N and Z flags
223 // based on the value of the resulting integer.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000224 void Integer32ToSmi(Register dst, Register src);
225
226 // Tag an integer value if possible, or jump the integer value cannot be
227 // represented as a smi. Only uses the low 32 bit of the src registers.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000228 // NOTICE: Destroys the dst register even if unsuccessful!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000229 void Integer32ToSmi(Register dst, Register src, Label* on_overflow);
230
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000231 // Stores an integer32 value into a memory field that already holds a smi.
232 void Integer32ToSmiField(const Operand& dst, Register src);
233
ager@chromium.org4af710e2009-09-15 12:20:11 +0000234 // Adds constant to src and tags the result as a smi.
235 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000236 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000237
238 // Convert smi to 32-bit integer. I.e., not sign extended into
239 // high 32 bits of destination.
240 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000241 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000242
243 // Convert smi to 64-bit integer (sign extended if necessary).
244 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000245 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000246
247 // Multiply a positive smi's integer value by a power of two.
248 // Provides result as 64-bit integer value.
249 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
250 Register src,
251 int power);
252
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000253 // Divide a positive smi's integer value by a power of two.
254 // Provides result as 32-bit integer value.
255 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
256 Register src,
257 int power);
258
259
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000260 // Simple comparison of smis.
261 void SmiCompare(Register dst, Register src);
262 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000263 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000264 void SmiCompare(const Operand& dst, Register src);
265 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000266 // Compare the int32 in src register to the value of the smi stored at dst.
267 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000268 // Sets sign and zero flags depending on value of smi in register.
269 void SmiTest(Register src);
270
ager@chromium.org4af710e2009-09-15 12:20:11 +0000271 // Functions performing a check on a known or potential smi. Returns
272 // a condition that is satisfied if the check is successful.
273
274 // Is the value a tagged smi.
275 Condition CheckSmi(Register src);
276
ager@chromium.org4af710e2009-09-15 12:20:11 +0000277 // Is the value a positive tagged smi.
278 Condition CheckPositiveSmi(Register src);
279
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000280 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000281 Condition CheckBothSmi(Register first, Register second);
282
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000283 // Are both values tagged smis.
284 Condition CheckBothPositiveSmi(Register first, Register second);
285
286 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000287 Condition CheckEitherSmi(Register first,
288 Register second,
289 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000290
ager@chromium.org4af710e2009-09-15 12:20:11 +0000291 // Is the value the minimum smi value (since we are using
292 // two's complement numbers, negating the value is known to yield
293 // a non-smi value).
294 Condition CheckIsMinSmi(Register src);
295
ager@chromium.org4af710e2009-09-15 12:20:11 +0000296 // Checks whether an 32-bit integer value is a valid for conversion
297 // to a smi.
298 Condition CheckInteger32ValidSmiValue(Register src);
299
ager@chromium.org3811b432009-10-28 14:53:37 +0000300 // Checks whether an 32-bit unsigned integer value is a valid for
301 // conversion to a smi.
302 Condition CheckUInteger32ValidSmiValue(Register src);
303
ager@chromium.org4af710e2009-09-15 12:20:11 +0000304 // Test-and-jump functions. Typically combines a check function
305 // above with a conditional jump.
306
307 // Jump if the value cannot be represented by a smi.
308 void JumpIfNotValidSmiValue(Register src, Label* on_invalid);
309
ager@chromium.org3811b432009-10-28 14:53:37 +0000310 // Jump if the unsigned integer value cannot be represented by a smi.
311 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid);
312
ager@chromium.org4af710e2009-09-15 12:20:11 +0000313 // Jump to label if the value is a tagged smi.
314 void JumpIfSmi(Register src, Label* on_smi);
315
316 // Jump to label if the value is not a tagged smi.
317 void JumpIfNotSmi(Register src, Label* on_not_smi);
318
319 // Jump to label if the value is not a positive tagged smi.
320 void JumpIfNotPositiveSmi(Register src, Label* on_not_smi);
321
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000322 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000323 // to the constant.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000324 void JumpIfSmiEqualsConstant(Register src, Smi* constant, Label* on_equals);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000325
ager@chromium.org4af710e2009-09-15 12:20:11 +0000326 // Jump if either or both register are not smi values.
327 void JumpIfNotBothSmi(Register src1, Register src2, Label* on_not_both_smi);
328
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000329 // Jump if either or both register are not positive smi values.
330 void JumpIfNotBothPositiveSmi(Register src1, Register src2,
331 Label* on_not_both_smi);
332
ager@chromium.org4af710e2009-09-15 12:20:11 +0000333 // Operations on tagged smi values.
334
335 // Smis represent a subset of integers. The subset is always equivalent to
336 // a two's complement interpretation of a fixed number of bits.
337
338 // Optimistically adds an integer constant to a supposed smi.
339 // If the src is not a smi, or the result is not a smi, jump to
340 // the label.
341 void SmiTryAddConstant(Register dst,
342 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000343 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000344 Label* on_not_smi_result);
345
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000346 // Add an integer constant to a tagged smi, giving a tagged smi as result.
347 // No overflow testing on the result is done.
348 void SmiAddConstant(Register dst, Register src, Smi* constant);
349
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000350 // Add an integer constant to a tagged smi, giving a tagged smi as result.
351 // No overflow testing on the result is done.
352 void SmiAddConstant(const Operand& dst, Smi* constant);
353
ager@chromium.org4af710e2009-09-15 12:20:11 +0000354 // Add an integer constant to a tagged smi, giving a tagged smi as result,
355 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000356 void SmiAddConstant(Register dst,
357 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000358 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000359 Label* on_not_smi_result);
360
361 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000362 // result. No testing on the result is done. Sets the N and Z flags
363 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000364 void SmiSubConstant(Register dst, Register src, Smi* constant);
365
366 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000367 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000368 void SmiSubConstant(Register dst,
369 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000370 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000371 Label* on_not_smi_result);
372
373 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000374 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000375 void SmiNeg(Register dst,
376 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000377 Label* on_smi_result);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000378
379 // Adds smi values and return the result as a smi.
380 // If dst is src1, then src1 will be destroyed, even if
381 // the operation is unsuccessful.
382 void SmiAdd(Register dst,
383 Register src1,
384 Register src2,
385 Label* on_not_smi_result);
386
387 // Subtracts smi values and return the result as a smi.
388 // If dst is src1, then src1 will be destroyed, even if
389 // the operation is unsuccessful.
390 void SmiSub(Register dst,
391 Register src1,
392 Register src2,
393 Label* on_not_smi_result);
394
ager@chromium.orgac091b72010-05-05 07:34:42 +0000395 void SmiSub(Register dst,
396 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000397 const Operand& src2,
ager@chromium.orgac091b72010-05-05 07:34:42 +0000398 Label* on_not_smi_result);
399
ager@chromium.org4af710e2009-09-15 12:20:11 +0000400 // Multiplies smi values and return the result as a smi,
401 // if possible.
402 // If dst is src1, then src1 will be destroyed, even if
403 // the operation is unsuccessful.
404 void SmiMul(Register dst,
405 Register src1,
406 Register src2,
407 Label* on_not_smi_result);
408
409 // Divides one smi by another and returns the quotient.
410 // Clobbers rax and rdx registers.
411 void SmiDiv(Register dst,
412 Register src1,
413 Register src2,
414 Label* on_not_smi_result);
415
416 // Divides one smi by another and returns the remainder.
417 // Clobbers rax and rdx registers.
418 void SmiMod(Register dst,
419 Register src1,
420 Register src2,
421 Label* on_not_smi_result);
422
423 // Bitwise operations.
424 void SmiNot(Register dst, Register src);
425 void SmiAnd(Register dst, Register src1, Register src2);
426 void SmiOr(Register dst, Register src1, Register src2);
427 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000428 void SmiAndConstant(Register dst, Register src1, Smi* constant);
429 void SmiOrConstant(Register dst, Register src1, Smi* constant);
430 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000431
432 void SmiShiftLeftConstant(Register dst,
433 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000434 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000435 void SmiShiftLogicalRightConstant(Register dst,
436 Register src,
437 int shift_value,
438 Label* on_not_smi_result);
439 void SmiShiftArithmeticRightConstant(Register dst,
440 Register src,
441 int shift_value);
442
443 // Shifts a smi value to the left, and returns the result if that is a smi.
444 // Uses and clobbers rcx, so dst may not be rcx.
445 void SmiShiftLeft(Register dst,
446 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000447 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000448 // Shifts a smi value to the right, shifting in zero bits at the top, and
449 // returns the unsigned intepretation of the result if that is a smi.
450 // Uses and clobbers rcx, so dst may not be rcx.
451 void SmiShiftLogicalRight(Register dst,
452 Register src1,
453 Register src2,
454 Label* on_not_smi_result);
455 // Shifts a smi value to the right, sign extending the top, and
456 // returns the signed intepretation of the result. That will always
457 // be a valid smi value, since it's numerically smaller than the
458 // original.
459 // Uses and clobbers rcx, so dst may not be rcx.
460 void SmiShiftArithmeticRight(Register dst,
461 Register src1,
462 Register src2);
463
464 // Specialized operations
465
466 // Select the non-smi register of two registers where exactly one is a
467 // smi. If neither are smis, jump to the failure label.
468 void SelectNonSmi(Register dst,
469 Register src1,
470 Register src2,
471 Label* on_not_smis);
472
473 // Converts, if necessary, a smi to a combination of number and
474 // multiplier to be used as a scaled index.
475 // The src register contains a *positive* smi value. The shift is the
476 // power of two to multiply the index value by (e.g.
477 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
478 // The returned index register may be either src or dst, depending
479 // on what is most efficient. If src and dst are different registers,
480 // src is always unchanged.
481 SmiIndex SmiToIndex(Register dst, Register src, int shift);
482
483 // Converts a positive smi to a negative index.
484 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
485
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000486 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000487 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000488 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000489 }
490
491 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000492 Register constant = GetSmiConstant(source);
493 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000494 }
495
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000496 void Push(Smi* smi);
497 void Test(const Operand& dst, Smi* source);
498
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000499 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000500 // String macros.
501 void JumpIfNotBothSequentialAsciiStrings(Register first_object,
502 Register second_object,
503 Register scratch1,
504 Register scratch2,
505 Label* on_not_both_flat_ascii);
506
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000507 // Check whether the instance type represents a flat ascii string. Jump to the
508 // label if not. If the instance type can be scratched specify same register
509 // for both instance type and scratch.
510 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
511 Register scratch,
512 Label *on_not_flat_ascii_string);
513
514 void JumpIfBothInstanceTypesAreNotSequentialAscii(
515 Register first_object_instance_type,
516 Register second_object_instance_type,
517 Register scratch1,
518 Register scratch2,
519 Label* on_fail);
520
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000521 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000522 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000523
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000524 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000525 void Set(Register dst, int64_t x);
526 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000527
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000528 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000529 void Move(Register dst, Handle<Object> source);
530 void Move(const Operand& dst, Handle<Object> source);
531 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000532 void Cmp(const Operand& dst, Handle<Object> source);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000533 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000534
535 // Emit code to discard a non-negative number of pointer-sized elements
536 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000537 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000538
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000539 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000540
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000541 // Control Flow
542 void Jump(Address destination, RelocInfo::Mode rmode);
543 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000544 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
545
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000546 void Call(Address destination, RelocInfo::Mode rmode);
547 void Call(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000548 void Call(Handle<Code> code_object, RelocInfo::Mode rmode);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000549
ager@chromium.org9085a012009-05-11 19:22:57 +0000550 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000551 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000552 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000553 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000554 void CmpObjectType(Register heap_object, InstanceType type, Register map);
555
556 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000557 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000558 void CmpInstanceType(Register map, InstanceType type);
559
ager@chromium.org5c838252010-02-19 08:53:10 +0000560 // Check if the map of an object is equal to a specified map and
561 // branch to label if not. Skip the smi check if not required
562 // (object is known to be a heap object)
563 void CheckMap(Register obj,
564 Handle<Map> map,
565 Label* fail,
566 bool is_heap_object);
567
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000568 // Check if the object in register heap_object is a string. Afterwards the
569 // register map contains the object map and the register instance_type
570 // contains the instance_type. The registers map and instance_type can be the
571 // same in which case it contains the instance type afterwards. Either of the
572 // registers map and instance_type can be the same as heap_object.
573 Condition IsObjectStringType(Register heap_object,
574 Register map,
575 Register instance_type);
576
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000577 // FCmp compares and pops the two values on top of the FPU stack.
578 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000579 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
580 void FCmp();
581
ager@chromium.org5c838252010-02-19 08:53:10 +0000582 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000583 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000584
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000585 // Abort execution if argument is a smi. Used in debug code.
586 void AbortIfSmi(Register object);
587
lrn@chromium.org25156de2010-04-06 13:10:27 +0000588 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000589 void AbortIfNotSmi(Register object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000590
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000591 // Abort execution if argument is not the root value with the given index.
592 void AbortIfNotRootValue(Register src,
593 Heap::RootListIndex root_value_index,
594 const char* message);
595
ager@chromium.org9085a012009-05-11 19:22:57 +0000596 // ---------------------------------------------------------------------------
597 // Exception handling
598
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000599 // Push a new try handler and link into try handler chain. The return
600 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000601 void PushTryHandler(CodeLocation try_location, HandlerType type);
602
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000603 // Unlink the stack handler on top of the stack from the try handler chain.
604 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000605
606 // ---------------------------------------------------------------------------
607 // Inline caching support
608
ager@chromium.org9085a012009-05-11 19:22:57 +0000609 // Generate code for checking access rights - used for security checks
610 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000611 // is left untouched, but the scratch register and kScratchRegister,
612 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000613 void CheckAccessGlobalProxy(Register holder_reg,
614 Register scratch,
615 Label* miss);
616
617
618 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000619 // Allocation support
620
621 // Allocate an object in new space. If the new space is exhausted control
622 // continues at the gc_required label. The allocated object is returned in
623 // result and end of the new object is returned in result_end. The register
624 // scratch can be passed as no_reg in which case an additional object
625 // reference will be added to the reloc info. The returned pointers in result
626 // and result_end have not yet been tagged as heap objects. If
627 // result_contains_top_on_entry is true the content of result is known to be
628 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000629 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000630 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000631 void AllocateInNewSpace(int object_size,
632 Register result,
633 Register result_end,
634 Register scratch,
635 Label* gc_required,
636 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000637
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000638 void AllocateInNewSpace(int header_size,
639 ScaleFactor element_size,
640 Register element_count,
641 Register result,
642 Register result_end,
643 Register scratch,
644 Label* gc_required,
645 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000646
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000647 void AllocateInNewSpace(Register object_size,
648 Register result,
649 Register result_end,
650 Register scratch,
651 Label* gc_required,
652 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000653
654 // Undo allocation in new space. The object passed and objects allocated after
655 // it will no longer be allocated. Make sure that no pointers are left to the
656 // object(s) no longer allocated as they would be invalid when allocation is
657 // un-done.
658 void UndoAllocationInNewSpace(Register object);
659
ager@chromium.org3811b432009-10-28 14:53:37 +0000660 // Allocate a heap number in new space with undefined value. Returns
661 // tagged pointer in result register, or jumps to gc_required if new
662 // space is full.
663 void AllocateHeapNumber(Register result,
664 Register scratch,
665 Label* gc_required);
666
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000667 // Allocate a sequential string. All the header fields of the string object
668 // are initialized.
669 void AllocateTwoByteString(Register result,
670 Register length,
671 Register scratch1,
672 Register scratch2,
673 Register scratch3,
674 Label* gc_required);
675 void AllocateAsciiString(Register result,
676 Register length,
677 Register scratch1,
678 Register scratch2,
679 Register scratch3,
680 Label* gc_required);
681
682 // Allocate a raw cons string object. Only the map field of the result is
683 // initialized.
684 void AllocateConsString(Register result,
685 Register scratch1,
686 Register scratch2,
687 Label* gc_required);
688 void AllocateAsciiConsString(Register result,
689 Register scratch1,
690 Register scratch2,
691 Label* gc_required);
692
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000693 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000694 // Support functions.
695
696 // Check if result is zero and op is negative.
697 void NegativeZeroTest(Register result, Register op, Label* then_label);
698
699 // Check if result is zero and op is negative in code using jump targets.
700 void NegativeZeroTest(CodeGenerator* cgen,
701 Register result,
702 Register op,
703 JumpTarget* then_target);
704
705 // Check if result is zero and any of op1 and op2 are negative.
706 // Register scratch is destroyed, and it must be different from op2.
707 void NegativeZeroTest(Register result, Register op1, Register op2,
708 Register scratch, Label* then_label);
709
710 // Try to get function prototype of a function and puts the value in
711 // the result register. Checks that the function really is a
712 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000713 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000714 // clobbered.
715 void TryGetFunctionPrototype(Register function,
716 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000717 Label* miss);
718
719 // Generates code for reporting that an illegal operation has
720 // occurred.
721 void IllegalOperation(int num_arguments);
722
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000723 // Find the function context up the context chain.
724 void LoadContext(Register dst, int context_chain_length);
725
ager@chromium.org9085a012009-05-11 19:22:57 +0000726 // ---------------------------------------------------------------------------
727 // Runtime calls
728
729 // Call a code stub.
730 void CallStub(CodeStub* stub);
731
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000732 // Call a code stub and return the code object called. Try to generate
733 // the code if necessary. Do not perform a GC but instead return a retry
734 // after GC failure.
735 Object* TryCallStub(CodeStub* stub);
736
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000737 // Tail call a code stub (jump).
738 void TailCallStub(CodeStub* stub);
739
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000740 // Tail call a code stub (jump) and return the code object called. Try to
741 // generate the code if necessary. Do not perform a GC but instead return
742 // a retry after GC failure.
743 Object* TryTailCallStub(CodeStub* stub);
744
ager@chromium.org9085a012009-05-11 19:22:57 +0000745 // Return from a code stub after popping its arguments.
746 void StubReturn(int argc);
747
748 // Call a runtime routine.
ager@chromium.org9085a012009-05-11 19:22:57 +0000749 void CallRuntime(Runtime::Function* f, int num_arguments);
750
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000751 // Call a runtime function, returning the CodeStub object called.
752 // Try to generate the stub code if necessary. Do not perform a GC
753 // but instead return a retry after GC failure.
754 Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
755
ager@chromium.org9085a012009-05-11 19:22:57 +0000756 // Convenience function: Same as above, but takes the fid instead.
757 void CallRuntime(Runtime::FunctionId id, int num_arguments);
758
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000759 // Convenience function: Same as above, but takes the fid instead.
760 Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments);
761
ager@chromium.org5c838252010-02-19 08:53:10 +0000762 // Convenience function: call an external reference.
763 void CallExternalReference(const ExternalReference& ext,
764 int num_arguments);
765
ager@chromium.org9085a012009-05-11 19:22:57 +0000766 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000767 // Like JumpToExternalReference, but also takes care of passing the number
768 // of parameters.
769 void TailCallExternalReference(const ExternalReference& ext,
770 int num_arguments,
771 int result_size);
772
773 // Convenience function: tail call a runtime routine (jump).
774 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000775 int num_arguments,
776 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000777
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000778 void PushHandleScope(Register scratch);
779
780 // Pops a handle scope using the specified scratch register and
781 // ensuring that saved register is left unchanged.
782 void PopHandleScope(Register saved, Register scratch);
783
784 // As PopHandleScope, but does not perform a GC. Instead, returns a
785 // retry after GC failure object if GC is necessary.
786 Object* TryPopHandleScope(Register saved, Register scratch);
787
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000788 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000789 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000790
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000791 // Before calling a C-function from generated code, align arguments on stack.
792 // After aligning the frame, arguments must be stored in esp[0], esp[4],
793 // etc., not pushed. The argument count assumes all arguments are word sized.
794 // The number of slots reserved for arguments depends on platform. On Windows
795 // stack slots are reserved for the arguments passed in registers. On other
796 // platforms stack slots are only reserved for the arguments actually passed
797 // on the stack.
798 void PrepareCallCFunction(int num_arguments);
799
800 // Calls a C function and cleans up the space for arguments allocated
801 // by PrepareCallCFunction. The called function is not allowed to trigger a
802 // garbage collection, since that might move the code and invalidate the
803 // return address (unless this is somehow accounted for by the called
804 // function).
805 void CallCFunction(ExternalReference function, int num_arguments);
806 void CallCFunction(Register function, int num_arguments);
807
808 // Calculate the number of stack slots to reserve for arguments when calling a
809 // C function.
810 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000811
812 // ---------------------------------------------------------------------------
813 // Utilities
814
815 void Ret();
816
ager@chromium.org9085a012009-05-11 19:22:57 +0000817 Handle<Object> CodeObject() { return code_object_; }
818
819
820 // ---------------------------------------------------------------------------
821 // StatsCounter support
822
823 void SetCounter(StatsCounter* counter, int value);
824 void IncrementCounter(StatsCounter* counter, int value);
825 void DecrementCounter(StatsCounter* counter, int value);
826
827
828 // ---------------------------------------------------------------------------
829 // Debugging
830
831 // Calls Abort(msg) if the condition cc is not satisfied.
832 // Use --debug_code to enable.
833 void Assert(Condition cc, const char* msg);
834
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000835 void AssertFastElements(Register elements);
836
ager@chromium.org9085a012009-05-11 19:22:57 +0000837 // Like Assert(), but always enabled.
838 void Check(Condition cc, const char* msg);
839
840 // Print a message to stdout and abort execution.
841 void Abort(const char* msg);
842
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000843 // Check that the stack is aligned.
844 void CheckStackAlignment();
845
ager@chromium.org9085a012009-05-11 19:22:57 +0000846 // Verify restrictions about code generated in stubs.
847 void set_generating_stub(bool value) { generating_stub_ = value; }
848 bool generating_stub() { return generating_stub_; }
849 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
850 bool allow_stub_calls() { return allow_stub_calls_; }
851
852 private:
ager@chromium.org9085a012009-05-11 19:22:57 +0000853 bool generating_stub_;
854 bool allow_stub_calls_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000855
856 // Returns a register holding the smi value. The register MUST NOT be
857 // modified. It may be the "smi 1 constant" register.
858 Register GetSmiConstant(Smi* value);
859
860 // Moves the smi value to the destination register.
861 void LoadSmiConstant(Register dst, Smi* value);
862
ager@chromium.org5c838252010-02-19 08:53:10 +0000863 // This handle will be patched with the code object on installation.
864 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +0000865
866 // Helper functions for generating invokes.
867 void InvokePrologue(const ParameterCount& expected,
868 const ParameterCount& actual,
869 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000870 Register code_register,
ager@chromium.org9085a012009-05-11 19:22:57 +0000871 Label* done,
872 InvokeFlag flag);
873
ager@chromium.org9085a012009-05-11 19:22:57 +0000874 // Activation support.
875 void EnterFrame(StackFrame::Type type);
876 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000877
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000878 void EnterExitFramePrologue(ExitFrame::Mode mode, bool save_rax);
879 void EnterExitFrameEpilogue(ExitFrame::Mode mode, int result_size, int argc);
880
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000881 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +0000882 // Loads the top of new-space into the result register.
883 // If flags contains RESULT_CONTAINS_TOP then result_end is valid and
884 // already contains the top of new-space, and scratch is invalid.
885 // Otherwise the address of the new-space top is loaded into scratch (if
886 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000887 void LoadAllocationTopHelper(Register result,
888 Register result_end,
889 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000890 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000891 // Update allocation top with value in result_end register.
892 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000893 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000894
895 // Helper for PopHandleScope. Allowed to perform a GC and returns
896 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
897 // possibly returns a failure object indicating an allocation failure.
898 Object* PopHandleScopeHelper(Register saved,
899 Register scratch,
900 bool gc_allowed);
ager@chromium.org9085a012009-05-11 19:22:57 +0000901};
902
903
ager@chromium.org4af710e2009-09-15 12:20:11 +0000904// The code patcher is used to patch (typically) small parts of code e.g. for
905// debugging and other types of instrumentation. When using the code patcher
906// the exact number of bytes specified must be emitted. Is not legal to emit
907// relocation information. If any of these constraints are violated it causes
908// an assertion.
909class CodePatcher {
910 public:
911 CodePatcher(byte* address, int size);
912 virtual ~CodePatcher();
913
914 // Macro assembler to emit code.
915 MacroAssembler* masm() { return &masm_; }
916
917 private:
918 byte* address_; // The address of the code being patched.
919 int size_; // Number of bytes of the expected patch size.
920 MacroAssembler masm_; // Macro assembler used to generate the code.
921};
922
923
ager@chromium.org9085a012009-05-11 19:22:57 +0000924// -----------------------------------------------------------------------------
925// Static helper functions.
926
927// Generate an Operand for loading a field from an object.
928static inline Operand FieldOperand(Register object, int offset) {
929 return Operand(object, offset - kHeapObjectTag);
930}
931
932
933// Generate an Operand for loading an indexed field from an object.
934static inline Operand FieldOperand(Register object,
935 Register index,
936 ScaleFactor scale,
937 int offset) {
938 return Operand(object, index, scale, offset - kHeapObjectTag);
939}
940
941
942#ifdef GENERATED_CODE_COVERAGE
943extern void LogGeneratedCodeCoverage(const char* file_line);
944#define CODE_COVERAGE_STRINGIFY(x) #x
945#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
946#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
947#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000948 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +0000949 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
950 masm->pushfd(); \
951 masm->pushad(); \
952 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000953 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +0000954 masm->pop(rax); \
955 masm->popad(); \
956 masm->popfd(); \
957 } \
958 masm->
959#else
960#define ACCESS_MASM(masm) masm->
961#endif
962
963
964} } // namespace v8::internal
965
966#endif // V8_X64_MACRO_ASSEMBLER_X64_H_