blob: 0546e6a15e38e030782ded50feb8cd69b03acaa5 [file] [log] [blame]
Ben Murdoch85b71792012-04-11 18:30:58 +01001// 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.
Ben Murdoch85b71792012-04-11 18:30:58 +010041static inline MemOperand FieldMemOperand(Register object, int offset) {
Andrei Popescu31002712010-02-23 13:46:05 +000042 return MemOperand(object, offset - kHeapObjectTag);
43}
44
Steve Blocka7e24c12009-10-30 11:49:00 +000045
Ben Murdoch85b71792012-04-11 18:30:58 +010046static inline Operand SmiUntagOperand(Register object) {
Steve Block1e0659c2011-05-24 12:43:12 +010047 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
Ben Murdochc7cc0282012-03-05 14:35:55 +000054const Register kRootRegister = { 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
Ben Murdochc7cc0282012-03-05 14:35:55 +0000160
Ben Murdoch85b71792012-04-11 18:30:58 +0100161 // 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,
165 Condition cond, // eq for new space, ne otherwise
166 Label* branch);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000167
Steve Block6ded16b2010-05-10 14:33:55 +0100168
Ben Murdoch85b71792012-04-11 18:30:58 +0100169 // For the page containing |object| mark the region covering [address]
170 // dirty. The object address must be in the first 8K of an allocated page.
171 void RecordWriteHelper(Register object,
172 Register address,
173 Register scratch);
Steve Block6ded16b2010-05-10 14:33:55 +0100174
Ben Murdoch85b71792012-04-11 18:30:58 +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.
181 void RecordWrite(Register object,
182 Operand offset,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100183 Register scratch0,
Ben Murdoch85b71792012-04-11 18:30:58 +0100184 Register scratch1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Ben Murdoch85b71792012-04-11 18:30:58 +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);
Steve Block8defd9f2010-07-08 12:39:36 +0100194
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).
Ben Murdoch85b71792012-04-11 18:30:58 +0100228 void Push(Register src1, Register src2,
229 Register src3, Register src4, Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100230 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 Murdoch85b71792012-04-11 18:30:58 +0100321
322 // ---------------------------------------------------------------------------
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
Ben Murdochc7cc0282012-03-05 14:35:55 +0000353 void InitializeRootRegister() {
Ben Murdoch85b71792012-04-11 18:30:58 +0100354 ExternalReference roots_address =
355 ExternalReference::roots_address(isolate());
356 mov(kRootRegister, Operand(roots_address));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000357 }
358
Steve Blocka7e24c12009-10-30 11:49:00 +0000359 // ---------------------------------------------------------------------------
360 // JavaScript invokes
361
Ben Murdoch85b71792012-04-11 18:30:58 +0100362 // Setup call kind marking in ecx. The method takes ecx as an
Ben Murdoch257744e2011-11-30 15:57:28 +0000363 // explicit first parameter to make the code more readable at the
364 // call sites.
365 void SetCallKind(Register dst, CallKind kind);
366
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 // Invoke the JavaScript function code by either calling or jumping.
368 void InvokeCode(Register code,
369 const ParameterCount& expected,
370 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100371 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000372 const CallWrapper& call_wrapper,
373 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000374
375 void InvokeCode(Handle<Code> code,
376 const ParameterCount& expected,
377 const ParameterCount& actual,
378 RelocInfo::Mode rmode,
Ben Murdoch257744e2011-11-30 15:57:28 +0000379 InvokeFlag flag,
380 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000381
382 // Invoke the JavaScript function in the given register. Changes the
383 // current context to the context in the function before invoking.
384 void InvokeFunction(Register function,
385 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100386 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000387 const CallWrapper& call_wrapper,
388 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000389
Ben Murdoch85b71792012-04-11 18:30:58 +0100390 void InvokeFunction(JSFunction* function,
Andrei Popescu402d9372010-02-26 13:31:12 +0000391 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000392 InvokeFlag flag,
393 CallKind call_kind);
Andrei Popescu402d9372010-02-26 13:31:12 +0000394
Ben Murdochb0fe1622011-05-05 13:52:32 +0100395 void IsObjectJSObjectType(Register heap_object,
396 Register map,
397 Register scratch,
398 Label* fail);
399
400 void IsInstanceJSObjectType(Register map,
401 Register scratch,
402 Label* fail);
403
404 void IsObjectJSStringType(Register object,
405 Register scratch,
406 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000407
408#ifdef ENABLE_DEBUGGER_SUPPORT
409 // ---------------------------------------------------------------------------
410 // Debugger Support
411
Andrei Popescu402d9372010-02-26 13:31:12 +0000412 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000413#endif
414
415 // ---------------------------------------------------------------------------
416 // Exception handling
417
418 // Push a new try handler and link into try handler chain.
Ben Murdoch85b71792012-04-11 18:30:58 +0100419 // The return address must be passed in register lr.
420 // On exit, r0 contains TOS (code slot).
421 void PushTryHandler(CodeLocation try_location, HandlerType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000422
Leon Clarkee46be812010-01-19 14:06:41 +0000423 // Unlink the stack handler on top of the stack from the try handler chain.
424 // Must preserve the result register.
425 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000426
Ben Murdoch85b71792012-04-11 18:30:58 +0100427 // Passes thrown value (in r0) to the handler of top of the try handler chain.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100428 void Throw(Register value);
429
430 // Propagates an uncatchable exception to the top of the current JS stack's
431 // handler chain.
Ben Murdoch85b71792012-04-11 18:30:58 +0100432 void ThrowUncatchable(UncatchableExceptionType type, Register value);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100433
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 // ---------------------------------------------------------------------------
435 // Inline caching support
436
Steve Blocka7e24c12009-10-30 11:49:00 +0000437 // Generate code for checking access rights - used for security checks
438 // on access to global objects across environments. The holder register
439 // is left untouched, whereas both scratch registers are clobbered.
440 void CheckAccessGlobalProxy(Register holder_reg,
441 Register scratch,
442 Label* miss);
443
Ben Murdochc7cc0282012-03-05 14:35:55 +0000444 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000445
446 void LoadFromNumberDictionary(Label* miss,
447 Register elements,
448 Register key,
449 Register result,
450 Register t0,
451 Register t1,
452 Register t2);
453
454
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800455 inline void MarkCode(NopMarkerTypes type) {
456 nop(type);
457 }
458
459 // Check if the given instruction is a 'type' marker.
Ben Murdoch85b71792012-04-11 18:30:58 +0100460 // ie. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800461 // These instructions are generated to mark special location in the code,
462 // like some special IC code.
463 static inline bool IsMarkedCode(Instr instr, int type) {
464 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
465 return IsNop(instr, type);
466 }
467
468
469 static inline int GetCodeMarker(Instr instr) {
470 int dst_reg_offset = 12;
471 int dst_mask = 0xf << dst_reg_offset;
472 int src_mask = 0xf;
473 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
474 int src_reg = instr & src_mask;
475 uint32_t non_register_mask = ~(dst_mask | src_mask);
476 uint32_t mov_mask = al | 13 << 21;
477
478 // Return <n> if we have a mov rn rn, else return -1.
479 int type = ((instr & non_register_mask) == mov_mask) &&
480 (dst_reg == src_reg) &&
481 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
482 ? src_reg
483 : -1;
484 ASSERT((type == -1) ||
485 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
486 return type;
487 }
488
Steve Blocka7e24c12009-10-30 11:49:00 +0000489
490 // ---------------------------------------------------------------------------
491 // Allocation support
492
Ben Murdoch086aeea2011-05-13 15:57:08 +0100493 // Allocate an object in new space. The object_size is specified
494 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
495 // is passed. If the new space is exhausted control continues at the
496 // gc_required label. The allocated object is returned in result. If
497 // the flag tag_allocated_object is true the result is tagged as as
498 // a heap object. All registers are clobbered also when control
499 // continues at the gc_required label.
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 void AllocateInNewSpace(int object_size,
501 Register result,
502 Register scratch1,
503 Register scratch2,
504 Label* gc_required,
505 AllocationFlags flags);
506 void AllocateInNewSpace(Register object_size,
507 Register result,
508 Register scratch1,
509 Register scratch2,
510 Label* gc_required,
511 AllocationFlags flags);
512
513 // Undo allocation in new space. The object passed and objects allocated after
514 // it will no longer be allocated. The caller must make sure that no pointers
515 // are left to the object(s) no longer allocated as they would be invalid when
516 // allocation is undone.
517 void UndoAllocationInNewSpace(Register object, Register scratch);
518
Andrei Popescu31002712010-02-23 13:46:05 +0000519
520 void AllocateTwoByteString(Register result,
521 Register length,
522 Register scratch1,
523 Register scratch2,
524 Register scratch3,
525 Label* gc_required);
526 void AllocateAsciiString(Register result,
527 Register length,
528 Register scratch1,
529 Register scratch2,
530 Register scratch3,
531 Label* gc_required);
532 void AllocateTwoByteConsString(Register result,
533 Register length,
534 Register scratch1,
535 Register scratch2,
536 Label* gc_required);
537 void AllocateAsciiConsString(Register result,
538 Register length,
539 Register scratch1,
540 Register scratch2,
541 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000542 void AllocateTwoByteSlicedString(Register result,
543 Register length,
544 Register scratch1,
545 Register scratch2,
546 Label* gc_required);
547 void AllocateAsciiSlicedString(Register result,
548 Register length,
549 Register scratch1,
550 Register scratch2,
551 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000552
Kristian Monsen25f61362010-05-21 11:50:48 +0100553 // Allocates a heap number or jumps to the gc_required label if the young
554 // space is full and a scavenge is needed. All registers are clobbered also
555 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100556 void AllocateHeapNumber(Register result,
557 Register scratch1,
558 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100559 Register heap_number_map,
Steve Block6ded16b2010-05-10 14:33:55 +0100560 Label* gc_required);
Steve Block8defd9f2010-07-08 12:39:36 +0100561 void AllocateHeapNumberWithValue(Register result,
562 DwVfpRegister value,
563 Register scratch1,
564 Register scratch2,
565 Register heap_number_map,
566 Label* gc_required);
567
Ben Murdochbb769b22010-08-11 14:56:33 +0100568 // Copies a fixed number of fields of heap objects from src to dst.
569 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000570
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100571 // Copies a number of bytes from src to dst. All registers are clobbered. On
572 // exit src and dst will point to the place just after where the last byte was
573 // read or written and length will be zero.
574 void CopyBytes(Register src,
575 Register dst,
576 Register length,
577 Register scratch);
578
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 // ---------------------------------------------------------------------------
580 // Support functions.
581
582 // Try to get function prototype of a function and puts the value in
583 // the result register. Checks that the function really is a
584 // function and jumps to the miss label if the fast checks fail. The
585 // function register will be untouched; the other registers may be
586 // clobbered.
587 void TryGetFunctionPrototype(Register function,
588 Register result,
589 Register scratch,
Ben Murdoch85b71792012-04-11 18:30:58 +0100590 Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000591
592 // Compare object type for heap object. heap_object contains a non-Smi
593 // whose object type should be compared with the given type. This both
594 // sets the flags and leaves the object type in the type_reg register.
595 // It leaves the map in the map register (unless the type_reg and map register
596 // are the same register). It leaves the heap object in the heap_object
597 // register unless the heap_object register is the same register as one of the
598 // other registers.
599 void CompareObjectType(Register heap_object,
600 Register map,
601 Register type_reg,
602 InstanceType type);
603
604 // Compare instance type in a map. map contains a valid map object whose
605 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000606 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000607 void CompareInstanceType(Register map,
608 Register type_reg,
609 InstanceType type);
610
Andrei Popescu31002712010-02-23 13:46:05 +0000611
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000612 // Check if a map for a JSObject indicates that the object has fast elements.
613 // Jump to the specified label if it does not.
614 void CheckFastElements(Register map,
615 Register scratch,
616 Label* fail);
617
Ben Murdoch85b71792012-04-11 18:30:58 +0100618 // Check if the map of an object is equal to a specified map (either
619 // given directly or as an index into the root list) and branch to
620 // label if not. Skip the smi check if not required (object is known
621 // to be a heap object)
Andrei Popescu31002712010-02-23 13:46:05 +0000622 void CheckMap(Register obj,
623 Register scratch,
624 Handle<Map> map,
625 Label* fail,
Ben Murdoch85b71792012-04-11 18:30:58 +0100626 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000627
Andrei Popescu31002712010-02-23 13:46:05 +0000628
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100629 void CheckMap(Register obj,
630 Register scratch,
631 Heap::RootListIndex index,
632 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000633 SmiCheckType smi_check_type);
634
635
636 // Check if the map of an object is equal to a specified map and branch to a
637 // specified target if equal. Skip the smi check if not required (object is
638 // known to be a heap object)
639 void DispatchMap(Register obj,
640 Register scratch,
641 Handle<Map> map,
642 Handle<Code> success,
643 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100644
645
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100646 // Compare the object in a register to a value from the root list.
647 // Uses the ip register as scratch.
648 void CompareRoot(Register obj, Heap::RootListIndex index);
649
650
Andrei Popescu31002712010-02-23 13:46:05 +0000651 // Load and check the instance type of an object for being a string.
652 // Loads the type into the second argument register.
653 // Returns a condition that will be enabled if the object was a string.
654 Condition IsObjectStringType(Register obj,
655 Register type) {
656 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset));
657 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
658 tst(type, Operand(kIsNotStringMask));
659 ASSERT_EQ(0, kStringTag);
660 return eq;
661 }
662
663
Steve Blocka7e24c12009-10-30 11:49:00 +0000664 // Generates code for reporting that an illegal operation has
665 // occurred.
666 void IllegalOperation(int num_arguments);
667
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100668 // Picks out an array index from the hash field.
669 // Register use:
670 // hash - holds the index's hash. Clobbered.
671 // index - holds the overwritten index on exit.
672 void IndexFromHash(Register hash, Register index);
673
Andrei Popescu31002712010-02-23 13:46:05 +0000674 // Get the number of least significant bits from a register
675 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100676 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000677
Steve Blockd0582a62009-12-15 09:54:21 +0000678 // Uses VFP instructions to Convert a Smi to a double.
679 void IntegerToDoubleConversionWithVFP3(Register inReg,
680 Register outHighReg,
681 Register outLowReg);
682
Steve Block8defd9f2010-07-08 12:39:36 +0100683 // Load the value of a number object into a VFP double register. If the object
684 // is not a number a jump to the label not_number is performed and the VFP
685 // double register is unchanged.
686 void ObjectToDoubleVFPRegister(
687 Register object,
688 DwVfpRegister value,
689 Register scratch1,
690 Register scratch2,
691 Register heap_number_map,
692 SwVfpRegister scratch3,
693 Label* not_number,
694 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
695
696 // Load the value of a smi object into a VFP double register. The register
697 // scratch1 can be the same register as smi in which case smi will hold the
698 // untagged value afterwards.
699 void SmiToDoubleVFPRegister(Register smi,
700 DwVfpRegister value,
701 Register scratch1,
702 SwVfpRegister scratch2);
703
Iain Merrick9ac36c92010-09-13 15:29:50 +0100704 // Convert the HeapNumber pointed to by source to a 32bits signed integer
705 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
Steve Block1e0659c2011-05-24 12:43:12 +0100706 // to not_int32 label. If VFP3 is available double_scratch is used but not
707 // scratch2.
Iain Merrick9ac36c92010-09-13 15:29:50 +0100708 void ConvertToInt32(Register source,
709 Register dest,
710 Register scratch,
711 Register scratch2,
Steve Block1e0659c2011-05-24 12:43:12 +0100712 DwVfpRegister double_scratch,
Iain Merrick9ac36c92010-09-13 15:29:50 +0100713 Label *not_int32);
714
Steve Block44f0eee2011-05-26 01:26:41 +0100715 // Truncates a double using a specific rounding mode.
716 // Clears the z flag (ne condition) if an overflow occurs.
717 // If exact_conversion is true, the z flag is also cleared if the conversion
Ben Murdoch85b71792012-04-11 18:30:58 +0100718 // was inexact, ie. if the double value could not be converted exactly
Steve Block44f0eee2011-05-26 01:26:41 +0100719 // to a 32bit integer.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100720 void EmitVFPTruncate(VFPRoundingMode rounding_mode,
721 SwVfpRegister result,
722 DwVfpRegister double_input,
723 Register scratch1,
724 Register scratch2,
725 CheckForInexactConversion check
726 = kDontCheckForInexactConversion);
727
Steve Block44f0eee2011-05-26 01:26:41 +0100728 // Helper for EmitECMATruncate.
729 // This will truncate a floating-point value outside of the singed 32bit
730 // integer range to a 32bit signed integer.
731 // Expects the double value loaded in input_high and input_low.
732 // Exits with the answer in 'result'.
733 // Note that this code does not work for values in the 32bit range!
734 void EmitOutOfInt32RangeTruncate(Register result,
735 Register input_high,
736 Register input_low,
737 Register scratch);
738
739 // Performs a truncating conversion of a floating point number as used by
740 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
741 // Exits with 'result' holding the answer and all other registers clobbered.
742 void EmitECMATruncate(Register result,
743 DwVfpRegister double_input,
744 SwVfpRegister single_scratch,
745 Register scratch,
746 Register scratch2,
747 Register scratch3);
748
Steve Block6ded16b2010-05-10 14:33:55 +0100749 // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz
750 // instruction. On pre-ARM5 hardware this routine gives the wrong answer
Steve Block8defd9f2010-07-08 12:39:36 +0100751 // for 0 (31 instead of 32). Source and scratch can be the same in which case
752 // the source is clobbered. Source and zeros can also be the same in which
753 // case scratch should be a different register.
754 void CountLeadingZeros(Register zeros,
755 Register source,
756 Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000757
758 // ---------------------------------------------------------------------------
759 // Runtime calls
760
761 // Call a code stub.
762 void CallStub(CodeStub* stub, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000763
Ben Murdoch85b71792012-04-11 18:30:58 +0100764 // Call a code stub and return the code object called. Try to generate
765 // the code if necessary. Do not perform a GC but instead return a retry
766 // after GC failure.
767 MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub, Condition cond = al);
768
Andrei Popescu31002712010-02-23 13:46:05 +0000769 // Call a code stub.
770 void TailCallStub(CodeStub* stub, Condition cond = al);
771
Ben Murdoch85b71792012-04-11 18:30:58 +0100772 // Tail call a code stub (jump) and return the code object called. Try to
773 // generate the code if necessary. Do not perform a GC but instead return
774 // a retry after GC failure.
775 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub,
776 Condition cond = al);
777
Steve Blocka7e24c12009-10-30 11:49:00 +0000778 // Call a runtime routine.
Steve Block44f0eee2011-05-26 01:26:41 +0100779 void CallRuntime(const Runtime::Function* f, int num_arguments);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100780 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000781
782 // Convenience function: Same as above, but takes the fid instead.
783 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
784
Andrei Popescu402d9372010-02-26 13:31:12 +0000785 // Convenience function: call an external reference.
786 void CallExternalReference(const ExternalReference& ext,
787 int num_arguments);
788
Steve Blocka7e24c12009-10-30 11:49:00 +0000789 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100790 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +0000791 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +0100792 void TailCallExternalReference(const ExternalReference& ext,
793 int num_arguments,
794 int result_size);
795
Ben Murdoch85b71792012-04-11 18:30:58 +0100796 // Tail call of a runtime routine (jump). Try to generate the code if
797 // necessary. Do not perform a GC but instead return a retry after GC
798 // failure.
799 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
800 const ExternalReference& ext, int num_arguments, int result_size);
801
Steve Block6ded16b2010-05-10 14:33:55 +0100802 // Convenience function: tail call a runtime routine (jump).
803 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +0000804 int num_arguments,
805 int result_size);
806
Ben Murdoch257744e2011-11-30 15:57:28 +0000807 int CalculateStackPassedWords(int num_reg_arguments,
808 int num_double_arguments);
809
Steve Block6ded16b2010-05-10 14:33:55 +0100810 // Before calling a C-function from generated code, align arguments on stack.
811 // After aligning the frame, non-register arguments must be stored in
812 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +0000813 // are word sized. If double arguments are used, this function assumes that
814 // all double arguments are stored before core registers; otherwise the
815 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +0100816 // Some compilers/platforms require the stack to be aligned when calling
817 // C++ code.
818 // Needs a scratch register to do some arithmetic. This register will be
819 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +0000820 void PrepareCallCFunction(int num_reg_arguments,
821 int num_double_registers,
822 Register scratch);
823 void PrepareCallCFunction(int num_reg_arguments,
824 Register scratch);
825
826 // There are two ways of passing double arguments on ARM, depending on
827 // whether soft or hard floating point ABI is used. These functions
828 // abstract parameter passing for the three different ways we call
829 // C functions from generated code.
830 void SetCallCDoubleArguments(DoubleRegister dreg);
831 void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2);
832 void SetCallCDoubleArguments(DoubleRegister dreg, Register reg);
Steve Block6ded16b2010-05-10 14:33:55 +0100833
834 // Calls a C function and cleans up the space for arguments allocated
835 // by PrepareCallCFunction. The called function is not allowed to trigger a
836 // garbage collection, since that might move the code and invalidate the
837 // return address (unless this is somehow accounted for by the called
838 // function).
839 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch85b71792012-04-11 18:30:58 +0100840 void CallCFunction(Register function, Register scratch, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +0000841 void CallCFunction(ExternalReference function,
842 int num_reg_arguments,
843 int num_double_arguments);
Ben Murdoch85b71792012-04-11 18:30:58 +0100844 void CallCFunction(Register function, Register scratch,
Ben Murdoch257744e2011-11-30 15:57:28 +0000845 int num_reg_arguments,
846 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +0100847
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100848 void GetCFunctionDoubleResult(const DoubleRegister dst);
849
Ben Murdoch85b71792012-04-11 18:30:58 +0100850 // Calls an API function. Allocates HandleScope, extracts returned value
851 // from handle and propagates exceptions. Restores context.
852 // stack_space - space to be unwound on exit (includes the call js
853 // arguments space and the additional space allocated for the fast call).
854 MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function,
855 int stack_space);
Steve Block1e0659c2011-05-24 12:43:12 +0100856
Steve Blocka7e24c12009-10-30 11:49:00 +0000857 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100858 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +0000859
Ben Murdoch85b71792012-04-11 18:30:58 +0100860 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext);
861
Steve Blocka7e24c12009-10-30 11:49:00 +0000862 // Invoke specified builtin JavaScript function. Adds an entry to
863 // the unresolved list if the name does not resolve.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100864 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +0000865 InvokeFlag flag,
866 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +0000867
868 // Store the code object for the given builtin in the target register and
869 // setup the function in r1.
870 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
871
Steve Block791712a2010-08-27 10:21:07 +0100872 // Store the function for the given builtin in the target register.
873 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
874
Ben Murdoch8b112d22011-06-08 16:22:53 +0100875 Handle<Object> CodeObject() {
876 ASSERT(!code_object_.is_null());
877 return code_object_;
878 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000879
880
881 // ---------------------------------------------------------------------------
882 // StatsCounter support
883
884 void SetCounter(StatsCounter* counter, int value,
885 Register scratch1, Register scratch2);
886 void IncrementCounter(StatsCounter* counter, int value,
887 Register scratch1, Register scratch2);
888 void DecrementCounter(StatsCounter* counter, int value,
889 Register scratch1, Register scratch2);
890
891
892 // ---------------------------------------------------------------------------
893 // Debugging
894
Steve Block1e0659c2011-05-24 12:43:12 +0100895 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +0000896 // Use --debug_code to enable.
Steve Block1e0659c2011-05-24 12:43:12 +0100897 void Assert(Condition cond, const char* msg);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100898 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
Iain Merrick75681382010-08-19 15:07:18 +0100899 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +0000900
901 // Like Assert(), but always enabled.
Steve Block1e0659c2011-05-24 12:43:12 +0100902 void Check(Condition cond, const char* msg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000903
904 // Print a message to stdout and abort execution.
905 void Abort(const char* msg);
906
907 // Verify restrictions about code generated in stubs.
908 void set_generating_stub(bool value) { generating_stub_ = value; }
909 bool generating_stub() { return generating_stub_; }
910 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
911 bool allow_stub_calls() { return allow_stub_calls_; }
912
Ben Murdoch257744e2011-11-30 15:57:28 +0000913 // EABI variant for double arguments in use.
914 bool use_eabi_hardfloat() {
915#if USE_EABI_HARDFLOAT
916 return true;
917#else
918 return false;
919#endif
920 }
921
Leon Clarked91b9f72010-01-27 17:25:45 +0000922 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +0100923 // Number utilities
924
925 // Check whether the value of reg is a power of two and not zero. If not
926 // control continues at the label not_power_of_two. If reg is a power of two
927 // the register scratch contains the value of (reg - 1) when control falls
928 // through.
929 void JumpIfNotPowerOfTwoOrZero(Register reg,
930 Register scratch,
931 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +0100932 // Check whether the value of reg is a power of two and not zero.
933 // Control falls through if it is, with scratch containing the mask
934 // value (reg - 1).
935 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
936 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
937 // strictly positive but not a power of two.
938 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
939 Register scratch,
940 Label* zero_and_neg,
941 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +0100942
943 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000944 // Smi utilities
945
Ben Murdochb0fe1622011-05-05 13:52:32 +0100946 void SmiTag(Register reg, SBit s = LeaveCC) {
947 add(reg, reg, Operand(reg), s);
948 }
Steve Block1e0659c2011-05-24 12:43:12 +0100949 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
950 add(dst, src, Operand(src), s);
951 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100952
Ben Murdochb8e0da22011-05-16 14:20:40 +0100953 // Try to convert int32 to smi. If the value is to large, preserve
954 // the original value and jump to not_a_smi. Destroys scratch and
955 // sets flags.
956 void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
957 mov(scratch, reg);
958 SmiTag(scratch, SetCC);
959 b(vs, not_a_smi);
960 mov(reg, scratch);
961 }
962
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100963 void SmiUntag(Register reg, SBit s = LeaveCC) {
964 mov(reg, Operand(reg, ASR, kSmiTagSize), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100965 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100966 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
967 mov(dst, Operand(src, ASR, kSmiTagSize), s);
Steve Block1e0659c2011-05-24 12:43:12 +0100968 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100969
Steve Block1e0659c2011-05-24 12:43:12 +0100970 // Jump the register contains a smi.
971 inline void JumpIfSmi(Register value, Label* smi_label) {
972 tst(value, Operand(kSmiTagMask));
973 b(eq, smi_label);
974 }
975 // Jump if either of the registers contain a non-smi.
976 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
977 tst(value, Operand(kSmiTagMask));
978 b(ne, not_smi_label);
979 }
Andrei Popescu31002712010-02-23 13:46:05 +0000980 // Jump if either of the registers contain a non-smi.
981 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
982 // Jump if either of the registers contain a smi.
983 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
984
Iain Merrick75681382010-08-19 15:07:18 +0100985 // Abort execution if argument is a smi. Used in debug code.
986 void AbortIfSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +0100987 void AbortIfNotSmi(Register object);
988
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100989 // Abort execution if argument is a string. Used in debug code.
990 void AbortIfNotString(Register object);
991
Steve Block1e0659c2011-05-24 12:43:12 +0100992 // Abort execution if argument is not the root value with the given index.
993 void AbortIfNotRootValue(Register src,
994 Heap::RootListIndex root_value_index,
995 const char* message);
996
997 // ---------------------------------------------------------------------------
998 // HeapNumber utilities
999
1000 void JumpIfNotHeapNumber(Register object,
1001 Register heap_number_map,
1002 Register scratch,
1003 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +01001004
Andrei Popescu31002712010-02-23 13:46:05 +00001005 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +00001006 // String utilities
1007
1008 // Checks if both objects are sequential ASCII strings and jumps to label
1009 // if either is not. Assumes that neither object is a smi.
1010 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
1011 Register object2,
1012 Register scratch1,
1013 Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +01001014 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001015
1016 // Checks if both objects are sequential ASCII strings and jumps to label
1017 // if either is not.
1018 void JumpIfNotBothSequentialAsciiStrings(Register first,
1019 Register second,
1020 Register scratch1,
1021 Register scratch2,
1022 Label* not_flat_ascii_strings);
1023
Steve Block6ded16b2010-05-10 14:33:55 +01001024 // Checks if both instance types are sequential ASCII strings and jumps to
1025 // label if either is not.
1026 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1027 Register first_object_instance_type,
1028 Register second_object_instance_type,
1029 Register scratch1,
1030 Register scratch2,
1031 Label* failure);
1032
1033 // Check if instance type is sequential ASCII string and jump to label if
1034 // it is not.
1035 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1036 Register scratch,
1037 Label* failure);
1038
1039
Steve Block1e0659c2011-05-24 12:43:12 +01001040 // ---------------------------------------------------------------------------
1041 // Patching helpers.
1042
1043 // Get the location of a relocated constant (its address in the constant pool)
1044 // from its load site.
1045 void GetRelocatedValueLocation(Register ldr_location,
1046 Register result);
1047
1048
Ben Murdoch257744e2011-11-30 15:57:28 +00001049 void ClampUint8(Register output_reg, Register input_reg);
1050
1051 void ClampDoubleToUint8(Register result_reg,
1052 DoubleRegister input_reg,
1053 DoubleRegister temp_double_reg);
1054
1055
1056 void LoadInstanceDescriptors(Register map, Register descriptors);
1057
Steve Blocka7e24c12009-10-30 11:49:00 +00001058 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001059 void CallCFunctionHelper(Register function,
Ben Murdoch85b71792012-04-11 18:30:58 +01001060 ExternalReference function_reference,
1061 Register scratch,
Ben Murdoch257744e2011-11-30 15:57:28 +00001062 int num_reg_arguments,
1063 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001064
Andrei Popescu31002712010-02-23 13:46:05 +00001065 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001066
1067 // Helper functions for generating invokes.
1068 void InvokePrologue(const ParameterCount& expected,
1069 const ParameterCount& actual,
1070 Handle<Code> code_constant,
1071 Register code_reg,
1072 Label* done,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001073 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +00001074 const CallWrapper& call_wrapper,
1075 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00001076
Ben Murdoch85b71792012-04-11 18:30:58 +01001077 // Activation support.
1078 void EnterFrame(StackFrame::Type type);
1079 void LeaveFrame(StackFrame::Type type);
1080
Steve Block6ded16b2010-05-10 14:33:55 +01001081 void InitializeNewString(Register string,
1082 Register length,
1083 Heap::RootListIndex map_index,
1084 Register scratch1,
1085 Register scratch2);
1086
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001087 // Compute memory operands for safepoint stack slots.
1088 static int SafepointRegisterStackIndex(int reg_code);
1089 MemOperand SafepointRegisterSlot(Register reg);
1090 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1091
Andrei Popescu31002712010-02-23 13:46:05 +00001092 bool generating_stub_;
1093 bool allow_stub_calls_;
1094 // This handle will be patched with the code object on installation.
1095 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001096
1097 // Needs access to SafepointRegisterStackIndex for optimized frame
1098 // traversal.
1099 friend class OptimizedFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001100};
1101
1102
1103#ifdef ENABLE_DEBUGGER_SUPPORT
1104// The code patcher is used to patch (typically) small parts of code e.g. for
1105// debugging and other types of instrumentation. When using the code patcher
1106// the exact number of bytes specified must be emitted. It is not legal to emit
1107// relocation information. If any of these constraints are violated it causes
1108// an assertion to fail.
1109class CodePatcher {
1110 public:
1111 CodePatcher(byte* address, int instructions);
1112 virtual ~CodePatcher();
1113
1114 // Macro assembler to emit code.
1115 MacroAssembler* masm() { return &masm_; }
1116
1117 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001118 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001119
1120 // Emit an address directly.
1121 void Emit(Address addr);
1122
Steve Block1e0659c2011-05-24 12:43:12 +01001123 // Emit the condition part of an instruction leaving the rest of the current
1124 // instruction unchanged.
1125 void EmitCondition(Condition cond);
1126
Steve Blocka7e24c12009-10-30 11:49:00 +00001127 private:
1128 byte* address_; // The address of the code being patched.
1129 int instructions_; // Number of instructions of the expected patch size.
1130 int size_; // Number of bytes of the expected patch size.
1131 MacroAssembler masm_; // Macro assembler used to generate the code.
1132};
1133#endif // ENABLE_DEBUGGER_SUPPORT
1134
1135
1136// -----------------------------------------------------------------------------
1137// Static helper functions.
1138
Ben Murdoch85b71792012-04-11 18:30:58 +01001139static MemOperand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001140 return MemOperand(context, Context::SlotOffset(index));
1141}
1142
1143
Ben Murdoch85b71792012-04-11 18:30:58 +01001144static inline MemOperand GlobalObjectOperand() {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001145 return ContextOperand(cp, Context::GLOBAL_INDEX);
1146}
1147
1148
Steve Blocka7e24c12009-10-30 11:49:00 +00001149#ifdef GENERATED_CODE_COVERAGE
1150#define CODE_COVERAGE_STRINGIFY(x) #x
1151#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1152#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1153#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1154#else
1155#define ACCESS_MASM(masm) masm->
1156#endif
1157
1158
1159} } // namespace v8::internal
1160
1161#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_