blob: f32630444e32aca934dea7654c71e6467974e333 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_
6#define V8_ARM_MACRO_ASSEMBLER_ARM_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/assembler.h"
9#include "src/bailout-reason.h"
10#include "src/frames.h"
11#include "src/globals.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000012
13namespace v8 {
14namespace internal {
15
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016// Give alias names to registers for calling conventions.
17const Register kReturnRegister0 = {Register::kCode_r0};
18const Register kReturnRegister1 = {Register::kCode_r1};
Ben Murdoch097c5b22016-05-18 11:27:45 +010019const Register kReturnRegister2 = {Register::kCode_r2};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000020const Register kJSFunctionRegister = {Register::kCode_r1};
21const Register kContextRegister = {Register::kCode_r7};
22const Register kInterpreterAccumulatorRegister = {Register::kCode_r0};
23const Register kInterpreterRegisterFileRegister = {Register::kCode_r4};
24const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_r5};
25const Register kInterpreterBytecodeArrayRegister = {Register::kCode_r6};
26const Register kInterpreterDispatchTableRegister = {Register::kCode_r8};
27const Register kJavaScriptCallArgCountRegister = {Register::kCode_r0};
28const Register kJavaScriptCallNewTargetRegister = {Register::kCode_r3};
29const Register kRuntimeCallFunctionRegister = {Register::kCode_r1};
30const Register kRuntimeCallArgCountRegister = {Register::kCode_r0};
31
Andrei Popescu31002712010-02-23 13:46:05 +000032// ----------------------------------------------------------------------------
33// Static helper functions
34
35// Generate a MemOperand for loading a field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010036inline MemOperand FieldMemOperand(Register object, int offset) {
Andrei Popescu31002712010-02-23 13:46:05 +000037 return MemOperand(object, offset - kHeapObjectTag);
38}
39
Steve Blocka7e24c12009-10-30 11:49:00 +000040
41// Give alias names to registers
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042const Register cp = {Register::kCode_r7}; // JavaScript context pointer.
43const Register pp = {Register::kCode_r8}; // Constant pool pointer.
44const Register kRootRegister = {Register::kCode_r10}; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000045
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046// Flags used for AllocateHeapNumber
47enum TaggingMode {
48 // Tag the result.
49 TAG_RESULT,
50 // Don't tag
51 DONT_TAG_RESULT
Steve Block8defd9f2010-07-08 12:39:36 +010052};
53
54
Ben Murdoch3ef787d2012-04-12 10:51:47 +010055enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
56enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057enum PointersToHereCheck {
58 kPointersToHereMaybeInteresting,
59 kPointersToHereAreAlwaysInteresting
60};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010061enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
62
63
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064Register GetRegisterThatIsNotOneOf(Register reg1,
65 Register reg2 = no_reg,
66 Register reg3 = no_reg,
67 Register reg4 = no_reg,
68 Register reg5 = no_reg,
69 Register reg6 = no_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010070
71
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072#ifdef DEBUG
73bool AreAliased(Register reg1,
74 Register reg2,
75 Register reg3 = no_reg,
76 Register reg4 = no_reg,
77 Register reg5 = no_reg,
78 Register reg6 = no_reg,
79 Register reg7 = no_reg,
80 Register reg8 = no_reg);
81#endif
82
83
84enum TargetAddressStorageMode {
85 CAN_INLINE_TARGET_ADDRESS,
86 NEVER_INLINE_TARGET_ADDRESS
87};
88
Steve Blocka7e24c12009-10-30 11:49:00 +000089// MacroAssembler implements a collection of frequently used macros.
90class MacroAssembler: public Assembler {
91 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 MacroAssembler(Isolate* isolate, void* buffer, int size,
93 CodeObjectRequired create_code_object);
Steve Blocka7e24c12009-10-30 11:49:00 +000094
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095
96 // Returns the size of a call in instructions. Note, the value returned is
97 // only valid as long as no entries are added to the constant pool between
98 // checking the call size and emitting the actual call.
99 static int CallSize(Register target, Condition cond = al);
100 int CallSize(Address target, RelocInfo::Mode rmode, Condition cond = al);
101 int CallStubSize(CodeStub* stub,
102 TypeFeedbackId ast_id = TypeFeedbackId::None(),
103 Condition cond = al);
104 static int CallSizeNotPredictableCodeSize(Isolate* isolate,
105 Address target,
106 RelocInfo::Mode rmode,
107 Condition cond = al);
108
Andrei Popescu31002712010-02-23 13:46:05 +0000109 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +0000110 void Jump(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000111 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
113 void Call(Register target, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114 void Call(Address target, RelocInfo::Mode rmode,
115 Condition cond = al,
116 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
117 int CallSize(Handle<Code> code,
118 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
119 TypeFeedbackId ast_id = TypeFeedbackId::None(),
120 Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000121 void Call(Handle<Code> code,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000122 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000123 TypeFeedbackId ast_id = TypeFeedbackId::None(),
124 Condition cond = al,
125 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000126 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000127
128 // Emit code to discard a non-negative number of pointer-sized elements
129 // from the stack, clobbering only the sp register.
130 void Drop(int count, Condition cond = al);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100131 void Drop(Register count, Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000132
Ben Murdochb0fe1622011-05-05 13:52:32 +0100133 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100134
135 // Swap two registers. If the scratch register is omitted then a slightly
136 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100137 void Swap(Register reg1,
138 Register reg2,
139 Register scratch = no_reg,
140 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100141
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142 void Mls(Register dst, Register src1, Register src2, Register srcA,
143 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100144 void And(Register dst, Register src1, const Operand& src2,
145 Condition cond = al);
146 void Ubfx(Register dst, Register src, int lsb, int width,
147 Condition cond = al);
148 void Sbfx(Register dst, Register src, int lsb, int width,
149 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100150 // The scratch register is not used for ARMv7.
151 // scratch can be the same register as src (in which case it is trashed), but
152 // not the same as dst.
153 void Bfi(Register dst,
154 Register src,
155 Register scratch,
156 int lsb,
157 int width,
158 Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000159 void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100160 void Usat(Register dst, int satpos, const Operand& src,
161 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100162
Leon Clarkee46be812010-01-19 14:06:41 +0000163 void Call(Label* target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000164 void Push(Register src) { push(src); }
165 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000166
167 // Register move. May do nothing if the registers are identical.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 void Move(Register dst, Smi* smi) { mov(dst, Operand(smi)); }
Leon Clarkee46be812010-01-19 14:06:41 +0000169 void Move(Register dst, Handle<Object> value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000170 void Move(Register dst, Register src, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000171 void Move(Register dst, const Operand& src, SBit sbit = LeaveCC,
172 Condition cond = al) {
173 if (!src.is_reg() || !src.rm().is(dst) || sbit != LeaveCC) {
174 mov(dst, src, sbit, cond);
175 }
176 }
177 void Move(DwVfpRegister dst, DwVfpRegister src);
178
179 void Load(Register dst, const MemOperand& src, Representation r);
180 void Store(Register src, const MemOperand& dst, Representation r);
Ben Murdoch257744e2011-11-30 15:57:28 +0000181
Steve Blocka7e24c12009-10-30 11:49:00 +0000182 // Load an object from the root table.
183 void LoadRoot(Register destination,
184 Heap::RootListIndex index,
185 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100186 // Store an object to the root table.
187 void StoreRoot(Register source,
188 Heap::RootListIndex index,
189 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000190
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100191 // ---------------------------------------------------------------------------
192 // GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100193
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100194 void IncrementalMarkingRecordWriteHelper(Register object,
195 Register value,
196 Register address);
Steve Block6ded16b2010-05-10 14:33:55 +0100197
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100198 enum RememberedSetFinalAction {
199 kReturnAtEnd,
200 kFallThroughAtEnd
201 };
202
203 // Record in the remembered set the fact that we have a pointer to new space
204 // at the address pointed to by the addr register. Only works if addr is not
205 // in new space.
206 void RememberedSetHelper(Register object, // Used for debug code.
207 Register addr,
208 Register scratch,
209 SaveFPRegsMode save_fp,
210 RememberedSetFinalAction and_then);
211
212 void CheckPageFlag(Register object,
213 Register scratch,
214 int mask,
215 Condition cc,
216 Label* condition_met);
217
218 // Check if object is in new space. Jumps if the object is not in new space.
219 // The register scratch can be object itself, but scratch will be clobbered.
220 void JumpIfNotInNewSpace(Register object,
221 Register scratch,
222 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100223 InNewSpace(object, scratch, eq, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100224 }
225
226 // Check if object is in new space. Jumps if the object is in new space.
227 // The register scratch can be object itself, but it will be clobbered.
228 void JumpIfInNewSpace(Register object,
229 Register scratch,
230 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100231 InNewSpace(object, scratch, ne, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100232 }
233
234 // Check if an object has a given incremental marking color.
235 void HasColor(Register object,
236 Register scratch0,
237 Register scratch1,
238 Label* has_color,
239 int first_bit,
240 int second_bit);
241
242 void JumpIfBlack(Register object,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100243 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100244 Register scratch1,
245 Label* on_black);
Steve Blocka7e24c12009-10-30 11:49:00 +0000246
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000247 // Checks the color of an object. If the object is white we jump to the
248 // incremental marker.
249 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
250 Register scratch3, Label* value_is_white);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100251
252 // Notify the garbage collector that we wrote a pointer into an object.
253 // |object| is the object being stored into, |value| is the object being
254 // stored. value and scratch registers are clobbered by the operation.
255 // The offset is the offset from the start of the object, not the offset from
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000256 // the tagged HeapObject pointer. For use with FieldMemOperand(reg, off).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100257 void RecordWriteField(
258 Register object,
259 int offset,
260 Register value,
261 Register scratch,
262 LinkRegisterStatus lr_status,
263 SaveFPRegsMode save_fp,
264 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000265 SmiCheck smi_check = INLINE_SMI_CHECK,
266 PointersToHereCheck pointers_to_here_check_for_value =
267 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100268
269 // As above, but the offset has the tag presubtracted. For use with
270 // MemOperand(reg, off).
271 inline void RecordWriteContextSlot(
272 Register context,
273 int offset,
274 Register value,
275 Register scratch,
276 LinkRegisterStatus lr_status,
277 SaveFPRegsMode save_fp,
278 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000279 SmiCheck smi_check = INLINE_SMI_CHECK,
280 PointersToHereCheck pointers_to_here_check_for_value =
281 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100282 RecordWriteField(context,
283 offset + kHeapObjectTag,
284 value,
285 scratch,
286 lr_status,
287 save_fp,
288 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 smi_check,
290 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100291 }
292
Ben Murdoch097c5b22016-05-18 11:27:45 +0100293 // Notify the garbage collector that we wrote a code entry into a
294 // JSFunction. Only scratch is clobbered by the operation.
295 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
296 Register scratch);
297
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298 void RecordWriteForMap(
299 Register object,
300 Register map,
301 Register dst,
302 LinkRegisterStatus lr_status,
303 SaveFPRegsMode save_fp);
304
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100305 // For a given |object| notify the garbage collector that the slot |address|
306 // has been written. |value| is the object being stored. The value and
307 // address registers are clobbered by the operation.
308 void RecordWrite(
309 Register object,
310 Register address,
311 Register value,
312 LinkRegisterStatus lr_status,
313 SaveFPRegsMode save_fp,
314 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315 SmiCheck smi_check = INLINE_SMI_CHECK,
316 PointersToHereCheck pointers_to_here_check_for_value =
317 kPointersToHereMaybeInteresting);
Steve Block8defd9f2010-07-08 12:39:36 +0100318
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000319 // Push a handle.
320 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000322
Steve Block6ded16b2010-05-10 14:33:55 +0100323 // Push two registers. Pushes leftmost register first (to highest address).
324 void Push(Register src1, Register src2, Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100325 if (src1.code() > src2.code()) {
326 stm(db_w, sp, src1.bit() | src2.bit(), cond);
327 } else {
328 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
329 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
330 }
331 }
332
333 // Push three registers. Pushes leftmost register first (to highest address).
334 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100335 if (src1.code() > src2.code()) {
336 if (src2.code() > src3.code()) {
337 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
338 } else {
339 stm(db_w, sp, src1.bit() | src2.bit(), cond);
340 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
341 }
342 } else {
343 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
344 Push(src2, src3, cond);
345 }
346 }
347
348 // Push four registers. Pushes leftmost register first (to highest address).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100349 void Push(Register src1,
350 Register src2,
351 Register src3,
352 Register src4,
353 Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100354 if (src1.code() > src2.code()) {
355 if (src2.code() > src3.code()) {
356 if (src3.code() > src4.code()) {
357 stm(db_w,
358 sp,
359 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
360 cond);
361 } else {
362 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
363 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
364 }
365 } else {
366 stm(db_w, sp, src1.bit() | src2.bit(), cond);
367 Push(src3, src4, cond);
368 }
369 } else {
370 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
371 Push(src2, src3, src4, cond);
372 }
373 }
374
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000375 // Push five registers. Pushes leftmost register first (to highest address).
376 void Push(Register src1, Register src2, Register src3, Register src4,
377 Register src5, Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000378 if (src1.code() > src2.code()) {
379 if (src2.code() > src3.code()) {
380 if (src3.code() > src4.code()) {
381 if (src4.code() > src5.code()) {
382 stm(db_w, sp,
383 src1.bit() | src2.bit() | src3.bit() | src4.bit() | src5.bit(),
384 cond);
385 } else {
386 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(),
387 cond);
388 str(src5, MemOperand(sp, 4, NegPreIndex), cond);
389 }
390 } else {
391 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
392 Push(src4, src5, cond);
393 }
394 } else {
395 stm(db_w, sp, src1.bit() | src2.bit(), cond);
396 Push(src3, src4, src5, cond);
397 }
398 } else {
399 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
400 Push(src2, src3, src4, src5, cond);
401 }
402 }
403
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100404 // Pop two registers. Pops rightmost register first (from lower address).
405 void Pop(Register src1, Register src2, Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406 DCHECK(!src1.is(src2));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100407 if (src1.code() > src2.code()) {
408 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
409 } else {
410 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
411 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
412 }
413 }
414
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100415 // Pop three registers. Pops rightmost register first (from lower address).
416 void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000417 DCHECK(!AreAliased(src1, src2, src3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100418 if (src1.code() > src2.code()) {
419 if (src2.code() > src3.code()) {
420 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
421 } else {
422 ldr(src3, MemOperand(sp, 4, PostIndex), cond);
423 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
424 }
425 } else {
426 Pop(src2, src3, cond);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000427 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100428 }
429 }
430
431 // Pop four registers. Pops rightmost register first (from lower address).
432 void Pop(Register src1,
433 Register src2,
434 Register src3,
435 Register src4,
436 Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 DCHECK(!AreAliased(src1, src2, src3, src4));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100438 if (src1.code() > src2.code()) {
439 if (src2.code() > src3.code()) {
440 if (src3.code() > src4.code()) {
441 ldm(ia_w,
442 sp,
443 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
444 cond);
445 } else {
446 ldr(src4, MemOperand(sp, 4, PostIndex), cond);
447 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
448 }
449 } else {
450 Pop(src3, src4, cond);
451 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
452 }
453 } else {
454 Pop(src2, src3, src4, cond);
455 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
456 }
457 }
458
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459 // Push a fixed frame, consisting of lr, fp, constant pool (if
Ben Murdochda12d292016-06-02 14:46:10 +0100460 // FLAG_enable_embedded_constant_pool)
461 void PushCommonFrame(Register marker_reg = no_reg);
462
463 // Push a standard frame, consisting of lr, fp, constant pool (if
464 // FLAG_enable_embedded_constant_pool), context and JS function
465 void PushStandardFrame(Register function_reg);
466
467 void PopCommonFrame(Register marker_reg = no_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000468
Ben Murdochb0fe1622011-05-05 13:52:32 +0100469 // Push and pop the registers that can hold pointers, as defined by the
470 // RegList constant kSafepointSavedRegisters.
471 void PushSafepointRegisters();
472 void PopSafepointRegisters();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100473 // Store value in register src in the safepoint stack slot for
474 // register dst.
475 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100476 // Load the value of the src register from its safepoint stack slot
477 // into register dst.
478 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100479
Leon Clarkef7060e22010-06-03 12:02:55 +0100480 // Load two consecutive registers with two consecutive memory locations.
481 void Ldrd(Register dst1,
482 Register dst2,
483 const MemOperand& src,
484 Condition cond = al);
485
486 // Store two consecutive registers to two consecutive memory locations.
487 void Strd(Register src1,
488 Register src2,
489 const MemOperand& dst,
490 Condition cond = al);
491
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000492 // Ensure that FPSCR contains values needed by JavaScript.
493 // We need the NaNModeControlBit to be sure that operations like
494 // vadd and vsub generate the Canonical NaN (if a NaN must be generated).
495 // In VFP3 it will be always the Canonical NaN.
496 // In VFP2 it will be either the Canonical NaN or the negative version
497 // of the Canonical NaN. It doesn't matter if we have two values. The aim
498 // is to be sure to never generate the hole NaN.
499 void VFPEnsureFPSCRState(Register scratch);
500
501 // If the value is a NaN, canonicalize the value else, do nothing.
502 void VFPCanonicalizeNaN(const DwVfpRegister dst,
503 const DwVfpRegister src,
504 const Condition cond = al);
505 void VFPCanonicalizeNaN(const DwVfpRegister value,
506 const Condition cond = al) {
507 VFPCanonicalizeNaN(value, value, cond);
508 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100509
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000510 // Compare single values and move the result to the normal condition flags.
511 void VFPCompareAndSetFlags(const SwVfpRegister src1, const SwVfpRegister src2,
512 const Condition cond = al);
513 void VFPCompareAndSetFlags(const SwVfpRegister src1, const float src2,
514 const Condition cond = al);
515
Ben Murdochb8e0da22011-05-16 14:20:40 +0100516 // Compare double values and move the result to the normal condition flags.
517 void VFPCompareAndSetFlags(const DwVfpRegister src1,
518 const DwVfpRegister src2,
519 const Condition cond = al);
520 void VFPCompareAndSetFlags(const DwVfpRegister src1,
521 const double src2,
522 const Condition cond = al);
523
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 // Compare single values and then load the fpscr flags to a register.
525 void VFPCompareAndLoadFlags(const SwVfpRegister src1,
526 const SwVfpRegister src2,
527 const Register fpscr_flags,
528 const Condition cond = al);
529 void VFPCompareAndLoadFlags(const SwVfpRegister src1, const float src2,
530 const Register fpscr_flags,
531 const Condition cond = al);
532
Ben Murdochb8e0da22011-05-16 14:20:40 +0100533 // Compare double values and then load the fpscr flags to a register.
534 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
535 const DwVfpRegister src2,
536 const Register fpscr_flags,
537 const Condition cond = al);
538 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
539 const double src2,
540 const Register fpscr_flags,
541 const Condition cond = al);
542
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000543 void Vmov(const DwVfpRegister dst,
544 const double imm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000545 const Register scratch = no_reg);
546
547 void VmovHigh(Register dst, DwVfpRegister src);
548 void VmovHigh(DwVfpRegister dst, Register src);
549 void VmovLow(Register dst, DwVfpRegister src);
550 void VmovLow(DwVfpRegister dst, Register src);
551
Ben Murdochda12d292016-06-02 14:46:10 +0100552 void LslPair(Register dst_low, Register dst_high, Register src_low,
553 Register src_high, Register scratch, Register shift);
554 void LslPair(Register dst_low, Register dst_high, Register src_low,
555 Register src_high, uint32_t shift);
556 void LsrPair(Register dst_low, Register dst_high, Register src_low,
557 Register src_high, Register scratch, Register shift);
558 void LsrPair(Register dst_low, Register dst_high, Register src_low,
559 Register src_high, uint32_t shift);
560 void AsrPair(Register dst_low, Register dst_high, Register src_low,
561 Register src_high, Register scratch, Register shift);
562 void AsrPair(Register dst_low, Register dst_high, Register src_low,
563 Register src_high, uint32_t shift);
564
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565 // Loads the number from object into dst register.
566 // If |object| is neither smi nor heap number, |not_number| is jumped to
567 // with |object| still intact.
568 void LoadNumber(Register object,
569 LowDwVfpRegister dst,
570 Register heap_number_map,
571 Register scratch,
572 Label* not_number);
573
574 // Loads the number from object into double_dst in the double format.
575 // Control will jump to not_int32 if the value cannot be exactly represented
576 // by a 32-bit integer.
577 // Floating point value in the 32-bit integer range that are not exact integer
578 // won't be loaded.
579 void LoadNumberAsInt32Double(Register object,
580 DwVfpRegister double_dst,
581 Register heap_number_map,
582 Register scratch,
583 LowDwVfpRegister double_scratch,
584 Label* not_int32);
585
586 // Loads the number from object into dst as a 32-bit integer.
587 // Control will jump to not_int32 if the object cannot be exactly represented
588 // by a 32-bit integer.
589 // Floating point value in the 32-bit integer range that are not exact integer
590 // won't be converted.
591 void LoadNumberAsInt32(Register object,
592 Register dst,
593 Register heap_number_map,
594 Register scratch,
595 DwVfpRegister double_scratch0,
596 LowDwVfpRegister double_scratch1,
597 Label* not_int32);
598
599 // Generates function and stub prologue code.
Ben Murdochda12d292016-06-02 14:46:10 +0100600 void StubPrologue(StackFrame::Type type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000601 void Prologue(bool code_pre_aging);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000602
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100603 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100604 // stack_space - extra stack space, used for alignment before call to C.
605 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
607 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100608 // Expect the number of values, pushed prior to the exit frame, to
609 // remove in a register (or no_reg, if there is nothing to remove).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000610 void LeaveExitFrame(bool save_doubles, Register argument_count,
611 bool restore_context,
612 bool argument_count_is_length = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000613
Steve Block6ded16b2010-05-10 14:33:55 +0100614 // Get the actual activation frame alignment for target environment.
615 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000616
Steve Blockd0582a62009-12-15 09:54:21 +0000617 void LoadContext(Register dst, int context_chain_length);
618
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000619 // Load the global object from the current context.
620 void LoadGlobalObject(Register dst) {
621 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
622 }
623
624 // Load the global proxy from the current context.
625 void LoadGlobalProxy(Register dst) {
626 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
627 }
628
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100629 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000630 // transitioned_kind from the native context if the map in register
631 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100632 // expected_kind.
633 void LoadTransitionedArrayMapConditional(
634 ElementsKind expected_kind,
635 ElementsKind transitioned_kind,
636 Register map_in_out,
637 Register scratch,
638 Label* no_map_match);
639
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000640 void LoadNativeContextSlot(int index, Register dst);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800641
642 // Load the initial map from the global function. The registers
643 // function and map can be the same, function is then overwritten.
644 void LoadGlobalFunctionInitialMap(Register function,
645 Register map,
646 Register scratch);
647
Ben Murdochc7cc0282012-03-05 14:35:55 +0000648 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100649 ExternalReference roots_array_start =
650 ExternalReference::roots_array_start(isolate());
651 mov(kRootRegister, Operand(roots_array_start));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000652 }
653
Steve Blocka7e24c12009-10-30 11:49:00 +0000654 // ---------------------------------------------------------------------------
655 // JavaScript invokes
656
Ben Murdochda12d292016-06-02 14:46:10 +0100657 // Removes current frame and its arguments from the stack preserving
658 // the arguments and a return address pushed to the stack for the next call.
659 // Both |callee_args_count| and |caller_args_count_reg| do not include
660 // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
661 // is trashed.
662 void PrepareForTailCall(const ParameterCount& callee_args_count,
663 Register caller_args_count_reg, Register scratch0,
664 Register scratch1);
665
Steve Blocka7e24c12009-10-30 11:49:00 +0000666 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 void InvokeFunctionCode(Register function, Register new_target,
668 const ParameterCount& expected,
669 const ParameterCount& actual, InvokeFlag flag,
670 const CallWrapper& call_wrapper);
671
672 void FloodFunctionIfStepping(Register fun, Register new_target,
673 const ParameterCount& expected,
674 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000675
676 // Invoke the JavaScript function in the given register. Changes the
677 // current context to the context in the function before invoking.
678 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000679 Register new_target,
Steve Blocka7e24c12009-10-30 11:49:00 +0000680 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100681 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000682 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000683
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 void InvokeFunction(Register function,
685 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000686 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000687 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000688 const CallWrapper& call_wrapper);
689
690 void InvokeFunction(Handle<JSFunction> function,
691 const ParameterCount& expected,
692 const ParameterCount& actual,
693 InvokeFlag flag,
694 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000695
Ben Murdochb0fe1622011-05-05 13:52:32 +0100696 void IsObjectJSStringType(Register object,
697 Register scratch,
698 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000699
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000700 void IsObjectNameType(Register object,
701 Register scratch,
702 Label* fail);
703
Steve Blocka7e24c12009-10-30 11:49:00 +0000704 // ---------------------------------------------------------------------------
705 // Debugger Support
706
Andrei Popescu402d9372010-02-26 13:31:12 +0000707 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000708
709 // ---------------------------------------------------------------------------
710 // Exception handling
711
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000712 // Push a new stack handler and link into stack handler chain.
713 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000714
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000715 // Unlink the stack handler on top of the stack from the stack handler chain.
Leon Clarkee46be812010-01-19 14:06:41 +0000716 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000717 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100718
Steve Blocka7e24c12009-10-30 11:49:00 +0000719 // ---------------------------------------------------------------------------
720 // Inline caching support
721
Steve Blocka7e24c12009-10-30 11:49:00 +0000722 // Generate code for checking access rights - used for security checks
723 // on access to global objects across environments. The holder register
724 // is left untouched, whereas both scratch registers are clobbered.
725 void CheckAccessGlobalProxy(Register holder_reg,
726 Register scratch,
727 Label* miss);
728
Ben Murdochc7cc0282012-03-05 14:35:55 +0000729 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000730
731 void LoadFromNumberDictionary(Label* miss,
732 Register elements,
733 Register key,
734 Register result,
735 Register t0,
736 Register t1,
737 Register t2);
738
739
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800740 inline void MarkCode(NopMarkerTypes type) {
741 nop(type);
742 }
743
744 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100745 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800746 // These instructions are generated to mark special location in the code,
747 // like some special IC code.
748 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000749 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800750 return IsNop(instr, type);
751 }
752
753
754 static inline int GetCodeMarker(Instr instr) {
755 int dst_reg_offset = 12;
756 int dst_mask = 0xf << dst_reg_offset;
757 int src_mask = 0xf;
758 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
759 int src_reg = instr & src_mask;
760 uint32_t non_register_mask = ~(dst_mask | src_mask);
761 uint32_t mov_mask = al | 13 << 21;
762
763 // Return <n> if we have a mov rn rn, else return -1.
764 int type = ((instr & non_register_mask) == mov_mask) &&
765 (dst_reg == src_reg) &&
766 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
767 ? src_reg
768 : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000769 DCHECK((type == -1) ||
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800770 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
771 return type;
772 }
773
Steve Blocka7e24c12009-10-30 11:49:00 +0000774
775 // ---------------------------------------------------------------------------
776 // Allocation support
777
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000778 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000779 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
780 // is passed. If the space is exhausted control continues at the gc_required
781 // label. The allocated object is returned in result. If the flag
782 // tag_allocated_object is true the result is tagged as as a heap object.
783 // All registers are clobbered also when control continues at the gc_required
784 // label.
785 void Allocate(int object_size,
786 Register result,
787 Register scratch1,
788 Register scratch2,
789 Label* gc_required,
790 AllocationFlags flags);
791
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000792 void Allocate(Register object_size, Register result, Register result_end,
793 Register scratch, Label* gc_required, AllocationFlags flags);
Andrei Popescu31002712010-02-23 13:46:05 +0000794
795 void AllocateTwoByteString(Register result,
796 Register length,
797 Register scratch1,
798 Register scratch2,
799 Register scratch3,
800 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000801 void AllocateOneByteString(Register result, Register length,
802 Register scratch1, Register scratch2,
803 Register scratch3, Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000804 void AllocateTwoByteConsString(Register result,
805 Register length,
806 Register scratch1,
807 Register scratch2,
808 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000809 void AllocateOneByteConsString(Register result, Register length,
810 Register scratch1, Register scratch2,
811 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000812 void AllocateTwoByteSlicedString(Register result,
813 Register length,
814 Register scratch1,
815 Register scratch2,
816 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000817 void AllocateOneByteSlicedString(Register result, Register length,
818 Register scratch1, Register scratch2,
819 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000820
Kristian Monsen25f61362010-05-21 11:50:48 +0100821 // Allocates a heap number or jumps to the gc_required label if the young
822 // space is full and a scavenge is needed. All registers are clobbered also
823 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100824 void AllocateHeapNumber(Register result,
825 Register scratch1,
826 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100827 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000828 Label* gc_required,
829 TaggingMode tagging_mode = TAG_RESULT,
830 MutableMode mode = IMMUTABLE);
Steve Block8defd9f2010-07-08 12:39:36 +0100831 void AllocateHeapNumberWithValue(Register result,
832 DwVfpRegister value,
833 Register scratch1,
834 Register scratch2,
835 Register heap_number_map,
836 Label* gc_required);
837
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000838 // Allocate and initialize a JSValue wrapper with the specified {constructor}
839 // and {value}.
840 void AllocateJSValue(Register result, Register constructor, Register value,
841 Register scratch1, Register scratch2,
842 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000843
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100844 // Copies a number of bytes from src to dst. All registers are clobbered. On
845 // exit src and dst will point to the place just after where the last byte was
846 // read or written and length will be zero.
847 void CopyBytes(Register src,
848 Register dst,
849 Register length,
850 Register scratch);
851
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000852 // Initialize fields with filler values. Fields starting at |current_address|
853 // not including |end_address| are overwritten with the value in |filler|. At
854 // the end the loop, |current_address| takes the value of |end_address|.
855 void InitializeFieldsWithFiller(Register current_address,
856 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100857
Steve Blocka7e24c12009-10-30 11:49:00 +0000858 // ---------------------------------------------------------------------------
859 // Support functions.
860
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000861 // Machine code version of Map::GetConstructor().
862 // |temp| holds |result|'s map when done, and |temp2| its instance type.
863 void GetMapConstructor(Register result, Register map, Register temp,
864 Register temp2);
865
Steve Blocka7e24c12009-10-30 11:49:00 +0000866 // Try to get function prototype of a function and puts the value in
867 // the result register. Checks that the function really is a
868 // function and jumps to the miss label if the fast checks fail. The
869 // function register will be untouched; the other registers may be
870 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000871 void TryGetFunctionPrototype(Register function, Register result,
872 Register scratch, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000873
874 // Compare object type for heap object. heap_object contains a non-Smi
875 // whose object type should be compared with the given type. This both
876 // sets the flags and leaves the object type in the type_reg register.
877 // It leaves the map in the map register (unless the type_reg and map register
878 // are the same register). It leaves the heap object in the heap_object
879 // register unless the heap_object register is the same register as one of the
880 // other registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000881 // Type_reg can be no_reg. In that case ip is used.
Steve Blocka7e24c12009-10-30 11:49:00 +0000882 void CompareObjectType(Register heap_object,
883 Register map,
884 Register type_reg,
885 InstanceType type);
886
887 // Compare instance type in a map. map contains a valid map object whose
888 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000889 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000890 void CompareInstanceType(Register map,
891 Register type_reg,
892 InstanceType type);
893
Andrei Popescu31002712010-02-23 13:46:05 +0000894
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000895 // Check if a map for a JSObject indicates that the object has fast elements.
896 // Jump to the specified label if it does not.
897 void CheckFastElements(Register map,
898 Register scratch,
899 Label* fail);
900
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100901 // Check if a map for a JSObject indicates that the object can have both smi
902 // and HeapObject elements. Jump to the specified label if it does not.
903 void CheckFastObjectElements(Register map,
904 Register scratch,
905 Label* fail);
906
907 // Check if a map for a JSObject indicates that the object has fast smi only
908 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000909 void CheckFastSmiElements(Register map,
910 Register scratch,
911 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100912
913 // Check to see if maybe_number can be stored as a double in
914 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000915 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100916 void StoreNumberToDoubleElements(Register value_reg,
917 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100918 Register elements_reg,
919 Register scratch1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000920 LowDwVfpRegister double_scratch,
921 Label* fail,
922 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100923
924 // Compare an object's map with the specified map and its transitioned
925 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
926 // set with result of map compare. If multiple map compares are required, the
927 // compare sequences branches to early_success.
928 void CompareMap(Register obj,
929 Register scratch,
930 Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000931 Label* early_success);
932
933 // As above, but the map of the object is already loaded into the register
934 // which is preserved by the code generated.
935 void CompareMap(Register obj_map,
936 Handle<Map> map,
937 Label* early_success);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100938
939 // Check if the map of an object is equal to a specified map and branch to
940 // label if not. Skip the smi check if not required (object is known to be a
941 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
942 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +0000943 void CheckMap(Register obj,
944 Register scratch,
945 Handle<Map> map,
946 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000947 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000948
Andrei Popescu31002712010-02-23 13:46:05 +0000949
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100950 void CheckMap(Register obj,
951 Register scratch,
952 Heap::RootListIndex index,
953 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000954 SmiCheckType smi_check_type);
955
956
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400957 // Check if the map of an object is equal to a specified weak map and branch
958 // to a specified target if equal. Skip the smi check if not required
959 // (object is known to be a heap object)
960 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
961 Handle<WeakCell> cell, Handle<Code> success,
962 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100963
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400964 // Compare the given value and the value of weak cell.
965 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
966
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000967 void GetWeakValue(Register value, Handle<WeakCell> cell);
968
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400969 // Load the value of the weak cell in the value register. Branch to the given
970 // miss label if the weak cell was cleared.
971 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100972
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100973 // Compare the object in a register to a value from the root list.
974 // Uses the ip register as scratch.
975 void CompareRoot(Register obj, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000976 void PushRoot(Heap::RootListIndex index) {
977 LoadRoot(ip, index);
978 Push(ip);
979 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100980
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000981 // Compare the object in a register to a value and jump if they are equal.
982 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
983 CompareRoot(with, index);
984 b(eq, if_equal);
985 }
986
987 // Compare the object in a register to a value and jump if they are not equal.
988 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
989 Label* if_not_equal) {
990 CompareRoot(with, index);
991 b(ne, if_not_equal);
992 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100993
Andrei Popescu31002712010-02-23 13:46:05 +0000994 // Load and check the instance type of an object for being a string.
995 // Loads the type into the second argument register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000996 // Returns a condition that will be enabled if the object was a string
997 // and the passed-in condition passed. If the passed-in condition failed
998 // then flags remain unchanged.
Andrei Popescu31002712010-02-23 13:46:05 +0000999 Condition IsObjectStringType(Register obj,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001000 Register type,
1001 Condition cond = al) {
1002 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond);
1003 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond);
1004 tst(type, Operand(kIsNotStringMask), cond);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001005 DCHECK_EQ(0u, kStringTag);
Andrei Popescu31002712010-02-23 13:46:05 +00001006 return eq;
1007 }
1008
1009
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001010 // Picks out an array index from the hash field.
1011 // Register use:
1012 // hash - holds the index's hash. Clobbered.
1013 // index - holds the overwritten index on exit.
1014 void IndexFromHash(Register hash, Register index);
1015
Andrei Popescu31002712010-02-23 13:46:05 +00001016 // Get the number of least significant bits from a register
1017 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +01001018 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +00001019
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020 // Load the value of a smi object into a double register.
1021 // The register value must be between d0 and d15.
1022 void SmiToDouble(LowDwVfpRegister value, Register smi);
Steve Blockd0582a62009-12-15 09:54:21 +00001023
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001024 // Check if a double can be exactly represented as a signed 32-bit integer.
1025 // Z flag set to one if true.
1026 void TestDoubleIsInt32(DwVfpRegister double_input,
1027 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001028
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001029 // Try to convert a double to a signed 32-bit integer.
1030 // Z flag set to one and result assigned if the conversion is exact.
1031 void TryDoubleToInt32Exact(Register result,
1032 DwVfpRegister double_input,
1033 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001034
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001035 // Floor a double and writes the value to the result register.
1036 // Go to exact if the conversion is exact (to be able to test -0),
1037 // fall through calling code if an overflow occurred, else go to done.
1038 // In return, input_high is loaded with high bits of input.
1039 void TryInt32Floor(Register result,
1040 DwVfpRegister double_input,
1041 Register input_high,
1042 LowDwVfpRegister double_scratch,
1043 Label* done,
1044 Label* exact);
Iain Merrick9ac36c92010-09-13 15:29:50 +01001045
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001046 // Performs a truncating conversion of a floating point number as used by
1047 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
1048 // succeeds, otherwise falls through if result is saturated. On return
1049 // 'result' either holds answer, or is clobbered on fall through.
1050 //
1051 // Only public for the test code in test-code-stubs-arm.cc.
1052 void TryInlineTruncateDoubleToI(Register result,
1053 DwVfpRegister input,
1054 Label* done);
Steve Block44f0eee2011-05-26 01:26:41 +01001055
1056 // Performs a truncating conversion of a floating point number as used by
1057 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001058 // Exits with 'result' holding the answer.
1059 void TruncateDoubleToI(Register result, DwVfpRegister double_input);
Steve Block44f0eee2011-05-26 01:26:41 +01001060
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001061 // Performs a truncating conversion of a heap number as used by
1062 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1063 // must be different registers. Exits with 'result' holding the answer.
1064 void TruncateHeapNumberToI(Register result, Register object);
1065
1066 // Converts the smi or heap number in object to an int32 using the rules
1067 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1068 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1069 // different registers.
1070 void TruncateNumberToI(Register object,
1071 Register result,
1072 Register heap_number_map,
1073 Register scratch1,
1074 Label* not_int32);
1075
1076 // Check whether d16-d31 are available on the CPU. The result is given by the
1077 // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
1078 void CheckFor32DRegs(Register scratch);
1079
1080 // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
1081 // values to location, saving [d0..(d15|d31)].
1082 void SaveFPRegs(Register location, Register scratch);
1083
1084 // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
1085 // values to location, restoring [d0..(d15|d31)].
1086 void RestoreFPRegs(Register location, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001087
1088 // ---------------------------------------------------------------------------
1089 // Runtime calls
1090
1091 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001092 void CallStub(CodeStub* stub,
1093 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1094 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001095
Andrei Popescu31002712010-02-23 13:46:05 +00001096 // Call a code stub.
1097 void TailCallStub(CodeStub* stub, Condition cond = al);
1098
Steve Blocka7e24c12009-10-30 11:49:00 +00001099 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001100 void CallRuntime(const Runtime::Function* f,
1101 int num_arguments,
1102 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001103 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1104 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001105 CallRuntime(function, function->nargs, kSaveFPRegs);
1106 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001107
1108 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001109 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001110 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001111 const Runtime::Function* function = Runtime::FunctionForId(fid);
1112 CallRuntime(function, function->nargs, save_doubles);
1113 }
1114
1115 // Convenience function: Same as above, but takes the fid instead.
1116 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1117 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1118 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001119 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001120
Andrei Popescu402d9372010-02-26 13:31:12 +00001121 // Convenience function: call an external reference.
1122 void CallExternalReference(const ExternalReference& ext,
1123 int num_arguments);
1124
Steve Block6ded16b2010-05-10 14:33:55 +01001125 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001126 void TailCallRuntime(Runtime::FunctionId fid);
Steve Blocka7e24c12009-10-30 11:49:00 +00001127
Ben Murdoch257744e2011-11-30 15:57:28 +00001128 int CalculateStackPassedWords(int num_reg_arguments,
1129 int num_double_arguments);
1130
Steve Block6ded16b2010-05-10 14:33:55 +01001131 // Before calling a C-function from generated code, align arguments on stack.
1132 // After aligning the frame, non-register arguments must be stored in
1133 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +00001134 // are word sized. If double arguments are used, this function assumes that
1135 // all double arguments are stored before core registers; otherwise the
1136 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +01001137 // Some compilers/platforms require the stack to be aligned when calling
1138 // C++ code.
1139 // Needs a scratch register to do some arithmetic. This register will be
1140 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +00001141 void PrepareCallCFunction(int num_reg_arguments,
1142 int num_double_registers,
1143 Register scratch);
1144 void PrepareCallCFunction(int num_reg_arguments,
1145 Register scratch);
1146
1147 // There are two ways of passing double arguments on ARM, depending on
1148 // whether soft or hard floating point ABI is used. These functions
1149 // abstract parameter passing for the three different ways we call
1150 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001151 void MovToFloatParameter(DwVfpRegister src);
1152 void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
1153 void MovToFloatResult(DwVfpRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001154
1155 // Calls a C function and cleans up the space for arguments allocated
1156 // by PrepareCallCFunction. The called function is not allowed to trigger a
1157 // garbage collection, since that might move the code and invalidate the
1158 // return address (unless this is somehow accounted for by the called
1159 // function).
1160 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001161 void CallCFunction(Register function, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001162 void CallCFunction(ExternalReference function,
1163 int num_reg_arguments,
1164 int num_double_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001165 void CallCFunction(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001166 int num_reg_arguments,
1167 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01001168
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001169 void MovFromFloatParameter(DwVfpRegister dst);
1170 void MovFromFloatResult(DwVfpRegister dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001171
Steve Blocka7e24c12009-10-30 11:49:00 +00001172 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001173 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +00001174
Ben Murdoch8b112d22011-06-08 16:22:53 +01001175 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001176 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001177 return code_object_;
1178 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001179
1180
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001181 // Emit code for a truncating division by a constant. The dividend register is
1182 // unchanged and ip gets clobbered. Dividend and result must be different.
1183 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1184
Steve Blocka7e24c12009-10-30 11:49:00 +00001185 // ---------------------------------------------------------------------------
1186 // StatsCounter support
1187
1188 void SetCounter(StatsCounter* counter, int value,
1189 Register scratch1, Register scratch2);
1190 void IncrementCounter(StatsCounter* counter, int value,
1191 Register scratch1, Register scratch2);
1192 void DecrementCounter(StatsCounter* counter, int value,
1193 Register scratch1, Register scratch2);
1194
1195
1196 // ---------------------------------------------------------------------------
1197 // Debugging
1198
Steve Block1e0659c2011-05-24 12:43:12 +01001199 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +00001200 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001201 void Assert(Condition cond, BailoutReason reason);
Iain Merrick75681382010-08-19 15:07:18 +01001202 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00001203
1204 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001205 void Check(Condition cond, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001206
1207 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001208 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001209
1210 // Verify restrictions about code generated in stubs.
1211 void set_generating_stub(bool value) { generating_stub_ = value; }
1212 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001213 void set_has_frame(bool value) { has_frame_ = value; }
1214 bool has_frame() { return has_frame_; }
1215 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001216
Ben Murdoch257744e2011-11-30 15:57:28 +00001217 // EABI variant for double arguments in use.
1218 bool use_eabi_hardfloat() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001219#ifdef __arm__
1220 return base::OS::ArmUsingHardFloat();
1221#elif USE_EABI_HARDFLOAT
Ben Murdoch257744e2011-11-30 15:57:28 +00001222 return true;
1223#else
1224 return false;
1225#endif
1226 }
1227
Leon Clarked91b9f72010-01-27 17:25:45 +00001228 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +01001229 // Number utilities
1230
1231 // Check whether the value of reg is a power of two and not zero. If not
1232 // control continues at the label not_power_of_two. If reg is a power of two
1233 // the register scratch contains the value of (reg - 1) when control falls
1234 // through.
1235 void JumpIfNotPowerOfTwoOrZero(Register reg,
1236 Register scratch,
1237 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +01001238 // Check whether the value of reg is a power of two and not zero.
1239 // Control falls through if it is, with scratch containing the mask
1240 // value (reg - 1).
1241 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1242 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1243 // strictly positive but not a power of two.
1244 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1245 Register scratch,
1246 Label* zero_and_neg,
1247 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +01001248
1249 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001250 // Smi utilities
1251
Ben Murdochb0fe1622011-05-05 13:52:32 +01001252 void SmiTag(Register reg, SBit s = LeaveCC) {
1253 add(reg, reg, Operand(reg), s);
1254 }
Steve Block1e0659c2011-05-24 12:43:12 +01001255 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1256 add(dst, src, Operand(src), s);
1257 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001258
Ben Murdochb8e0da22011-05-16 14:20:40 +01001259 // Try to convert int32 to smi. If the value is to large, preserve
1260 // the original value and jump to not_a_smi. Destroys scratch and
1261 // sets flags.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001262 void TrySmiTag(Register reg, Label* not_a_smi) {
1263 TrySmiTag(reg, reg, not_a_smi);
1264 }
1265 void TrySmiTag(Register reg, Register src, Label* not_a_smi) {
1266 SmiTag(ip, src, SetCC);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001267 b(vs, not_a_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001268 mov(reg, ip);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001269 }
1270
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001271
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001272 void SmiUntag(Register reg, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001273 mov(reg, Operand::SmiUntag(reg), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001274 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001275 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001276 mov(dst, Operand::SmiUntag(src), s);
Steve Block1e0659c2011-05-24 12:43:12 +01001277 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001278
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001279 // Untag the source value into destination and jump if source is a smi.
1280 // Souce and destination can be the same register.
1281 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1282
1283 // Untag the source value into destination and jump if source is not a smi.
1284 // Souce and destination can be the same register.
1285 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1286
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001287 // Test if the register contains a smi (Z == 0 (eq) if true).
1288 inline void SmiTst(Register value) {
1289 tst(value, Operand(kSmiTagMask));
1290 }
1291 inline void NonNegativeSmiTst(Register value) {
1292 tst(value, Operand(kSmiTagMask | kSmiSignMask));
1293 }
1294 // Jump if the register contains a smi.
Steve Block1e0659c2011-05-24 12:43:12 +01001295 inline void JumpIfSmi(Register value, Label* smi_label) {
1296 tst(value, Operand(kSmiTagMask));
1297 b(eq, smi_label);
1298 }
1299 // Jump if either of the registers contain a non-smi.
1300 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1301 tst(value, Operand(kSmiTagMask));
1302 b(ne, not_smi_label);
1303 }
Andrei Popescu31002712010-02-23 13:46:05 +00001304 // Jump if either of the registers contain a non-smi.
1305 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1306 // Jump if either of the registers contain a smi.
1307 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1308
Ben Murdochda12d292016-06-02 14:46:10 +01001309 // Abort execution if argument is a number, enabled via --debug-code.
1310 void AssertNotNumber(Register object);
1311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001312 // Abort execution if argument is a smi, enabled via --debug-code.
1313 void AssertNotSmi(Register object);
1314 void AssertSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +01001315
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001316 // Abort execution if argument is not a string, enabled via --debug-code.
1317 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001318
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001319 // Abort execution if argument is not a name, enabled via --debug-code.
1320 void AssertName(Register object);
1321
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001322 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1323 void AssertFunction(Register object);
1324
1325 // Abort execution if argument is not a JSBoundFunction,
1326 // enabled via --debug-code.
1327 void AssertBoundFunction(Register object);
1328
Ben Murdoch097c5b22016-05-18 11:27:45 +01001329 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1330 void AssertReceiver(Register object);
1331
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001332 // Abort execution if argument is not undefined or an AllocationSite, enabled
1333 // via --debug-code.
1334 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1335
1336 // Abort execution if reg is not the root value with the given index,
1337 // enabled via --debug-code.
1338 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block1e0659c2011-05-24 12:43:12 +01001339
1340 // ---------------------------------------------------------------------------
1341 // HeapNumber utilities
1342
1343 void JumpIfNotHeapNumber(Register object,
1344 Register heap_number_map,
1345 Register scratch,
1346 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +01001347
Andrei Popescu31002712010-02-23 13:46:05 +00001348 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +00001349 // String utilities
1350
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001351 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001352 // if either is not. Assumes that neither object is a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001353 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register object1,
1354 Register object2,
1355 Register scratch1,
1356 Register scratch2,
1357 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001358
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001359 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001360 // if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001361 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1362 Register scratch1,
1363 Register scratch2,
1364 Label* not_flat_one_byte_strings);
Leon Clarked91b9f72010-01-27 17:25:45 +00001365
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001366 // Checks if both instance types are sequential one-byte strings and jumps to
Steve Block6ded16b2010-05-10 14:33:55 +01001367 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001368 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1369 Register first_object_instance_type, Register second_object_instance_type,
1370 Register scratch1, Register scratch2, Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001371
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001372 // Check if instance type is sequential one-byte string and jump to label if
Steve Block6ded16b2010-05-10 14:33:55 +01001373 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001374 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1375 Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001376
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001377 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1378
1379 void EmitSeqStringSetCharCheck(Register string,
1380 Register index,
1381 Register value,
1382 uint32_t encoding_mask);
Steve Block6ded16b2010-05-10 14:33:55 +01001383
Steve Block1e0659c2011-05-24 12:43:12 +01001384
Ben Murdoch257744e2011-11-30 15:57:28 +00001385 void ClampUint8(Register output_reg, Register input_reg);
1386
1387 void ClampDoubleToUint8(Register result_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001388 DwVfpRegister input_reg,
1389 LowDwVfpRegister double_scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001390
1391
1392 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001393 void EnumLength(Register dst, Register map);
1394 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001395 void LoadAccessor(Register dst, Register holder, int accessor_index,
1396 AccessorComponent accessor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001397
1398 template<typename Field>
1399 void DecodeField(Register dst, Register src) {
1400 Ubfx(dst, src, Field::kShift, Field::kSize);
1401 }
1402
1403 template<typename Field>
1404 void DecodeField(Register reg) {
1405 DecodeField<Field>(reg, reg);
1406 }
1407
1408 template<typename Field>
1409 void DecodeFieldToSmi(Register dst, Register src) {
1410 static const int shift = Field::kShift;
1411 static const int mask = Field::kMask >> shift << kSmiTagSize;
1412 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1413 STATIC_ASSERT(kSmiTag == 0);
1414 if (shift < kSmiTagSize) {
1415 mov(dst, Operand(src, LSL, kSmiTagSize - shift));
1416 and_(dst, dst, Operand(mask));
1417 } else if (shift > kSmiTagSize) {
1418 mov(dst, Operand(src, LSR, shift - kSmiTagSize));
1419 and_(dst, dst, Operand(mask));
1420 } else {
1421 and_(dst, src, Operand(mask));
1422 }
1423 }
1424
1425 template<typename Field>
1426 void DecodeFieldToSmi(Register reg) {
1427 DecodeField<Field>(reg, reg);
1428 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001429
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001430 // Load the type feedback vector from a JavaScript frame.
1431 void EmitLoadTypeFeedbackVector(Register vector);
1432
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001433 // Activation support.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001434 void EnterFrame(StackFrame::Type type,
1435 bool load_constant_pool_pointer_reg = false);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001436 // Returns the pc offset at which the frame ends.
1437 int LeaveFrame(StackFrame::Type type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001438
1439 // Expects object in r0 and returns map with validated enum cache
1440 // in r0. Assumes that any other register can be used as a scratch.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001441 void CheckEnumCache(Label* call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001442
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001443 // AllocationMemento support. Arrays may have an associated
1444 // AllocationMemento object that can be checked for in order to pretransition
1445 // to another type.
1446 // On entry, receiver_reg should point to the array object.
1447 // scratch_reg gets clobbered.
1448 // If allocation info is present, condition flags are set to eq.
1449 void TestJSArrayForAllocationMemento(Register receiver_reg,
1450 Register scratch_reg,
1451 Label* no_memento_found);
1452
1453 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1454 Register scratch_reg,
1455 Label* memento_found) {
1456 Label no_memento_found;
1457 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1458 &no_memento_found);
1459 b(eq, memento_found);
1460 bind(&no_memento_found);
1461 }
1462
1463 // Jumps to found label if a prototype map has dictionary elements.
1464 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1465 Register scratch1, Label* found);
1466
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001467 // Loads the constant pool pointer (pp) register.
1468 void LoadConstantPoolPointerRegisterFromCodeTargetAddress(
1469 Register code_target_address);
1470 void LoadConstantPoolPointerRegister();
1471
Steve Blocka7e24c12009-10-30 11:49:00 +00001472 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001473 void CallCFunctionHelper(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001474 int num_reg_arguments,
1475 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001476
Andrei Popescu31002712010-02-23 13:46:05 +00001477 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001478
1479 // Helper functions for generating invokes.
1480 void InvokePrologue(const ParameterCount& expected,
1481 const ParameterCount& actual,
Steve Blocka7e24c12009-10-30 11:49:00 +00001482 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001483 bool* definitely_mismatches,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001484 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001485 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001486
Steve Block6ded16b2010-05-10 14:33:55 +01001487 void InitializeNewString(Register string,
1488 Register length,
1489 Heap::RootListIndex map_index,
1490 Register scratch1,
1491 Register scratch2);
1492
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001493 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1494 void InNewSpace(Register object,
1495 Register scratch,
1496 Condition cond, // eq for new space, ne otherwise.
1497 Label* branch);
1498
1499 // Helper for finding the mark bits for an address. Afterwards, the
1500 // bitmap register points at the word with the mark bits and the mask
1501 // the position of the first bit. Leaves addr_reg unchanged.
1502 inline void GetMarkBits(Register addr_reg,
1503 Register bitmap_reg,
1504 Register mask_reg);
1505
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001506 // Compute memory operands for safepoint stack slots.
1507 static int SafepointRegisterStackIndex(int reg_code);
1508 MemOperand SafepointRegisterSlot(Register reg);
1509 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1510
Andrei Popescu31002712010-02-23 13:46:05 +00001511 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001512 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +00001513 // This handle will be patched with the code object on installation.
1514 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001515
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001517 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001518 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001519};
1520
1521
Steve Blocka7e24c12009-10-30 11:49:00 +00001522// The code patcher is used to patch (typically) small parts of code e.g. for
1523// debugging and other types of instrumentation. When using the code patcher
1524// the exact number of bytes specified must be emitted. It is not legal to emit
1525// relocation information. If any of these constraints are violated it causes
1526// an assertion to fail.
1527class CodePatcher {
1528 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001529 enum FlushICache {
1530 FLUSH,
1531 DONT_FLUSH
1532 };
1533
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001534 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001535 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001536 ~CodePatcher();
Steve Blocka7e24c12009-10-30 11:49:00 +00001537
1538 // Macro assembler to emit code.
1539 MacroAssembler* masm() { return &masm_; }
1540
1541 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001542 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001543
1544 // Emit an address directly.
1545 void Emit(Address addr);
1546
Steve Block1e0659c2011-05-24 12:43:12 +01001547 // Emit the condition part of an instruction leaving the rest of the current
1548 // instruction unchanged.
1549 void EmitCondition(Condition cond);
1550
Steve Blocka7e24c12009-10-30 11:49:00 +00001551 private:
1552 byte* address_; // The address of the code being patched.
Steve Blocka7e24c12009-10-30 11:49:00 +00001553 int size_; // Number of bytes of the expected patch size.
1554 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Blocka7e24c12009-10-30 11:49:00 +00001556};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001557
1558
Steve Blocka7e24c12009-10-30 11:49:00 +00001559// -----------------------------------------------------------------------------
1560// Static helper functions.
1561
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001562inline MemOperand ContextMemOperand(Register context, int index = 0) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001563 return MemOperand(context, Context::SlotOffset(index));
1564}
1565
1566
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001567inline MemOperand NativeContextMemOperand() {
1568 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001569}
1570
1571
Steve Blocka7e24c12009-10-30 11:49:00 +00001572#ifdef GENERATED_CODE_COVERAGE
1573#define CODE_COVERAGE_STRINGIFY(x) #x
1574#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1575#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1576#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1577#else
1578#define ACCESS_MASM(masm) masm->
1579#endif
1580
1581
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001582} // namespace internal
1583} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001584
1585#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_