blob: 9f5a746581088d426a4e270ed563f95ea46e589e [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
ager@chromium.org5c838252010-02-19 08:53:10 +0000135 void DebugBreak();
ager@chromium.org9085a012009-05-11 19:22:57 +0000136#endif
137
138 // ---------------------------------------------------------------------------
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000139 // Stack limit support
140
141 // Do simple test for stack overflow. This doesn't handle an overflow.
142 void StackLimitCheck(Label* on_stack_limit_hit);
143
144 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000145 // Activation frames
146
147 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
148 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
149
150 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
151 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
152
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000153 // Enter specific kind of exit frame; either in normal or
154 // debug mode. Expects the number of arguments in register rax and
ager@chromium.orga1645e22009-09-09 19:27:10 +0000155 // sets up the number of arguments in register rdi and the pointer
156 // to the first argument in register rsi.
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000157 void EnterExitFrame(int result_size = 1);
ager@chromium.org9085a012009-05-11 19:22:57 +0000158
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000159 void EnterApiExitFrame(int stack_space,
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000160 int argc,
161 int result_size = 1);
162
ager@chromium.orga1645e22009-09-09 19:27:10 +0000163 // Leave the current exit frame. Expects/provides the return value in
164 // register rax:rdx (untouched) and the pointer to the first
165 // argument in register rsi.
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000166 void LeaveExitFrame(int result_size = 1);
ager@chromium.org9085a012009-05-11 19:22:57 +0000167
168
169 // ---------------------------------------------------------------------------
170 // JavaScript invokes
171
172 // Invoke the JavaScript function code by either calling or jumping.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000173 void InvokeCode(Register code,
ager@chromium.org9085a012009-05-11 19:22:57 +0000174 const ParameterCount& expected,
175 const ParameterCount& actual,
176 InvokeFlag flag);
177
178 void InvokeCode(Handle<Code> code,
179 const ParameterCount& expected,
180 const ParameterCount& actual,
181 RelocInfo::Mode rmode,
182 InvokeFlag flag);
183
184 // Invoke the JavaScript function in the given register. Changes the
185 // current context to the context in the function before invoking.
186 void InvokeFunction(Register function,
187 const ParameterCount& actual,
188 InvokeFlag flag);
189
ager@chromium.org5c838252010-02-19 08:53:10 +0000190 void InvokeFunction(JSFunction* function,
191 const ParameterCount& actual,
192 InvokeFlag flag);
193
ager@chromium.org9085a012009-05-11 19:22:57 +0000194 // Invoke specified builtin JavaScript function. Adds an entry to
195 // the unresolved list if the name does not resolve.
196 void InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag);
197
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000198 // Store the function for the given builtin in the target register.
199 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
200
ager@chromium.org9085a012009-05-11 19:22:57 +0000201 // Store the code object for the given builtin in the target register.
202 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
203
ager@chromium.org4af710e2009-09-15 12:20:11 +0000204
205 // ---------------------------------------------------------------------------
206 // Smi tagging, untagging and operations on tagged smis.
207
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000208 void InitializeSmiConstantRegister() {
209 movq(kSmiConstantRegister,
210 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
211 RelocInfo::NONE);
212 }
213
ager@chromium.org4af710e2009-09-15 12:20:11 +0000214 // Conversions between tagged smi values and non-tagged integer values.
215
216 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000217 // Only uses the low 32 bits of the src register. Sets the N and Z flags
218 // based on the value of the resulting integer.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000219 void Integer32ToSmi(Register dst, Register src);
220
221 // Tag an integer value if possible, or jump the integer value cannot be
222 // represented as a smi. Only uses the low 32 bit of the src registers.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000223 // NOTICE: Destroys the dst register even if unsuccessful!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000224 void Integer32ToSmi(Register dst, Register src, Label* on_overflow);
225
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000226 // Stores an integer32 value into a memory field that already holds a smi.
227 void Integer32ToSmiField(const Operand& dst, Register src);
228
ager@chromium.org4af710e2009-09-15 12:20:11 +0000229 // Adds constant to src and tags the result as a smi.
230 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000231 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000232
233 // Convert smi to 32-bit integer. I.e., not sign extended into
234 // high 32 bits of destination.
235 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000236 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000237
238 // Convert smi to 64-bit integer (sign extended if necessary).
239 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000240 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000241
242 // Multiply a positive smi's integer value by a power of two.
243 // Provides result as 64-bit integer value.
244 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
245 Register src,
246 int power);
247
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000248 // Divide a positive smi's integer value by a power of two.
249 // Provides result as 32-bit integer value.
250 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
251 Register src,
252 int power);
253
254
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000255 // Simple comparison of smis.
256 void SmiCompare(Register dst, Register src);
257 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000258 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000259 void SmiCompare(const Operand& dst, Register src);
260 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000261 // Compare the int32 in src register to the value of the smi stored at dst.
262 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000263 // Sets sign and zero flags depending on value of smi in register.
264 void SmiTest(Register src);
265
ager@chromium.org4af710e2009-09-15 12:20:11 +0000266 // Functions performing a check on a known or potential smi. Returns
267 // a condition that is satisfied if the check is successful.
268
269 // Is the value a tagged smi.
270 Condition CheckSmi(Register src);
271
ager@chromium.org4af710e2009-09-15 12:20:11 +0000272 // Is the value a positive tagged smi.
273 Condition CheckPositiveSmi(Register src);
274
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000275 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000276 Condition CheckBothSmi(Register first, Register second);
277
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000278 // Are both values tagged smis.
279 Condition CheckBothPositiveSmi(Register first, Register second);
280
281 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000282 Condition CheckEitherSmi(Register first,
283 Register second,
284 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000285
ager@chromium.org4af710e2009-09-15 12:20:11 +0000286 // Is the value the minimum smi value (since we are using
287 // two's complement numbers, negating the value is known to yield
288 // a non-smi value).
289 Condition CheckIsMinSmi(Register src);
290
ager@chromium.org4af710e2009-09-15 12:20:11 +0000291 // Checks whether an 32-bit integer value is a valid for conversion
292 // to a smi.
293 Condition CheckInteger32ValidSmiValue(Register src);
294
ager@chromium.org3811b432009-10-28 14:53:37 +0000295 // Checks whether an 32-bit unsigned integer value is a valid for
296 // conversion to a smi.
297 Condition CheckUInteger32ValidSmiValue(Register src);
298
ager@chromium.org4af710e2009-09-15 12:20:11 +0000299 // Test-and-jump functions. Typically combines a check function
300 // above with a conditional jump.
301
302 // Jump if the value cannot be represented by a smi.
303 void JumpIfNotValidSmiValue(Register src, Label* on_invalid);
304
ager@chromium.org3811b432009-10-28 14:53:37 +0000305 // Jump if the unsigned integer value cannot be represented by a smi.
306 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid);
307
ager@chromium.org4af710e2009-09-15 12:20:11 +0000308 // Jump to label if the value is a tagged smi.
309 void JumpIfSmi(Register src, Label* on_smi);
310
311 // Jump to label if the value is not a tagged smi.
312 void JumpIfNotSmi(Register src, Label* on_not_smi);
313
314 // Jump to label if the value is not a positive tagged smi.
315 void JumpIfNotPositiveSmi(Register src, Label* on_not_smi);
316
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000317 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000318 // to the constant.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000319 void JumpIfSmiEqualsConstant(Register src, Smi* constant, Label* on_equals);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000320
ager@chromium.org4af710e2009-09-15 12:20:11 +0000321 // Jump if either or both register are not smi values.
322 void JumpIfNotBothSmi(Register src1, Register src2, Label* on_not_both_smi);
323
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000324 // Jump if either or both register are not positive smi values.
325 void JumpIfNotBothPositiveSmi(Register src1, Register src2,
326 Label* on_not_both_smi);
327
ager@chromium.org4af710e2009-09-15 12:20:11 +0000328 // Operations on tagged smi values.
329
330 // Smis represent a subset of integers. The subset is always equivalent to
331 // a two's complement interpretation of a fixed number of bits.
332
333 // Optimistically adds an integer constant to a supposed smi.
334 // If the src is not a smi, or the result is not a smi, jump to
335 // the label.
336 void SmiTryAddConstant(Register dst,
337 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000338 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000339 Label* on_not_smi_result);
340
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000341 // Add an integer constant to a tagged smi, giving a tagged smi as result.
342 // No overflow testing on the result is done.
343 void SmiAddConstant(Register dst, Register src, Smi* constant);
344
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000345 // Add an integer constant to a tagged smi, giving a tagged smi as result.
346 // No overflow testing on the result is done.
347 void SmiAddConstant(const Operand& dst, Smi* constant);
348
ager@chromium.org4af710e2009-09-15 12:20:11 +0000349 // Add an integer constant to a tagged smi, giving a tagged smi as result,
350 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000351 void SmiAddConstant(Register dst,
352 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000353 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000354 Label* on_not_smi_result);
355
356 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000357 // result. No testing on the result is done. Sets the N and Z flags
358 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000359 void SmiSubConstant(Register dst, Register src, Smi* constant);
360
361 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000362 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000363 void SmiSubConstant(Register dst,
364 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000365 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000366 Label* on_not_smi_result);
367
368 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000369 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000370 void SmiNeg(Register dst,
371 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000372 Label* on_smi_result);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000373
374 // Adds smi values and return the result as a smi.
375 // If dst is src1, then src1 will be destroyed, even if
376 // the operation is unsuccessful.
377 void SmiAdd(Register dst,
378 Register src1,
379 Register src2,
380 Label* on_not_smi_result);
381
382 // Subtracts smi values and return the result as a smi.
383 // If dst is src1, then src1 will be destroyed, even if
384 // the operation is unsuccessful.
385 void SmiSub(Register dst,
386 Register src1,
387 Register src2,
388 Label* on_not_smi_result);
389
ager@chromium.orgac091b72010-05-05 07:34:42 +0000390 void SmiSub(Register dst,
391 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000392 const Operand& src2,
ager@chromium.orgac091b72010-05-05 07:34:42 +0000393 Label* on_not_smi_result);
394
ager@chromium.org4af710e2009-09-15 12:20:11 +0000395 // Multiplies smi values and return the result as a smi,
396 // if possible.
397 // If dst is src1, then src1 will be destroyed, even if
398 // the operation is unsuccessful.
399 void SmiMul(Register dst,
400 Register src1,
401 Register src2,
402 Label* on_not_smi_result);
403
404 // Divides one smi by another and returns the quotient.
405 // Clobbers rax and rdx registers.
406 void SmiDiv(Register dst,
407 Register src1,
408 Register src2,
409 Label* on_not_smi_result);
410
411 // Divides one smi by another and returns the remainder.
412 // Clobbers rax and rdx registers.
413 void SmiMod(Register dst,
414 Register src1,
415 Register src2,
416 Label* on_not_smi_result);
417
418 // Bitwise operations.
419 void SmiNot(Register dst, Register src);
420 void SmiAnd(Register dst, Register src1, Register src2);
421 void SmiOr(Register dst, Register src1, Register src2);
422 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000423 void SmiAndConstant(Register dst, Register src1, Smi* constant);
424 void SmiOrConstant(Register dst, Register src1, Smi* constant);
425 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000426
427 void SmiShiftLeftConstant(Register dst,
428 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000429 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000430 void SmiShiftLogicalRightConstant(Register dst,
431 Register src,
432 int shift_value,
433 Label* on_not_smi_result);
434 void SmiShiftArithmeticRightConstant(Register dst,
435 Register src,
436 int shift_value);
437
438 // Shifts a smi value to the left, and returns the result if that is a smi.
439 // Uses and clobbers rcx, so dst may not be rcx.
440 void SmiShiftLeft(Register dst,
441 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000442 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000443 // Shifts a smi value to the right, shifting in zero bits at the top, and
444 // returns the unsigned intepretation of the result if that is a smi.
445 // Uses and clobbers rcx, so dst may not be rcx.
446 void SmiShiftLogicalRight(Register dst,
447 Register src1,
448 Register src2,
449 Label* on_not_smi_result);
450 // Shifts a smi value to the right, sign extending the top, and
451 // returns the signed intepretation of the result. That will always
452 // be a valid smi value, since it's numerically smaller than the
453 // original.
454 // Uses and clobbers rcx, so dst may not be rcx.
455 void SmiShiftArithmeticRight(Register dst,
456 Register src1,
457 Register src2);
458
459 // Specialized operations
460
461 // Select the non-smi register of two registers where exactly one is a
462 // smi. If neither are smis, jump to the failure label.
463 void SelectNonSmi(Register dst,
464 Register src1,
465 Register src2,
466 Label* on_not_smis);
467
468 // Converts, if necessary, a smi to a combination of number and
469 // multiplier to be used as a scaled index.
470 // The src register contains a *positive* smi value. The shift is the
471 // power of two to multiply the index value by (e.g.
472 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
473 // The returned index register may be either src or dst, depending
474 // on what is most efficient. If src and dst are different registers,
475 // src is always unchanged.
476 SmiIndex SmiToIndex(Register dst, Register src, int shift);
477
478 // Converts a positive smi to a negative index.
479 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
480
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000481 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000482 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000483 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000484 }
485
486 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000487 Register constant = GetSmiConstant(source);
488 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000489 }
490
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000491 void Push(Smi* smi);
492 void Test(const Operand& dst, Smi* source);
493
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000494 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000495 // String macros.
496 void JumpIfNotBothSequentialAsciiStrings(Register first_object,
497 Register second_object,
498 Register scratch1,
499 Register scratch2,
500 Label* on_not_both_flat_ascii);
501
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000502 // Check whether the instance type represents a flat ascii string. Jump to the
503 // label if not. If the instance type can be scratched specify same register
504 // for both instance type and scratch.
505 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
506 Register scratch,
507 Label *on_not_flat_ascii_string);
508
509 void JumpIfBothInstanceTypesAreNotSequentialAscii(
510 Register first_object_instance_type,
511 Register second_object_instance_type,
512 Register scratch1,
513 Register scratch2,
514 Label* on_fail);
515
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000516 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000517 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000518
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000519 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000520 void Set(Register dst, int64_t x);
521 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000522
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000523 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000524 void Move(Register dst, Handle<Object> source);
525 void Move(const Operand& dst, Handle<Object> source);
526 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000527 void Cmp(const Operand& dst, Handle<Object> source);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000528 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000529
530 // Emit code to discard a non-negative number of pointer-sized elements
531 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000532 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000533
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000534 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000535
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000536 // Control Flow
537 void Jump(Address destination, RelocInfo::Mode rmode);
538 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000539 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
540
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000541 void Call(Address destination, RelocInfo::Mode rmode);
542 void Call(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000543 void Call(Handle<Code> code_object, RelocInfo::Mode rmode);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000544
ager@chromium.org9085a012009-05-11 19:22:57 +0000545 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000546 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000547 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000548 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000549 void CmpObjectType(Register heap_object, InstanceType type, Register map);
550
551 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000552 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000553 void CmpInstanceType(Register map, InstanceType type);
554
ager@chromium.org5c838252010-02-19 08:53:10 +0000555 // Check if the map of an object is equal to a specified map and
556 // branch to label if not. Skip the smi check if not required
557 // (object is known to be a heap object)
558 void CheckMap(Register obj,
559 Handle<Map> map,
560 Label* fail,
561 bool is_heap_object);
562
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000563 // Check if the object in register heap_object is a string. Afterwards the
564 // register map contains the object map and the register instance_type
565 // contains the instance_type. The registers map and instance_type can be the
566 // same in which case it contains the instance type afterwards. Either of the
567 // registers map and instance_type can be the same as heap_object.
568 Condition IsObjectStringType(Register heap_object,
569 Register map,
570 Register instance_type);
571
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000572 // FCmp compares and pops the two values on top of the FPU stack.
573 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000574 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
575 void FCmp();
576
ager@chromium.org5c838252010-02-19 08:53:10 +0000577 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000578 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000579
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000580 // Abort execution if argument is a smi. Used in debug code.
581 void AbortIfSmi(Register object);
582
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
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000718 // Picks out an array index from the hash field.
719 // Register use:
720 // hash - holds the index's hash. Clobbered.
721 // index - holds the overwritten index on exit.
722 void IndexFromHash(Register hash, Register index);
723
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000724 // Find the function context up the context chain.
725 void LoadContext(Register dst, int context_chain_length);
726
ager@chromium.org9085a012009-05-11 19:22:57 +0000727 // ---------------------------------------------------------------------------
728 // Runtime calls
729
730 // Call a code stub.
731 void CallStub(CodeStub* stub);
732
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000733 // Call a code stub and return the code object called. Try to generate
734 // the code if necessary. Do not perform a GC but instead return a retry
735 // after GC failure.
736 Object* TryCallStub(CodeStub* stub);
737
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000738 // Tail call a code stub (jump).
739 void TailCallStub(CodeStub* stub);
740
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000741 // Tail call a code stub (jump) and return the code object called. Try to
742 // generate the code if necessary. Do not perform a GC but instead return
743 // a retry after GC failure.
744 Object* TryTailCallStub(CodeStub* stub);
745
ager@chromium.org9085a012009-05-11 19:22:57 +0000746 // Return from a code stub after popping its arguments.
747 void StubReturn(int argc);
748
749 // Call a runtime routine.
ager@chromium.org9085a012009-05-11 19:22:57 +0000750 void CallRuntime(Runtime::Function* f, int num_arguments);
751
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000752 // Call a runtime function, returning the CodeStub object called.
753 // Try to generate the stub code if necessary. Do not perform a GC
754 // but instead return a retry after GC failure.
755 Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
756
ager@chromium.org9085a012009-05-11 19:22:57 +0000757 // Convenience function: Same as above, but takes the fid instead.
758 void CallRuntime(Runtime::FunctionId id, int num_arguments);
759
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000760 // Convenience function: Same as above, but takes the fid instead.
761 Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments);
762
ager@chromium.org5c838252010-02-19 08:53:10 +0000763 // Convenience function: call an external reference.
764 void CallExternalReference(const ExternalReference& ext,
765 int num_arguments);
766
ager@chromium.org9085a012009-05-11 19:22:57 +0000767 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000768 // Like JumpToExternalReference, but also takes care of passing the number
769 // of parameters.
770 void TailCallExternalReference(const ExternalReference& ext,
771 int num_arguments,
772 int result_size);
773
774 // Convenience function: tail call a runtime routine (jump).
775 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000776 int num_arguments,
777 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000778
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000779 void PushHandleScope(Register scratch);
780
781 // Pops a handle scope using the specified scratch register and
782 // ensuring that saved register is left unchanged.
783 void PopHandleScope(Register saved, Register scratch);
784
785 // As PopHandleScope, but does not perform a GC. Instead, returns a
786 // retry after GC failure object if GC is necessary.
787 Object* TryPopHandleScope(Register saved, Register scratch);
788
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000789 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000790 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000791
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000792 // Before calling a C-function from generated code, align arguments on stack.
793 // After aligning the frame, arguments must be stored in esp[0], esp[4],
794 // etc., not pushed. The argument count assumes all arguments are word sized.
795 // The number of slots reserved for arguments depends on platform. On Windows
796 // stack slots are reserved for the arguments passed in registers. On other
797 // platforms stack slots are only reserved for the arguments actually passed
798 // on the stack.
799 void PrepareCallCFunction(int num_arguments);
800
801 // Calls a C function and cleans up the space for arguments allocated
802 // by PrepareCallCFunction. The called function is not allowed to trigger a
803 // garbage collection, since that might move the code and invalidate the
804 // return address (unless this is somehow accounted for by the called
805 // function).
806 void CallCFunction(ExternalReference function, int num_arguments);
807 void CallCFunction(Register function, int num_arguments);
808
809 // Calculate the number of stack slots to reserve for arguments when calling a
810 // C function.
811 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000812
813 // ---------------------------------------------------------------------------
814 // Utilities
815
816 void Ret();
817
ager@chromium.org9085a012009-05-11 19:22:57 +0000818 Handle<Object> CodeObject() { return code_object_; }
819
820
821 // ---------------------------------------------------------------------------
822 // StatsCounter support
823
824 void SetCounter(StatsCounter* counter, int value);
825 void IncrementCounter(StatsCounter* counter, int value);
826 void DecrementCounter(StatsCounter* counter, int value);
827
828
829 // ---------------------------------------------------------------------------
830 // Debugging
831
832 // Calls Abort(msg) if the condition cc is not satisfied.
833 // Use --debug_code to enable.
834 void Assert(Condition cc, const char* msg);
835
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000836 void AssertFastElements(Register elements);
837
ager@chromium.org9085a012009-05-11 19:22:57 +0000838 // Like Assert(), but always enabled.
839 void Check(Condition cc, const char* msg);
840
841 // Print a message to stdout and abort execution.
842 void Abort(const char* msg);
843
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000844 // Check that the stack is aligned.
845 void CheckStackAlignment();
846
ager@chromium.org9085a012009-05-11 19:22:57 +0000847 // Verify restrictions about code generated in stubs.
848 void set_generating_stub(bool value) { generating_stub_ = value; }
849 bool generating_stub() { return generating_stub_; }
850 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
851 bool allow_stub_calls() { return allow_stub_calls_; }
852
853 private:
ager@chromium.org9085a012009-05-11 19:22:57 +0000854 bool generating_stub_;
855 bool allow_stub_calls_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000856
857 // Returns a register holding the smi value. The register MUST NOT be
858 // modified. It may be the "smi 1 constant" register.
859 Register GetSmiConstant(Smi* value);
860
861 // Moves the smi value to the destination register.
862 void LoadSmiConstant(Register dst, Smi* value);
863
ager@chromium.org5c838252010-02-19 08:53:10 +0000864 // This handle will be patched with the code object on installation.
865 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +0000866
867 // Helper functions for generating invokes.
868 void InvokePrologue(const ParameterCount& expected,
869 const ParameterCount& actual,
870 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000871 Register code_register,
ager@chromium.org9085a012009-05-11 19:22:57 +0000872 Label* done,
873 InvokeFlag flag);
874
ager@chromium.org9085a012009-05-11 19:22:57 +0000875 // Activation support.
876 void EnterFrame(StackFrame::Type type);
877 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000878
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000879 void EnterExitFramePrologue(bool save_rax);
880 void EnterExitFrameEpilogue(int result_size, int argc);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000881
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000882 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +0000883 // Loads the top of new-space into the result register.
884 // If flags contains RESULT_CONTAINS_TOP then result_end is valid and
885 // already contains the top of new-space, and scratch is invalid.
886 // Otherwise the address of the new-space top is loaded into scratch (if
887 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000888 void LoadAllocationTopHelper(Register result,
889 Register result_end,
890 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000891 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000892 // Update allocation top with value in result_end register.
893 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000894 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000895
896 // Helper for PopHandleScope. Allowed to perform a GC and returns
897 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
898 // possibly returns a failure object indicating an allocation failure.
899 Object* PopHandleScopeHelper(Register saved,
900 Register scratch,
901 bool gc_allowed);
ager@chromium.org9085a012009-05-11 19:22:57 +0000902};
903
904
ager@chromium.org4af710e2009-09-15 12:20:11 +0000905// The code patcher is used to patch (typically) small parts of code e.g. for
906// debugging and other types of instrumentation. When using the code patcher
907// the exact number of bytes specified must be emitted. Is not legal to emit
908// relocation information. If any of these constraints are violated it causes
909// an assertion.
910class CodePatcher {
911 public:
912 CodePatcher(byte* address, int size);
913 virtual ~CodePatcher();
914
915 // Macro assembler to emit code.
916 MacroAssembler* masm() { return &masm_; }
917
918 private:
919 byte* address_; // The address of the code being patched.
920 int size_; // Number of bytes of the expected patch size.
921 MacroAssembler masm_; // Macro assembler used to generate the code.
922};
923
924
ager@chromium.org9085a012009-05-11 19:22:57 +0000925// -----------------------------------------------------------------------------
926// Static helper functions.
927
928// Generate an Operand for loading a field from an object.
929static inline Operand FieldOperand(Register object, int offset) {
930 return Operand(object, offset - kHeapObjectTag);
931}
932
933
934// Generate an Operand for loading an indexed field from an object.
935static inline Operand FieldOperand(Register object,
936 Register index,
937 ScaleFactor scale,
938 int offset) {
939 return Operand(object, index, scale, offset - kHeapObjectTag);
940}
941
942
943#ifdef GENERATED_CODE_COVERAGE
944extern void LogGeneratedCodeCoverage(const char* file_line);
945#define CODE_COVERAGE_STRINGIFY(x) #x
946#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
947#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
948#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000949 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +0000950 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
951 masm->pushfd(); \
952 masm->pushad(); \
953 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000954 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +0000955 masm->pop(rax); \
956 masm->popad(); \
957 masm->popfd(); \
958 } \
959 masm->
960#else
961#define ACCESS_MASM(masm) masm->
962#endif
963
964
965} } // namespace v8::internal
966
967#endif // V8_X64_MACRO_ASSEMBLER_X64_H_