blob: 08cb37737039e0d78563e2c5220455c45f2abe61 [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
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000206 // Store the function for the given builtin in the target register.
207 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
208
ager@chromium.org9085a012009-05-11 19:22:57 +0000209 // Store the code object for the given builtin in the target register.
210 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
211
ager@chromium.org4af710e2009-09-15 12:20:11 +0000212
213 // ---------------------------------------------------------------------------
214 // Smi tagging, untagging and operations on tagged smis.
215
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000216 void InitializeSmiConstantRegister() {
217 movq(kSmiConstantRegister,
218 reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)),
219 RelocInfo::NONE);
220 }
221
ager@chromium.org4af710e2009-09-15 12:20:11 +0000222 // Conversions between tagged smi values and non-tagged integer values.
223
224 // Tag an integer value. The result must be known to be a valid smi value.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000225 // Only uses the low 32 bits of the src register. Sets the N and Z flags
226 // based on the value of the resulting integer.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000227 void Integer32ToSmi(Register dst, Register src);
228
229 // Tag an integer value if possible, or jump the integer value cannot be
230 // represented as a smi. Only uses the low 32 bit of the src registers.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000231 // NOTICE: Destroys the dst register even if unsuccessful!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000232 void Integer32ToSmi(Register dst, Register src, Label* on_overflow);
233
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000234 // Stores an integer32 value into a memory field that already holds a smi.
235 void Integer32ToSmiField(const Operand& dst, Register src);
236
ager@chromium.org4af710e2009-09-15 12:20:11 +0000237 // Adds constant to src and tags the result as a smi.
238 // Result must be a valid smi.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000239 void Integer64PlusConstantToSmi(Register dst, Register src, int constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000240
241 // Convert smi to 32-bit integer. I.e., not sign extended into
242 // high 32 bits of destination.
243 void SmiToInteger32(Register dst, Register src);
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000244 void SmiToInteger32(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000245
246 // Convert smi to 64-bit integer (sign extended if necessary).
247 void SmiToInteger64(Register dst, Register src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000248 void SmiToInteger64(Register dst, const Operand& src);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000249
250 // Multiply a positive smi's integer value by a power of two.
251 // Provides result as 64-bit integer value.
252 void PositiveSmiTimesPowerOfTwoToInteger64(Register dst,
253 Register src,
254 int power);
255
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000256 // Divide a positive smi's integer value by a power of two.
257 // Provides result as 32-bit integer value.
258 void PositiveSmiDivPowerOfTwoToInteger32(Register dst,
259 Register src,
260 int power);
261
262
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000263 // Simple comparison of smis.
264 void SmiCompare(Register dst, Register src);
265 void SmiCompare(Register dst, Smi* src);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000266 void SmiCompare(Register dst, const Operand& src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000267 void SmiCompare(const Operand& dst, Register src);
268 void SmiCompare(const Operand& dst, Smi* src);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000269 // Compare the int32 in src register to the value of the smi stored at dst.
270 void SmiCompareInteger32(const Operand& dst, Register src);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000271 // Sets sign and zero flags depending on value of smi in register.
272 void SmiTest(Register src);
273
ager@chromium.org4af710e2009-09-15 12:20:11 +0000274 // Functions performing a check on a known or potential smi. Returns
275 // a condition that is satisfied if the check is successful.
276
277 // Is the value a tagged smi.
278 Condition CheckSmi(Register src);
279
ager@chromium.org4af710e2009-09-15 12:20:11 +0000280 // Is the value a positive tagged smi.
281 Condition CheckPositiveSmi(Register src);
282
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000283 // Are both values tagged smis.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000284 Condition CheckBothSmi(Register first, Register second);
285
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000286 // Are both values tagged smis.
287 Condition CheckBothPositiveSmi(Register first, Register second);
288
289 // Are either value a tagged smi.
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000290 Condition CheckEitherSmi(Register first,
291 Register second,
292 Register scratch = kScratchRegister);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000293
ager@chromium.org4af710e2009-09-15 12:20:11 +0000294 // Is the value the minimum smi value (since we are using
295 // two's complement numbers, negating the value is known to yield
296 // a non-smi value).
297 Condition CheckIsMinSmi(Register src);
298
ager@chromium.org4af710e2009-09-15 12:20:11 +0000299 // Checks whether an 32-bit integer value is a valid for conversion
300 // to a smi.
301 Condition CheckInteger32ValidSmiValue(Register src);
302
ager@chromium.org3811b432009-10-28 14:53:37 +0000303 // Checks whether an 32-bit unsigned integer value is a valid for
304 // conversion to a smi.
305 Condition CheckUInteger32ValidSmiValue(Register src);
306
ager@chromium.org4af710e2009-09-15 12:20:11 +0000307 // Test-and-jump functions. Typically combines a check function
308 // above with a conditional jump.
309
310 // Jump if the value cannot be represented by a smi.
311 void JumpIfNotValidSmiValue(Register src, Label* on_invalid);
312
ager@chromium.org3811b432009-10-28 14:53:37 +0000313 // Jump if the unsigned integer value cannot be represented by a smi.
314 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid);
315
ager@chromium.org4af710e2009-09-15 12:20:11 +0000316 // Jump to label if the value is a tagged smi.
317 void JumpIfSmi(Register src, Label* on_smi);
318
319 // Jump to label if the value is not a tagged smi.
320 void JumpIfNotSmi(Register src, Label* on_not_smi);
321
322 // Jump to label if the value is not a positive tagged smi.
323 void JumpIfNotPositiveSmi(Register src, Label* on_not_smi);
324
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000325 // Jump to label if the value, which must be a tagged smi, has value equal
ager@chromium.org4af710e2009-09-15 12:20:11 +0000326 // to the constant.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000327 void JumpIfSmiEqualsConstant(Register src, Smi* constant, Label* on_equals);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000328
ager@chromium.org4af710e2009-09-15 12:20:11 +0000329 // Jump if either or both register are not smi values.
330 void JumpIfNotBothSmi(Register src1, Register src2, Label* on_not_both_smi);
331
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000332 // Jump if either or both register are not positive smi values.
333 void JumpIfNotBothPositiveSmi(Register src1, Register src2,
334 Label* on_not_both_smi);
335
ager@chromium.org4af710e2009-09-15 12:20:11 +0000336 // Operations on tagged smi values.
337
338 // Smis represent a subset of integers. The subset is always equivalent to
339 // a two's complement interpretation of a fixed number of bits.
340
341 // Optimistically adds an integer constant to a supposed smi.
342 // If the src is not a smi, or the result is not a smi, jump to
343 // the label.
344 void SmiTryAddConstant(Register dst,
345 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000346 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000347 Label* on_not_smi_result);
348
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000349 // Add an integer constant to a tagged smi, giving a tagged smi as result.
350 // No overflow testing on the result is done.
351 void SmiAddConstant(Register dst, Register src, Smi* constant);
352
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000353 // Add an integer constant to a tagged smi, giving a tagged smi as result.
354 // No overflow testing on the result is done.
355 void SmiAddConstant(const Operand& dst, Smi* constant);
356
ager@chromium.org4af710e2009-09-15 12:20:11 +0000357 // Add an integer constant to a tagged smi, giving a tagged smi as result,
358 // or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000359 void SmiAddConstant(Register dst,
360 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000361 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000362 Label* on_not_smi_result);
363
364 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.orgac091b72010-05-05 07:34:42 +0000365 // result. No testing on the result is done. Sets the N and Z flags
366 // based on the value of the resulting integer.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000367 void SmiSubConstant(Register dst, Register src, Smi* constant);
368
369 // Subtract an integer constant from a tagged smi, giving a tagged smi as
ager@chromium.org4af710e2009-09-15 12:20:11 +0000370 // result, or jumping to a label if the result cannot be represented by a smi.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000371 void SmiSubConstant(Register dst,
372 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000373 Smi* constant,
ager@chromium.org4af710e2009-09-15 12:20:11 +0000374 Label* on_not_smi_result);
375
376 // Negating a smi can give a negative zero or too large positive value.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000377 // NOTICE: This operation jumps on success, not failure!
ager@chromium.org4af710e2009-09-15 12:20:11 +0000378 void SmiNeg(Register dst,
379 Register src,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000380 Label* on_smi_result);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000381
382 // Adds 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 SmiAdd(Register dst,
386 Register src1,
387 Register src2,
388 Label* on_not_smi_result);
389
390 // Subtracts smi values and return the result as a smi.
391 // If dst is src1, then src1 will be destroyed, even if
392 // the operation is unsuccessful.
393 void SmiSub(Register dst,
394 Register src1,
395 Register src2,
396 Label* on_not_smi_result);
397
ager@chromium.orgac091b72010-05-05 07:34:42 +0000398 void SmiSub(Register dst,
399 Register src1,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000400 const Operand& src2,
ager@chromium.orgac091b72010-05-05 07:34:42 +0000401 Label* on_not_smi_result);
402
ager@chromium.org4af710e2009-09-15 12:20:11 +0000403 // Multiplies smi values and return the result as a smi,
404 // if possible.
405 // If dst is src1, then src1 will be destroyed, even if
406 // the operation is unsuccessful.
407 void SmiMul(Register dst,
408 Register src1,
409 Register src2,
410 Label* on_not_smi_result);
411
412 // Divides one smi by another and returns the quotient.
413 // Clobbers rax and rdx registers.
414 void SmiDiv(Register dst,
415 Register src1,
416 Register src2,
417 Label* on_not_smi_result);
418
419 // Divides one smi by another and returns the remainder.
420 // Clobbers rax and rdx registers.
421 void SmiMod(Register dst,
422 Register src1,
423 Register src2,
424 Label* on_not_smi_result);
425
426 // Bitwise operations.
427 void SmiNot(Register dst, Register src);
428 void SmiAnd(Register dst, Register src1, Register src2);
429 void SmiOr(Register dst, Register src1, Register src2);
430 void SmiXor(Register dst, Register src1, Register src2);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000431 void SmiAndConstant(Register dst, Register src1, Smi* constant);
432 void SmiOrConstant(Register dst, Register src1, Smi* constant);
433 void SmiXorConstant(Register dst, Register src1, Smi* constant);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000434
435 void SmiShiftLeftConstant(Register dst,
436 Register src,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000437 int shift_value);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000438 void SmiShiftLogicalRightConstant(Register dst,
439 Register src,
440 int shift_value,
441 Label* on_not_smi_result);
442 void SmiShiftArithmeticRightConstant(Register dst,
443 Register src,
444 int shift_value);
445
446 // Shifts a smi value to the left, and returns the result if that is a smi.
447 // Uses and clobbers rcx, so dst may not be rcx.
448 void SmiShiftLeft(Register dst,
449 Register src1,
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000450 Register src2);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000451 // Shifts a smi value to the right, shifting in zero bits at the top, and
452 // returns the unsigned intepretation of the result if that is a smi.
453 // Uses and clobbers rcx, so dst may not be rcx.
454 void SmiShiftLogicalRight(Register dst,
455 Register src1,
456 Register src2,
457 Label* on_not_smi_result);
458 // Shifts a smi value to the right, sign extending the top, and
459 // returns the signed intepretation of the result. That will always
460 // be a valid smi value, since it's numerically smaller than the
461 // original.
462 // Uses and clobbers rcx, so dst may not be rcx.
463 void SmiShiftArithmeticRight(Register dst,
464 Register src1,
465 Register src2);
466
467 // Specialized operations
468
469 // Select the non-smi register of two registers where exactly one is a
470 // smi. If neither are smis, jump to the failure label.
471 void SelectNonSmi(Register dst,
472 Register src1,
473 Register src2,
474 Label* on_not_smis);
475
476 // Converts, if necessary, a smi to a combination of number and
477 // multiplier to be used as a scaled index.
478 // The src register contains a *positive* smi value. The shift is the
479 // power of two to multiply the index value by (e.g.
480 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2).
481 // The returned index register may be either src or dst, depending
482 // on what is most efficient. If src and dst are different registers,
483 // src is always unchanged.
484 SmiIndex SmiToIndex(Register dst, Register src, int shift);
485
486 // Converts a positive smi to a negative index.
487 SmiIndex SmiToNegativeIndex(Register dst, Register src, int shift);
488
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000489 // Basic Smi operations.
ager@chromium.org3811b432009-10-28 14:53:37 +0000490 void Move(Register dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000491 LoadSmiConstant(dst, source);
ager@chromium.org3811b432009-10-28 14:53:37 +0000492 }
493
494 void Move(const Operand& dst, Smi* source) {
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000495 Register constant = GetSmiConstant(source);
496 movq(dst, constant);
ager@chromium.org3811b432009-10-28 14:53:37 +0000497 }
498
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000499 void Push(Smi* smi);
500 void Test(const Operand& dst, Smi* source);
501
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000502 // ---------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000503 // String macros.
504 void JumpIfNotBothSequentialAsciiStrings(Register first_object,
505 Register second_object,
506 Register scratch1,
507 Register scratch2,
508 Label* on_not_both_flat_ascii);
509
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000510 // Check whether the instance type represents a flat ascii string. Jump to the
511 // label if not. If the instance type can be scratched specify same register
512 // for both instance type and scratch.
513 void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type,
514 Register scratch,
515 Label *on_not_flat_ascii_string);
516
517 void JumpIfBothInstanceTypesAreNotSequentialAscii(
518 Register first_object_instance_type,
519 Register second_object_instance_type,
520 Register scratch1,
521 Register scratch2,
522 Label* on_fail);
523
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000524 // ---------------------------------------------------------------------------
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000525 // Macro instructions.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000526
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000527 // Load a register with a long value as efficiently as possible.
ager@chromium.orge2902be2009-06-08 12:21:35 +0000528 void Set(Register dst, int64_t x);
529 void Set(const Operand& dst, int64_t x);
ager@chromium.org9085a012009-05-11 19:22:57 +0000530
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000531 // Handle support
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000532 void Move(Register dst, Handle<Object> source);
533 void Move(const Operand& dst, Handle<Object> source);
534 void Cmp(Register dst, Handle<Object> source);
ager@chromium.org3e875802009-06-29 08:26:34 +0000535 void Cmp(const Operand& dst, Handle<Object> source);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000536 void Push(Handle<Object> source);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000537
538 // Emit code to discard a non-negative number of pointer-sized elements
539 // from the stack, clobbering only the rsp register.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000540 void Drop(int stack_elements);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000541
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000542 void Call(Label* target) { call(target); }
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000543
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000544 // Control Flow
545 void Jump(Address destination, RelocInfo::Mode rmode);
546 void Jump(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000547 void Jump(Handle<Code> code_object, RelocInfo::Mode rmode);
548
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000549 void Call(Address destination, RelocInfo::Mode rmode);
550 void Call(ExternalReference ext);
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000551 void Call(Handle<Code> code_object, RelocInfo::Mode rmode);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000552
ager@chromium.org9085a012009-05-11 19:22:57 +0000553 // Compare object type for heap object.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000554 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000555 // Incoming register is heap_object and outgoing register is map.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000556 // They may be the same register, and may be kScratchRegister.
ager@chromium.org9085a012009-05-11 19:22:57 +0000557 void CmpObjectType(Register heap_object, InstanceType type, Register map);
558
559 // Compare instance type for map.
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000560 // Always use unsigned comparisons: above and below, not less and greater.
ager@chromium.org9085a012009-05-11 19:22:57 +0000561 void CmpInstanceType(Register map, InstanceType type);
562
ager@chromium.org5c838252010-02-19 08:53:10 +0000563 // Check if the map of an object is equal to a specified map and
564 // branch to label if not. Skip the smi check if not required
565 // (object is known to be a heap object)
566 void CheckMap(Register obj,
567 Handle<Map> map,
568 Label* fail,
569 bool is_heap_object);
570
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000571 // Check if the object in register heap_object is a string. Afterwards the
572 // register map contains the object map and the register instance_type
573 // contains the instance_type. The registers map and instance_type can be the
574 // same in which case it contains the instance type afterwards. Either of the
575 // registers map and instance_type can be the same as heap_object.
576 Condition IsObjectStringType(Register heap_object,
577 Register map,
578 Register instance_type);
579
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000580 // FCmp compares and pops the two values on top of the FPU stack.
581 // The flag results are similar to integer cmp, but requires unsigned
ager@chromium.org9085a012009-05-11 19:22:57 +0000582 // jcc instructions (je, ja, jae, jb, jbe, je, and jz).
583 void FCmp();
584
ager@chromium.org5c838252010-02-19 08:53:10 +0000585 // Abort execution if argument is not a number. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000586 void AbortIfNotNumber(Register object);
ager@chromium.org5c838252010-02-19 08:53:10 +0000587
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000588 // Abort execution if argument is a smi. Used in debug code.
589 void AbortIfSmi(Register object);
590
lrn@chromium.org25156de2010-04-06 13:10:27 +0000591 // Abort execution if argument is not a smi. Used in debug code.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000592 void AbortIfNotSmi(Register object);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000593
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000594 // Abort execution if argument is not the root value with the given index.
595 void AbortIfNotRootValue(Register src,
596 Heap::RootListIndex root_value_index,
597 const char* message);
598
ager@chromium.org9085a012009-05-11 19:22:57 +0000599 // ---------------------------------------------------------------------------
600 // Exception handling
601
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000602 // Push a new try handler and link into try handler chain. The return
603 // address must be pushed before calling this helper.
ager@chromium.org9085a012009-05-11 19:22:57 +0000604 void PushTryHandler(CodeLocation try_location, HandlerType type);
605
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000606 // Unlink the stack handler on top of the stack from the try handler chain.
607 void PopTryHandler();
ager@chromium.org9085a012009-05-11 19:22:57 +0000608
609 // ---------------------------------------------------------------------------
610 // Inline caching support
611
ager@chromium.org9085a012009-05-11 19:22:57 +0000612 // Generate code for checking access rights - used for security checks
613 // on access to global objects across environments. The holder register
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000614 // is left untouched, but the scratch register and kScratchRegister,
615 // which must be different, are clobbered.
ager@chromium.org9085a012009-05-11 19:22:57 +0000616 void CheckAccessGlobalProxy(Register holder_reg,
617 Register scratch,
618 Label* miss);
619
620
621 // ---------------------------------------------------------------------------
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000622 // Allocation support
623
624 // Allocate an object in new space. If the new space is exhausted control
625 // continues at the gc_required label. The allocated object is returned in
626 // result and end of the new object is returned in result_end. The register
627 // scratch can be passed as no_reg in which case an additional object
628 // reference will be added to the reloc info. The returned pointers in result
629 // and result_end have not yet been tagged as heap objects. If
630 // result_contains_top_on_entry is true the content of result is known to be
631 // the allocation top on entry (could be result_end from a previous call to
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000632 // AllocateInNewSpace). If result_contains_top_on_entry is true scratch
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000633 // should be no_reg as it is never used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000634 void AllocateInNewSpace(int object_size,
635 Register result,
636 Register result_end,
637 Register scratch,
638 Label* gc_required,
639 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000640
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000641 void AllocateInNewSpace(int header_size,
642 ScaleFactor element_size,
643 Register element_count,
644 Register result,
645 Register result_end,
646 Register scratch,
647 Label* gc_required,
648 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000649
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000650 void AllocateInNewSpace(Register object_size,
651 Register result,
652 Register result_end,
653 Register scratch,
654 Label* gc_required,
655 AllocationFlags flags);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000656
657 // Undo allocation in new space. The object passed and objects allocated after
658 // it will no longer be allocated. Make sure that no pointers are left to the
659 // object(s) no longer allocated as they would be invalid when allocation is
660 // un-done.
661 void UndoAllocationInNewSpace(Register object);
662
ager@chromium.org3811b432009-10-28 14:53:37 +0000663 // Allocate a heap number in new space with undefined value. Returns
664 // tagged pointer in result register, or jumps to gc_required if new
665 // space is full.
666 void AllocateHeapNumber(Register result,
667 Register scratch,
668 Label* gc_required);
669
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000670 // Allocate a sequential string. All the header fields of the string object
671 // are initialized.
672 void AllocateTwoByteString(Register result,
673 Register length,
674 Register scratch1,
675 Register scratch2,
676 Register scratch3,
677 Label* gc_required);
678 void AllocateAsciiString(Register result,
679 Register length,
680 Register scratch1,
681 Register scratch2,
682 Register scratch3,
683 Label* gc_required);
684
685 // Allocate a raw cons string object. Only the map field of the result is
686 // initialized.
687 void AllocateConsString(Register result,
688 Register scratch1,
689 Register scratch2,
690 Label* gc_required);
691 void AllocateAsciiConsString(Register result,
692 Register scratch1,
693 Register scratch2,
694 Label* gc_required);
695
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000696 // ---------------------------------------------------------------------------
ager@chromium.org9085a012009-05-11 19:22:57 +0000697 // Support functions.
698
699 // Check if result is zero and op is negative.
700 void NegativeZeroTest(Register result, Register op, Label* then_label);
701
702 // Check if result is zero and op is negative in code using jump targets.
703 void NegativeZeroTest(CodeGenerator* cgen,
704 Register result,
705 Register op,
706 JumpTarget* then_target);
707
708 // Check if result is zero and any of op1 and op2 are negative.
709 // Register scratch is destroyed, and it must be different from op2.
710 void NegativeZeroTest(Register result, Register op1, Register op2,
711 Register scratch, Label* then_label);
712
713 // Try to get function prototype of a function and puts the value in
714 // the result register. Checks that the function really is a
715 // function and jumps to the miss label if the fast checks fail. The
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000716 // function register will be untouched; the other register may be
ager@chromium.org9085a012009-05-11 19:22:57 +0000717 // clobbered.
718 void TryGetFunctionPrototype(Register function,
719 Register result,
ager@chromium.org9085a012009-05-11 19:22:57 +0000720 Label* miss);
721
722 // Generates code for reporting that an illegal operation has
723 // occurred.
724 void IllegalOperation(int num_arguments);
725
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000726 // Find the function context up the context chain.
727 void LoadContext(Register dst, int context_chain_length);
728
ager@chromium.org9085a012009-05-11 19:22:57 +0000729 // ---------------------------------------------------------------------------
730 // Runtime calls
731
732 // Call a code stub.
733 void CallStub(CodeStub* stub);
734
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000735 // Call a code stub and return the code object called. Try to generate
736 // the code if necessary. Do not perform a GC but instead return a retry
737 // after GC failure.
738 Object* TryCallStub(CodeStub* stub);
739
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000740 // Tail call a code stub (jump).
741 void TailCallStub(CodeStub* stub);
742
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000743 // Tail call a code stub (jump) and return the code object called. Try to
744 // generate the code if necessary. Do not perform a GC but instead return
745 // a retry after GC failure.
746 Object* TryTailCallStub(CodeStub* stub);
747
ager@chromium.org9085a012009-05-11 19:22:57 +0000748 // Return from a code stub after popping its arguments.
749 void StubReturn(int argc);
750
751 // Call a runtime routine.
ager@chromium.org9085a012009-05-11 19:22:57 +0000752 void CallRuntime(Runtime::Function* f, int num_arguments);
753
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000754 // Call a runtime function, returning the CodeStub object called.
755 // Try to generate the stub code if necessary. Do not perform a GC
756 // but instead return a retry after GC failure.
757 Object* TryCallRuntime(Runtime::Function* f, int num_arguments);
758
ager@chromium.org9085a012009-05-11 19:22:57 +0000759 // Convenience function: Same as above, but takes the fid instead.
760 void CallRuntime(Runtime::FunctionId id, int num_arguments);
761
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000762 // Convenience function: Same as above, but takes the fid instead.
763 Object* TryCallRuntime(Runtime::FunctionId id, int num_arguments);
764
ager@chromium.org5c838252010-02-19 08:53:10 +0000765 // Convenience function: call an external reference.
766 void CallExternalReference(const ExternalReference& ext,
767 int num_arguments);
768
ager@chromium.org9085a012009-05-11 19:22:57 +0000769 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000770 // Like JumpToExternalReference, but also takes care of passing the number
771 // of parameters.
772 void TailCallExternalReference(const ExternalReference& ext,
773 int num_arguments,
774 int result_size);
775
776 // Convenience function: tail call a runtime routine (jump).
777 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000778 int num_arguments,
779 int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000780
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000781 void PushHandleScope(Register scratch);
782
783 // Pops a handle scope using the specified scratch register and
784 // ensuring that saved register is left unchanged.
785 void PopHandleScope(Register saved, Register scratch);
786
787 // As PopHandleScope, but does not perform a GC. Instead, returns a
788 // retry after GC failure object if GC is necessary.
789 Object* TryPopHandleScope(Register saved, Register scratch);
790
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000791 // Jump to a runtime routine.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000792 void JumpToExternalReference(const ExternalReference& ext, int result_size);
ager@chromium.org9085a012009-05-11 19:22:57 +0000793
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000794 // Before calling a C-function from generated code, align arguments on stack.
795 // After aligning the frame, arguments must be stored in esp[0], esp[4],
796 // etc., not pushed. The argument count assumes all arguments are word sized.
797 // The number of slots reserved for arguments depends on platform. On Windows
798 // stack slots are reserved for the arguments passed in registers. On other
799 // platforms stack slots are only reserved for the arguments actually passed
800 // on the stack.
801 void PrepareCallCFunction(int num_arguments);
802
803 // Calls a C function and cleans up the space for arguments allocated
804 // by PrepareCallCFunction. The called function is not allowed to trigger a
805 // garbage collection, since that might move the code and invalidate the
806 // return address (unless this is somehow accounted for by the called
807 // function).
808 void CallCFunction(ExternalReference function, int num_arguments);
809 void CallCFunction(Register function, int num_arguments);
810
811 // Calculate the number of stack slots to reserve for arguments when calling a
812 // C function.
813 int ArgumentStackSlotsForCFunctionCall(int num_arguments);
ager@chromium.org9085a012009-05-11 19:22:57 +0000814
815 // ---------------------------------------------------------------------------
816 // Utilities
817
818 void Ret();
819
ager@chromium.org9085a012009-05-11 19:22:57 +0000820 Handle<Object> CodeObject() { return code_object_; }
821
822
823 // ---------------------------------------------------------------------------
824 // StatsCounter support
825
826 void SetCounter(StatsCounter* counter, int value);
827 void IncrementCounter(StatsCounter* counter, int value);
828 void DecrementCounter(StatsCounter* counter, int value);
829
830
831 // ---------------------------------------------------------------------------
832 // Debugging
833
834 // Calls Abort(msg) if the condition cc is not satisfied.
835 // Use --debug_code to enable.
836 void Assert(Condition cc, const char* msg);
837
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000838 void AssertFastElements(Register elements);
839
ager@chromium.org9085a012009-05-11 19:22:57 +0000840 // Like Assert(), but always enabled.
841 void Check(Condition cc, const char* msg);
842
843 // Print a message to stdout and abort execution.
844 void Abort(const char* msg);
845
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000846 // Check that the stack is aligned.
847 void CheckStackAlignment();
848
ager@chromium.org9085a012009-05-11 19:22:57 +0000849 // Verify restrictions about code generated in stubs.
850 void set_generating_stub(bool value) { generating_stub_ = value; }
851 bool generating_stub() { return generating_stub_; }
852 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
853 bool allow_stub_calls() { return allow_stub_calls_; }
854
855 private:
ager@chromium.org9085a012009-05-11 19:22:57 +0000856 bool generating_stub_;
857 bool allow_stub_calls_;
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000858
859 // Returns a register holding the smi value. The register MUST NOT be
860 // modified. It may be the "smi 1 constant" register.
861 Register GetSmiConstant(Smi* value);
862
863 // Moves the smi value to the destination register.
864 void LoadSmiConstant(Register dst, Smi* value);
865
ager@chromium.org5c838252010-02-19 08:53:10 +0000866 // This handle will be patched with the code object on installation.
867 Handle<Object> code_object_;
ager@chromium.org9085a012009-05-11 19:22:57 +0000868
869 // Helper functions for generating invokes.
870 void InvokePrologue(const ParameterCount& expected,
871 const ParameterCount& actual,
872 Handle<Code> code_constant,
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000873 Register code_register,
ager@chromium.org9085a012009-05-11 19:22:57 +0000874 Label* done,
875 InvokeFlag flag);
876
ager@chromium.org9085a012009-05-11 19:22:57 +0000877 // Activation support.
878 void EnterFrame(StackFrame::Type type);
879 void LeaveFrame(StackFrame::Type type);
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000880
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000881 void EnterExitFramePrologue(ExitFrame::Mode mode, bool save_rax);
882 void EnterExitFrameEpilogue(ExitFrame::Mode mode, int result_size, int argc);
883
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000884 // Allocation support helpers.
ager@chromium.orgac091b72010-05-05 07:34:42 +0000885 // Loads the top of new-space into the result register.
886 // If flags contains RESULT_CONTAINS_TOP then result_end is valid and
887 // already contains the top of new-space, and scratch is invalid.
888 // Otherwise the address of the new-space top is loaded into scratch (if
889 // scratch is valid), and the new-space top is loaded into result.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000890 void LoadAllocationTopHelper(Register result,
891 Register result_end,
892 Register scratch,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000893 AllocationFlags flags);
ager@chromium.orgac091b72010-05-05 07:34:42 +0000894 // Update allocation top with value in result_end register.
895 // If scratch is valid, it contains the address of the allocation top.
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000896 void UpdateAllocationTopHelper(Register result_end, Register scratch);
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000897
898 // Helper for PopHandleScope. Allowed to perform a GC and returns
899 // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
900 // possibly returns a failure object indicating an allocation failure.
901 Object* PopHandleScopeHelper(Register saved,
902 Register scratch,
903 bool gc_allowed);
ager@chromium.org9085a012009-05-11 19:22:57 +0000904};
905
906
ager@chromium.org4af710e2009-09-15 12:20:11 +0000907// The code patcher is used to patch (typically) small parts of code e.g. for
908// debugging and other types of instrumentation. When using the code patcher
909// the exact number of bytes specified must be emitted. Is not legal to emit
910// relocation information. If any of these constraints are violated it causes
911// an assertion.
912class CodePatcher {
913 public:
914 CodePatcher(byte* address, int size);
915 virtual ~CodePatcher();
916
917 // Macro assembler to emit code.
918 MacroAssembler* masm() { return &masm_; }
919
920 private:
921 byte* address_; // The address of the code being patched.
922 int size_; // Number of bytes of the expected patch size.
923 MacroAssembler masm_; // Macro assembler used to generate the code.
924};
925
926
ager@chromium.org9085a012009-05-11 19:22:57 +0000927// -----------------------------------------------------------------------------
928// Static helper functions.
929
930// Generate an Operand for loading a field from an object.
931static inline Operand FieldOperand(Register object, int offset) {
932 return Operand(object, offset - kHeapObjectTag);
933}
934
935
936// Generate an Operand for loading an indexed field from an object.
937static inline Operand FieldOperand(Register object,
938 Register index,
939 ScaleFactor scale,
940 int offset) {
941 return Operand(object, index, scale, offset - kHeapObjectTag);
942}
943
944
945#ifdef GENERATED_CODE_COVERAGE
946extern void LogGeneratedCodeCoverage(const char* file_line);
947#define CODE_COVERAGE_STRINGIFY(x) #x
948#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
949#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
950#define ACCESS_MASM(masm) { \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000951 byte* x64_coverage_function = \
ager@chromium.org9085a012009-05-11 19:22:57 +0000952 reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \
953 masm->pushfd(); \
954 masm->pushad(); \
955 masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000956 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \
ager@chromium.org9085a012009-05-11 19:22:57 +0000957 masm->pop(rax); \
958 masm->popad(); \
959 masm->popfd(); \
960 } \
961 masm->
962#else
963#define ACCESS_MASM(masm) masm->
964#endif
965
966
967} } // namespace v8::internal
968
969#endif // V8_X64_MACRO_ASSEMBLER_X64_H_