blob: 16dcd47790a6820a65464c8a0799e1ca722e1423 [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};
Ben Murdochc5610432016-08-08 18:44:38 +010022const Register kAllocateSizeRegister = {Register::kCode_r1};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000023const Register kInterpreterAccumulatorRegister = {Register::kCode_r0};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024const 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000104
Andrei Popescu31002712010-02-23 13:46:05 +0000105 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +0000106 void Jump(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000107 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000108 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
109 void Call(Register target, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110 void Call(Address target, RelocInfo::Mode rmode,
111 Condition cond = al,
112 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100113 void Call(Handle<Code> code, RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
114 TypeFeedbackId ast_id = TypeFeedbackId::None(), Condition cond = al,
115 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116 int CallSize(Handle<Code> code,
117 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
118 TypeFeedbackId ast_id = TypeFeedbackId::None(),
119 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000120 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000121
Ben Murdoch61f157c2016-09-16 13:49:30 +0100122 // Used for patching in calls to the deoptimizer.
123 void CallDeoptimizer(Address target);
124 static int CallDeoptimizerSize();
125
Leon Clarkee46be812010-01-19 14:06:41 +0000126 // Emit code to discard a non-negative number of pointer-sized elements
127 // from the stack, clobbering only the sp register.
128 void Drop(int count, Condition cond = al);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100129 void Drop(Register count, Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000130
Ben Murdochb0fe1622011-05-05 13:52:32 +0100131 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100132
133 // Swap two registers. If the scratch register is omitted then a slightly
134 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100135 void Swap(Register reg1,
136 Register reg2,
137 Register scratch = no_reg,
138 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100139
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000140 void Mls(Register dst, Register src1, Register src2, Register srcA,
141 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100142 void And(Register dst, Register src1, const Operand& src2,
143 Condition cond = al);
144 void Ubfx(Register dst, Register src, int lsb, int width,
145 Condition cond = al);
146 void Sbfx(Register dst, Register src, int lsb, int width,
147 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100148 // The scratch register is not used for ARMv7.
149 // scratch can be the same register as src (in which case it is trashed), but
150 // not the same as dst.
151 void Bfi(Register dst,
152 Register src,
153 Register scratch,
154 int lsb,
155 int width,
156 Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157 void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100158
Leon Clarkee46be812010-01-19 14:06:41 +0000159 void Call(Label* target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160 void Push(Register src) { push(src); }
161 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000162
163 // Register move. May do nothing if the registers are identical.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000164 void Move(Register dst, Smi* smi) { mov(dst, Operand(smi)); }
Leon Clarkee46be812010-01-19 14:06:41 +0000165 void Move(Register dst, Handle<Object> value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000166 void Move(Register dst, Register src, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167 void Move(Register dst, const Operand& src, SBit sbit = LeaveCC,
168 Condition cond = al) {
169 if (!src.is_reg() || !src.rm().is(dst) || sbit != LeaveCC) {
170 mov(dst, src, sbit, cond);
171 }
172 }
Ben Murdoch61f157c2016-09-16 13:49:30 +0100173 void Move(SwVfpRegister dst, SwVfpRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174 void Move(DwVfpRegister dst, DwVfpRegister src);
175
176 void Load(Register dst, const MemOperand& src, Representation r);
177 void Store(Register src, const MemOperand& dst, Representation r);
Ben Murdoch257744e2011-11-30 15:57:28 +0000178
Steve Blocka7e24c12009-10-30 11:49:00 +0000179 // Load an object from the root table.
180 void LoadRoot(Register destination,
181 Heap::RootListIndex index,
182 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100183 // Store an object to the root table.
184 void StoreRoot(Register source,
185 Heap::RootListIndex index,
186 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100188 // ---------------------------------------------------------------------------
189 // GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100190
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100191 void IncrementalMarkingRecordWriteHelper(Register object,
192 Register value,
193 Register address);
Steve Block6ded16b2010-05-10 14:33:55 +0100194
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100195 enum RememberedSetFinalAction {
196 kReturnAtEnd,
197 kFallThroughAtEnd
198 };
199
200 // Record in the remembered set the fact that we have a pointer to new space
201 // at the address pointed to by the addr register. Only works if addr is not
202 // in new space.
203 void RememberedSetHelper(Register object, // Used for debug code.
204 Register addr,
205 Register scratch,
206 SaveFPRegsMode save_fp,
207 RememberedSetFinalAction and_then);
208
209 void CheckPageFlag(Register object,
210 Register scratch,
211 int mask,
212 Condition cc,
213 Label* condition_met);
214
215 // Check if object is in new space. Jumps if the object is not in new space.
216 // The register scratch can be object itself, but scratch will be clobbered.
217 void JumpIfNotInNewSpace(Register object,
218 Register scratch,
219 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100220 InNewSpace(object, scratch, eq, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100221 }
222
223 // Check if object is in new space. Jumps if the object is in new space.
224 // The register scratch can be object itself, but it will be clobbered.
225 void JumpIfInNewSpace(Register object,
226 Register scratch,
227 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100228 InNewSpace(object, scratch, ne, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100229 }
230
231 // Check if an object has a given incremental marking color.
232 void HasColor(Register object,
233 Register scratch0,
234 Register scratch1,
235 Label* has_color,
236 int first_bit,
237 int second_bit);
238
239 void JumpIfBlack(Register object,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100240 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100241 Register scratch1,
242 Label* on_black);
Steve Blocka7e24c12009-10-30 11:49:00 +0000243
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000244 // Checks the color of an object. If the object is white we jump to the
245 // incremental marker.
246 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
247 Register scratch3, Label* value_is_white);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100248
249 // Notify the garbage collector that we wrote a pointer into an object.
250 // |object| is the object being stored into, |value| is the object being
251 // stored. value and scratch registers are clobbered by the operation.
252 // The offset is the offset from the start of the object, not the offset from
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000253 // the tagged HeapObject pointer. For use with FieldMemOperand(reg, off).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100254 void RecordWriteField(
255 Register object,
256 int offset,
257 Register value,
258 Register scratch,
259 LinkRegisterStatus lr_status,
260 SaveFPRegsMode save_fp,
261 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262 SmiCheck smi_check = INLINE_SMI_CHECK,
263 PointersToHereCheck pointers_to_here_check_for_value =
264 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100265
266 // As above, but the offset has the tag presubtracted. For use with
267 // MemOperand(reg, off).
268 inline void RecordWriteContextSlot(
269 Register context,
270 int offset,
271 Register value,
272 Register scratch,
273 LinkRegisterStatus lr_status,
274 SaveFPRegsMode save_fp,
275 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 SmiCheck smi_check = INLINE_SMI_CHECK,
277 PointersToHereCheck pointers_to_here_check_for_value =
278 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100279 RecordWriteField(context,
280 offset + kHeapObjectTag,
281 value,
282 scratch,
283 lr_status,
284 save_fp,
285 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 smi_check,
287 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100288 }
289
Ben Murdoch097c5b22016-05-18 11:27:45 +0100290 // Notify the garbage collector that we wrote a code entry into a
291 // JSFunction. Only scratch is clobbered by the operation.
292 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
293 Register scratch);
294
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000295 void RecordWriteForMap(
296 Register object,
297 Register map,
298 Register dst,
299 LinkRegisterStatus lr_status,
300 SaveFPRegsMode save_fp);
301
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100302 // For a given |object| notify the garbage collector that the slot |address|
303 // has been written. |value| is the object being stored. The value and
304 // address registers are clobbered by the operation.
305 void RecordWrite(
306 Register object,
307 Register address,
308 Register value,
309 LinkRegisterStatus lr_status,
310 SaveFPRegsMode save_fp,
311 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312 SmiCheck smi_check = INLINE_SMI_CHECK,
313 PointersToHereCheck pointers_to_here_check_for_value =
314 kPointersToHereMaybeInteresting);
Steve Block8defd9f2010-07-08 12:39:36 +0100315
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000316 // Push a handle.
317 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000318 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000319
Steve Block6ded16b2010-05-10 14:33:55 +0100320 // Push two registers. Pushes leftmost register first (to highest address).
321 void Push(Register src1, Register src2, Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100322 if (src1.code() > src2.code()) {
323 stm(db_w, sp, src1.bit() | src2.bit(), cond);
324 } else {
325 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
326 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
327 }
328 }
329
330 // Push three registers. Pushes leftmost register first (to highest address).
331 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100332 if (src1.code() > src2.code()) {
333 if (src2.code() > src3.code()) {
334 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
335 } else {
336 stm(db_w, sp, src1.bit() | src2.bit(), cond);
337 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
338 }
339 } else {
340 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
341 Push(src2, src3, cond);
342 }
343 }
344
345 // Push four registers. Pushes leftmost register first (to highest address).
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100346 void Push(Register src1,
347 Register src2,
348 Register src3,
349 Register src4,
350 Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100351 if (src1.code() > src2.code()) {
352 if (src2.code() > src3.code()) {
353 if (src3.code() > src4.code()) {
354 stm(db_w,
355 sp,
356 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
357 cond);
358 } else {
359 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
360 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
361 }
362 } else {
363 stm(db_w, sp, src1.bit() | src2.bit(), cond);
364 Push(src3, src4, cond);
365 }
366 } else {
367 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
368 Push(src2, src3, src4, cond);
369 }
370 }
371
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372 // Push five registers. Pushes leftmost register first (to highest address).
373 void Push(Register src1, Register src2, Register src3, Register src4,
374 Register src5, Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000375 if (src1.code() > src2.code()) {
376 if (src2.code() > src3.code()) {
377 if (src3.code() > src4.code()) {
378 if (src4.code() > src5.code()) {
379 stm(db_w, sp,
380 src1.bit() | src2.bit() | src3.bit() | src4.bit() | src5.bit(),
381 cond);
382 } else {
383 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit() | src4.bit(),
384 cond);
385 str(src5, MemOperand(sp, 4, NegPreIndex), cond);
386 }
387 } else {
388 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
389 Push(src4, src5, cond);
390 }
391 } else {
392 stm(db_w, sp, src1.bit() | src2.bit(), cond);
393 Push(src3, src4, src5, cond);
394 }
395 } else {
396 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
397 Push(src2, src3, src4, src5, cond);
398 }
399 }
400
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100401 // Pop two registers. Pops rightmost register first (from lower address).
402 void Pop(Register src1, Register src2, Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403 DCHECK(!src1.is(src2));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100404 if (src1.code() > src2.code()) {
405 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
406 } else {
407 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
408 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
409 }
410 }
411
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100412 // Pop three registers. Pops rightmost register first (from lower address).
413 void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000414 DCHECK(!AreAliased(src1, src2, src3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100415 if (src1.code() > src2.code()) {
416 if (src2.code() > src3.code()) {
417 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
418 } else {
419 ldr(src3, MemOperand(sp, 4, PostIndex), cond);
420 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
421 }
422 } else {
423 Pop(src2, src3, cond);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000424 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100425 }
426 }
427
428 // Pop four registers. Pops rightmost register first (from lower address).
429 void Pop(Register src1,
430 Register src2,
431 Register src3,
432 Register src4,
433 Condition cond = al) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434 DCHECK(!AreAliased(src1, src2, src3, src4));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100435 if (src1.code() > src2.code()) {
436 if (src2.code() > src3.code()) {
437 if (src3.code() > src4.code()) {
438 ldm(ia_w,
439 sp,
440 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
441 cond);
442 } else {
443 ldr(src4, MemOperand(sp, 4, PostIndex), cond);
444 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
445 }
446 } else {
447 Pop(src3, src4, cond);
448 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
449 }
450 } else {
451 Pop(src2, src3, src4, cond);
452 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
453 }
454 }
455
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 // Push a fixed frame, consisting of lr, fp, constant pool (if
Ben Murdochda12d292016-06-02 14:46:10 +0100457 // FLAG_enable_embedded_constant_pool)
458 void PushCommonFrame(Register marker_reg = no_reg);
459
460 // Push a standard frame, consisting of lr, fp, constant pool (if
461 // FLAG_enable_embedded_constant_pool), context and JS function
462 void PushStandardFrame(Register function_reg);
463
464 void PopCommonFrame(Register marker_reg = no_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000465
Ben Murdochb0fe1622011-05-05 13:52:32 +0100466 // Push and pop the registers that can hold pointers, as defined by the
467 // RegList constant kSafepointSavedRegisters.
468 void PushSafepointRegisters();
469 void PopSafepointRegisters();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100470 // Store value in register src in the safepoint stack slot for
471 // register dst.
472 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100473 // Load the value of the src register from its safepoint stack slot
474 // into register dst.
475 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100476
Leon Clarkef7060e22010-06-03 12:02:55 +0100477 // Load two consecutive registers with two consecutive memory locations.
478 void Ldrd(Register dst1,
479 Register dst2,
480 const MemOperand& src,
481 Condition cond = al);
482
483 // Store two consecutive registers to two consecutive memory locations.
484 void Strd(Register src1,
485 Register src2,
486 const MemOperand& dst,
487 Condition cond = al);
488
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000489 // If the value is a NaN, canonicalize the value else, do nothing.
490 void VFPCanonicalizeNaN(const DwVfpRegister dst,
491 const DwVfpRegister src,
492 const Condition cond = al);
493 void VFPCanonicalizeNaN(const DwVfpRegister value,
494 const Condition cond = al) {
495 VFPCanonicalizeNaN(value, value, cond);
496 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100497
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000498 // Compare single values and move the result to the normal condition flags.
499 void VFPCompareAndSetFlags(const SwVfpRegister src1, const SwVfpRegister src2,
500 const Condition cond = al);
501 void VFPCompareAndSetFlags(const SwVfpRegister src1, const float src2,
502 const Condition cond = al);
503
Ben Murdochb8e0da22011-05-16 14:20:40 +0100504 // Compare double values and move the result to the normal condition flags.
505 void VFPCompareAndSetFlags(const DwVfpRegister src1,
506 const DwVfpRegister src2,
507 const Condition cond = al);
508 void VFPCompareAndSetFlags(const DwVfpRegister src1,
509 const double src2,
510 const Condition cond = al);
511
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512 // Compare single values and then load the fpscr flags to a register.
513 void VFPCompareAndLoadFlags(const SwVfpRegister src1,
514 const SwVfpRegister src2,
515 const Register fpscr_flags,
516 const Condition cond = al);
517 void VFPCompareAndLoadFlags(const SwVfpRegister src1, const float src2,
518 const Register fpscr_flags,
519 const Condition cond = al);
520
Ben Murdochb8e0da22011-05-16 14:20:40 +0100521 // Compare double values and then load the fpscr flags to a register.
522 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
523 const DwVfpRegister src2,
524 const Register fpscr_flags,
525 const Condition cond = al);
526 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
527 const double src2,
528 const Register fpscr_flags,
529 const Condition cond = al);
530
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000531 void Vmov(const DwVfpRegister dst,
532 const double imm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000533 const Register scratch = no_reg);
534
535 void VmovHigh(Register dst, DwVfpRegister src);
536 void VmovHigh(DwVfpRegister dst, Register src);
537 void VmovLow(Register dst, DwVfpRegister src);
538 void VmovLow(DwVfpRegister dst, Register src);
539
Ben Murdochda12d292016-06-02 14:46:10 +0100540 void LslPair(Register dst_low, Register dst_high, Register src_low,
541 Register src_high, Register scratch, Register shift);
542 void LslPair(Register dst_low, Register dst_high, Register src_low,
543 Register src_high, uint32_t shift);
544 void LsrPair(Register dst_low, Register dst_high, Register src_low,
545 Register src_high, Register scratch, Register shift);
546 void LsrPair(Register dst_low, Register dst_high, Register src_low,
547 Register src_high, uint32_t shift);
548 void AsrPair(Register dst_low, Register dst_high, Register src_low,
549 Register src_high, Register scratch, Register shift);
550 void AsrPair(Register dst_low, Register dst_high, Register src_low,
551 Register src_high, uint32_t shift);
552
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000553 // Loads the number from object into dst register.
554 // If |object| is neither smi nor heap number, |not_number| is jumped to
555 // with |object| still intact.
556 void LoadNumber(Register object,
557 LowDwVfpRegister dst,
558 Register heap_number_map,
559 Register scratch,
560 Label* not_number);
561
562 // Loads the number from object into double_dst in the double format.
563 // Control will jump to not_int32 if the value cannot be exactly represented
564 // by a 32-bit integer.
565 // Floating point value in the 32-bit integer range that are not exact integer
566 // won't be loaded.
567 void LoadNumberAsInt32Double(Register object,
568 DwVfpRegister double_dst,
569 Register heap_number_map,
570 Register scratch,
571 LowDwVfpRegister double_scratch,
572 Label* not_int32);
573
574 // Loads the number from object into dst as a 32-bit integer.
575 // Control will jump to not_int32 if the object 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 converted.
579 void LoadNumberAsInt32(Register object,
580 Register dst,
581 Register heap_number_map,
582 Register scratch,
583 DwVfpRegister double_scratch0,
584 LowDwVfpRegister double_scratch1,
585 Label* not_int32);
586
587 // Generates function and stub prologue code.
Ben Murdochda12d292016-06-02 14:46:10 +0100588 void StubPrologue(StackFrame::Type type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000589 void Prologue(bool code_pre_aging);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000590
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100591 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100592 // stack_space - extra stack space, used for alignment before call to C.
593 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000594
595 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100596 // Expect the number of values, pushed prior to the exit frame, to
597 // remove in a register (or no_reg, if there is nothing to remove).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000598 void LeaveExitFrame(bool save_doubles, Register argument_count,
599 bool restore_context,
600 bool argument_count_is_length = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000601
Steve Block6ded16b2010-05-10 14:33:55 +0100602 // Get the actual activation frame alignment for target environment.
603 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000604
Steve Blockd0582a62009-12-15 09:54:21 +0000605 void LoadContext(Register dst, int context_chain_length);
606
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000607 // Load the global object from the current context.
608 void LoadGlobalObject(Register dst) {
609 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
610 }
611
612 // Load the global proxy from the current context.
613 void LoadGlobalProxy(Register dst) {
614 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
615 }
616
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100617 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000618 // transitioned_kind from the native context if the map in register
619 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100620 // expected_kind.
621 void LoadTransitionedArrayMapConditional(
622 ElementsKind expected_kind,
623 ElementsKind transitioned_kind,
624 Register map_in_out,
625 Register scratch,
626 Label* no_map_match);
627
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000628 void LoadNativeContextSlot(int index, Register dst);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800629
630 // Load the initial map from the global function. The registers
631 // function and map can be the same, function is then overwritten.
632 void LoadGlobalFunctionInitialMap(Register function,
633 Register map,
634 Register scratch);
635
Ben Murdochc7cc0282012-03-05 14:35:55 +0000636 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100637 ExternalReference roots_array_start =
638 ExternalReference::roots_array_start(isolate());
639 mov(kRootRegister, Operand(roots_array_start));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000640 }
641
Steve Blocka7e24c12009-10-30 11:49:00 +0000642 // ---------------------------------------------------------------------------
643 // JavaScript invokes
644
Ben Murdochda12d292016-06-02 14:46:10 +0100645 // Removes current frame and its arguments from the stack preserving
646 // the arguments and a return address pushed to the stack for the next call.
647 // Both |callee_args_count| and |caller_args_count_reg| do not include
648 // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
649 // is trashed.
650 void PrepareForTailCall(const ParameterCount& callee_args_count,
651 Register caller_args_count_reg, Register scratch0,
652 Register scratch1);
653
Steve Blocka7e24c12009-10-30 11:49:00 +0000654 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000655 void InvokeFunctionCode(Register function, Register new_target,
656 const ParameterCount& expected,
657 const ParameterCount& actual, InvokeFlag flag,
658 const CallWrapper& call_wrapper);
659
660 void FloodFunctionIfStepping(Register fun, Register new_target,
661 const ParameterCount& expected,
662 const ParameterCount& actual);
Steve Blocka7e24c12009-10-30 11:49:00 +0000663
664 // Invoke the JavaScript function in the given register. Changes the
665 // current context to the context in the function before invoking.
666 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 Register new_target,
Steve Blocka7e24c12009-10-30 11:49:00 +0000668 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100669 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000670 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000671
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000672 void InvokeFunction(Register function,
673 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000674 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000675 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000676 const CallWrapper& call_wrapper);
677
678 void InvokeFunction(Handle<JSFunction> function,
679 const ParameterCount& expected,
680 const ParameterCount& actual,
681 InvokeFlag flag,
682 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000683
Ben Murdochb0fe1622011-05-05 13:52:32 +0100684 void IsObjectJSStringType(Register object,
685 Register scratch,
686 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000687
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000688 void IsObjectNameType(Register object,
689 Register scratch,
690 Label* fail);
691
Steve Blocka7e24c12009-10-30 11:49:00 +0000692 // ---------------------------------------------------------------------------
693 // Debugger Support
694
Andrei Popescu402d9372010-02-26 13:31:12 +0000695 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000696
697 // ---------------------------------------------------------------------------
698 // Exception handling
699
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000700 // Push a new stack handler and link into stack handler chain.
701 void PushStackHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000702
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000703 // Unlink the stack handler on top of the stack from the stack handler chain.
Leon Clarkee46be812010-01-19 14:06:41 +0000704 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000705 void PopStackHandler();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100706
Steve Blocka7e24c12009-10-30 11:49:00 +0000707 // ---------------------------------------------------------------------------
708 // Inline caching support
709
Steve Blocka7e24c12009-10-30 11:49:00 +0000710 // Generate code for checking access rights - used for security checks
711 // on access to global objects across environments. The holder register
712 // is left untouched, whereas both scratch registers are clobbered.
713 void CheckAccessGlobalProxy(Register holder_reg,
714 Register scratch,
715 Label* miss);
716
Ben Murdochc7cc0282012-03-05 14:35:55 +0000717 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000718
719 void LoadFromNumberDictionary(Label* miss,
720 Register elements,
721 Register key,
722 Register result,
723 Register t0,
724 Register t1,
725 Register t2);
726
727
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800728 inline void MarkCode(NopMarkerTypes type) {
729 nop(type);
730 }
731
732 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100733 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800734 // These instructions are generated to mark special location in the code,
735 // like some special IC code.
736 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000737 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800738 return IsNop(instr, type);
739 }
740
741
742 static inline int GetCodeMarker(Instr instr) {
743 int dst_reg_offset = 12;
744 int dst_mask = 0xf << dst_reg_offset;
745 int src_mask = 0xf;
746 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
747 int src_reg = instr & src_mask;
748 uint32_t non_register_mask = ~(dst_mask | src_mask);
749 uint32_t mov_mask = al | 13 << 21;
750
751 // Return <n> if we have a mov rn rn, else return -1.
752 int type = ((instr & non_register_mask) == mov_mask) &&
753 (dst_reg == src_reg) &&
754 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
755 ? src_reg
756 : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000757 DCHECK((type == -1) ||
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800758 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
759 return type;
760 }
761
Steve Blocka7e24c12009-10-30 11:49:00 +0000762
763 // ---------------------------------------------------------------------------
764 // Allocation support
765
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000766 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000767 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
768 // is passed. If the space is exhausted control continues at the gc_required
769 // label. The allocated object is returned in result. If the flag
770 // tag_allocated_object is true the result is tagged as as a heap object.
771 // All registers are clobbered also when control continues at the gc_required
772 // label.
773 void Allocate(int object_size,
774 Register result,
775 Register scratch1,
776 Register scratch2,
777 Label* gc_required,
778 AllocationFlags flags);
779
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000780 void Allocate(Register object_size, Register result, Register result_end,
781 Register scratch, Label* gc_required, AllocationFlags flags);
Andrei Popescu31002712010-02-23 13:46:05 +0000782
Ben Murdochc5610432016-08-08 18:44:38 +0100783 // FastAllocate is right now only used for folded allocations. It just
784 // increments the top pointer without checking against limit. This can only
785 // be done if it was proved earlier that the allocation will succeed.
786 void FastAllocate(int object_size, Register result, Register scratch1,
787 Register scratch2, AllocationFlags flags);
788
789 void FastAllocate(Register object_size, Register result, Register result_end,
790 Register scratch, AllocationFlags flags);
791
Andrei Popescu31002712010-02-23 13:46:05 +0000792 void AllocateTwoByteString(Register result,
793 Register length,
794 Register scratch1,
795 Register scratch2,
796 Register scratch3,
797 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000798 void AllocateOneByteString(Register result, Register length,
799 Register scratch1, Register scratch2,
800 Register scratch3, Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000801 void AllocateTwoByteConsString(Register result,
802 Register length,
803 Register scratch1,
804 Register scratch2,
805 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000806 void AllocateOneByteConsString(Register result, Register length,
807 Register scratch1, Register scratch2,
808 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000809 void AllocateTwoByteSlicedString(Register result,
810 Register length,
811 Register scratch1,
812 Register scratch2,
813 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000814 void AllocateOneByteSlicedString(Register result, Register length,
815 Register scratch1, Register scratch2,
816 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000817
Kristian Monsen25f61362010-05-21 11:50:48 +0100818 // Allocates a heap number or jumps to the gc_required label if the young
819 // space is full and a scavenge is needed. All registers are clobbered also
820 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100821 void AllocateHeapNumber(Register result,
822 Register scratch1,
823 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100824 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000825 Label* gc_required,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000826 MutableMode mode = IMMUTABLE);
Steve Block8defd9f2010-07-08 12:39:36 +0100827 void AllocateHeapNumberWithValue(Register result,
828 DwVfpRegister value,
829 Register scratch1,
830 Register scratch2,
831 Register heap_number_map,
832 Label* gc_required);
833
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000834 // Allocate and initialize a JSValue wrapper with the specified {constructor}
835 // and {value}.
836 void AllocateJSValue(Register result, Register constructor, Register value,
837 Register scratch1, Register scratch2,
838 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000839
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100840 // Copies a number of bytes from src to dst. All registers are clobbered. On
841 // exit src and dst will point to the place just after where the last byte was
842 // read or written and length will be zero.
843 void CopyBytes(Register src,
844 Register dst,
845 Register length,
846 Register scratch);
847
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000848 // Initialize fields with filler values. Fields starting at |current_address|
849 // not including |end_address| are overwritten with the value in |filler|. At
850 // the end the loop, |current_address| takes the value of |end_address|.
851 void InitializeFieldsWithFiller(Register current_address,
852 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100853
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 // ---------------------------------------------------------------------------
855 // Support functions.
856
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000857 // Machine code version of Map::GetConstructor().
858 // |temp| holds |result|'s map when done, and |temp2| its instance type.
859 void GetMapConstructor(Register result, Register map, Register temp,
860 Register temp2);
861
Steve Blocka7e24c12009-10-30 11:49:00 +0000862 // Try to get function prototype of a function and puts the value in
863 // the result register. Checks that the function really is a
864 // function and jumps to the miss label if the fast checks fail. The
865 // function register will be untouched; the other registers may be
866 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000867 void TryGetFunctionPrototype(Register function, Register result,
868 Register scratch, Label* miss);
Steve Blocka7e24c12009-10-30 11:49:00 +0000869
870 // Compare object type for heap object. heap_object contains a non-Smi
871 // whose object type should be compared with the given type. This both
872 // sets the flags and leaves the object type in the type_reg register.
873 // It leaves the map in the map register (unless the type_reg and map register
874 // are the same register). It leaves the heap object in the heap_object
875 // register unless the heap_object register is the same register as one of the
876 // other registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000877 // Type_reg can be no_reg. In that case ip is used.
Steve Blocka7e24c12009-10-30 11:49:00 +0000878 void CompareObjectType(Register heap_object,
879 Register map,
880 Register type_reg,
881 InstanceType type);
882
883 // Compare instance type in a map. map contains a valid map object whose
884 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000885 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000886 void CompareInstanceType(Register map,
887 Register type_reg,
888 InstanceType type);
889
Andrei Popescu31002712010-02-23 13:46:05 +0000890
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000891 // Check if a map for a JSObject indicates that the object has fast elements.
892 // Jump to the specified label if it does not.
893 void CheckFastElements(Register map,
894 Register scratch,
895 Label* fail);
896
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100897 // Check if a map for a JSObject indicates that the object can have both smi
898 // and HeapObject elements. Jump to the specified label if it does not.
899 void CheckFastObjectElements(Register map,
900 Register scratch,
901 Label* fail);
902
903 // Check if a map for a JSObject indicates that the object has fast smi only
904 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 void CheckFastSmiElements(Register map,
906 Register scratch,
907 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100908
909 // Check to see if maybe_number can be stored as a double in
910 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000911 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100912 void StoreNumberToDoubleElements(Register value_reg,
913 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100914 Register elements_reg,
915 Register scratch1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000916 LowDwVfpRegister double_scratch,
917 Label* fail,
918 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100919
920 // Compare an object's map with the specified map and its transitioned
921 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
922 // set with result of map compare. If multiple map compares are required, the
923 // compare sequences branches to early_success.
924 void CompareMap(Register obj,
925 Register scratch,
926 Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000927 Label* early_success);
928
929 // As above, but the map of the object is already loaded into the register
930 // which is preserved by the code generated.
931 void CompareMap(Register obj_map,
932 Handle<Map> map,
933 Label* early_success);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100934
935 // Check if the map of an object is equal to a specified map and branch to
936 // label if not. Skip the smi check if not required (object is known to be a
937 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
938 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +0000939 void CheckMap(Register obj,
940 Register scratch,
941 Handle<Map> map,
942 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000943 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000944
Andrei Popescu31002712010-02-23 13:46:05 +0000945
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100946 void CheckMap(Register obj,
947 Register scratch,
948 Heap::RootListIndex index,
949 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000950 SmiCheckType smi_check_type);
951
952
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400953 // Check if the map of an object is equal to a specified weak map and branch
954 // to a specified target if equal. Skip the smi check if not required
955 // (object is known to be a heap object)
956 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
957 Handle<WeakCell> cell, Handle<Code> success,
958 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100959
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400960 // Compare the given value and the value of weak cell.
961 void CmpWeakValue(Register value, Handle<WeakCell> cell, Register scratch);
962
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000963 void GetWeakValue(Register value, Handle<WeakCell> cell);
964
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400965 // Load the value of the weak cell in the value register. Branch to the given
966 // miss label if the weak cell was cleared.
967 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100968
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100969 // Compare the object in a register to a value from the root list.
970 // Uses the ip register as scratch.
971 void CompareRoot(Register obj, Heap::RootListIndex index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000972 void PushRoot(Heap::RootListIndex index) {
973 LoadRoot(ip, index);
974 Push(ip);
975 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100976
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000977 // Compare the object in a register to a value and jump if they are equal.
978 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
979 CompareRoot(with, index);
980 b(eq, if_equal);
981 }
982
983 // Compare the object in a register to a value and jump if they are not equal.
984 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
985 Label* if_not_equal) {
986 CompareRoot(with, index);
987 b(ne, if_not_equal);
988 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100989
Andrei Popescu31002712010-02-23 13:46:05 +0000990 // Load and check the instance type of an object for being a string.
991 // Loads the type into the second argument register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000992 // Returns a condition that will be enabled if the object was a string
993 // and the passed-in condition passed. If the passed-in condition failed
994 // then flags remain unchanged.
Andrei Popescu31002712010-02-23 13:46:05 +0000995 Condition IsObjectStringType(Register obj,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000996 Register type,
997 Condition cond = al) {
998 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond);
999 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond);
1000 tst(type, Operand(kIsNotStringMask), cond);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001001 DCHECK_EQ(0u, kStringTag);
Andrei Popescu31002712010-02-23 13:46:05 +00001002 return eq;
1003 }
1004
1005
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001006 // Picks out an array index from the hash field.
1007 // Register use:
1008 // hash - holds the index's hash. Clobbered.
1009 // index - holds the overwritten index on exit.
1010 void IndexFromHash(Register hash, Register index);
1011
Andrei Popescu31002712010-02-23 13:46:05 +00001012 // Get the number of least significant bits from a register
1013 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +01001014 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +00001015
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 // Load the value of a smi object into a double register.
1017 // The register value must be between d0 and d15.
1018 void SmiToDouble(LowDwVfpRegister value, Register smi);
Steve Blockd0582a62009-12-15 09:54:21 +00001019
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020 // Check if a double can be exactly represented as a signed 32-bit integer.
1021 // Z flag set to one if true.
1022 void TestDoubleIsInt32(DwVfpRegister double_input,
1023 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001024
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001025 // Try to convert a double to a signed 32-bit integer.
1026 // Z flag set to one and result assigned if the conversion is exact.
1027 void TryDoubleToInt32Exact(Register result,
1028 DwVfpRegister double_input,
1029 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +01001030
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001031 // Floor a double and writes the value to the result register.
1032 // Go to exact if the conversion is exact (to be able to test -0),
1033 // fall through calling code if an overflow occurred, else go to done.
1034 // In return, input_high is loaded with high bits of input.
1035 void TryInt32Floor(Register result,
1036 DwVfpRegister double_input,
1037 Register input_high,
1038 LowDwVfpRegister double_scratch,
1039 Label* done,
1040 Label* exact);
Iain Merrick9ac36c92010-09-13 15:29:50 +01001041
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001042 // Performs a truncating conversion of a floating point number as used by
1043 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
1044 // succeeds, otherwise falls through if result is saturated. On return
1045 // 'result' either holds answer, or is clobbered on fall through.
1046 //
1047 // Only public for the test code in test-code-stubs-arm.cc.
1048 void TryInlineTruncateDoubleToI(Register result,
1049 DwVfpRegister input,
1050 Label* done);
Steve Block44f0eee2011-05-26 01:26:41 +01001051
1052 // Performs a truncating conversion of a floating point number as used by
1053 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001054 // Exits with 'result' holding the answer.
1055 void TruncateDoubleToI(Register result, DwVfpRegister double_input);
Steve Block44f0eee2011-05-26 01:26:41 +01001056
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001057 // Performs a truncating conversion of a heap number as used by
1058 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1059 // must be different registers. Exits with 'result' holding the answer.
1060 void TruncateHeapNumberToI(Register result, Register object);
1061
1062 // Converts the smi or heap number in object to an int32 using the rules
1063 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1064 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1065 // different registers.
1066 void TruncateNumberToI(Register object,
1067 Register result,
1068 Register heap_number_map,
1069 Register scratch1,
1070 Label* not_int32);
1071
1072 // Check whether d16-d31 are available on the CPU. The result is given by the
1073 // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
1074 void CheckFor32DRegs(Register scratch);
1075
1076 // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
1077 // values to location, saving [d0..(d15|d31)].
1078 void SaveFPRegs(Register location, Register scratch);
1079
1080 // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
1081 // values to location, restoring [d0..(d15|d31)].
1082 void RestoreFPRegs(Register location, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001083
1084 // ---------------------------------------------------------------------------
1085 // Runtime calls
1086
1087 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001088 void CallStub(CodeStub* stub,
1089 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1090 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001091
Andrei Popescu31002712010-02-23 13:46:05 +00001092 // Call a code stub.
1093 void TailCallStub(CodeStub* stub, Condition cond = al);
1094
Steve Blocka7e24c12009-10-30 11:49:00 +00001095 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001096 void CallRuntime(const Runtime::Function* f,
1097 int num_arguments,
1098 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001099 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1100 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001101 CallRuntime(function, function->nargs, kSaveFPRegs);
1102 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001103
1104 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001105 void CallRuntime(Runtime::FunctionId fid,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001106 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001107 const Runtime::Function* function = Runtime::FunctionForId(fid);
1108 CallRuntime(function, function->nargs, save_doubles);
1109 }
1110
1111 // Convenience function: Same as above, but takes the fid instead.
1112 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1113 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1114 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001115 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001116
Andrei Popescu402d9372010-02-26 13:31:12 +00001117 // Convenience function: call an external reference.
1118 void CallExternalReference(const ExternalReference& ext,
1119 int num_arguments);
1120
Steve Block6ded16b2010-05-10 14:33:55 +01001121 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001122 void TailCallRuntime(Runtime::FunctionId fid);
Steve Blocka7e24c12009-10-30 11:49:00 +00001123
Ben Murdoch257744e2011-11-30 15:57:28 +00001124 int CalculateStackPassedWords(int num_reg_arguments,
1125 int num_double_arguments);
1126
Steve Block6ded16b2010-05-10 14:33:55 +01001127 // Before calling a C-function from generated code, align arguments on stack.
1128 // After aligning the frame, non-register arguments must be stored in
1129 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +00001130 // are word sized. If double arguments are used, this function assumes that
1131 // all double arguments are stored before core registers; otherwise the
1132 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +01001133 // Some compilers/platforms require the stack to be aligned when calling
1134 // C++ code.
1135 // Needs a scratch register to do some arithmetic. This register will be
1136 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +00001137 void PrepareCallCFunction(int num_reg_arguments,
1138 int num_double_registers,
1139 Register scratch);
1140 void PrepareCallCFunction(int num_reg_arguments,
1141 Register scratch);
1142
1143 // There are two ways of passing double arguments on ARM, depending on
1144 // whether soft or hard floating point ABI is used. These functions
1145 // abstract parameter passing for the three different ways we call
1146 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001147 void MovToFloatParameter(DwVfpRegister src);
1148 void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
1149 void MovToFloatResult(DwVfpRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001150
1151 // Calls a C function and cleans up the space for arguments allocated
1152 // by PrepareCallCFunction. The called function is not allowed to trigger a
1153 // garbage collection, since that might move the code and invalidate the
1154 // return address (unless this is somehow accounted for by the called
1155 // function).
1156 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001157 void CallCFunction(Register function, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001158 void CallCFunction(ExternalReference function,
1159 int num_reg_arguments,
1160 int num_double_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001161 void CallCFunction(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001162 int num_reg_arguments,
1163 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01001164
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001165 void MovFromFloatParameter(DwVfpRegister dst);
1166 void MovFromFloatResult(DwVfpRegister dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001167
Steve Blocka7e24c12009-10-30 11:49:00 +00001168 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001169 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +00001170
Ben Murdoch8b112d22011-06-08 16:22:53 +01001171 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001172 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001173 return code_object_;
1174 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001175
1176
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001177 // Emit code for a truncating division by a constant. The dividend register is
1178 // unchanged and ip gets clobbered. Dividend and result must be different.
1179 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1180
Steve Blocka7e24c12009-10-30 11:49:00 +00001181 // ---------------------------------------------------------------------------
1182 // StatsCounter support
1183
1184 void SetCounter(StatsCounter* counter, int value,
1185 Register scratch1, Register scratch2);
1186 void IncrementCounter(StatsCounter* counter, int value,
1187 Register scratch1, Register scratch2);
1188 void DecrementCounter(StatsCounter* counter, int value,
1189 Register scratch1, Register scratch2);
1190
1191
1192 // ---------------------------------------------------------------------------
1193 // Debugging
1194
Steve Block1e0659c2011-05-24 12:43:12 +01001195 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +00001196 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001197 void Assert(Condition cond, BailoutReason reason);
Iain Merrick75681382010-08-19 15:07:18 +01001198 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00001199
1200 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001201 void Check(Condition cond, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001202
1203 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001204 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001205
1206 // Verify restrictions about code generated in stubs.
1207 void set_generating_stub(bool value) { generating_stub_ = value; }
1208 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001209 void set_has_frame(bool value) { has_frame_ = value; }
1210 bool has_frame() { return has_frame_; }
1211 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001212
Ben Murdoch257744e2011-11-30 15:57:28 +00001213 // EABI variant for double arguments in use.
1214 bool use_eabi_hardfloat() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001215#ifdef __arm__
1216 return base::OS::ArmUsingHardFloat();
1217#elif USE_EABI_HARDFLOAT
Ben Murdoch257744e2011-11-30 15:57:28 +00001218 return true;
1219#else
1220 return false;
1221#endif
1222 }
1223
Leon Clarked91b9f72010-01-27 17:25:45 +00001224 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +01001225 // Number utilities
1226
1227 // Check whether the value of reg is a power of two and not zero. If not
1228 // control continues at the label not_power_of_two. If reg is a power of two
1229 // the register scratch contains the value of (reg - 1) when control falls
1230 // through.
1231 void JumpIfNotPowerOfTwoOrZero(Register reg,
1232 Register scratch,
1233 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +01001234 // Check whether the value of reg is a power of two and not zero.
1235 // Control falls through if it is, with scratch containing the mask
1236 // value (reg - 1).
1237 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1238 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1239 // strictly positive but not a power of two.
1240 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1241 Register scratch,
1242 Label* zero_and_neg,
1243 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +01001244
1245 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001246 // Smi utilities
1247
Ben Murdochb0fe1622011-05-05 13:52:32 +01001248 void SmiTag(Register reg, SBit s = LeaveCC) {
1249 add(reg, reg, Operand(reg), s);
1250 }
Steve Block1e0659c2011-05-24 12:43:12 +01001251 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1252 add(dst, src, Operand(src), s);
1253 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001254
Ben Murdochb8e0da22011-05-16 14:20:40 +01001255 // Try to convert int32 to smi. If the value is to large, preserve
1256 // the original value and jump to not_a_smi. Destroys scratch and
1257 // sets flags.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001258 void TrySmiTag(Register reg, Label* not_a_smi) {
1259 TrySmiTag(reg, reg, not_a_smi);
1260 }
1261 void TrySmiTag(Register reg, Register src, Label* not_a_smi) {
1262 SmiTag(ip, src, SetCC);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001263 b(vs, not_a_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001264 mov(reg, ip);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001265 }
1266
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001267
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001268 void SmiUntag(Register reg, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001269 mov(reg, Operand::SmiUntag(reg), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001270 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001271 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001272 mov(dst, Operand::SmiUntag(src), s);
Steve Block1e0659c2011-05-24 12:43:12 +01001273 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001274
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001275 // Untag the source value into destination and jump if source is a smi.
1276 // Souce and destination can be the same register.
1277 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1278
1279 // Untag the source value into destination and jump if source is not a smi.
1280 // Souce and destination can be the same register.
1281 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1282
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001283 // Test if the register contains a smi (Z == 0 (eq) if true).
1284 inline void SmiTst(Register value) {
1285 tst(value, Operand(kSmiTagMask));
1286 }
1287 inline void NonNegativeSmiTst(Register value) {
1288 tst(value, Operand(kSmiTagMask | kSmiSignMask));
1289 }
1290 // Jump if the register contains a smi.
Steve Block1e0659c2011-05-24 12:43:12 +01001291 inline void JumpIfSmi(Register value, Label* smi_label) {
1292 tst(value, Operand(kSmiTagMask));
1293 b(eq, smi_label);
1294 }
1295 // Jump if either of the registers contain a non-smi.
1296 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1297 tst(value, Operand(kSmiTagMask));
1298 b(ne, not_smi_label);
1299 }
Andrei Popescu31002712010-02-23 13:46:05 +00001300 // Jump if either of the registers contain a non-smi.
1301 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1302 // Jump if either of the registers contain a smi.
1303 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1304
Ben Murdochda12d292016-06-02 14:46:10 +01001305 // Abort execution if argument is a number, enabled via --debug-code.
1306 void AssertNotNumber(Register object);
1307
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001308 // Abort execution if argument is a smi, enabled via --debug-code.
1309 void AssertNotSmi(Register object);
1310 void AssertSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +01001311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001312 // Abort execution if argument is not a string, enabled via --debug-code.
1313 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001314
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001315 // Abort execution if argument is not a name, enabled via --debug-code.
1316 void AssertName(Register object);
1317
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001318 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1319 void AssertFunction(Register object);
1320
1321 // Abort execution if argument is not a JSBoundFunction,
1322 // enabled via --debug-code.
1323 void AssertBoundFunction(Register object);
1324
Ben Murdochc5610432016-08-08 18:44:38 +01001325 // Abort execution if argument is not a JSGeneratorObject,
1326 // enabled via --debug-code.
1327 void AssertGeneratorObject(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_