blob: 7a90dd0175e5285669c086fba76ad450d568106b [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.
287 Condition CheckEitherSmi(Register first, Register second);
288
ager@chromium.org4af710e2009-09-15 12:20:11 +0000289 // Is the value the minimum smi value (since we are using
290 // two's complement numbers, negating the value is known to yield
291 // a non-smi value).
292 Condition CheckIsMinSmi(Register src);
293
ager@chromium.org4af710e2009-09-15 12:20:11 +0000294 // Checks whether an 32-bit integer value is a valid for conversion
295 // to a smi.
296 Condition CheckInteger32ValidSmiValue(Register src);
297
ager@chromium.org3811b432009-10-28 14:53:37 +0000298 // Checks whether an 32-bit unsigned integer value is a valid for
299 // conversion to a smi.
300 Condition CheckUInteger32ValidSmiValue(Register src);
301
ager@chromium.org4af710e2009-09-15 12:20:11 +0000302 // Test-and-jump functions. Typically combines a check function
303 // above with a conditional jump.
304
305 // Jump if the value cannot be represented by a smi.
306 void JumpIfNotValidSmiValue(Register src, Label* on_invalid);
307
ager@chromium.org3811b432009-10-28 14:53:37 +0000308 // Jump if the unsigned integer value cannot be represented by a smi.
309 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid);
310
ager@chromium.org4af710e2009-09-15 12:20:11 +0000311 // Jump to label if the value is a tagged smi.
312 void JumpIfSmi(Register src, Label* on_smi);
313
314 // Jump to label if the value is not a tagged smi.
315 void JumpIfNotSmi(Register src, Label* on_not_smi);
316
317 // Jump to label if the value is not a positive tagged smi.
318 void JumpIfNotPositiveSmi(Register src, Label* on_not_smi);
319
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000320 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000321 // to the constant.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000322 void JumpIfSmiEqualsConstant(Register src, Smi* constant, Label* on_equals);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000323
ager@chromium.org4af710e2009-09-15 12:20:11 +0000324 // Jump if either or both register are not smi values.
325 void JumpIfNotBothSmi(Register src1, Register src2, Label* on_not_both_smi);
326
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000327 // Jump if either or both register are not positive smi values.
328 void JumpIfNotBothPositiveSmi(Register src1, Register src2,
329 Label* on_not_both_smi);
330
ager@chromium.org4af710e2009-09-15 12:20:11 +0000331 // Operations on tagged smi values.
332
333 // Smis represent a subset of integers. The subset is always equivalent to
334 // a two's complement interpretation of a fixed number of bits.
335
336 // Optimistically adds an integer constant to a supposed smi.
337 // If the src is not a smi, or the result is not a smi, jump to
338 // the label.
339 void SmiTryAddConstant(Register dst,
340 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000341 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000342 Label* on_not_smi_result);
343
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000344 // Add an integer constant to a tagged smi, giving a tagged smi as result.
345 // No overflow testing on the result is done.
346 void SmiAddConstant(Register dst, Register src, Smi* constant);
347
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000348 // Add an integer constant to a tagged smi, giving a tagged smi as result.
349 // No overflow testing on the result is done.
350 void SmiAddConstant(const Operand& dst, Smi* constant);
351
ager@chromium.org4af710e2009-09-15 12:20:11 +0000352 // Add an integer constant to a tagged smi, giving a tagged smi as result,
353 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000354 void SmiAddConstant(Register dst,
355 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000356 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000357 Label* on_not_smi_result);
358
359 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000360 // result. No testing on the result is done. Sets the N and Z flags
361 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000362 void SmiSubConstant(Register dst, Register src, Smi* constant);
363
364 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000365 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000366 void SmiSubConstant(Register dst,
367 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000368 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000369 Label* on_not_smi_result);
370
371 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000372 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000373 void SmiNeg(Register dst,
374 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000375 Label* on_smi_result);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000376
377 // Adds smi values and return the result as a smi.
378 // If dst is src1, then src1 will be destroyed, even if
379 // the operation is unsuccessful.
380 void SmiAdd(Register dst,
381 Register src1,
382 Register src2,
383 Label* on_not_smi_result);
384
385 // Subtracts smi values and return the result as a smi.
386 // If dst is src1, then src1 will be destroyed, even if
387 // the operation is unsuccessful.
388 void SmiSub(Register dst,
389 Register src1,
390 Register src2,
391 Label* on_not_smi_result);
392
ager@chromium.orgac091b72010-05-05 07:34:42 +0000393 void SmiSub(Register dst,
394 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000395 const Operand& src2,
ager@chromium.orgac091b72010-05-05 07:34:42 +0000396 Label* on_not_smi_result);
397
ager@chromium.org4af710e2009-09-15 12:20:11 +0000398 // Multiplies smi values and return the result as a smi,
399 // if possible.
400 // If dst is src1, then src1 will be destroyed, even if
401 // the operation is unsuccessful.
402 void SmiMul(Register dst,
403 Register src1,
404 Register src2,
405 Label* on_not_smi_result);
406
407 // Divides one smi by another and returns the quotient.
408 // Clobbers rax and rdx registers.
409 void SmiDiv(Register dst,
410 Register src1,
411 Register src2,
412 Label* on_not_smi_result);
413
414 // Divides one smi by another and returns the remainder.
415 // Clobbers rax and rdx registers.
416 void SmiMod(Register dst,
417 Register src1,
418 Register src2,
419 Label* on_not_smi_result);
420
421 // Bitwise operations.
422 void SmiNot(Register dst, Register src);
423 void SmiAnd(Register dst, Register src1, Register src2);
424 void SmiOr(Register dst, Register src1, Register src2);
425 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000426 void SmiAndConstant(Register dst, Register src1, Smi* constant);
427 void SmiOrConstant(Register dst, Register src1, Smi* constant);
428 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000429
430 void SmiShiftLeftConstant(Register dst,
431 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000432 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000433 void SmiShiftLogicalRightConstant(Register dst,
434 Register src,
435 int shift_value,
436 Label* on_not_smi_result);
437 void SmiShiftArithmeticRightConstant(Register dst,
438 Register src,
439 int shift_value);
440
441 // Shifts a smi value to the left, and returns the result if that is a smi.
442 // Uses and clobbers rcx, so dst may not be rcx.
443 void SmiShiftLeft(Register dst,
444 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000445 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000446 // Shifts a smi value to the right, shifting in zero bits at the top, and
447 // returns the unsigned intepretation of the result if that is a smi.
448 // Uses and clobbers rcx, so dst may not be rcx.
449 void SmiShiftLogicalRight(Register dst,
450 Register src1,
451 Register src2,
452 Label* on_not_smi_result);
453 // Shifts a smi value to the right, sign extending the top, and
454 // returns the signed intepretation of the result. That will always
455 // be a valid smi value, since it's numerically smaller than the
456 // original.
457 // Uses and clobbers rcx, so dst may not be rcx.
458 void SmiShiftArithmeticRight(Register dst,
459 Register src1,
460 Register src2);
461
462 // Specialized operations
463
464 // Select the non-smi register of two registers where exactly one is a
465 // smi. If neither are smis, jump to the failure label.
466 void SelectNonSmi(Register dst,
467 Register src1,
468 Register src2,
469 Label* on_not_smis);
470
471 // Converts, if necessary, a smi to a combination of number and
472 // multiplier to be used as a scaled index.
473 // The src register contains a *positive* smi value. The shift is the
474 // power of two to multiply the index value by (e.g.
475 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
476 // The returned index register may be either src or dst, depending
477 // on what is most efficient. If src and dst are different registers,
478 // src is always unchanged.
479 SmiIndex SmiToIndex(Register dst, Register src, int shift);
480
481 // Converts a positive smi to a negative index.
482 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
483
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000484 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000485 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000486 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000487 }
488
489 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000490 Register constant = GetSmiConstant(source);
491 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000492 }
493
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000494 void Push(Smi* smi);
495 void Test(const Operand& dst, Smi* source);
496
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000497 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000498 // String macros.
499 void JumpIfNotBothSequentialAsciiStrings(Register first_object,
500 Register second_object,
501 Register scratch1,
502 Register scratch2,
503 Label* on_not_both_flat_ascii);
504
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000505 // Check whether the instance type represents a flat ascii string. Jump to the
506 // label if not. If the instance type can be scratched specify same register
507 // for both instance type and scratch.
508 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
509 Register scratch,
510 Label *on_not_flat_ascii_string);
511
512 void JumpIfBothInstanceTypesAreNotSequentialAscii(
513 Register first_object_instance_type,
514 Register second_object_instance_type,
515 Register scratch1,
516 Register scratch2,
517 Label* on_fail);
518
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000519 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000520 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000521
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000522 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000523 void Set(Register dst, int64_t x);
524 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000525
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000526 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000527 void Move(Register dst, Handle<Object> source);
528 void Move(const Operand& dst, Handle<Object> source);
529 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000530 void Cmp(const Operand& dst, Handle<Object> source);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000531 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000532
533 // Emit code to discard a non-negative number of pointer-sized elements
534 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000535 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000536
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000537 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000538
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000539 // Control Flow
540 void Jump(Address destination, RelocInfo::Mode rmode);
541 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000542 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
543
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000544 void Call(Address destination, RelocInfo::Mode rmode);
545 void Call(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000546 void Call(Handle<Code> code_object, RelocInfo::Mode rmode);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000547
ager@chromium.org9085a012009-05-11 19:22:57 +0000548 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000549 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000550 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000551 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000552 void CmpObjectType(Register heap_object, InstanceType type, Register map);
553
554 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000555 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000556 void CmpInstanceType(Register map, InstanceType type);
557
ager@chromium.org5c838252010-02-19 08:53:10 +0000558 // Check if the map of an object is equal to a specified map and
559 // branch to label if not. Skip the smi check if not required
560 // (object is known to be a heap object)
561 void CheckMap(Register obj,
562 Handle<Map> map,
563 Label* fail,
564 bool is_heap_object);
565
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000566 // Check if the object in register heap_object is a string. Afterwards the
567 // register map contains the object map and the register instance_type
568 // contains the instance_type. The registers map and instance_type can be the
569 // same in which case it contains the instance type afterwards. Either of the
570 // registers map and instance_type can be the same as heap_object.
571 Condition IsObjectStringType(Register heap_object,
572 Register map,
573 Register instance_type);
574
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000575 // FCmp compares and pops the two values on top of the FPU stack.
576 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000577 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
578 void FCmp();
579
ager@chromium.org5c838252010-02-19 08:53:10 +0000580 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000581 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000582
lrn@chromium.org25156de2010-04-06 13:10:27 +0000583 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000584 void AbortIfNotSmi(Register object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000585
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000586 // Abort execution if argument is not the root value with the given index.
587 void AbortIfNotRootValue(Register src,
588 Heap::RootListIndex root_value_index,
589 const char* message);
590
ager@chromium.org9085a012009-05-11 19:22:57 +0000591 // ---------------------------------------------------------------------------
592 // Exception handling
593
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000594 // Push a new try handler and link into try handler chain. The return
595 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000596 void PushTryHandler(CodeLocation try_location, HandlerType type);
597
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000598 // Unlink the stack handler on top of the stack from the try handler chain.
599 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000600
601 // ---------------------------------------------------------------------------
602 // Inline caching support
603
ager@chromium.org9085a012009-05-11 19:22:57 +0000604 // Generate code for checking access rights - used for security checks
605 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000606 // is left untouched, but the scratch register and kScratchRegister,
607 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000608 void CheckAccessGlobalProxy(Register holder_reg,
609 Register scratch,
610 Label* miss);
611
612
613 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000614 // Allocation support
615
616 // Allocate an object in new space. If the new space is exhausted control
617 // continues at the gc_required label. The allocated object is returned in
618 // result and end of the new object is returned in result_end. The register
619 // scratch can be passed as no_reg in which case an additional object
620 // reference will be added to the reloc info. The returned pointers in result
621 // and result_end have not yet been tagged as heap objects. If
622 // result_contains_top_on_entry is true the content of result is known to be
623 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000624 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000625 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000626 void AllocateInNewSpace(int object_size,
627 Register result,
628 Register result_end,
629 Register scratch,
630 Label* gc_required,
631 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000632
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000633 void AllocateInNewSpace(int header_size,
634 ScaleFactor element_size,
635 Register element_count,
636 Register result,
637 Register result_end,
638 Register scratch,
639 Label* gc_required,
640 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000641
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000642 void AllocateInNewSpace(Register object_size,
643 Register result,
644 Register result_end,
645 Register scratch,
646 Label* gc_required,
647 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000648
649 // Undo allocation in new space. The object passed and objects allocated after
650 // it will no longer be allocated. Make sure that no pointers are left to the
651 // object(s) no longer allocated as they would be invalid when allocation is
652 // un-done.
653 void UndoAllocationInNewSpace(Register object);
654
ager@chromium.org3811b432009-10-28 14:53:37 +0000655 // Allocate a heap number in new space with undefined value. Returns
656 // tagged pointer in result register, or jumps to gc_required if new
657 // space is full.
658 void AllocateHeapNumber(Register result,
659 Register scratch,
660 Label* gc_required);
661
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000662 // Allocate a sequential string. All the header fields of the string object
663 // are initialized.
664 void AllocateTwoByteString(Register result,
665 Register length,
666 Register scratch1,
667 Register scratch2,
668 Register scratch3,
669 Label* gc_required);
670 void AllocateAsciiString(Register result,
671 Register length,
672 Register scratch1,
673 Register scratch2,
674 Register scratch3,
675 Label* gc_required);
676
677 // Allocate a raw cons string object. Only the map field of the result is
678 // initialized.
679 void AllocateConsString(Register result,
680 Register scratch1,
681 Register scratch2,
682 Label* gc_required);
683 void AllocateAsciiConsString(Register result,
684 Register scratch1,
685 Register scratch2,
686 Label* gc_required);
687
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000688 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000689 // Support functions.
690
691 // Check if result is zero and op is negative.
692 void NegativeZeroTest(Register result, Register op, Label* then_label);
693
694 // Check if result is zero and op is negative in code using jump targets.
695 void NegativeZeroTest(CodeGenerator* cgen,
696 Register result,
697 Register op,
698 JumpTarget* then_target);
699
700 // Check if result is zero and any of op1 and op2 are negative.
701 // Register scratch is destroyed, and it must be different from op2.
702 void NegativeZeroTest(Register result, Register op1, Register op2,
703 Register scratch, Label* then_label);
704
705 // Try to get function prototype of a function and puts the value in
706 // the result register. Checks that the function really is a
707 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000708 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000709 // clobbered.
710 void TryGetFunctionPrototype(Register function,
711 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000712 Label* miss);
713
714 // Generates code for reporting that an illegal operation has
715 // occurred.
716 void IllegalOperation(int num_arguments);
717
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000718 // Find the function context up the context chain.
719 void LoadContext(Register dst, int context_chain_length);
720
ager@chromium.org9085a012009-05-11 19:22:57 +0000721 // ---------------------------------------------------------------------------
722 // Runtime calls
723
724 // Call a code stub.
725 void CallStub(CodeStub* stub);
726
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000727 // Call a code stub and return the code object called. Try to generate
728 // the code if necessary. Do not perform a GC but instead return a retry
729 // after GC failure.
730 Object* TryCallStub(CodeStub* stub);
731
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000732 // Tail call a code stub (jump).
733 void TailCallStub(CodeStub* stub);
734
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000735 // Tail call a code stub (jump) and return the code object called. Try to
736 // generate the code if necessary. Do not perform a GC but instead return
737 // a retry after GC failure.
738 Object* TryTailCallStub(CodeStub* stub);
739
ager@chromium.org9085a012009-05-11 19:22:57 +0000740 // Return from a code stub after popping its arguments.
741 void StubReturn(int argc);
742
743 // Call a runtime routine.
ager@chromium.org9085a012009-05-11 19:22:57 +0000744 void CallRuntime(Runtime::Function* f, int num_arguments);
745
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000746 // Call a runtime function, returning the CodeStub object called.
747 // Try to generate the stub code if necessary. Do not perform a GC
748 // but instead return a retry after GC failure.
749 Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
750
ager@chromium.org9085a012009-05-11 19:22:57 +0000751 // Convenience function: Same as above, but takes the fid instead.
752 void CallRuntime(Runtime::FunctionId id, int num_arguments);
753
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000754 // Convenience function: Same as above, but takes the fid instead.
755 Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments);
756
ager@chromium.org5c838252010-02-19 08:53:10 +0000757 // Convenience function: call an external reference.
758 void CallExternalReference(const ExternalReference& ext,
759 int num_arguments);
760
ager@chromium.org9085a012009-05-11 19:22:57 +0000761 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000762 // Like JumpToExternalReference, but also takes care of passing the number
763 // of parameters.
764 void TailCallExternalReference(const ExternalReference& ext,
765 int num_arguments,
766 int result_size);
767
768 // Convenience function: tail call a runtime routine (jump).
769 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000770 int num_arguments,
771 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000772
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000773 void PushHandleScope(Register scratch);
774
775 // Pops a handle scope using the specified scratch register and
776 // ensuring that saved register is left unchanged.
777 void PopHandleScope(Register saved, Register scratch);
778
779 // As PopHandleScope, but does not perform a GC. Instead, returns a
780 // retry after GC failure object if GC is necessary.
781 Object* TryPopHandleScope(Register saved, Register scratch);
782
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000783 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000784 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000785
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000786 // Before calling a C-function from generated code, align arguments on stack.
787 // After aligning the frame, arguments must be stored in esp[0], esp[4],
788 // etc., not pushed. The argument count assumes all arguments are word sized.
789 // The number of slots reserved for arguments depends on platform. On Windows
790 // stack slots are reserved for the arguments passed in registers. On other
791 // platforms stack slots are only reserved for the arguments actually passed
792 // on the stack.
793 void PrepareCallCFunction(int num_arguments);
794
795 // Calls a C function and cleans up the space for arguments allocated
796 // by PrepareCallCFunction. The called function is not allowed to trigger a
797 // garbage collection, since that might move the code and invalidate the
798 // return address (unless this is somehow accounted for by the called
799 // function).
800 void CallCFunction(ExternalReference function, int num_arguments);
801 void CallCFunction(Register function, int num_arguments);
802
803 // Calculate the number of stack slots to reserve for arguments when calling a
804 // C function.
805 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000806
807 // ---------------------------------------------------------------------------
808 // Utilities
809
810 void Ret();
811
ager@chromium.org9085a012009-05-11 19:22:57 +0000812 Handle<Object> CodeObject() { return code_object_; }
813
814
815 // ---------------------------------------------------------------------------
816 // StatsCounter support
817
818 void SetCounter(StatsCounter* counter, int value);
819 void IncrementCounter(StatsCounter* counter, int value);
820 void DecrementCounter(StatsCounter* counter, int value);
821
822
823 // ---------------------------------------------------------------------------
824 // Debugging
825
826 // Calls Abort(msg) if the condition cc is not satisfied.
827 // Use --debug_code to enable.
828 void Assert(Condition cc, const char* msg);
829
830 // Like Assert(), but always enabled.
831 void Check(Condition cc, const char* msg);
832
833 // Print a message to stdout and abort execution.
834 void Abort(const char* msg);
835
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000836 // Check that the stack is aligned.
837 void CheckStackAlignment();
838
ager@chromium.org9085a012009-05-11 19:22:57 +0000839 // Verify restrictions about code generated in stubs.
840 void set_generating_stub(bool value) { generating_stub_ = value; }
841 bool generating_stub() { return generating_stub_; }
842 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
843 bool allow_stub_calls() { return allow_stub_calls_; }
844
845 private:
ager@chromium.org9085a012009-05-11 19:22:57 +0000846 bool generating_stub_;
847 bool allow_stub_calls_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000848
849 // Returns a register holding the smi value. The register MUST NOT be
850 // modified. It may be the "smi 1 constant" register.
851 Register GetSmiConstant(Smi* value);
852
853 // Moves the smi value to the destination register.
854 void LoadSmiConstant(Register dst, Smi* value);
855
ager@chromium.org5c838252010-02-19 08:53:10 +0000856 // This handle will be patched with the code object on installation.
857 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +0000858
859 // Helper functions for generating invokes.
860 void InvokePrologue(const ParameterCount& expected,
861 const ParameterCount& actual,
862 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000863 Register code_register,
ager@chromium.org9085a012009-05-11 19:22:57 +0000864 Label* done,
865 InvokeFlag flag);
866
ager@chromium.org9085a012009-05-11 19:22:57 +0000867 // Activation support.
868 void EnterFrame(StackFrame::Type type);
869 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000870
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000871 void EnterExitFramePrologue(ExitFrame::Mode mode, bool save_rax);
872 void EnterExitFrameEpilogue(ExitFrame::Mode mode, int result_size, int argc);
873
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000874 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +0000875 // Loads the top of new-space into the result register.
876 // If flags contains RESULT_CONTAINS_TOP then result_end is valid and
877 // already contains the top of new-space, and scratch is invalid.
878 // Otherwise the address of the new-space top is loaded into scratch (if
879 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000880 void LoadAllocationTopHelper(Register result,
881 Register result_end,
882 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000883 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000884 // Update allocation top with value in result_end register.
885 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000886 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000887
888 // Helper for PopHandleScope. Allowed to perform a GC and returns
889 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
890 // possibly returns a failure object indicating an allocation failure.
891 Object* PopHandleScopeHelper(Register saved,
892 Register scratch,
893 bool gc_allowed);
ager@chromium.org9085a012009-05-11 19:22:57 +0000894};
895
896
ager@chromium.org4af710e2009-09-15 12:20:11 +0000897// The code patcher is used to patch (typically) small parts of code e.g. for
898// debugging and other types of instrumentation. When using the code patcher
899// the exact number of bytes specified must be emitted. Is not legal to emit
900// relocation information. If any of these constraints are violated it causes
901// an assertion.
902class CodePatcher {
903 public:
904 CodePatcher(byte* address, int size);
905 virtual ~CodePatcher();
906
907 // Macro assembler to emit code.
908 MacroAssembler* masm() { return &masm_; }
909
910 private:
911 byte* address_; // The address of the code being patched.
912 int size_; // Number of bytes of the expected patch size.
913 MacroAssembler masm_; // Macro assembler used to generate the code.
914};
915
916
ager@chromium.org9085a012009-05-11 19:22:57 +0000917// -----------------------------------------------------------------------------
918// Static helper functions.
919
920// Generate an Operand for loading a field from an object.
921static inline Operand FieldOperand(Register object, int offset) {
922 return Operand(object, offset - kHeapObjectTag);
923}
924
925
926// Generate an Operand for loading an indexed field from an object.
927static inline Operand FieldOperand(Register object,
928 Register index,
929 ScaleFactor scale,
930 int offset) {
931 return Operand(object, index, scale, offset - kHeapObjectTag);
932}
933
934
935#ifdef GENERATED_CODE_COVERAGE
936extern void LogGeneratedCodeCoverage(const char* file_line);
937#define CODE_COVERAGE_STRINGIFY(x) #x
938#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
939#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
940#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000941 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +0000942 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
943 masm->pushfd(); \
944 masm->pushad(); \
945 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000946 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +0000947 masm->pop(rax); \
948 masm->popad(); \
949 masm->popfd(); \
950 } \
951 masm->
952#else
953#define ACCESS_MASM(masm) masm->
954#endif
955
956
957} } // namespace v8::internal
958
959#endif // V8_X64_MACRO_ASSEMBLER_X64_H_