blob: 6084fde2d367d7104b501c9cc8546fd925c40de4 [file] [log] [blame]
Ben Murdoch257744e2011-11-30 15:57:28 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +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
28#ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_
29#define V8_ARM_MACRO_ASSEMBLER_ARM_H_
30
31#include "assembler.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000032#include "v8globals.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000033
34namespace v8 {
35namespace internal {
36
Andrei Popescu31002712010-02-23 13:46:05 +000037// ----------------------------------------------------------------------------
38// Static helper functions
39
40// Generate a MemOperand for loading a field from an object.
41static inline MemOperand FieldMemOperand(Register object, int offset) {
42 return MemOperand(object, offset - kHeapObjectTag);
43}
44
Steve Blocka7e24c12009-10-30 11:49:00 +000045
Steve Block1e0659c2011-05-24 12:43:12 +010046static inline Operand SmiUntagOperand(Register object) {
47 return Operand(object, ASR, kSmiTagSize);
48}
49
50
51
Steve Blocka7e24c12009-10-30 11:49:00 +000052// Give alias names to registers
53const Register cp = { 8 }; // JavaScript context pointer
Andrei Popescu31002712010-02-23 13:46:05 +000054const Register roots = { 10 }; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000055
Kristian Monsen25f61362010-05-21 11:50:48 +010056// Flags used for the AllocateInNewSpace functions.
57enum AllocationFlags {
58 // No special flags.
59 NO_ALLOCATION_FLAGS = 0,
60 // Return the pointer to the allocated already tagged as a heap object.
61 TAG_OBJECT = 1 << 0,
62 // The content of the result register already contains the allocation top in
63 // new space.
64 RESULT_CONTAINS_TOP = 1 << 1,
65 // Specify that the requested size of the space to allocate is specified in
66 // words instead of bytes.
67 SIZE_IN_WORDS = 1 << 2
68};
69
70
Steve Block8defd9f2010-07-08 12:39:36 +010071// Flags used for the ObjectToDoubleVFPRegister function.
72enum ObjectToDoubleFlags {
73 // No special flags.
74 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
75 // Object is known to be a non smi.
76 OBJECT_NOT_SMI = 1 << 0,
77 // Don't load NaNs or infinities, branch to the non number case instead.
78 AVOID_NANS_AND_INFINITIES = 1 << 1
79};
80
81
Steve Blocka7e24c12009-10-30 11:49:00 +000082// MacroAssembler implements a collection of frequently used macros.
83class MacroAssembler: public Assembler {
84 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +010085 // The isolate parameter can be NULL if the macro assembler should
86 // not use isolate-dependent functionality. In this case, it's the
87 // responsibility of the caller to never invoke such function on the
88 // macro assembler.
89 MacroAssembler(Isolate* isolate, void* buffer, int size);
Steve Blocka7e24c12009-10-30 11:49:00 +000090
Andrei Popescu31002712010-02-23 13:46:05 +000091 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +000092 void Jump(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000093 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +000094 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
Ben Murdoch42effa52011-08-19 16:40:31 +010095 static int CallSize(Register target, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +000096 void Call(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000097 static int CallSize(Address target,
Ben Murdoch42effa52011-08-19 16:40:31 +010098 RelocInfo::Mode rmode,
99 Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000100 void Call(Address target, RelocInfo::Mode rmode, Condition cond = al);
101 static int CallSize(Handle<Code> code,
102 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
103 unsigned ast_id = kNoASTId,
104 Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000105 void Call(Handle<Code> code,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000106 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
107 unsigned ast_id = kNoASTId,
Ben Murdoch257744e2011-11-30 15:57:28 +0000108 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000109 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000110
111 // Emit code to discard a non-negative number of pointer-sized elements
112 // from the stack, clobbering only the sp register.
113 void Drop(int count, Condition cond = al);
114
Ben Murdochb0fe1622011-05-05 13:52:32 +0100115 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100116
117 // Swap two registers. If the scratch register is omitted then a slightly
118 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100119 void Swap(Register reg1,
120 Register reg2,
121 Register scratch = no_reg,
122 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100123
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100124
125 void And(Register dst, Register src1, const Operand& src2,
126 Condition cond = al);
127 void Ubfx(Register dst, Register src, int lsb, int width,
128 Condition cond = al);
129 void Sbfx(Register dst, Register src, int lsb, int width,
130 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100131 // The scratch register is not used for ARMv7.
132 // scratch can be the same register as src (in which case it is trashed), but
133 // not the same as dst.
134 void Bfi(Register dst,
135 Register src,
136 Register scratch,
137 int lsb,
138 int width,
139 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100140 void Bfc(Register dst, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100141 void Usat(Register dst, int satpos, const Operand& src,
142 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100143
Leon Clarkee46be812010-01-19 14:06:41 +0000144 void Call(Label* target);
Ben Murdoch257744e2011-11-30 15:57:28 +0000145
146 // Register move. May do nothing if the registers are identical.
Leon Clarkee46be812010-01-19 14:06:41 +0000147 void Move(Register dst, Handle<Object> value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000148 void Move(Register dst, Register src, Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000149 void Move(DoubleRegister dst, DoubleRegister src);
150
Steve Blocka7e24c12009-10-30 11:49:00 +0000151 // Load an object from the root table.
152 void LoadRoot(Register destination,
153 Heap::RootListIndex index,
154 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100155 // Store an object to the root table.
156 void StoreRoot(Register source,
157 Heap::RootListIndex index,
158 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000159
Steve Block6ded16b2010-05-10 14:33:55 +0100160
161 // Check if object is in new space.
162 // scratch can be object itself, but it will be clobbered.
163 void InNewSpace(Register object,
164 Register scratch,
Steve Block1e0659c2011-05-24 12:43:12 +0100165 Condition cond, // eq for new space, ne otherwise
Steve Block6ded16b2010-05-10 14:33:55 +0100166 Label* branch);
167
168
Steve Block8defd9f2010-07-08 12:39:36 +0100169 // For the page containing |object| mark the region covering [address]
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100170 // dirty. The object address must be in the first 8K of an allocated page.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100171 void RecordWriteHelper(Register object,
Steve Block8defd9f2010-07-08 12:39:36 +0100172 Register address,
173 Register scratch);
Steve Block6ded16b2010-05-10 14:33:55 +0100174
Steve Block8defd9f2010-07-08 12:39:36 +0100175 // For the page containing |object| mark the region covering
176 // [object+offset] dirty. The object address must be in the first 8K
177 // of an allocated page. The 'scratch' registers are used in the
178 // implementation and all 3 registers are clobbered by the
179 // operation, as well as the ip register. RecordWrite updates the
180 // write barrier even when storing smis.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100181 void RecordWrite(Register object,
182 Operand offset,
183 Register scratch0,
184 Register scratch1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Steve Block8defd9f2010-07-08 12:39:36 +0100186 // For the page containing |object| mark the region covering
187 // [address] dirty. The object address must be in the first 8K of an
188 // allocated page. All 3 registers are clobbered by the operation,
189 // as well as the ip register. RecordWrite updates the write barrier
190 // even when storing smis.
191 void RecordWrite(Register object,
192 Register address,
193 Register scratch);
194
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000195 // Push a handle.
196 void Push(Handle<Object> handle);
197
Steve Block6ded16b2010-05-10 14:33:55 +0100198 // Push two registers. Pushes leftmost register first (to highest address).
199 void Push(Register src1, Register src2, Condition cond = al) {
200 ASSERT(!src1.is(src2));
201 if (src1.code() > src2.code()) {
202 stm(db_w, sp, src1.bit() | src2.bit(), cond);
203 } else {
204 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
205 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
206 }
207 }
208
209 // Push three registers. Pushes leftmost register first (to highest address).
210 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
211 ASSERT(!src1.is(src2));
212 ASSERT(!src2.is(src3));
213 ASSERT(!src1.is(src3));
214 if (src1.code() > src2.code()) {
215 if (src2.code() > src3.code()) {
216 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
217 } else {
218 stm(db_w, sp, src1.bit() | src2.bit(), cond);
219 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
220 }
221 } else {
222 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
223 Push(src2, src3, cond);
224 }
225 }
226
227 // Push four registers. Pushes leftmost register first (to highest address).
228 void Push(Register src1, Register src2,
229 Register src3, Register src4, Condition cond = al) {
230 ASSERT(!src1.is(src2));
231 ASSERT(!src2.is(src3));
232 ASSERT(!src1.is(src3));
233 ASSERT(!src1.is(src4));
234 ASSERT(!src2.is(src4));
235 ASSERT(!src3.is(src4));
236 if (src1.code() > src2.code()) {
237 if (src2.code() > src3.code()) {
238 if (src3.code() > src4.code()) {
239 stm(db_w,
240 sp,
241 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
242 cond);
243 } else {
244 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
245 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
246 }
247 } else {
248 stm(db_w, sp, src1.bit() | src2.bit(), cond);
249 Push(src3, src4, cond);
250 }
251 } else {
252 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
253 Push(src2, src3, src4, cond);
254 }
255 }
256
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100257 // Pop two registers. Pops rightmost register first (from lower address).
258 void Pop(Register src1, Register src2, Condition cond = al) {
259 ASSERT(!src1.is(src2));
260 if (src1.code() > src2.code()) {
261 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
262 } else {
263 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
264 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
265 }
266 }
267
Ben Murdochb0fe1622011-05-05 13:52:32 +0100268 // Push and pop the registers that can hold pointers, as defined by the
269 // RegList constant kSafepointSavedRegisters.
270 void PushSafepointRegisters();
271 void PopSafepointRegisters();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100272 void PushSafepointRegistersAndDoubles();
273 void PopSafepointRegistersAndDoubles();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100274 // Store value in register src in the safepoint stack slot for
275 // register dst.
276 void StoreToSafepointRegisterSlot(Register src, Register dst);
277 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
278 // Load the value of the src register from its safepoint stack slot
279 // into register dst.
280 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100281
Leon Clarkef7060e22010-06-03 12:02:55 +0100282 // Load two consecutive registers with two consecutive memory locations.
283 void Ldrd(Register dst1,
284 Register dst2,
285 const MemOperand& src,
286 Condition cond = al);
287
288 // Store two consecutive registers to two consecutive memory locations.
289 void Strd(Register src1,
290 Register src2,
291 const MemOperand& dst,
292 Condition cond = al);
293
Ben Murdochb8e0da22011-05-16 14:20:40 +0100294 // Clear specified FPSCR bits.
295 void ClearFPSCRBits(const uint32_t bits_to_clear,
296 const Register scratch,
297 const Condition cond = al);
298
299 // Compare double values and move the result to the normal condition flags.
300 void VFPCompareAndSetFlags(const DwVfpRegister src1,
301 const DwVfpRegister src2,
302 const Condition cond = al);
303 void VFPCompareAndSetFlags(const DwVfpRegister src1,
304 const double src2,
305 const Condition cond = al);
306
307 // Compare double values and then load the fpscr flags to a register.
308 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
309 const DwVfpRegister src2,
310 const Register fpscr_flags,
311 const Condition cond = al);
312 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
313 const double src2,
314 const Register fpscr_flags,
315 const Condition cond = al);
316
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000317 void Vmov(const DwVfpRegister dst,
318 const double imm,
319 const Condition cond = al);
320
Ben Murdoch086aeea2011-05-13 15:57:08 +0100321
Steve Blocka7e24c12009-10-30 11:49:00 +0000322 // ---------------------------------------------------------------------------
323 // Activation frames
324
325 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
326 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
327
328 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
329 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
330
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100331 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100332 // stack_space - extra stack space, used for alignment before call to C.
333 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
335 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100336 // Expect the number of values, pushed prior to the exit frame, to
337 // remove in a register (or no_reg, if there is nothing to remove).
338 void LeaveExitFrame(bool save_doubles, Register argument_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000339
Steve Block6ded16b2010-05-10 14:33:55 +0100340 // Get the actual activation frame alignment for target environment.
341 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000342
Steve Blockd0582a62009-12-15 09:54:21 +0000343 void LoadContext(Register dst, int context_chain_length);
344
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800345 void LoadGlobalFunction(int index, Register function);
346
347 // Load the initial map from the global function. The registers
348 // function and map can be the same, function is then overwritten.
349 void LoadGlobalFunctionInitialMap(Register function,
350 Register map,
351 Register scratch);
352
Steve Blocka7e24c12009-10-30 11:49:00 +0000353 // ---------------------------------------------------------------------------
354 // JavaScript invokes
355
Ben Murdoch257744e2011-11-30 15:57:28 +0000356 // Setup call kind marking in ecx. The method takes ecx as an
357 // explicit first parameter to make the code more readable at the
358 // call sites.
359 void SetCallKind(Register dst, CallKind kind);
360
Steve Blocka7e24c12009-10-30 11:49:00 +0000361 // Invoke the JavaScript function code by either calling or jumping.
362 void InvokeCode(Register code,
363 const ParameterCount& expected,
364 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100365 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000366 const CallWrapper& call_wrapper,
367 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369 void InvokeCode(Handle<Code> code,
370 const ParameterCount& expected,
371 const ParameterCount& actual,
372 RelocInfo::Mode rmode,
Ben Murdoch257744e2011-11-30 15:57:28 +0000373 InvokeFlag flag,
374 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
376 // Invoke the JavaScript function in the given register. Changes the
377 // current context to the context in the function before invoking.
378 void InvokeFunction(Register function,
379 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100380 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000381 const CallWrapper& call_wrapper,
382 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000383
Andrei Popescu402d9372010-02-26 13:31:12 +0000384 void InvokeFunction(JSFunction* function,
385 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000386 InvokeFlag flag,
387 CallKind call_kind);
Andrei Popescu402d9372010-02-26 13:31:12 +0000388
Ben Murdochb0fe1622011-05-05 13:52:32 +0100389 void IsObjectJSObjectType(Register heap_object,
390 Register map,
391 Register scratch,
392 Label* fail);
393
394 void IsInstanceJSObjectType(Register map,
395 Register scratch,
396 Label* fail);
397
398 void IsObjectJSStringType(Register object,
399 Register scratch,
400 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000401
402#ifdef ENABLE_DEBUGGER_SUPPORT
403 // ---------------------------------------------------------------------------
404 // Debugger Support
405
Andrei Popescu402d9372010-02-26 13:31:12 +0000406 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000407#endif
408
409 // ---------------------------------------------------------------------------
410 // Exception handling
411
412 // Push a new try handler and link into try handler chain.
413 // The return address must be passed in register lr.
414 // On exit, r0 contains TOS (code slot).
415 void PushTryHandler(CodeLocation try_location, HandlerType type);
416
Leon Clarkee46be812010-01-19 14:06:41 +0000417 // Unlink the stack handler on top of the stack from the try handler chain.
418 // Must preserve the result register.
419 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000420
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100421 // Passes thrown value (in r0) to the handler of top of the try handler chain.
422 void Throw(Register value);
423
424 // Propagates an uncatchable exception to the top of the current JS stack's
425 // handler chain.
426 void ThrowUncatchable(UncatchableExceptionType type, Register value);
427
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 // ---------------------------------------------------------------------------
429 // Inline caching support
430
Steve Blocka7e24c12009-10-30 11:49:00 +0000431 // Generate code for checking access rights - used for security checks
432 // on access to global objects across environments. The holder register
433 // is left untouched, whereas both scratch registers are clobbered.
434 void CheckAccessGlobalProxy(Register holder_reg,
435 Register scratch,
436 Label* miss);
437
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000438
439 void LoadFromNumberDictionary(Label* miss,
440 Register elements,
441 Register key,
442 Register result,
443 Register t0,
444 Register t1,
445 Register t2);
446
447
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800448 inline void MarkCode(NopMarkerTypes type) {
449 nop(type);
450 }
451
452 // Check if the given instruction is a 'type' marker.
453 // ie. check if is is a mov r<type>, r<type> (referenced as nop(type))
454 // These instructions are generated to mark special location in the code,
455 // like some special IC code.
456 static inline bool IsMarkedCode(Instr instr, int type) {
457 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
458 return IsNop(instr, type);
459 }
460
461
462 static inline int GetCodeMarker(Instr instr) {
463 int dst_reg_offset = 12;
464 int dst_mask = 0xf << dst_reg_offset;
465 int src_mask = 0xf;
466 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
467 int src_reg = instr & src_mask;
468 uint32_t non_register_mask = ~(dst_mask | src_mask);
469 uint32_t mov_mask = al | 13 << 21;
470
471 // Return <n> if we have a mov rn rn, else return -1.
472 int type = ((instr & non_register_mask) == mov_mask) &&
473 (dst_reg == src_reg) &&
474 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
475 ? src_reg
476 : -1;
477 ASSERT((type == -1) ||
478 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
479 return type;
480 }
481
Steve Blocka7e24c12009-10-30 11:49:00 +0000482
483 // ---------------------------------------------------------------------------
484 // Allocation support
485
Ben Murdoch086aeea2011-05-13 15:57:08 +0100486 // Allocate an object in new space. The object_size is specified
487 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
488 // is passed. If the new space is exhausted control continues at the
489 // gc_required label. The allocated object is returned in result. If
490 // the flag tag_allocated_object is true the result is tagged as as
491 // a heap object. All registers are clobbered also when control
492 // continues at the gc_required label.
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 void AllocateInNewSpace(int object_size,
494 Register result,
495 Register scratch1,
496 Register scratch2,
497 Label* gc_required,
498 AllocationFlags flags);
499 void AllocateInNewSpace(Register object_size,
500 Register result,
501 Register scratch1,
502 Register scratch2,
503 Label* gc_required,
504 AllocationFlags flags);
505
506 // Undo allocation in new space. The object passed and objects allocated after
507 // it will no longer be allocated. The caller must make sure that no pointers
508 // are left to the object(s) no longer allocated as they would be invalid when
509 // allocation is undone.
510 void UndoAllocationInNewSpace(Register object, Register scratch);
511
Andrei Popescu31002712010-02-23 13:46:05 +0000512
513 void AllocateTwoByteString(Register result,
514 Register length,
515 Register scratch1,
516 Register scratch2,
517 Register scratch3,
518 Label* gc_required);
519 void AllocateAsciiString(Register result,
520 Register length,
521 Register scratch1,
522 Register scratch2,
523 Register scratch3,
524 Label* gc_required);
525 void AllocateTwoByteConsString(Register result,
526 Register length,
527 Register scratch1,
528 Register scratch2,
529 Label* gc_required);
530 void AllocateAsciiConsString(Register result,
531 Register length,
532 Register scratch1,
533 Register scratch2,
534 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000535 void AllocateTwoByteSlicedString(Register result,
536 Register length,
537 Register scratch1,
538 Register scratch2,
539 Label* gc_required);
540 void AllocateAsciiSlicedString(Register result,
541 Register length,
542 Register scratch1,
543 Register scratch2,
544 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000545
Kristian Monsen25f61362010-05-21 11:50:48 +0100546 // Allocates a heap number or jumps to the gc_required label if the young
547 // space is full and a scavenge is needed. All registers are clobbered also
548 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100549 void AllocateHeapNumber(Register result,
550 Register scratch1,
551 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100552 Register heap_number_map,
Steve Block6ded16b2010-05-10 14:33:55 +0100553 Label* gc_required);
Steve Block8defd9f2010-07-08 12:39:36 +0100554 void AllocateHeapNumberWithValue(Register result,
555 DwVfpRegister value,
556 Register scratch1,
557 Register scratch2,
558 Register heap_number_map,
559 Label* gc_required);
560
Ben Murdochbb769b22010-08-11 14:56:33 +0100561 // Copies a fixed number of fields of heap objects from src to dst.
562 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000563
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100564 // Copies a number of bytes from src to dst. All registers are clobbered. On
565 // exit src and dst will point to the place just after where the last byte was
566 // read or written and length will be zero.
567 void CopyBytes(Register src,
568 Register dst,
569 Register length,
570 Register scratch);
571
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 // ---------------------------------------------------------------------------
573 // Support functions.
574
575 // Try to get function prototype of a function and puts the value in
576 // the result register. Checks that the function really is a
577 // function and jumps to the miss label if the fast checks fail. The
578 // function register will be untouched; the other registers may be
579 // clobbered.
580 void TryGetFunctionPrototype(Register function,
581 Register result,
582 Register scratch,
583 Label* miss);
584
585 // Compare object type for heap object. heap_object contains a non-Smi
586 // whose object type should be compared with the given type. This both
587 // sets the flags and leaves the object type in the type_reg register.
588 // It leaves the map in the map register (unless the type_reg and map register
589 // are the same register). It leaves the heap object in the heap_object
590 // register unless the heap_object register is the same register as one of the
591 // other registers.
592 void CompareObjectType(Register heap_object,
593 Register map,
594 Register type_reg,
595 InstanceType type);
596
597 // Compare instance type in a map. map contains a valid map object whose
598 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000599 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 void CompareInstanceType(Register map,
601 Register type_reg,
602 InstanceType type);
603
Andrei Popescu31002712010-02-23 13:46:05 +0000604
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000605 // Check if a map for a JSObject indicates that the object has fast elements.
606 // Jump to the specified label if it does not.
607 void CheckFastElements(Register map,
608 Register scratch,
609 Label* fail);
610
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100611 // Check if the map of an object is equal to a specified map (either
612 // given directly or as an index into the root list) and branch to
613 // label if not. Skip the smi check if not required (object is known
614 // to be a heap object)
Andrei Popescu31002712010-02-23 13:46:05 +0000615 void CheckMap(Register obj,
616 Register scratch,
617 Handle<Map> map,
618 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000619 SmiCheckType smi_check_type);
620
Andrei Popescu31002712010-02-23 13:46:05 +0000621
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100622 void CheckMap(Register obj,
623 Register scratch,
624 Heap::RootListIndex index,
625 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000626 SmiCheckType smi_check_type);
627
628
629 // Check if the map of an object is equal to a specified map and branch to a
630 // specified target if equal. Skip the smi check if not required (object is
631 // known to be a heap object)
632 void DispatchMap(Register obj,
633 Register scratch,
634 Handle<Map> map,
635 Handle<Code> success,
636 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100637
638
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100639 // Compare the object in a register to a value from the root list.
640 // Uses the ip register as scratch.
641 void CompareRoot(Register obj, Heap::RootListIndex index);
642
643
Andrei Popescu31002712010-02-23 13:46:05 +0000644 // Load and check the instance type of an object for being a string.
645 // Loads the type into the second argument register.
646 // Returns a condition that will be enabled if the object was a string.
647 Condition IsObjectStringType(Register obj,
648 Register type) {
649 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset));
650 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
651 tst(type, Operand(kIsNotStringMask));
652 ASSERT_EQ(0, kStringTag);
653 return eq;
654 }
655
656
Steve Blocka7e24c12009-10-30 11:49:00 +0000657 // Generates code for reporting that an illegal operation has
658 // occurred.
659 void IllegalOperation(int num_arguments);
660
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100661 // Picks out an array index from the hash field.
662 // Register use:
663 // hash - holds the index's hash. Clobbered.
664 // index - holds the overwritten index on exit.
665 void IndexFromHash(Register hash, Register index);
666
Andrei Popescu31002712010-02-23 13:46:05 +0000667 // Get the number of least significant bits from a register
668 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100669 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000670
Steve Blockd0582a62009-12-15 09:54:21 +0000671 // Uses VFP instructions to Convert a Smi to a double.
672 void IntegerToDoubleConversionWithVFP3(Register inReg,
673 Register outHighReg,
674 Register outLowReg);
675
Steve Block8defd9f2010-07-08 12:39:36 +0100676 // Load the value of a number object into a VFP double register. If the object
677 // is not a number a jump to the label not_number is performed and the VFP
678 // double register is unchanged.
679 void ObjectToDoubleVFPRegister(
680 Register object,
681 DwVfpRegister value,
682 Register scratch1,
683 Register scratch2,
684 Register heap_number_map,
685 SwVfpRegister scratch3,
686 Label* not_number,
687 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
688
689 // Load the value of a smi object into a VFP double register. The register
690 // scratch1 can be the same register as smi in which case smi will hold the
691 // untagged value afterwards.
692 void SmiToDoubleVFPRegister(Register smi,
693 DwVfpRegister value,
694 Register scratch1,
695 SwVfpRegister scratch2);
696
Iain Merrick9ac36c92010-09-13 15:29:50 +0100697 // Convert the HeapNumber pointed to by source to a 32bits signed integer
698 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
Steve Block1e0659c2011-05-24 12:43:12 +0100699 // to not_int32 label. If VFP3 is available double_scratch is used but not
700 // scratch2.
Iain Merrick9ac36c92010-09-13 15:29:50 +0100701 void ConvertToInt32(Register source,
702 Register dest,
703 Register scratch,
704 Register scratch2,
Steve Block1e0659c2011-05-24 12:43:12 +0100705 DwVfpRegister double_scratch,
Iain Merrick9ac36c92010-09-13 15:29:50 +0100706 Label *not_int32);
707
Steve Block44f0eee2011-05-26 01:26:41 +0100708 // Truncates a double using a specific rounding mode.
709 // Clears the z flag (ne condition) if an overflow occurs.
710 // If exact_conversion is true, the z flag is also cleared if the conversion
711 // was inexact, ie. if the double value could not be converted exactly
712 // to a 32bit integer.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100713 void EmitVFPTruncate(VFPRoundingMode rounding_mode,
714 SwVfpRegister result,
715 DwVfpRegister double_input,
716 Register scratch1,
717 Register scratch2,
718 CheckForInexactConversion check
719 = kDontCheckForInexactConversion);
720
Steve Block44f0eee2011-05-26 01:26:41 +0100721 // Helper for EmitECMATruncate.
722 // This will truncate a floating-point value outside of the singed 32bit
723 // integer range to a 32bit signed integer.
724 // Expects the double value loaded in input_high and input_low.
725 // Exits with the answer in 'result'.
726 // Note that this code does not work for values in the 32bit range!
727 void EmitOutOfInt32RangeTruncate(Register result,
728 Register input_high,
729 Register input_low,
730 Register scratch);
731
732 // Performs a truncating conversion of a floating point number as used by
733 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
734 // Exits with 'result' holding the answer and all other registers clobbered.
735 void EmitECMATruncate(Register result,
736 DwVfpRegister double_input,
737 SwVfpRegister single_scratch,
738 Register scratch,
739 Register scratch2,
740 Register scratch3);
741
Steve Block6ded16b2010-05-10 14:33:55 +0100742 // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz
743 // instruction. On pre-ARM5 hardware this routine gives the wrong answer
Steve Block8defd9f2010-07-08 12:39:36 +0100744 // for 0 (31 instead of 32). Source and scratch can be the same in which case
745 // the source is clobbered. Source and zeros can also be the same in which
746 // case scratch should be a different register.
747 void CountLeadingZeros(Register zeros,
748 Register source,
749 Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000750
751 // ---------------------------------------------------------------------------
752 // Runtime calls
753
754 // Call a code stub.
755 void CallStub(CodeStub* stub, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000756
Ben Murdoch257744e2011-11-30 15:57:28 +0000757 // Call a code stub and return the code object called. Try to generate
758 // the code if necessary. Do not perform a GC but instead return a retry
759 // after GC failure.
760 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub, Condition cond = al);
761
Andrei Popescu31002712010-02-23 13:46:05 +0000762 // Call a code stub.
763 void TailCallStub(CodeStub* stub, Condition cond = al);
764
Steve Block1e0659c2011-05-24 12:43:12 +0100765 // Tail call a code stub (jump) and return the code object called. Try to
766 // generate the code if necessary. Do not perform a GC but instead return
767 // a retry after GC failure.
768 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub,
769 Condition cond = al);
770
Steve Blocka7e24c12009-10-30 11:49:00 +0000771 // Call a runtime routine.
Steve Block44f0eee2011-05-26 01:26:41 +0100772 void CallRuntime(const Runtime::Function* f, int num_arguments);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100773 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000774
775 // Convenience function: Same as above, but takes the fid instead.
776 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
777
Andrei Popescu402d9372010-02-26 13:31:12 +0000778 // Convenience function: call an external reference.
779 void CallExternalReference(const ExternalReference& ext,
780 int num_arguments);
781
Steve Blocka7e24c12009-10-30 11:49:00 +0000782 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100783 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +0000784 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +0100785 void TailCallExternalReference(const ExternalReference& ext,
786 int num_arguments,
787 int result_size);
788
Steve Block1e0659c2011-05-24 12:43:12 +0100789 // Tail call of a runtime routine (jump). Try to generate the code if
790 // necessary. Do not perform a GC but instead return a retry after GC
791 // failure.
792 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
793 const ExternalReference& ext, int num_arguments, int result_size);
794
Steve Block6ded16b2010-05-10 14:33:55 +0100795 // Convenience function: tail call a runtime routine (jump).
796 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +0000797 int num_arguments,
798 int result_size);
799
Ben Murdoch257744e2011-11-30 15:57:28 +0000800 int CalculateStackPassedWords(int num_reg_arguments,
801 int num_double_arguments);
802
Steve Block6ded16b2010-05-10 14:33:55 +0100803 // Before calling a C-function from generated code, align arguments on stack.
804 // After aligning the frame, non-register arguments must be stored in
805 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +0000806 // are word sized. If double arguments are used, this function assumes that
807 // all double arguments are stored before core registers; otherwise the
808 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +0100809 // Some compilers/platforms require the stack to be aligned when calling
810 // C++ code.
811 // Needs a scratch register to do some arithmetic. This register will be
812 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +0000813 void PrepareCallCFunction(int num_reg_arguments,
814 int num_double_registers,
815 Register scratch);
816 void PrepareCallCFunction(int num_reg_arguments,
817 Register scratch);
818
819 // There are two ways of passing double arguments on ARM, depending on
820 // whether soft or hard floating point ABI is used. These functions
821 // abstract parameter passing for the three different ways we call
822 // C functions from generated code.
823 void SetCallCDoubleArguments(DoubleRegister dreg);
824 void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2);
825 void SetCallCDoubleArguments(DoubleRegister dreg, Register reg);
Steve Block6ded16b2010-05-10 14:33:55 +0100826
827 // Calls a C function and cleans up the space for arguments allocated
828 // by PrepareCallCFunction. The called function is not allowed to trigger a
829 // garbage collection, since that might move the code and invalidate the
830 // return address (unless this is somehow accounted for by the called
831 // function).
832 void CallCFunction(ExternalReference function, int num_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +0100833 void CallCFunction(Register function, Register scratch, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +0000834 void CallCFunction(ExternalReference function,
835 int num_reg_arguments,
836 int num_double_arguments);
837 void CallCFunction(Register function, Register scratch,
838 int num_reg_arguments,
839 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +0100840
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100841 void GetCFunctionDoubleResult(const DoubleRegister dst);
842
Steve Block1e0659c2011-05-24 12:43:12 +0100843 // Calls an API function. Allocates HandleScope, extracts returned value
844 // from handle and propagates exceptions. Restores context.
845 // stack_space - space to be unwound on exit (includes the call js
846 // arguments space and the additional space allocated for the fast call).
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100847 MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function,
Steve Block1e0659c2011-05-24 12:43:12 +0100848 int stack_space);
849
Steve Blocka7e24c12009-10-30 11:49:00 +0000850 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100851 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +0000852
Steve Block1e0659c2011-05-24 12:43:12 +0100853 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext);
854
Steve Blocka7e24c12009-10-30 11:49:00 +0000855 // Invoke specified builtin JavaScript function. Adds an entry to
856 // the unresolved list if the name does not resolve.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100857 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +0000858 InvokeFlag flag,
859 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +0000860
861 // Store the code object for the given builtin in the target register and
862 // setup the function in r1.
863 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
864
Steve Block791712a2010-08-27 10:21:07 +0100865 // Store the function for the given builtin in the target register.
866 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
867
Ben Murdoch8b112d22011-06-08 16:22:53 +0100868 Handle<Object> CodeObject() {
869 ASSERT(!code_object_.is_null());
870 return code_object_;
871 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000872
873
874 // ---------------------------------------------------------------------------
875 // StatsCounter support
876
877 void SetCounter(StatsCounter* counter, int value,
878 Register scratch1, Register scratch2);
879 void IncrementCounter(StatsCounter* counter, int value,
880 Register scratch1, Register scratch2);
881 void DecrementCounter(StatsCounter* counter, int value,
882 Register scratch1, Register scratch2);
883
884
885 // ---------------------------------------------------------------------------
886 // Debugging
887
Steve Block1e0659c2011-05-24 12:43:12 +0100888 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +0000889 // Use --debug_code to enable.
Steve Block1e0659c2011-05-24 12:43:12 +0100890 void Assert(Condition cond, const char* msg);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100891 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
Iain Merrick75681382010-08-19 15:07:18 +0100892 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +0000893
894 // Like Assert(), but always enabled.
Steve Block1e0659c2011-05-24 12:43:12 +0100895 void Check(Condition cond, const char* msg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000896
897 // Print a message to stdout and abort execution.
898 void Abort(const char* msg);
899
900 // Verify restrictions about code generated in stubs.
901 void set_generating_stub(bool value) { generating_stub_ = value; }
902 bool generating_stub() { return generating_stub_; }
903 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
904 bool allow_stub_calls() { return allow_stub_calls_; }
905
Ben Murdoch257744e2011-11-30 15:57:28 +0000906 // EABI variant for double arguments in use.
907 bool use_eabi_hardfloat() {
908#if USE_EABI_HARDFLOAT
909 return true;
910#else
911 return false;
912#endif
913 }
914
Leon Clarked91b9f72010-01-27 17:25:45 +0000915 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +0100916 // Number utilities
917
918 // Check whether the value of reg is a power of two and not zero. If not
919 // control continues at the label not_power_of_two. If reg is a power of two
920 // the register scratch contains the value of (reg - 1) when control falls
921 // through.
922 void JumpIfNotPowerOfTwoOrZero(Register reg,
923 Register scratch,
924 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +0100925 // Check whether the value of reg is a power of two and not zero.
926 // Control falls through if it is, with scratch containing the mask
927 // value (reg - 1).
928 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
929 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
930 // strictly positive but not a power of two.
931 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
932 Register scratch,
933 Label* zero_and_neg,
934 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +0100935
936 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000937 // Smi utilities
938
Ben Murdochb0fe1622011-05-05 13:52:32 +0100939 void SmiTag(Register reg, SBit s = LeaveCC) {
940 add(reg, reg, Operand(reg), s);
941 }
Steve Block1e0659c2011-05-24 12:43:12 +0100942 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
943 add(dst, src, Operand(src), s);
944 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100945
Ben Murdochb8e0da22011-05-16 14:20:40 +0100946 // Try to convert int32 to smi. If the value is to large, preserve
947 // the original value and jump to not_a_smi. Destroys scratch and
948 // sets flags.
949 void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
950 mov(scratch, reg);
951 SmiTag(scratch, SetCC);
952 b(vs, not_a_smi);
953 mov(reg, scratch);
954 }
955
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100956 void SmiUntag(Register reg, SBit s = LeaveCC) {
957 mov(reg, Operand(reg, ASR, kSmiTagSize), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100958 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100959 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
960 mov(dst, Operand(src, ASR, kSmiTagSize), s);
Steve Block1e0659c2011-05-24 12:43:12 +0100961 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100962
Steve Block1e0659c2011-05-24 12:43:12 +0100963 // Jump the register contains a smi.
964 inline void JumpIfSmi(Register value, Label* smi_label) {
965 tst(value, Operand(kSmiTagMask));
966 b(eq, smi_label);
967 }
968 // Jump if either of the registers contain a non-smi.
969 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
970 tst(value, Operand(kSmiTagMask));
971 b(ne, not_smi_label);
972 }
Andrei Popescu31002712010-02-23 13:46:05 +0000973 // Jump if either of the registers contain a non-smi.
974 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
975 // Jump if either of the registers contain a smi.
976 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
977
Iain Merrick75681382010-08-19 15:07:18 +0100978 // Abort execution if argument is a smi. Used in debug code.
979 void AbortIfSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +0100980 void AbortIfNotSmi(Register object);
981
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100982 // Abort execution if argument is a string. Used in debug code.
983 void AbortIfNotString(Register object);
984
Steve Block1e0659c2011-05-24 12:43:12 +0100985 // Abort execution if argument is not the root value with the given index.
986 void AbortIfNotRootValue(Register src,
987 Heap::RootListIndex root_value_index,
988 const char* message);
989
990 // ---------------------------------------------------------------------------
991 // HeapNumber utilities
992
993 void JumpIfNotHeapNumber(Register object,
994 Register heap_number_map,
995 Register scratch,
996 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +0100997
Andrei Popescu31002712010-02-23 13:46:05 +0000998 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +0000999 // String utilities
1000
1001 // Checks if both objects are sequential ASCII strings and jumps to label
1002 // if either is not. Assumes that neither object is a smi.
1003 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
1004 Register object2,
1005 Register scratch1,
1006 Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +01001007 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001008
1009 // Checks if both objects are sequential ASCII strings and jumps to label
1010 // if either is not.
1011 void JumpIfNotBothSequentialAsciiStrings(Register first,
1012 Register second,
1013 Register scratch1,
1014 Register scratch2,
1015 Label* not_flat_ascii_strings);
1016
Steve Block6ded16b2010-05-10 14:33:55 +01001017 // Checks if both instance types are sequential ASCII strings and jumps to
1018 // label if either is not.
1019 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1020 Register first_object_instance_type,
1021 Register second_object_instance_type,
1022 Register scratch1,
1023 Register scratch2,
1024 Label* failure);
1025
1026 // Check if instance type is sequential ASCII string and jump to label if
1027 // it is not.
1028 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1029 Register scratch,
1030 Label* failure);
1031
1032
Steve Block1e0659c2011-05-24 12:43:12 +01001033 // ---------------------------------------------------------------------------
1034 // Patching helpers.
1035
1036 // Get the location of a relocated constant (its address in the constant pool)
1037 // from its load site.
1038 void GetRelocatedValueLocation(Register ldr_location,
1039 Register result);
1040
1041
Ben Murdoch257744e2011-11-30 15:57:28 +00001042 void ClampUint8(Register output_reg, Register input_reg);
1043
1044 void ClampDoubleToUint8(Register result_reg,
1045 DoubleRegister input_reg,
1046 DoubleRegister temp_double_reg);
1047
1048
1049 void LoadInstanceDescriptors(Register map, Register descriptors);
1050
Steve Blocka7e24c12009-10-30 11:49:00 +00001051 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001052 void CallCFunctionHelper(Register function,
1053 ExternalReference function_reference,
1054 Register scratch,
Ben Murdoch257744e2011-11-30 15:57:28 +00001055 int num_reg_arguments,
1056 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001057
Andrei Popescu31002712010-02-23 13:46:05 +00001058 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001059
1060 // Helper functions for generating invokes.
1061 void InvokePrologue(const ParameterCount& expected,
1062 const ParameterCount& actual,
1063 Handle<Code> code_constant,
1064 Register code_reg,
1065 Label* done,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001066 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +00001067 const CallWrapper& call_wrapper,
1068 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00001069
Steve Blocka7e24c12009-10-30 11:49:00 +00001070 // Activation support.
1071 void EnterFrame(StackFrame::Type type);
1072 void LeaveFrame(StackFrame::Type type);
Andrei Popescu31002712010-02-23 13:46:05 +00001073
Steve Block6ded16b2010-05-10 14:33:55 +01001074 void InitializeNewString(Register string,
1075 Register length,
1076 Heap::RootListIndex map_index,
1077 Register scratch1,
1078 Register scratch2);
1079
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001080 // Compute memory operands for safepoint stack slots.
1081 static int SafepointRegisterStackIndex(int reg_code);
1082 MemOperand SafepointRegisterSlot(Register reg);
1083 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1084
Andrei Popescu31002712010-02-23 13:46:05 +00001085 bool generating_stub_;
1086 bool allow_stub_calls_;
1087 // This handle will be patched with the code object on installation.
1088 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001089
1090 // Needs access to SafepointRegisterStackIndex for optimized frame
1091 // traversal.
1092 friend class OptimizedFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001093};
1094
1095
1096#ifdef ENABLE_DEBUGGER_SUPPORT
1097// The code patcher is used to patch (typically) small parts of code e.g. for
1098// debugging and other types of instrumentation. When using the code patcher
1099// the exact number of bytes specified must be emitted. It is not legal to emit
1100// relocation information. If any of these constraints are violated it causes
1101// an assertion to fail.
1102class CodePatcher {
1103 public:
1104 CodePatcher(byte* address, int instructions);
1105 virtual ~CodePatcher();
1106
1107 // Macro assembler to emit code.
1108 MacroAssembler* masm() { return &masm_; }
1109
1110 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001111 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001112
1113 // Emit an address directly.
1114 void Emit(Address addr);
1115
Steve Block1e0659c2011-05-24 12:43:12 +01001116 // Emit the condition part of an instruction leaving the rest of the current
1117 // instruction unchanged.
1118 void EmitCondition(Condition cond);
1119
Steve Blocka7e24c12009-10-30 11:49:00 +00001120 private:
1121 byte* address_; // The address of the code being patched.
1122 int instructions_; // Number of instructions of the expected patch size.
1123 int size_; // Number of bytes of the expected patch size.
1124 MacroAssembler masm_; // Macro assembler used to generate the code.
1125};
1126#endif // ENABLE_DEBUGGER_SUPPORT
1127
1128
1129// -----------------------------------------------------------------------------
1130// Static helper functions.
1131
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001132static MemOperand ContextOperand(Register context, int index) {
1133 return MemOperand(context, Context::SlotOffset(index));
1134}
1135
1136
1137static inline MemOperand GlobalObjectOperand() {
1138 return ContextOperand(cp, Context::GLOBAL_INDEX);
1139}
1140
1141
Steve Blocka7e24c12009-10-30 11:49:00 +00001142#ifdef GENERATED_CODE_COVERAGE
1143#define CODE_COVERAGE_STRINGIFY(x) #x
1144#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1145#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1146#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1147#else
1148#define ACCESS_MASM(masm) masm->
1149#endif
1150
1151
1152} } // namespace v8::internal
1153
1154#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_