blob: 468f4b521a8852c39eda9578845b901287da0916 [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 Murdoch4a90d5f2016-03-22 12:00:34 +0000460 // FLAG_enable_embedded_constant_pool), context and JS function / marker id if
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 // marker_reg is a valid register.
462 void PushFixedFrame(Register marker_reg = no_reg);
463 void PopFixedFrame(Register marker_reg = no_reg);
464
Ben Murdochb0fe1622011-05-05 13:52:32 +0100465 // Push and pop the registers that can hold pointers, as defined by the
466 // RegList constant kSafepointSavedRegisters.
467 void PushSafepointRegisters();
468 void PopSafepointRegisters();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100469 // Store value in register src in the safepoint stack slot for
470 // register dst.
471 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100472 // Load the value of the src register from its safepoint stack slot
473 // into register dst.
474 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100475
Leon Clarkef7060e22010-06-03 12:02:55 +0100476 // Load two consecutive registers with two consecutive memory locations.
477 void Ldrd(Register dst1,
478 Register dst2,
479 const MemOperand& src,
480 Condition cond = al);
481
482 // Store two consecutive registers to two consecutive memory locations.
483 void Strd(Register src1,
484 Register src2,
485 const MemOperand& dst,
486 Condition cond = al);
487
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000488 // Ensure that FPSCR contains values needed by JavaScript.
489 // We need the NaNModeControlBit to be sure that operations like
490 // vadd and vsub generate the Canonical NaN (if a NaN must be generated).
491 // In VFP3 it will be always the Canonical NaN.
492 // In VFP2 it will be either the Canonical NaN or the negative version
493 // of the Canonical NaN. It doesn't matter if we have two values. The aim
494 // is to be sure to never generate the hole NaN.
495 void VFPEnsureFPSCRState(Register scratch);
496
497 // If the value is a NaN, canonicalize the value else, do nothing.
498 void VFPCanonicalizeNaN(const DwVfpRegister dst,
499 const DwVfpRegister src,
500 const Condition cond = al);
501 void VFPCanonicalizeNaN(const DwVfpRegister value,
502 const Condition cond = al) {
503 VFPCanonicalizeNaN(value, value, cond);
504 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100505
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000506 // Compare single values and move the result to the normal condition flags.
507 void VFPCompareAndSetFlags(const SwVfpRegister src1, const SwVfpRegister src2,
508 const Condition cond = al);
509 void VFPCompareAndSetFlags(const SwVfpRegister src1, const float src2,
510 const Condition cond = al);
511
Ben Murdochb8e0da22011-05-16 14:20:40 +0100512 // Compare double values and move the result to the normal condition flags.
513 void VFPCompareAndSetFlags(const DwVfpRegister src1,
514 const DwVfpRegister src2,
515 const Condition cond = al);
516 void VFPCompareAndSetFlags(const DwVfpRegister src1,
517 const double src2,
518 const Condition cond = al);
519
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000520 // Compare single values and then load the fpscr flags to a register.
521 void VFPCompareAndLoadFlags(const SwVfpRegister src1,
522 const SwVfpRegister src2,
523 const Register fpscr_flags,
524 const Condition cond = al);
525 void VFPCompareAndLoadFlags(const SwVfpRegister src1, const float src2,
526 const Register fpscr_flags,
527 const Condition cond = al);
528
Ben Murdochb8e0da22011-05-16 14:20:40 +0100529 // Compare double values and then load the fpscr flags to a register.
530 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
531 const DwVfpRegister src2,
532 const Register fpscr_flags,
533 const Condition cond = al);
534 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
535 const double src2,
536 const Register fpscr_flags,
537 const Condition cond = al);
538
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000539 void Vmov(const DwVfpRegister dst,
540 const double imm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000541 const Register scratch = no_reg);
542
543 void VmovHigh(Register dst, DwVfpRegister src);
544 void VmovHigh(DwVfpRegister dst, Register src);
545 void VmovLow(Register dst, DwVfpRegister src);
546 void VmovLow(DwVfpRegister dst, Register src);
547
548 // Loads the number from object into dst register.
549 // If |object| is neither smi nor heap number, |not_number| is jumped to
550 // with |object| still intact.
551 void LoadNumber(Register object,
552 LowDwVfpRegister dst,
553 Register heap_number_map,
554 Register scratch,
555 Label* not_number);
556
557 // Loads the number from object into double_dst in the double format.
558 // Control will jump to not_int32 if the value cannot be exactly represented
559 // by a 32-bit integer.
560 // Floating point value in the 32-bit integer range that are not exact integer
561 // won't be loaded.
562 void LoadNumberAsInt32Double(Register object,
563 DwVfpRegister double_dst,
564 Register heap_number_map,
565 Register scratch,
566 LowDwVfpRegister double_scratch,
567 Label* not_int32);
568
569 // Loads the number from object into dst as a 32-bit integer.
570 // Control will jump to not_int32 if the object cannot be exactly represented
571 // by a 32-bit integer.
572 // Floating point value in the 32-bit integer range that are not exact integer
573 // won't be converted.
574 void LoadNumberAsInt32(Register object,
575 Register dst,
576 Register heap_number_map,
577 Register scratch,
578 DwVfpRegister double_scratch0,
579 LowDwVfpRegister double_scratch1,
580 Label* not_int32);
581
582 // Generates function and stub prologue code.
583 void StubPrologue();
584 void Prologue(bool code_pre_aging);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000585
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100586 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100587 // stack_space - extra stack space, used for alignment before call to C.
588 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000589
590 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100591 // Expect the number of values, pushed prior to the exit frame, to
592 // remove in a register (or no_reg, if there is nothing to remove).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000593 void LeaveExitFrame(bool save_doubles, Register argument_count,
594 bool restore_context,
595 bool argument_count_is_length = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000596
Steve Block6ded16b2010-05-10 14:33:55 +0100597 // Get the actual activation frame alignment for target environment.
598 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000599
Steve Blockd0582a62009-12-15 09:54:21 +0000600 void LoadContext(Register dst, int context_chain_length);
601
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000602 // Load the global object from the current context.
603 void LoadGlobalObject(Register dst) {
604 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
605 }
606
607 // Load the global proxy from the current context.
608 void LoadGlobalProxy(Register dst) {
609 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
610 }
611
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100612 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000613 // transitioned_kind from the native context if the map in register
614 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100615 // expected_kind.
616 void LoadTransitionedArrayMapConditional(
617 ElementsKind expected_kind,
618 ElementsKind transitioned_kind,
619 Register map_in_out,
620 Register scratch,
621 Label* no_map_match);
622
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000623 void LoadNativeContextSlot(int index, Register dst);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800624
625 // Load the initial map from the global function. The registers
626 // function and map can be the same, function is then overwritten.
627 void LoadGlobalFunctionInitialMap(Register function,
628 Register map,
629 Register scratch);
630
Ben Murdochc7cc0282012-03-05 14:35:55 +0000631 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100632 ExternalReference roots_array_start =
633 ExternalReference::roots_array_start(isolate());
634 mov(kRootRegister, Operand(roots_array_start));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000635 }
636
Steve Blocka7e24c12009-10-30 11:49:00 +0000637 // ---------------------------------------------------------------------------
638 // JavaScript invokes
639
640 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000641 void InvokeFunctionCode(Register function, Register new_target,
642 const ParameterCount& expected,
643 const ParameterCount& actual, InvokeFlag flag,
644 const CallWrapper& call_wrapper);
645
646 void FloodFunctionIfStepping(Register fun, Register new_target,
647 const ParameterCount& expected,
648 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000649
650 // Invoke the JavaScript function in the given register. Changes the
651 // current context to the context in the function before invoking.
652 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000653 Register new_target,
Steve Blocka7e24c12009-10-30 11:49:00 +0000654 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100655 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000657
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000658 void InvokeFunction(Register function,
659 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000660 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000661 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000662 const CallWrapper& call_wrapper);
663
664 void InvokeFunction(Handle<JSFunction> function,
665 const ParameterCount& expected,
666 const ParameterCount& actual,
667 InvokeFlag flag,
668 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000669
Ben Murdochb0fe1622011-05-05 13:52:32 +0100670 void IsObjectJSStringType(Register object,
671 Register scratch,
672 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000673
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000674 void IsObjectNameType(Register object,
675 Register scratch,
676 Label* fail);
677
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 // ---------------------------------------------------------------------------
679 // Debugger Support
680
Andrei Popescu402d9372010-02-26 13:31:12 +0000681 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000682
683 // ---------------------------------------------------------------------------
684 // Exception handling
685
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000686 // Push a new stack handler and link into stack handler chain.
687 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000688
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689 // Unlink the stack handler on top of the stack from the stack handler chain.
Leon Clarkee46be812010-01-19 14:06:41 +0000690 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000691 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100692
Steve Blocka7e24c12009-10-30 11:49:00 +0000693 // ---------------------------------------------------------------------------
694 // Inline caching support
695
Steve Blocka7e24c12009-10-30 11:49:00 +0000696 // Generate code for checking access rights - used for security checks
697 // on access to global objects across environments. The holder register
698 // is left untouched, whereas both scratch registers are clobbered.
699 void CheckAccessGlobalProxy(Register holder_reg,
700 Register scratch,
701 Label* miss);
702
Ben Murdochc7cc0282012-03-05 14:35:55 +0000703 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000704
705 void LoadFromNumberDictionary(Label* miss,
706 Register elements,
707 Register key,
708 Register result,
709 Register t0,
710 Register t1,
711 Register t2);
712
713
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800714 inline void MarkCode(NopMarkerTypes type) {
715 nop(type);
716 }
717
718 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100719 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800720 // These instructions are generated to mark special location in the code,
721 // like some special IC code.
722 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800724 return IsNop(instr, type);
725 }
726
727
728 static inline int GetCodeMarker(Instr instr) {
729 int dst_reg_offset = 12;
730 int dst_mask = 0xf << dst_reg_offset;
731 int src_mask = 0xf;
732 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
733 int src_reg = instr & src_mask;
734 uint32_t non_register_mask = ~(dst_mask | src_mask);
735 uint32_t mov_mask = al | 13 << 21;
736
737 // Return <n> if we have a mov rn rn, else return -1.
738 int type = ((instr & non_register_mask) == mov_mask) &&
739 (dst_reg == src_reg) &&
740 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
741 ? src_reg
742 : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000743 DCHECK((type == -1) ||
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800744 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
745 return type;
746 }
747
Steve Blocka7e24c12009-10-30 11:49:00 +0000748
749 // ---------------------------------------------------------------------------
750 // Allocation support
751
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000752 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000753 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
754 // is passed. If the space is exhausted control continues at the gc_required
755 // label. The allocated object is returned in result. If the flag
756 // tag_allocated_object is true the result is tagged as as a heap object.
757 // All registers are clobbered also when control continues at the gc_required
758 // label.
759 void Allocate(int object_size,
760 Register result,
761 Register scratch1,
762 Register scratch2,
763 Label* gc_required,
764 AllocationFlags flags);
765
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000766 void Allocate(Register object_size, Register result, Register result_end,
767 Register scratch, Label* gc_required, AllocationFlags flags);
Andrei Popescu31002712010-02-23 13:46:05 +0000768
769 void AllocateTwoByteString(Register result,
770 Register length,
771 Register scratch1,
772 Register scratch2,
773 Register scratch3,
774 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000775 void AllocateOneByteString(Register result, Register length,
776 Register scratch1, Register scratch2,
777 Register scratch3, Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000778 void AllocateTwoByteConsString(Register result,
779 Register length,
780 Register scratch1,
781 Register scratch2,
782 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000783 void AllocateOneByteConsString(Register result, Register length,
784 Register scratch1, Register scratch2,
785 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000786 void AllocateTwoByteSlicedString(Register result,
787 Register length,
788 Register scratch1,
789 Register scratch2,
790 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791 void AllocateOneByteSlicedString(Register result, Register length,
792 Register scratch1, Register scratch2,
793 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000794
Kristian Monsen25f61362010-05-21 11:50:48 +0100795 // Allocates a heap number or jumps to the gc_required label if the young
796 // space is full and a scavenge is needed. All registers are clobbered also
797 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100798 void AllocateHeapNumber(Register result,
799 Register scratch1,
800 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100801 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 Label* gc_required,
803 TaggingMode tagging_mode = TAG_RESULT,
804 MutableMode mode = IMMUTABLE);
Steve Block8defd9f2010-07-08 12:39:36 +0100805 void AllocateHeapNumberWithValue(Register result,
806 DwVfpRegister value,
807 Register scratch1,
808 Register scratch2,
809 Register heap_number_map,
810 Label* gc_required);
811
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000812 // Allocate and initialize a JSValue wrapper with the specified {constructor}
813 // and {value}.
814 void AllocateJSValue(Register result, Register constructor, Register value,
815 Register scratch1, Register scratch2,
816 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000817
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100818 // Copies a number of bytes from src to dst. All registers are clobbered. On
819 // exit src and dst will point to the place just after where the last byte was
820 // read or written and length will be zero.
821 void CopyBytes(Register src,
822 Register dst,
823 Register length,
824 Register scratch);
825
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000826 // Initialize fields with filler values. Fields starting at |current_address|
827 // not including |end_address| are overwritten with the value in |filler|. At
828 // the end the loop, |current_address| takes the value of |end_address|.
829 void InitializeFieldsWithFiller(Register current_address,
830 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100831
Steve Blocka7e24c12009-10-30 11:49:00 +0000832 // ---------------------------------------------------------------------------
833 // Support functions.
834
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000835 // Machine code version of Map::GetConstructor().
836 // |temp| holds |result|'s map when done, and |temp2| its instance type.
837 void GetMapConstructor(Register result, Register map, Register temp,
838 Register temp2);
839
Steve Blocka7e24c12009-10-30 11:49:00 +0000840 // Try to get function prototype of a function and puts the value in
841 // the result register. Checks that the function really is a
842 // function and jumps to the miss label if the fast checks fail. The
843 // function register will be untouched; the other registers may be
844 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000845 void TryGetFunctionPrototype(Register function, Register result,
846 Register scratch, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000847
848 // Compare object type for heap object. heap_object contains a non-Smi
849 // whose object type should be compared with the given type. This both
850 // sets the flags and leaves the object type in the type_reg register.
851 // It leaves the map in the map register (unless the type_reg and map register
852 // are the same register). It leaves the heap object in the heap_object
853 // register unless the heap_object register is the same register as one of the
854 // other registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000855 // Type_reg can be no_reg. In that case ip is used.
Steve Blocka7e24c12009-10-30 11:49:00 +0000856 void CompareObjectType(Register heap_object,
857 Register map,
858 Register type_reg,
859 InstanceType type);
860
861 // Compare instance type in a map. map contains a valid map object whose
862 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000863 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000864 void CompareInstanceType(Register map,
865 Register type_reg,
866 InstanceType type);
867
Andrei Popescu31002712010-02-23 13:46:05 +0000868
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000869 // Check if a map for a JSObject indicates that the object has fast elements.
870 // Jump to the specified label if it does not.
871 void CheckFastElements(Register map,
872 Register scratch,
873 Label* fail);
874
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100875 // Check if a map for a JSObject indicates that the object can have both smi
876 // and HeapObject elements. Jump to the specified label if it does not.
877 void CheckFastObjectElements(Register map,
878 Register scratch,
879 Label* fail);
880
881 // Check if a map for a JSObject indicates that the object has fast smi only
882 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000883 void CheckFastSmiElements(Register map,
884 Register scratch,
885 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100886
887 // Check to see if maybe_number can be stored as a double in
888 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000889 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100890 void StoreNumberToDoubleElements(Register value_reg,
891 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100892 Register elements_reg,
893 Register scratch1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000894 LowDwVfpRegister double_scratch,
895 Label* fail,
896 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100897
898 // Compare an object's map with the specified map and its transitioned
899 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
900 // set with result of map compare. If multiple map compares are required, the
901 // compare sequences branches to early_success.
902 void CompareMap(Register obj,
903 Register scratch,
904 Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 Label* early_success);
906
907 // As above, but the map of the object is already loaded into the register
908 // which is preserved by the code generated.
909 void CompareMap(Register obj_map,
910 Handle<Map> map,
911 Label* early_success);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100912
913 // Check if the map of an object is equal to a specified map and branch to
914 // label if not. Skip the smi check if not required (object is known to be a
915 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
916 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +0000917 void CheckMap(Register obj,
918 Register scratch,
919 Handle<Map> map,
920 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000921 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000922
Andrei Popescu31002712010-02-23 13:46:05 +0000923
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100924 void CheckMap(Register obj,
925 Register scratch,
926 Heap::RootListIndex index,
927 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000928 SmiCheckType smi_check_type);
929
930
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400931 // Check if the map of an object is equal to a specified weak map and branch
932 // to a specified target if equal. Skip the smi check if not required
933 // (object is known to be a heap object)
934 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
935 Handle<WeakCell> cell, Handle<Code> success,
936 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100937
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400938 // Compare the given value and the value of weak cell.
939 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
940
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000941 void GetWeakValue(Register value, Handle<WeakCell> cell);
942
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400943 // Load the value of the weak cell in the value register. Branch to the given
944 // miss label if the weak cell was cleared.
945 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100946
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100947 // Compare the object in a register to a value from the root list.
948 // Uses the ip register as scratch.
949 void CompareRoot(Register obj, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000950 void PushRoot(Heap::RootListIndex index) {
951 LoadRoot(ip, index);
952 Push(ip);
953 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100954
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000955 // Compare the object in a register to a value and jump if they are equal.
956 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
957 CompareRoot(with, index);
958 b(eq, if_equal);
959 }
960
961 // Compare the object in a register to a value and jump if they are not equal.
962 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
963 Label* if_not_equal) {
964 CompareRoot(with, index);
965 b(ne, if_not_equal);
966 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100967
Andrei Popescu31002712010-02-23 13:46:05 +0000968 // Load and check the instance type of an object for being a string.
969 // Loads the type into the second argument register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000970 // Returns a condition that will be enabled if the object was a string
971 // and the passed-in condition passed. If the passed-in condition failed
972 // then flags remain unchanged.
Andrei Popescu31002712010-02-23 13:46:05 +0000973 Condition IsObjectStringType(Register obj,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000974 Register type,
975 Condition cond = al) {
976 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond);
977 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond);
978 tst(type, Operand(kIsNotStringMask), cond);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000979 DCHECK_EQ(0u, kStringTag);
Andrei Popescu31002712010-02-23 13:46:05 +0000980 return eq;
981 }
982
983
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100984 // Picks out an array index from the hash field.
985 // Register use:
986 // hash - holds the index's hash. Clobbered.
987 // index - holds the overwritten index on exit.
988 void IndexFromHash(Register hash, Register index);
989
Andrei Popescu31002712010-02-23 13:46:05 +0000990 // Get the number of least significant bits from a register
991 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100992 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000993
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000994 // Load the value of a smi object into a double register.
995 // The register value must be between d0 and d15.
996 void SmiToDouble(LowDwVfpRegister value, Register smi);
Steve Blockd0582a62009-12-15 09:54:21 +0000997
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000998 // Check if a double can be exactly represented as a signed 32-bit integer.
999 // Z flag set to one if true.
1000 void TestDoubleIsInt32(DwVfpRegister double_input,
1001 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 // Try to convert a double to a signed 32-bit integer.
1004 // Z flag set to one and result assigned if the conversion is exact.
1005 void TryDoubleToInt32Exact(Register result,
1006 DwVfpRegister double_input,
1007 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001009 // Floor a double and writes the value to the result register.
1010 // Go to exact if the conversion is exact (to be able to test -0),
1011 // fall through calling code if an overflow occurred, else go to done.
1012 // In return, input_high is loaded with high bits of input.
1013 void TryInt32Floor(Register result,
1014 DwVfpRegister double_input,
1015 Register input_high,
1016 LowDwVfpRegister double_scratch,
1017 Label* done,
1018 Label* exact);
Iain Merrick9ac36c92010-09-13 15:29:50 +01001019
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020 // Performs a truncating conversion of a floating point number as used by
1021 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
1022 // succeeds, otherwise falls through if result is saturated. On return
1023 // 'result' either holds answer, or is clobbered on fall through.
1024 //
1025 // Only public for the test code in test-code-stubs-arm.cc.
1026 void TryInlineTruncateDoubleToI(Register result,
1027 DwVfpRegister input,
1028 Label* done);
Steve Block44f0eee2011-05-26 01:26:41 +01001029
1030 // Performs a truncating conversion of a floating point number as used by
1031 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001032 // Exits with 'result' holding the answer.
1033 void TruncateDoubleToI(Register result, DwVfpRegister double_input);
Steve Block44f0eee2011-05-26 01:26:41 +01001034
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001035 // Performs a truncating conversion of a heap number as used by
1036 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1037 // must be different registers. Exits with 'result' holding the answer.
1038 void TruncateHeapNumberToI(Register result, Register object);
1039
1040 // Converts the smi or heap number in object to an int32 using the rules
1041 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1042 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1043 // different registers.
1044 void TruncateNumberToI(Register object,
1045 Register result,
1046 Register heap_number_map,
1047 Register scratch1,
1048 Label* not_int32);
1049
1050 // Check whether d16-d31 are available on the CPU. The result is given by the
1051 // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
1052 void CheckFor32DRegs(Register scratch);
1053
1054 // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
1055 // values to location, saving [d0..(d15|d31)].
1056 void SaveFPRegs(Register location, Register scratch);
1057
1058 // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
1059 // values to location, restoring [d0..(d15|d31)].
1060 void RestoreFPRegs(Register location, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001061
1062 // ---------------------------------------------------------------------------
1063 // Runtime calls
1064
1065 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001066 void CallStub(CodeStub* stub,
1067 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1068 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001069
Andrei Popescu31002712010-02-23 13:46:05 +00001070 // Call a code stub.
1071 void TailCallStub(CodeStub* stub, Condition cond = al);
1072
Steve Blocka7e24c12009-10-30 11:49:00 +00001073 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074 void CallRuntime(const Runtime::Function* f,
1075 int num_arguments,
1076 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001077 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1078 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001079 CallRuntime(function, function->nargs, kSaveFPRegs);
1080 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001081
1082 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001083 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001084 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001085 const Runtime::Function* function = Runtime::FunctionForId(fid);
1086 CallRuntime(function, function->nargs, save_doubles);
1087 }
1088
1089 // Convenience function: Same as above, but takes the fid instead.
1090 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1091 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1092 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001093 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001094
Andrei Popescu402d9372010-02-26 13:31:12 +00001095 // Convenience function: call an external reference.
1096 void CallExternalReference(const ExternalReference& ext,
1097 int num_arguments);
1098
Steve Block6ded16b2010-05-10 14:33:55 +01001099 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001100 void TailCallRuntime(Runtime::FunctionId fid);
Steve Blocka7e24c12009-10-30 11:49:00 +00001101
Ben Murdoch257744e2011-11-30 15:57:28 +00001102 int CalculateStackPassedWords(int num_reg_arguments,
1103 int num_double_arguments);
1104
Steve Block6ded16b2010-05-10 14:33:55 +01001105 // Before calling a C-function from generated code, align arguments on stack.
1106 // After aligning the frame, non-register arguments must be stored in
1107 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +00001108 // are word sized. If double arguments are used, this function assumes that
1109 // all double arguments are stored before core registers; otherwise the
1110 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +01001111 // Some compilers/platforms require the stack to be aligned when calling
1112 // C++ code.
1113 // Needs a scratch register to do some arithmetic. This register will be
1114 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +00001115 void PrepareCallCFunction(int num_reg_arguments,
1116 int num_double_registers,
1117 Register scratch);
1118 void PrepareCallCFunction(int num_reg_arguments,
1119 Register scratch);
1120
1121 // There are two ways of passing double arguments on ARM, depending on
1122 // whether soft or hard floating point ABI is used. These functions
1123 // abstract parameter passing for the three different ways we call
1124 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001125 void MovToFloatParameter(DwVfpRegister src);
1126 void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
1127 void MovToFloatResult(DwVfpRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001128
1129 // Calls a C function and cleans up the space for arguments allocated
1130 // by PrepareCallCFunction. The called function is not allowed to trigger a
1131 // garbage collection, since that might move the code and invalidate the
1132 // return address (unless this is somehow accounted for by the called
1133 // function).
1134 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001135 void CallCFunction(Register function, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001136 void CallCFunction(ExternalReference function,
1137 int num_reg_arguments,
1138 int num_double_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001139 void CallCFunction(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001140 int num_reg_arguments,
1141 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01001142
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001143 void MovFromFloatParameter(DwVfpRegister dst);
1144 void MovFromFloatResult(DwVfpRegister dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001145
Steve Blocka7e24c12009-10-30 11:49:00 +00001146 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001147 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +00001148
Ben Murdoch8b112d22011-06-08 16:22:53 +01001149 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001150 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001151 return code_object_;
1152 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001153
1154
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001155 // Emit code for a truncating division by a constant. The dividend register is
1156 // unchanged and ip gets clobbered. Dividend and result must be different.
1157 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1158
Steve Blocka7e24c12009-10-30 11:49:00 +00001159 // ---------------------------------------------------------------------------
1160 // StatsCounter support
1161
1162 void SetCounter(StatsCounter* counter, int value,
1163 Register scratch1, Register scratch2);
1164 void IncrementCounter(StatsCounter* counter, int value,
1165 Register scratch1, Register scratch2);
1166 void DecrementCounter(StatsCounter* counter, int value,
1167 Register scratch1, Register scratch2);
1168
1169
1170 // ---------------------------------------------------------------------------
1171 // Debugging
1172
Steve Block1e0659c2011-05-24 12:43:12 +01001173 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +00001174 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001175 void Assert(Condition cond, BailoutReason reason);
Iain Merrick75681382010-08-19 15:07:18 +01001176 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00001177
1178 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001179 void Check(Condition cond, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001180
1181 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001182 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001183
1184 // Verify restrictions about code generated in stubs.
1185 void set_generating_stub(bool value) { generating_stub_ = value; }
1186 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001187 void set_has_frame(bool value) { has_frame_ = value; }
1188 bool has_frame() { return has_frame_; }
1189 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001190
Ben Murdoch257744e2011-11-30 15:57:28 +00001191 // EABI variant for double arguments in use.
1192 bool use_eabi_hardfloat() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001193#ifdef __arm__
1194 return base::OS::ArmUsingHardFloat();
1195#elif USE_EABI_HARDFLOAT
Ben Murdoch257744e2011-11-30 15:57:28 +00001196 return true;
1197#else
1198 return false;
1199#endif
1200 }
1201
Leon Clarked91b9f72010-01-27 17:25:45 +00001202 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +01001203 // Number utilities
1204
1205 // Check whether the value of reg is a power of two and not zero. If not
1206 // control continues at the label not_power_of_two. If reg is a power of two
1207 // the register scratch contains the value of (reg - 1) when control falls
1208 // through.
1209 void JumpIfNotPowerOfTwoOrZero(Register reg,
1210 Register scratch,
1211 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +01001212 // Check whether the value of reg is a power of two and not zero.
1213 // Control falls through if it is, with scratch containing the mask
1214 // value (reg - 1).
1215 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1216 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1217 // strictly positive but not a power of two.
1218 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1219 Register scratch,
1220 Label* zero_and_neg,
1221 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +01001222
1223 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001224 // Smi utilities
1225
Ben Murdochb0fe1622011-05-05 13:52:32 +01001226 void SmiTag(Register reg, SBit s = LeaveCC) {
1227 add(reg, reg, Operand(reg), s);
1228 }
Steve Block1e0659c2011-05-24 12:43:12 +01001229 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1230 add(dst, src, Operand(src), s);
1231 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001232
Ben Murdochb8e0da22011-05-16 14:20:40 +01001233 // Try to convert int32 to smi. If the value is to large, preserve
1234 // the original value and jump to not_a_smi. Destroys scratch and
1235 // sets flags.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001236 void TrySmiTag(Register reg, Label* not_a_smi) {
1237 TrySmiTag(reg, reg, not_a_smi);
1238 }
1239 void TrySmiTag(Register reg, Register src, Label* not_a_smi) {
1240 SmiTag(ip, src, SetCC);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001241 b(vs, not_a_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001242 mov(reg, ip);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001243 }
1244
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001245
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001246 void SmiUntag(Register reg, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001247 mov(reg, Operand::SmiUntag(reg), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001248 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001249 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001250 mov(dst, Operand::SmiUntag(src), s);
Steve Block1e0659c2011-05-24 12:43:12 +01001251 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001252
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001253 // Untag the source value into destination and jump if source is a smi.
1254 // Souce and destination can be the same register.
1255 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1256
1257 // Untag the source value into destination and jump if source is not a smi.
1258 // Souce and destination can be the same register.
1259 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1260
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001261 // Test if the register contains a smi (Z == 0 (eq) if true).
1262 inline void SmiTst(Register value) {
1263 tst(value, Operand(kSmiTagMask));
1264 }
1265 inline void NonNegativeSmiTst(Register value) {
1266 tst(value, Operand(kSmiTagMask | kSmiSignMask));
1267 }
1268 // Jump if the register contains a smi.
Steve Block1e0659c2011-05-24 12:43:12 +01001269 inline void JumpIfSmi(Register value, Label* smi_label) {
1270 tst(value, Operand(kSmiTagMask));
1271 b(eq, smi_label);
1272 }
1273 // Jump if either of the registers contain a non-smi.
1274 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1275 tst(value, Operand(kSmiTagMask));
1276 b(ne, not_smi_label);
1277 }
Andrei Popescu31002712010-02-23 13:46:05 +00001278 // Jump if either of the registers contain a non-smi.
1279 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1280 // Jump if either of the registers contain a smi.
1281 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1282
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001283 // Abort execution if argument is a smi, enabled via --debug-code.
1284 void AssertNotSmi(Register object);
1285 void AssertSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +01001286
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001287 // Abort execution if argument is not a string, enabled via --debug-code.
1288 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001289
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001290 // Abort execution if argument is not a name, enabled via --debug-code.
1291 void AssertName(Register object);
1292
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001293 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1294 void AssertFunction(Register object);
1295
1296 // Abort execution if argument is not a JSBoundFunction,
1297 // enabled via --debug-code.
1298 void AssertBoundFunction(Register object);
1299
Ben Murdoch097c5b22016-05-18 11:27:45 +01001300 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1301 void AssertReceiver(Register object);
1302
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001303 // Abort execution if argument is not undefined or an AllocationSite, enabled
1304 // via --debug-code.
1305 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1306
1307 // Abort execution if reg is not the root value with the given index,
1308 // enabled via --debug-code.
1309 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block1e0659c2011-05-24 12:43:12 +01001310
1311 // ---------------------------------------------------------------------------
1312 // HeapNumber utilities
1313
1314 void JumpIfNotHeapNumber(Register object,
1315 Register heap_number_map,
1316 Register scratch,
1317 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +01001318
Andrei Popescu31002712010-02-23 13:46:05 +00001319 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +00001320 // String utilities
1321
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001322 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001323 // if either is not. Assumes that neither object is a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001324 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register object1,
1325 Register object2,
1326 Register scratch1,
1327 Register scratch2,
1328 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001329
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001330 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001331 // if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001332 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1333 Register scratch1,
1334 Register scratch2,
1335 Label* not_flat_one_byte_strings);
Leon Clarked91b9f72010-01-27 17:25:45 +00001336
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001337 // Checks if both instance types are sequential one-byte strings and jumps to
Steve Block6ded16b2010-05-10 14:33:55 +01001338 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001339 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1340 Register first_object_instance_type, Register second_object_instance_type,
1341 Register scratch1, Register scratch2, Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001342
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001343 // Check if instance type is sequential one-byte string and jump to label if
Steve Block6ded16b2010-05-10 14:33:55 +01001344 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001345 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1346 Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001347
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001348 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1349
1350 void EmitSeqStringSetCharCheck(Register string,
1351 Register index,
1352 Register value,
1353 uint32_t encoding_mask);
Steve Block6ded16b2010-05-10 14:33:55 +01001354
Steve Block1e0659c2011-05-24 12:43:12 +01001355
Ben Murdoch257744e2011-11-30 15:57:28 +00001356 void ClampUint8(Register output_reg, Register input_reg);
1357
1358 void ClampDoubleToUint8(Register result_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001359 DwVfpRegister input_reg,
1360 LowDwVfpRegister double_scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001361
1362
1363 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001364 void EnumLength(Register dst, Register map);
1365 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001366 void LoadAccessor(Register dst, Register holder, int accessor_index,
1367 AccessorComponent accessor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001368
1369 template<typename Field>
1370 void DecodeField(Register dst, Register src) {
1371 Ubfx(dst, src, Field::kShift, Field::kSize);
1372 }
1373
1374 template<typename Field>
1375 void DecodeField(Register reg) {
1376 DecodeField<Field>(reg, reg);
1377 }
1378
1379 template<typename Field>
1380 void DecodeFieldToSmi(Register dst, Register src) {
1381 static const int shift = Field::kShift;
1382 static const int mask = Field::kMask >> shift << kSmiTagSize;
1383 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1384 STATIC_ASSERT(kSmiTag == 0);
1385 if (shift < kSmiTagSize) {
1386 mov(dst, Operand(src, LSL, kSmiTagSize - shift));
1387 and_(dst, dst, Operand(mask));
1388 } else if (shift > kSmiTagSize) {
1389 mov(dst, Operand(src, LSR, shift - kSmiTagSize));
1390 and_(dst, dst, Operand(mask));
1391 } else {
1392 and_(dst, src, Operand(mask));
1393 }
1394 }
1395
1396 template<typename Field>
1397 void DecodeFieldToSmi(Register reg) {
1398 DecodeField<Field>(reg, reg);
1399 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001400
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001401 // Load the type feedback vector from a JavaScript frame.
1402 void EmitLoadTypeFeedbackVector(Register vector);
1403
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001404 // Activation support.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001405 void EnterFrame(StackFrame::Type type,
1406 bool load_constant_pool_pointer_reg = false);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001407 // Returns the pc offset at which the frame ends.
1408 int LeaveFrame(StackFrame::Type type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001409
1410 // Expects object in r0 and returns map with validated enum cache
1411 // in r0. Assumes that any other register can be used as a scratch.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001412 void CheckEnumCache(Label* call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001413
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001414 // AllocationMemento support. Arrays may have an associated
1415 // AllocationMemento object that can be checked for in order to pretransition
1416 // to another type.
1417 // On entry, receiver_reg should point to the array object.
1418 // scratch_reg gets clobbered.
1419 // If allocation info is present, condition flags are set to eq.
1420 void TestJSArrayForAllocationMemento(Register receiver_reg,
1421 Register scratch_reg,
1422 Label* no_memento_found);
1423
1424 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1425 Register scratch_reg,
1426 Label* memento_found) {
1427 Label no_memento_found;
1428 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1429 &no_memento_found);
1430 b(eq, memento_found);
1431 bind(&no_memento_found);
1432 }
1433
1434 // Jumps to found label if a prototype map has dictionary elements.
1435 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1436 Register scratch1, Label* found);
1437
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001438 // Loads the constant pool pointer (pp) register.
1439 void LoadConstantPoolPointerRegisterFromCodeTargetAddress(
1440 Register code_target_address);
1441 void LoadConstantPoolPointerRegister();
1442
Steve Blocka7e24c12009-10-30 11:49:00 +00001443 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001444 void CallCFunctionHelper(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001445 int num_reg_arguments,
1446 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001447
Andrei Popescu31002712010-02-23 13:46:05 +00001448 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001449
1450 // Helper functions for generating invokes.
1451 void InvokePrologue(const ParameterCount& expected,
1452 const ParameterCount& actual,
Steve Blocka7e24c12009-10-30 11:49:00 +00001453 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001454 bool* definitely_mismatches,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001455 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001456 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001457
Steve Block6ded16b2010-05-10 14:33:55 +01001458 void InitializeNewString(Register string,
1459 Register length,
1460 Heap::RootListIndex map_index,
1461 Register scratch1,
1462 Register scratch2);
1463
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001464 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1465 void InNewSpace(Register object,
1466 Register scratch,
1467 Condition cond, // eq for new space, ne otherwise.
1468 Label* branch);
1469
1470 // Helper for finding the mark bits for an address. Afterwards, the
1471 // bitmap register points at the word with the mark bits and the mask
1472 // the position of the first bit. Leaves addr_reg unchanged.
1473 inline void GetMarkBits(Register addr_reg,
1474 Register bitmap_reg,
1475 Register mask_reg);
1476
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001477 // Compute memory operands for safepoint stack slots.
1478 static int SafepointRegisterStackIndex(int reg_code);
1479 MemOperand SafepointRegisterSlot(Register reg);
1480 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1481
Andrei Popescu31002712010-02-23 13:46:05 +00001482 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001483 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +00001484 // This handle will be patched with the code object on installation.
1485 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001486
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001487 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001488 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001489 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001490};
1491
1492
Steve Blocka7e24c12009-10-30 11:49:00 +00001493// The code patcher is used to patch (typically) small parts of code e.g. for
1494// debugging and other types of instrumentation. When using the code patcher
1495// the exact number of bytes specified must be emitted. It is not legal to emit
1496// relocation information. If any of these constraints are violated it causes
1497// an assertion to fail.
1498class CodePatcher {
1499 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001500 enum FlushICache {
1501 FLUSH,
1502 DONT_FLUSH
1503 };
1504
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001505 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001506 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001507 ~CodePatcher();
Steve Blocka7e24c12009-10-30 11:49:00 +00001508
1509 // Macro assembler to emit code.
1510 MacroAssembler* masm() { return &masm_; }
1511
1512 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001513 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001514
1515 // Emit an address directly.
1516 void Emit(Address addr);
1517
Steve Block1e0659c2011-05-24 12:43:12 +01001518 // Emit the condition part of an instruction leaving the rest of the current
1519 // instruction unchanged.
1520 void EmitCondition(Condition cond);
1521
Steve Blocka7e24c12009-10-30 11:49:00 +00001522 private:
1523 byte* address_; // The address of the code being patched.
Steve Blocka7e24c12009-10-30 11:49:00 +00001524 int size_; // Number of bytes of the expected patch size.
1525 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001526 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Blocka7e24c12009-10-30 11:49:00 +00001527};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528
1529
Steve Blocka7e24c12009-10-30 11:49:00 +00001530// -----------------------------------------------------------------------------
1531// Static helper functions.
1532
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001533inline MemOperand ContextMemOperand(Register context, int index = 0) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001534 return MemOperand(context, Context::SlotOffset(index));
1535}
1536
1537
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001538inline MemOperand NativeContextMemOperand() {
1539 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001540}
1541
1542
Steve Blocka7e24c12009-10-30 11:49:00 +00001543#ifdef GENERATED_CODE_COVERAGE
1544#define CODE_COVERAGE_STRINGIFY(x) #x
1545#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1546#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1547#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1548#else
1549#define ACCESS_MASM(masm) masm->
1550#endif
1551
1552
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001553} // namespace internal
1554} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001555
1556#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_