blob: d2a178664e0f18796e422670050a30e73ad76ec3 [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
Andrei Popescu31002712010-02-23 13:46:05 +000016// ----------------------------------------------------------------------------
17// Static helper functions
18
19// Generate a MemOperand for loading a field from an object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010020inline MemOperand FieldMemOperand(Register object, int offset) {
Andrei Popescu31002712010-02-23 13:46:05 +000021 return MemOperand(object, offset - kHeapObjectTag);
22}
23
Steve Blocka7e24c12009-10-30 11:49:00 +000024
25// Give alias names to registers
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026const Register cp = { kRegister_r7_Code }; // JavaScript context pointer.
27const Register pp = { kRegister_r8_Code }; // Constant pool pointer.
28const Register kRootRegister = { kRegister_r10_Code }; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000029
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030// Flags used for AllocateHeapNumber
31enum TaggingMode {
32 // Tag the result.
33 TAG_RESULT,
34 // Don't tag
35 DONT_TAG_RESULT
Steve Block8defd9f2010-07-08 12:39:36 +010036};
37
38
Ben Murdoch3ef787d2012-04-12 10:51:47 +010039enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
40enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041enum PointersToHereCheck {
42 kPointersToHereMaybeInteresting,
43 kPointersToHereAreAlwaysInteresting
44};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010045enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
46
47
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048Register GetRegisterThatIsNotOneOf(Register reg1,
49 Register reg2 = no_reg,
50 Register reg3 = no_reg,
51 Register reg4 = no_reg,
52 Register reg5 = no_reg,
53 Register reg6 = no_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010054
55
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056#ifdef DEBUG
57bool AreAliased(Register reg1,
58 Register reg2,
59 Register reg3 = no_reg,
60 Register reg4 = no_reg,
61 Register reg5 = no_reg,
62 Register reg6 = no_reg,
63 Register reg7 = no_reg,
64 Register reg8 = no_reg);
65#endif
66
67
68enum TargetAddressStorageMode {
69 CAN_INLINE_TARGET_ADDRESS,
70 NEVER_INLINE_TARGET_ADDRESS
71};
72
Steve Blocka7e24c12009-10-30 11:49:00 +000073// MacroAssembler implements a collection of frequently used macros.
74class MacroAssembler: public Assembler {
75 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +010076 // The isolate parameter can be NULL if the macro assembler should
77 // not use isolate-dependent functionality. In this case, it's the
78 // responsibility of the caller to never invoke such function on the
79 // macro assembler.
80 MacroAssembler(Isolate* isolate, void* buffer, int size);
Steve Blocka7e24c12009-10-30 11:49:00 +000081
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082
83 // Returns the size of a call in instructions. Note, the value returned is
84 // only valid as long as no entries are added to the constant pool between
85 // checking the call size and emitting the actual call.
86 static int CallSize(Register target, Condition cond = al);
87 int CallSize(Address target, RelocInfo::Mode rmode, Condition cond = al);
88 int CallStubSize(CodeStub* stub,
89 TypeFeedbackId ast_id = TypeFeedbackId::None(),
90 Condition cond = al);
91 static int CallSizeNotPredictableCodeSize(Isolate* isolate,
92 Address target,
93 RelocInfo::Mode rmode,
94 Condition cond = al);
95
Andrei Popescu31002712010-02-23 13:46:05 +000096 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +000097 void Jump(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000098 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +000099 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
100 void Call(Register target, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 void Call(Address target, RelocInfo::Mode rmode,
102 Condition cond = al,
103 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
104 int CallSize(Handle<Code> code,
105 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
106 TypeFeedbackId ast_id = TypeFeedbackId::None(),
107 Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000108 void Call(Handle<Code> code,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000109 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110 TypeFeedbackId ast_id = TypeFeedbackId::None(),
111 Condition cond = al,
112 TargetAddressStorageMode mode = CAN_INLINE_TARGET_ADDRESS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000113 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000114
115 // Emit code to discard a non-negative number of pointer-sized elements
116 // from the stack, clobbering only the sp register.
117 void Drop(int count, Condition cond = al);
118
Ben Murdochb0fe1622011-05-05 13:52:32 +0100119 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100120
121 // Swap two registers. If the scratch register is omitted then a slightly
122 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100123 void Swap(Register reg1,
124 Register reg2,
125 Register scratch = no_reg,
126 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100127
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 void Mls(Register dst, Register src1, Register src2, Register srcA,
129 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100130 void And(Register dst, Register src1, const Operand& src2,
131 Condition cond = al);
132 void Ubfx(Register dst, Register src, int lsb, int width,
133 Condition cond = al);
134 void Sbfx(Register dst, Register src, int lsb, int width,
135 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100136 // The scratch register is not used for ARMv7.
137 // scratch can be the same register as src (in which case it is trashed), but
138 // not the same as dst.
139 void Bfi(Register dst,
140 Register src,
141 Register scratch,
142 int lsb,
143 int width,
144 Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145 void Bfc(Register dst, Register src, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100146 void Usat(Register dst, int satpos, const Operand& src,
147 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100148
Leon Clarkee46be812010-01-19 14:06:41 +0000149 void Call(Label* target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150 void Push(Register src) { push(src); }
151 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000152
153 // Register move. May do nothing if the registers are identical.
Leon Clarkee46be812010-01-19 14:06:41 +0000154 void Move(Register dst, Handle<Object> value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000155 void Move(Register dst, Register src, Condition cond = al);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000156 void Move(Register dst, const Operand& src, SBit sbit = LeaveCC,
157 Condition cond = al) {
158 if (!src.is_reg() || !src.rm().is(dst) || sbit != LeaveCC) {
159 mov(dst, src, sbit, cond);
160 }
161 }
162 void Move(DwVfpRegister dst, DwVfpRegister src);
163
164 void Load(Register dst, const MemOperand& src, Representation r);
165 void Store(Register src, const MemOperand& dst, Representation r);
Ben Murdoch257744e2011-11-30 15:57:28 +0000166
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 // Load an object from the root table.
168 void LoadRoot(Register destination,
169 Heap::RootListIndex index,
170 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100171 // Store an object to the root table.
172 void StoreRoot(Register source,
173 Heap::RootListIndex index,
174 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000175
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100176 // ---------------------------------------------------------------------------
177 // GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100178
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100179 void IncrementalMarkingRecordWriteHelper(Register object,
180 Register value,
181 Register address);
Steve Block6ded16b2010-05-10 14:33:55 +0100182
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100183 enum RememberedSetFinalAction {
184 kReturnAtEnd,
185 kFallThroughAtEnd
186 };
187
188 // Record in the remembered set the fact that we have a pointer to new space
189 // at the address pointed to by the addr register. Only works if addr is not
190 // in new space.
191 void RememberedSetHelper(Register object, // Used for debug code.
192 Register addr,
193 Register scratch,
194 SaveFPRegsMode save_fp,
195 RememberedSetFinalAction and_then);
196
197 void CheckPageFlag(Register object,
198 Register scratch,
199 int mask,
200 Condition cc,
201 Label* condition_met);
202
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000203 void CheckMapDeprecated(Handle<Map> map,
204 Register scratch,
205 Label* if_deprecated);
206
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100207 // Check if object is in new space. Jumps if the object is not in new space.
208 // The register scratch can be object itself, but scratch will be clobbered.
209 void JumpIfNotInNewSpace(Register object,
210 Register scratch,
211 Label* branch) {
212 InNewSpace(object, scratch, ne, branch);
213 }
214
215 // Check if object is in new space. Jumps if the object is in new space.
216 // The register scratch can be object itself, but it will be clobbered.
217 void JumpIfInNewSpace(Register object,
218 Register scratch,
219 Label* branch) {
220 InNewSpace(object, scratch, eq, branch);
221 }
222
223 // Check if an object has a given incremental marking color.
224 void HasColor(Register object,
225 Register scratch0,
226 Register scratch1,
227 Label* has_color,
228 int first_bit,
229 int second_bit);
230
231 void JumpIfBlack(Register object,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100232 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100233 Register scratch1,
234 Label* on_black);
Steve Blocka7e24c12009-10-30 11:49:00 +0000235
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100236 // Checks the color of an object. If the object is already grey or black
237 // then we just fall through, since it is already live. If it is white and
238 // we can determine that it doesn't need to be scanned, then we just mark it
239 // black and fall through. For the rest we jump to the label so the
240 // incremental marker can fix its assumptions.
241 void EnsureNotWhite(Register object,
242 Register scratch1,
243 Register scratch2,
244 Register scratch3,
245 Label* object_is_white_and_not_data);
246
247 // Detects conservatively whether an object is data-only, i.e. it does need to
248 // be scanned by the garbage collector.
249 void JumpIfDataObject(Register value,
250 Register scratch,
251 Label* not_data_object);
252
253 // Notify the garbage collector that we wrote a pointer into an object.
254 // |object| is the object being stored into, |value| is the object being
255 // stored. value and scratch registers are clobbered by the operation.
256 // The offset is the offset from the start of the object, not the offset from
257 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
258 void RecordWriteField(
259 Register object,
260 int offset,
261 Register value,
262 Register scratch,
263 LinkRegisterStatus lr_status,
264 SaveFPRegsMode save_fp,
265 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266 SmiCheck smi_check = INLINE_SMI_CHECK,
267 PointersToHereCheck pointers_to_here_check_for_value =
268 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100269
270 // As above, but the offset has the tag presubtracted. For use with
271 // MemOperand(reg, off).
272 inline void RecordWriteContextSlot(
273 Register context,
274 int offset,
275 Register value,
276 Register scratch,
277 LinkRegisterStatus lr_status,
278 SaveFPRegsMode save_fp,
279 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280 SmiCheck smi_check = INLINE_SMI_CHECK,
281 PointersToHereCheck pointers_to_here_check_for_value =
282 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100283 RecordWriteField(context,
284 offset + kHeapObjectTag,
285 value,
286 scratch,
287 lr_status,
288 save_fp,
289 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290 smi_check,
291 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100292 }
293
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294 void RecordWriteForMap(
295 Register object,
296 Register map,
297 Register dst,
298 LinkRegisterStatus lr_status,
299 SaveFPRegsMode save_fp);
300
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100301 // For a given |object| notify the garbage collector that the slot |address|
302 // has been written. |value| is the object being stored. The value and
303 // address registers are clobbered by the operation.
304 void RecordWrite(
305 Register object,
306 Register address,
307 Register value,
308 LinkRegisterStatus lr_status,
309 SaveFPRegsMode save_fp,
310 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 SmiCheck smi_check = INLINE_SMI_CHECK,
312 PointersToHereCheck pointers_to_here_check_for_value =
313 kPointersToHereMaybeInteresting);
Steve Block8defd9f2010-07-08 12:39:36 +0100314
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000315 // Push a handle.
316 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000317 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000318
Steve Block6ded16b2010-05-10 14:33:55 +0100319 // Push two registers. Pushes leftmost register first (to highest address).
320 void Push(Register src1, Register src2, Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321 DCHECK(!src1.is(src2));
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) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000332 DCHECK(!src1.is(src2));
333 DCHECK(!src2.is(src3));
334 DCHECK(!src1.is(src3));
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) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000354 DCHECK(!src1.is(src2));
355 DCHECK(!src2.is(src3));
356 DCHECK(!src1.is(src3));
357 DCHECK(!src1.is(src4));
358 DCHECK(!src2.is(src4));
359 DCHECK(!src3.is(src4));
Steve Block6ded16b2010-05-10 14:33:55 +0100360 if (src1.code() > src2.code()) {
361 if (src2.code() > src3.code()) {
362 if (src3.code() > src4.code()) {
363 stm(db_w,
364 sp,
365 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
366 cond);
367 } else {
368 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
369 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
370 }
371 } else {
372 stm(db_w, sp, src1.bit() | src2.bit(), cond);
373 Push(src3, src4, cond);
374 }
375 } else {
376 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
377 Push(src2, src3, src4, cond);
378 }
379 }
380
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100381 // Pop two registers. Pops rightmost register first (from lower address).
382 void Pop(Register src1, Register src2, Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 DCHECK(!src1.is(src2));
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100384 if (src1.code() > src2.code()) {
385 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
386 } else {
387 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
388 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
389 }
390 }
391
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100392 // Pop three registers. Pops rightmost register first (from lower address).
393 void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000394 DCHECK(!src1.is(src2));
395 DCHECK(!src2.is(src3));
396 DCHECK(!src1.is(src3));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100397 if (src1.code() > src2.code()) {
398 if (src2.code() > src3.code()) {
399 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
400 } else {
401 ldr(src3, MemOperand(sp, 4, PostIndex), cond);
402 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
403 }
404 } else {
405 Pop(src2, src3, cond);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100407 }
408 }
409
410 // Pop four registers. Pops rightmost register first (from lower address).
411 void Pop(Register src1,
412 Register src2,
413 Register src3,
414 Register src4,
415 Condition cond = al) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000416 DCHECK(!src1.is(src2));
417 DCHECK(!src2.is(src3));
418 DCHECK(!src1.is(src3));
419 DCHECK(!src1.is(src4));
420 DCHECK(!src2.is(src4));
421 DCHECK(!src3.is(src4));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100422 if (src1.code() > src2.code()) {
423 if (src2.code() > src3.code()) {
424 if (src3.code() > src4.code()) {
425 ldm(ia_w,
426 sp,
427 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
428 cond);
429 } else {
430 ldr(src4, MemOperand(sp, 4, PostIndex), cond);
431 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
432 }
433 } else {
434 Pop(src3, src4, cond);
435 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
436 }
437 } else {
438 Pop(src2, src3, src4, cond);
439 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
440 }
441 }
442
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443 // Push a fixed frame, consisting of lr, fp, constant pool (if
444 // FLAG_enable_ool_constant_pool), context and JS function / marker id if
445 // marker_reg is a valid register.
446 void PushFixedFrame(Register marker_reg = no_reg);
447 void PopFixedFrame(Register marker_reg = no_reg);
448
Ben Murdochb0fe1622011-05-05 13:52:32 +0100449 // Push and pop the registers that can hold pointers, as defined by the
450 // RegList constant kSafepointSavedRegisters.
451 void PushSafepointRegisters();
452 void PopSafepointRegisters();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100453 // Store value in register src in the safepoint stack slot for
454 // register dst.
455 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100456 // Load the value of the src register from its safepoint stack slot
457 // into register dst.
458 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100459
Leon Clarkef7060e22010-06-03 12:02:55 +0100460 // Load two consecutive registers with two consecutive memory locations.
461 void Ldrd(Register dst1,
462 Register dst2,
463 const MemOperand& src,
464 Condition cond = al);
465
466 // Store two consecutive registers to two consecutive memory locations.
467 void Strd(Register src1,
468 Register src2,
469 const MemOperand& dst,
470 Condition cond = al);
471
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000472 // Ensure that FPSCR contains values needed by JavaScript.
473 // We need the NaNModeControlBit to be sure that operations like
474 // vadd and vsub generate the Canonical NaN (if a NaN must be generated).
475 // In VFP3 it will be always the Canonical NaN.
476 // In VFP2 it will be either the Canonical NaN or the negative version
477 // of the Canonical NaN. It doesn't matter if we have two values. The aim
478 // is to be sure to never generate the hole NaN.
479 void VFPEnsureFPSCRState(Register scratch);
480
481 // If the value is a NaN, canonicalize the value else, do nothing.
482 void VFPCanonicalizeNaN(const DwVfpRegister dst,
483 const DwVfpRegister src,
484 const Condition cond = al);
485 void VFPCanonicalizeNaN(const DwVfpRegister value,
486 const Condition cond = al) {
487 VFPCanonicalizeNaN(value, value, cond);
488 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100489
490 // Compare double values and move the result to the normal condition flags.
491 void VFPCompareAndSetFlags(const DwVfpRegister src1,
492 const DwVfpRegister src2,
493 const Condition cond = al);
494 void VFPCompareAndSetFlags(const DwVfpRegister src1,
495 const double src2,
496 const Condition cond = al);
497
498 // Compare double values and then load the fpscr flags to a register.
499 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
500 const DwVfpRegister src2,
501 const Register fpscr_flags,
502 const Condition cond = al);
503 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
504 const double src2,
505 const Register fpscr_flags,
506 const Condition cond = al);
507
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000508 void Vmov(const DwVfpRegister dst,
509 const double imm,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000510 const Register scratch = no_reg);
511
512 void VmovHigh(Register dst, DwVfpRegister src);
513 void VmovHigh(DwVfpRegister dst, Register src);
514 void VmovLow(Register dst, DwVfpRegister src);
515 void VmovLow(DwVfpRegister dst, Register src);
516
517 // Loads the number from object into dst register.
518 // If |object| is neither smi nor heap number, |not_number| is jumped to
519 // with |object| still intact.
520 void LoadNumber(Register object,
521 LowDwVfpRegister dst,
522 Register heap_number_map,
523 Register scratch,
524 Label* not_number);
525
526 // Loads the number from object into double_dst in the double format.
527 // Control will jump to not_int32 if the value cannot be exactly represented
528 // by a 32-bit integer.
529 // Floating point value in the 32-bit integer range that are not exact integer
530 // won't be loaded.
531 void LoadNumberAsInt32Double(Register object,
532 DwVfpRegister double_dst,
533 Register heap_number_map,
534 Register scratch,
535 LowDwVfpRegister double_scratch,
536 Label* not_int32);
537
538 // Loads the number from object into dst as a 32-bit integer.
539 // Control will jump to not_int32 if the object cannot be exactly represented
540 // by a 32-bit integer.
541 // Floating point value in the 32-bit integer range that are not exact integer
542 // won't be converted.
543 void LoadNumberAsInt32(Register object,
544 Register dst,
545 Register heap_number_map,
546 Register scratch,
547 DwVfpRegister double_scratch0,
548 LowDwVfpRegister double_scratch1,
549 Label* not_int32);
550
551 // Generates function and stub prologue code.
552 void StubPrologue();
553 void Prologue(bool code_pre_aging);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000554
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100555 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100556 // stack_space - extra stack space, used for alignment before call to C.
557 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000558
559 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100560 // Expect the number of values, pushed prior to the exit frame, to
561 // remove in a register (or no_reg, if there is nothing to remove).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000562 void LeaveExitFrame(bool save_doubles,
563 Register argument_count,
564 bool restore_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000565
Steve Block6ded16b2010-05-10 14:33:55 +0100566 // Get the actual activation frame alignment for target environment.
567 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000568
Steve Blockd0582a62009-12-15 09:54:21 +0000569 void LoadContext(Register dst, int context_chain_length);
570
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100571 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000572 // transitioned_kind from the native context if the map in register
573 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100574 // expected_kind.
575 void LoadTransitionedArrayMapConditional(
576 ElementsKind expected_kind,
577 ElementsKind transitioned_kind,
578 Register map_in_out,
579 Register scratch,
580 Label* no_map_match);
581
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800582 void LoadGlobalFunction(int index, Register function);
583
584 // Load the initial map from the global function. The registers
585 // function and map can be the same, function is then overwritten.
586 void LoadGlobalFunctionInitialMap(Register function,
587 Register map,
588 Register scratch);
589
Ben Murdochc7cc0282012-03-05 14:35:55 +0000590 void InitializeRootRegister() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100591 ExternalReference roots_array_start =
592 ExternalReference::roots_array_start(isolate());
593 mov(kRootRegister, Operand(roots_array_start));
Ben Murdochc7cc0282012-03-05 14:35:55 +0000594 }
595
Steve Blocka7e24c12009-10-30 11:49:00 +0000596 // ---------------------------------------------------------------------------
597 // JavaScript invokes
598
599 // Invoke the JavaScript function code by either calling or jumping.
600 void InvokeCode(Register code,
601 const ParameterCount& expected,
602 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100603 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000604 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000605
606 // Invoke the JavaScript function in the given register. Changes the
607 // current context to the context in the function before invoking.
608 void InvokeFunction(Register function,
609 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100610 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000611 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +0000612
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000613 void InvokeFunction(Register function,
614 const ParameterCount& expected,
Andrei Popescu402d9372010-02-26 13:31:12 +0000615 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000616 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000617 const CallWrapper& call_wrapper);
618
619 void InvokeFunction(Handle<JSFunction> function,
620 const ParameterCount& expected,
621 const ParameterCount& actual,
622 InvokeFlag flag,
623 const CallWrapper& call_wrapper);
Andrei Popescu402d9372010-02-26 13:31:12 +0000624
Ben Murdochb0fe1622011-05-05 13:52:32 +0100625 void IsObjectJSObjectType(Register heap_object,
626 Register map,
627 Register scratch,
628 Label* fail);
629
630 void IsInstanceJSObjectType(Register map,
631 Register scratch,
632 Label* fail);
633
634 void IsObjectJSStringType(Register object,
635 Register scratch,
636 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000637
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000638 void IsObjectNameType(Register object,
639 Register scratch,
640 Label* fail);
641
Steve Blocka7e24c12009-10-30 11:49:00 +0000642 // ---------------------------------------------------------------------------
643 // Debugger Support
644
Andrei Popescu402d9372010-02-26 13:31:12 +0000645 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000646
647 // ---------------------------------------------------------------------------
648 // Exception handling
649
650 // Push a new try handler and link into try handler chain.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100651 void PushTryHandler(StackHandler::Kind kind, int handler_index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000652
Leon Clarkee46be812010-01-19 14:06:41 +0000653 // Unlink the stack handler on top of the stack from the try handler chain.
654 // Must preserve the result register.
655 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000656
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100657 // Passes thrown value to the handler of top of the try handler chain.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100658 void Throw(Register value);
659
660 // Propagates an uncatchable exception to the top of the current JS stack's
661 // handler chain.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100662 void ThrowUncatchable(Register value);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100663
Steve Blocka7e24c12009-10-30 11:49:00 +0000664 // ---------------------------------------------------------------------------
665 // Inline caching support
666
Steve Blocka7e24c12009-10-30 11:49:00 +0000667 // Generate code for checking access rights - used for security checks
668 // on access to global objects across environments. The holder register
669 // is left untouched, whereas both scratch registers are clobbered.
670 void CheckAccessGlobalProxy(Register holder_reg,
671 Register scratch,
672 Label* miss);
673
Ben Murdochc7cc0282012-03-05 14:35:55 +0000674 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000675
676 void LoadFromNumberDictionary(Label* miss,
677 Register elements,
678 Register key,
679 Register result,
680 Register t0,
681 Register t1,
682 Register t2);
683
684
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800685 inline void MarkCode(NopMarkerTypes type) {
686 nop(type);
687 }
688
689 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100690 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800691 // These instructions are generated to mark special location in the code,
692 // like some special IC code.
693 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000694 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800695 return IsNop(instr, type);
696 }
697
698
699 static inline int GetCodeMarker(Instr instr) {
700 int dst_reg_offset = 12;
701 int dst_mask = 0xf << dst_reg_offset;
702 int src_mask = 0xf;
703 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
704 int src_reg = instr & src_mask;
705 uint32_t non_register_mask = ~(dst_mask | src_mask);
706 uint32_t mov_mask = al | 13 << 21;
707
708 // Return <n> if we have a mov rn rn, else return -1.
709 int type = ((instr & non_register_mask) == mov_mask) &&
710 (dst_reg == src_reg) &&
711 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
712 ? src_reg
713 : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000714 DCHECK((type == -1) ||
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800715 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
716 return type;
717 }
718
Steve Blocka7e24c12009-10-30 11:49:00 +0000719
720 // ---------------------------------------------------------------------------
721 // Allocation support
722
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723 // Allocate an object in new space or old pointer space. The object_size is
724 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
725 // is passed. If the space is exhausted control continues at the gc_required
726 // label. The allocated object is returned in result. If the flag
727 // tag_allocated_object is true the result is tagged as as a heap object.
728 // All registers are clobbered also when control continues at the gc_required
729 // label.
730 void Allocate(int object_size,
731 Register result,
732 Register scratch1,
733 Register scratch2,
734 Label* gc_required,
735 AllocationFlags flags);
736
737 void Allocate(Register object_size,
738 Register result,
739 Register scratch1,
740 Register scratch2,
741 Label* gc_required,
742 AllocationFlags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000743
744 // Undo allocation in new space. The object passed and objects allocated after
745 // it will no longer be allocated. The caller must make sure that no pointers
746 // are left to the object(s) no longer allocated as they would be invalid when
747 // allocation is undone.
748 void UndoAllocationInNewSpace(Register object, Register scratch);
749
Andrei Popescu31002712010-02-23 13:46:05 +0000750
751 void AllocateTwoByteString(Register result,
752 Register length,
753 Register scratch1,
754 Register scratch2,
755 Register scratch3,
756 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000757 void AllocateOneByteString(Register result, Register length,
758 Register scratch1, Register scratch2,
759 Register scratch3, Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000760 void AllocateTwoByteConsString(Register result,
761 Register length,
762 Register scratch1,
763 Register scratch2,
764 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000765 void AllocateOneByteConsString(Register result, Register length,
766 Register scratch1, Register scratch2,
767 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000768 void AllocateTwoByteSlicedString(Register result,
769 Register length,
770 Register scratch1,
771 Register scratch2,
772 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000773 void AllocateOneByteSlicedString(Register result, Register length,
774 Register scratch1, Register scratch2,
775 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000776
Kristian Monsen25f61362010-05-21 11:50:48 +0100777 // Allocates a heap number or jumps to the gc_required label if the young
778 // space is full and a scavenge is needed. All registers are clobbered also
779 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100780 void AllocateHeapNumber(Register result,
781 Register scratch1,
782 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100783 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784 Label* gc_required,
785 TaggingMode tagging_mode = TAG_RESULT,
786 MutableMode mode = IMMUTABLE);
Steve Block8defd9f2010-07-08 12:39:36 +0100787 void AllocateHeapNumberWithValue(Register result,
788 DwVfpRegister value,
789 Register scratch1,
790 Register scratch2,
791 Register heap_number_map,
792 Label* gc_required);
793
Ben Murdochbb769b22010-08-11 14:56:33 +0100794 // Copies a fixed number of fields of heap objects from src to dst.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000795 void CopyFields(Register dst,
796 Register src,
797 LowDwVfpRegister double_scratch,
798 int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000799
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100800 // Copies a number of bytes from src to dst. All registers are clobbered. On
801 // exit src and dst will point to the place just after where the last byte was
802 // read or written and length will be zero.
803 void CopyBytes(Register src,
804 Register dst,
805 Register length,
806 Register scratch);
807
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100808 // Initialize fields with filler values. Fields starting at |start_offset|
809 // not including end_offset are overwritten with the value in |filler|. At
810 // the end the loop, |start_offset| takes the value of |end_offset|.
811 void InitializeFieldsWithFiller(Register start_offset,
812 Register end_offset,
813 Register filler);
814
Steve Blocka7e24c12009-10-30 11:49:00 +0000815 // ---------------------------------------------------------------------------
816 // Support functions.
817
818 // Try to get function prototype of a function and puts the value in
819 // the result register. Checks that the function really is a
820 // function and jumps to the miss label if the fast checks fail. The
821 // function register will be untouched; the other registers may be
822 // clobbered.
823 void TryGetFunctionPrototype(Register function,
824 Register result,
825 Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100826 Label* miss,
827 bool miss_on_bound_function = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000828
829 // Compare object type for heap object. heap_object contains a non-Smi
830 // whose object type should be compared with the given type. This both
831 // sets the flags and leaves the object type in the type_reg register.
832 // It leaves the map in the map register (unless the type_reg and map register
833 // are the same register). It leaves the heap object in the heap_object
834 // register unless the heap_object register is the same register as one of the
835 // other registers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000836 // Type_reg can be no_reg. In that case ip is used.
Steve Blocka7e24c12009-10-30 11:49:00 +0000837 void CompareObjectType(Register heap_object,
838 Register map,
839 Register type_reg,
840 InstanceType type);
841
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000842 // Compare object type for heap object. Branch to false_label if type
843 // is lower than min_type or greater than max_type.
844 // Load map into the register map.
845 void CheckObjectTypeRange(Register heap_object,
846 Register map,
847 InstanceType min_type,
848 InstanceType max_type,
849 Label* false_label);
850
Steve Blocka7e24c12009-10-30 11:49:00 +0000851 // Compare instance type in a map. map contains a valid map object whose
852 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000853 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 void CompareInstanceType(Register map,
855 Register type_reg,
856 InstanceType type);
857
Andrei Popescu31002712010-02-23 13:46:05 +0000858
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000859 // Check if a map for a JSObject indicates that the object has fast elements.
860 // Jump to the specified label if it does not.
861 void CheckFastElements(Register map,
862 Register scratch,
863 Label* fail);
864
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100865 // Check if a map for a JSObject indicates that the object can have both smi
866 // and HeapObject elements. Jump to the specified label if it does not.
867 void CheckFastObjectElements(Register map,
868 Register scratch,
869 Label* fail);
870
871 // Check if a map for a JSObject indicates that the object has fast smi only
872 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000873 void CheckFastSmiElements(Register map,
874 Register scratch,
875 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100876
877 // Check to see if maybe_number can be stored as a double in
878 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000879 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100880 void StoreNumberToDoubleElements(Register value_reg,
881 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100882 Register elements_reg,
883 Register scratch1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000884 LowDwVfpRegister double_scratch,
885 Label* fail,
886 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100887
888 // Compare an object's map with the specified map and its transitioned
889 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
890 // set with result of map compare. If multiple map compares are required, the
891 // compare sequences branches to early_success.
892 void CompareMap(Register obj,
893 Register scratch,
894 Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000895 Label* early_success);
896
897 // As above, but the map of the object is already loaded into the register
898 // which is preserved by the code generated.
899 void CompareMap(Register obj_map,
900 Handle<Map> map,
901 Label* early_success);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100902
903 // Check if the map of an object is equal to a specified map and branch to
904 // label if not. Skip the smi check if not required (object is known to be a
905 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
906 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +0000907 void CheckMap(Register obj,
908 Register scratch,
909 Handle<Map> map,
910 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000911 SmiCheckType smi_check_type);
Ben Murdoch257744e2011-11-30 15:57:28 +0000912
Andrei Popescu31002712010-02-23 13:46:05 +0000913
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100914 void CheckMap(Register obj,
915 Register scratch,
916 Heap::RootListIndex index,
917 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000918 SmiCheckType smi_check_type);
919
920
921 // Check if the map of an object is equal to a specified map and branch to a
922 // specified target if equal. Skip the smi check if not required (object is
923 // known to be a heap object)
924 void DispatchMap(Register obj,
925 Register scratch,
926 Handle<Map> map,
927 Handle<Code> success,
928 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100929
930
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100931 // Compare the object in a register to a value from the root list.
932 // Uses the ip register as scratch.
933 void CompareRoot(Register obj, Heap::RootListIndex index);
934
935
Andrei Popescu31002712010-02-23 13:46:05 +0000936 // Load and check the instance type of an object for being a string.
937 // Loads the type into the second argument register.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000938 // Returns a condition that will be enabled if the object was a string
939 // and the passed-in condition passed. If the passed-in condition failed
940 // then flags remain unchanged.
Andrei Popescu31002712010-02-23 13:46:05 +0000941 Condition IsObjectStringType(Register obj,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 Register type,
943 Condition cond = al) {
944 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset), cond);
945 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset), cond);
946 tst(type, Operand(kIsNotStringMask), cond);
947 DCHECK_EQ(0, kStringTag);
Andrei Popescu31002712010-02-23 13:46:05 +0000948 return eq;
949 }
950
951
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100952 // Picks out an array index from the hash field.
953 // Register use:
954 // hash - holds the index's hash. Clobbered.
955 // index - holds the overwritten index on exit.
956 void IndexFromHash(Register hash, Register index);
957
Andrei Popescu31002712010-02-23 13:46:05 +0000958 // Get the number of least significant bits from a register
959 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100960 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000961
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000962 // Load the value of a smi object into a double register.
963 // The register value must be between d0 and d15.
964 void SmiToDouble(LowDwVfpRegister value, Register smi);
Steve Blockd0582a62009-12-15 09:54:21 +0000965
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000966 // Check if a double can be exactly represented as a signed 32-bit integer.
967 // Z flag set to one if true.
968 void TestDoubleIsInt32(DwVfpRegister double_input,
969 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +0100970
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000971 // Try to convert a double to a signed 32-bit integer.
972 // Z flag set to one and result assigned if the conversion is exact.
973 void TryDoubleToInt32Exact(Register result,
974 DwVfpRegister double_input,
975 LowDwVfpRegister double_scratch);
Steve Block8defd9f2010-07-08 12:39:36 +0100976
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000977 // Floor a double and writes the value to the result register.
978 // Go to exact if the conversion is exact (to be able to test -0),
979 // fall through calling code if an overflow occurred, else go to done.
980 // In return, input_high is loaded with high bits of input.
981 void TryInt32Floor(Register result,
982 DwVfpRegister double_input,
983 Register input_high,
984 LowDwVfpRegister double_scratch,
985 Label* done,
986 Label* exact);
Iain Merrick9ac36c92010-09-13 15:29:50 +0100987
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000988 // Performs a truncating conversion of a floating point number as used by
989 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
990 // succeeds, otherwise falls through if result is saturated. On return
991 // 'result' either holds answer, or is clobbered on fall through.
992 //
993 // Only public for the test code in test-code-stubs-arm.cc.
994 void TryInlineTruncateDoubleToI(Register result,
995 DwVfpRegister input,
996 Label* done);
Steve Block44f0eee2011-05-26 01:26:41 +0100997
998 // Performs a truncating conversion of a floating point number as used by
999 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001000 // Exits with 'result' holding the answer.
1001 void TruncateDoubleToI(Register result, DwVfpRegister double_input);
Steve Block44f0eee2011-05-26 01:26:41 +01001002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 // Performs a truncating conversion of a heap number as used by
1004 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
1005 // must be different registers. Exits with 'result' holding the answer.
1006 void TruncateHeapNumberToI(Register result, Register object);
1007
1008 // Converts the smi or heap number in object to an int32 using the rules
1009 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
1010 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
1011 // different registers.
1012 void TruncateNumberToI(Register object,
1013 Register result,
1014 Register heap_number_map,
1015 Register scratch1,
1016 Label* not_int32);
1017
1018 // Check whether d16-d31 are available on the CPU. The result is given by the
1019 // Z condition flag: Z==0 if d16-d31 available, Z==1 otherwise.
1020 void CheckFor32DRegs(Register scratch);
1021
1022 // Does a runtime check for 16/32 FP registers. Either way, pushes 32 double
1023 // values to location, saving [d0..(d15|d31)].
1024 void SaveFPRegs(Register location, Register scratch);
1025
1026 // Does a runtime check for 16/32 FP registers. Either way, pops 32 double
1027 // values to location, restoring [d0..(d15|d31)].
1028 void RestoreFPRegs(Register location, Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +00001029
1030 // ---------------------------------------------------------------------------
1031 // Runtime calls
1032
1033 // Call a code stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001034 void CallStub(CodeStub* stub,
1035 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1036 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001037
Andrei Popescu31002712010-02-23 13:46:05 +00001038 // Call a code stub.
1039 void TailCallStub(CodeStub* stub, Condition cond = al);
1040
Steve Blocka7e24c12009-10-30 11:49:00 +00001041 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001042 void CallRuntime(const Runtime::Function* f,
1043 int num_arguments,
1044 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1045 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1046 const Runtime::Function* function = Runtime::FunctionForId(id);
1047 CallRuntime(function, function->nargs, kSaveFPRegs);
1048 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001049
1050 // Convenience function: Same as above, but takes the fid instead.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001051 void CallRuntime(Runtime::FunctionId id,
1052 int num_arguments,
1053 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1054 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1055 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001056
Andrei Popescu402d9372010-02-26 13:31:12 +00001057 // Convenience function: call an external reference.
1058 void CallExternalReference(const ExternalReference& ext,
1059 int num_arguments);
1060
Steve Blocka7e24c12009-10-30 11:49:00 +00001061 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +01001062 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +00001063 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +01001064 void TailCallExternalReference(const ExternalReference& ext,
1065 int num_arguments,
1066 int result_size);
1067
1068 // Convenience function: tail call a runtime routine (jump).
1069 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +00001070 int num_arguments,
1071 int result_size);
1072
Ben Murdoch257744e2011-11-30 15:57:28 +00001073 int CalculateStackPassedWords(int num_reg_arguments,
1074 int num_double_arguments);
1075
Steve Block6ded16b2010-05-10 14:33:55 +01001076 // Before calling a C-function from generated code, align arguments on stack.
1077 // After aligning the frame, non-register arguments must be stored in
1078 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +00001079 // are word sized. If double arguments are used, this function assumes that
1080 // all double arguments are stored before core registers; otherwise the
1081 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +01001082 // Some compilers/platforms require the stack to be aligned when calling
1083 // C++ code.
1084 // Needs a scratch register to do some arithmetic. This register will be
1085 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +00001086 void PrepareCallCFunction(int num_reg_arguments,
1087 int num_double_registers,
1088 Register scratch);
1089 void PrepareCallCFunction(int num_reg_arguments,
1090 Register scratch);
1091
1092 // There are two ways of passing double arguments on ARM, depending on
1093 // whether soft or hard floating point ABI is used. These functions
1094 // abstract parameter passing for the three different ways we call
1095 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001096 void MovToFloatParameter(DwVfpRegister src);
1097 void MovToFloatParameters(DwVfpRegister src1, DwVfpRegister src2);
1098 void MovToFloatResult(DwVfpRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001099
1100 // Calls a C function and cleans up the space for arguments allocated
1101 // by PrepareCallCFunction. The called function is not allowed to trigger a
1102 // garbage collection, since that might move the code and invalidate the
1103 // return address (unless this is somehow accounted for by the called
1104 // function).
1105 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001106 void CallCFunction(Register function, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001107 void CallCFunction(ExternalReference function,
1108 int num_reg_arguments,
1109 int num_double_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001110 void CallCFunction(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001111 int num_reg_arguments,
1112 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01001113
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001114 void MovFromFloatParameter(DwVfpRegister dst);
1115 void MovFromFloatResult(DwVfpRegister dst);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001116
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001117 // Calls an API function. Allocates HandleScope, extracts returned value
1118 // from handle and propagates exceptions. Restores context. stack_space
1119 // - space to be unwound on exit (includes the call JS arguments space and
1120 // the additional space allocated for the fast call).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001121 void CallApiFunctionAndReturn(Register function_address,
1122 ExternalReference thunk_ref,
1123 int stack_space,
1124 MemOperand return_value_operand,
1125 MemOperand* context_restore_operand);
Steve Block1e0659c2011-05-24 12:43:12 +01001126
Steve Blocka7e24c12009-10-30 11:49:00 +00001127 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001128 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +00001129
1130 // Invoke specified builtin JavaScript function. Adds an entry to
1131 // the unresolved list if the name does not resolve.
Ben Murdochb8e0da22011-05-16 14:20:40 +01001132 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +00001133 InvokeFlag flag,
1134 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +00001135
1136 // Store the code object for the given builtin in the target register and
1137 // setup the function in r1.
1138 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1139
Steve Block791712a2010-08-27 10:21:07 +01001140 // Store the function for the given builtin in the target register.
1141 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1142
Ben Murdoch8b112d22011-06-08 16:22:53 +01001143 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001144 DCHECK(!code_object_.is_null());
Ben Murdoch8b112d22011-06-08 16:22:53 +01001145 return code_object_;
1146 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001147
1148
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001149 // Emit code for a truncating division by a constant. The dividend register is
1150 // unchanged and ip gets clobbered. Dividend and result must be different.
1151 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1152
Steve Blocka7e24c12009-10-30 11:49:00 +00001153 // ---------------------------------------------------------------------------
1154 // StatsCounter support
1155
1156 void SetCounter(StatsCounter* counter, int value,
1157 Register scratch1, Register scratch2);
1158 void IncrementCounter(StatsCounter* counter, int value,
1159 Register scratch1, Register scratch2);
1160 void DecrementCounter(StatsCounter* counter, int value,
1161 Register scratch1, Register scratch2);
1162
1163
1164 // ---------------------------------------------------------------------------
1165 // Debugging
1166
Steve Block1e0659c2011-05-24 12:43:12 +01001167 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +00001168 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001169 void Assert(Condition cond, BailoutReason reason);
Iain Merrick75681382010-08-19 15:07:18 +01001170 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00001171
1172 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001173 void Check(Condition cond, BailoutReason reason);
Steve Blocka7e24c12009-10-30 11:49:00 +00001174
1175 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001176 void Abort(BailoutReason msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001177
1178 // Verify restrictions about code generated in stubs.
1179 void set_generating_stub(bool value) { generating_stub_ = value; }
1180 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001181 void set_has_frame(bool value) { has_frame_ = value; }
1182 bool has_frame() { return has_frame_; }
1183 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001184
Ben Murdoch257744e2011-11-30 15:57:28 +00001185 // EABI variant for double arguments in use.
1186 bool use_eabi_hardfloat() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001187#ifdef __arm__
1188 return base::OS::ArmUsingHardFloat();
1189#elif USE_EABI_HARDFLOAT
Ben Murdoch257744e2011-11-30 15:57:28 +00001190 return true;
1191#else
1192 return false;
1193#endif
1194 }
1195
Leon Clarked91b9f72010-01-27 17:25:45 +00001196 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +01001197 // Number utilities
1198
1199 // Check whether the value of reg is a power of two and not zero. If not
1200 // control continues at the label not_power_of_two. If reg is a power of two
1201 // the register scratch contains the value of (reg - 1) when control falls
1202 // through.
1203 void JumpIfNotPowerOfTwoOrZero(Register reg,
1204 Register scratch,
1205 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +01001206 // Check whether the value of reg is a power of two and not zero.
1207 // Control falls through if it is, with scratch containing the mask
1208 // value (reg - 1).
1209 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1210 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1211 // strictly positive but not a power of two.
1212 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1213 Register scratch,
1214 Label* zero_and_neg,
1215 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +01001216
1217 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001218 // Smi utilities
1219
Ben Murdochb0fe1622011-05-05 13:52:32 +01001220 void SmiTag(Register reg, SBit s = LeaveCC) {
1221 add(reg, reg, Operand(reg), s);
1222 }
Steve Block1e0659c2011-05-24 12:43:12 +01001223 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1224 add(dst, src, Operand(src), s);
1225 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001226
Ben Murdochb8e0da22011-05-16 14:20:40 +01001227 // Try to convert int32 to smi. If the value is to large, preserve
1228 // the original value and jump to not_a_smi. Destroys scratch and
1229 // sets flags.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001230 void TrySmiTag(Register reg, Label* not_a_smi) {
1231 TrySmiTag(reg, reg, not_a_smi);
1232 }
1233 void TrySmiTag(Register reg, Register src, Label* not_a_smi) {
1234 SmiTag(ip, src, SetCC);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001235 b(vs, not_a_smi);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001236 mov(reg, ip);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001237 }
1238
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001239
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001240 void SmiUntag(Register reg, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001241 mov(reg, Operand::SmiUntag(reg), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001242 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001243 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001244 mov(dst, Operand::SmiUntag(src), s);
Steve Block1e0659c2011-05-24 12:43:12 +01001245 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001246
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001247 // Untag the source value into destination and jump if source is a smi.
1248 // Souce and destination can be the same register.
1249 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1250
1251 // Untag the source value into destination and jump if source is not a smi.
1252 // Souce and destination can be the same register.
1253 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1254
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001255 // Test if the register contains a smi (Z == 0 (eq) if true).
1256 inline void SmiTst(Register value) {
1257 tst(value, Operand(kSmiTagMask));
1258 }
1259 inline void NonNegativeSmiTst(Register value) {
1260 tst(value, Operand(kSmiTagMask | kSmiSignMask));
1261 }
1262 // Jump if the register contains a smi.
Steve Block1e0659c2011-05-24 12:43:12 +01001263 inline void JumpIfSmi(Register value, Label* smi_label) {
1264 tst(value, Operand(kSmiTagMask));
1265 b(eq, smi_label);
1266 }
1267 // Jump if either of the registers contain a non-smi.
1268 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1269 tst(value, Operand(kSmiTagMask));
1270 b(ne, not_smi_label);
1271 }
Andrei Popescu31002712010-02-23 13:46:05 +00001272 // Jump if either of the registers contain a non-smi.
1273 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1274 // Jump if either of the registers contain a smi.
1275 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1276
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001277 // Abort execution if argument is a smi, enabled via --debug-code.
1278 void AssertNotSmi(Register object);
1279 void AssertSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +01001280
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001281 // Abort execution if argument is not a string, enabled via --debug-code.
1282 void AssertString(Register object);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001283
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001284 // Abort execution if argument is not a name, enabled via --debug-code.
1285 void AssertName(Register object);
1286
1287 // Abort execution if argument is not undefined or an AllocationSite, enabled
1288 // via --debug-code.
1289 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1290
1291 // Abort execution if reg is not the root value with the given index,
1292 // enabled via --debug-code.
1293 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block1e0659c2011-05-24 12:43:12 +01001294
1295 // ---------------------------------------------------------------------------
1296 // HeapNumber utilities
1297
1298 void JumpIfNotHeapNumber(Register object,
1299 Register heap_number_map,
1300 Register scratch,
1301 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +01001302
Andrei Popescu31002712010-02-23 13:46:05 +00001303 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +00001304 // String utilities
1305
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001306 // Generate code to do a lookup in the number string cache. If the number in
1307 // the register object is found in the cache the generated code falls through
1308 // with the result in the result register. The object and the result register
1309 // can be the same. If the number is not found in the cache the code jumps to
1310 // the label not_found with only the content of register object unchanged.
1311 void LookupNumberStringCache(Register object,
1312 Register result,
1313 Register scratch1,
1314 Register scratch2,
1315 Register scratch3,
1316 Label* not_found);
1317
1318 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001319 // if either is not. Assumes that neither object is a smi.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001320 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register object1,
1321 Register object2,
1322 Register scratch1,
1323 Register scratch2,
1324 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001325
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001326 // Checks if both objects are sequential one-byte strings and jumps to label
Leon Clarked91b9f72010-01-27 17:25:45 +00001327 // if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001328 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1329 Register scratch1,
1330 Register scratch2,
1331 Label* not_flat_one_byte_strings);
Leon Clarked91b9f72010-01-27 17:25:45 +00001332
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001333 // Checks if both instance types are sequential one-byte strings and jumps to
Steve Block6ded16b2010-05-10 14:33:55 +01001334 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001335 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1336 Register first_object_instance_type, Register second_object_instance_type,
1337 Register scratch1, Register scratch2, Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001338
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001339 // Check if instance type is sequential one-byte string and jump to label if
Steve Block6ded16b2010-05-10 14:33:55 +01001340 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001341 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1342 Label* failure);
Steve Block6ded16b2010-05-10 14:33:55 +01001343
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001344 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1345
1346 void EmitSeqStringSetCharCheck(Register string,
1347 Register index,
1348 Register value,
1349 uint32_t encoding_mask);
Steve Block6ded16b2010-05-10 14:33:55 +01001350
Steve Block1e0659c2011-05-24 12:43:12 +01001351 // ---------------------------------------------------------------------------
1352 // Patching helpers.
1353
1354 // Get the location of a relocated constant (its address in the constant pool)
1355 // from its load site.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001356 void GetRelocatedValueLocation(Register ldr_location, Register result,
1357 Register scratch);
Steve Block1e0659c2011-05-24 12:43:12 +01001358
1359
Ben Murdoch257744e2011-11-30 15:57:28 +00001360 void ClampUint8(Register output_reg, Register input_reg);
1361
1362 void ClampDoubleToUint8(Register result_reg,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001363 DwVfpRegister input_reg,
1364 LowDwVfpRegister double_scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001365
1366
1367 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001368 void EnumLength(Register dst, Register map);
1369 void NumberOfOwnDescriptors(Register dst, Register map);
1370
1371 template<typename Field>
1372 void DecodeField(Register dst, Register src) {
1373 Ubfx(dst, src, Field::kShift, Field::kSize);
1374 }
1375
1376 template<typename Field>
1377 void DecodeField(Register reg) {
1378 DecodeField<Field>(reg, reg);
1379 }
1380
1381 template<typename Field>
1382 void DecodeFieldToSmi(Register dst, Register src) {
1383 static const int shift = Field::kShift;
1384 static const int mask = Field::kMask >> shift << kSmiTagSize;
1385 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1386 STATIC_ASSERT(kSmiTag == 0);
1387 if (shift < kSmiTagSize) {
1388 mov(dst, Operand(src, LSL, kSmiTagSize - shift));
1389 and_(dst, dst, Operand(mask));
1390 } else if (shift > kSmiTagSize) {
1391 mov(dst, Operand(src, LSR, shift - kSmiTagSize));
1392 and_(dst, dst, Operand(mask));
1393 } else {
1394 and_(dst, src, Operand(mask));
1395 }
1396 }
1397
1398 template<typename Field>
1399 void DecodeFieldToSmi(Register reg) {
1400 DecodeField<Field>(reg, reg);
1401 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001402
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001403 // Activation support.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001404 void EnterFrame(StackFrame::Type type, bool load_constant_pool = false);
1405 // Returns the pc offset at which the frame ends.
1406 int LeaveFrame(StackFrame::Type type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001407
1408 // Expects object in r0 and returns map with validated enum cache
1409 // in r0. Assumes that any other register can be used as a scratch.
1410 void CheckEnumCache(Register null_value, Label* call_runtime);
1411
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001412 // AllocationMemento support. Arrays may have an associated
1413 // AllocationMemento object that can be checked for in order to pretransition
1414 // to another type.
1415 // On entry, receiver_reg should point to the array object.
1416 // scratch_reg gets clobbered.
1417 // If allocation info is present, condition flags are set to eq.
1418 void TestJSArrayForAllocationMemento(Register receiver_reg,
1419 Register scratch_reg,
1420 Label* no_memento_found);
1421
1422 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1423 Register scratch_reg,
1424 Label* memento_found) {
1425 Label no_memento_found;
1426 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1427 &no_memento_found);
1428 b(eq, memento_found);
1429 bind(&no_memento_found);
1430 }
1431
1432 // Jumps to found label if a prototype map has dictionary elements.
1433 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1434 Register scratch1, Label* found);
1435
Steve Blocka7e24c12009-10-30 11:49:00 +00001436 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001437 void CallCFunctionHelper(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001438 int num_reg_arguments,
1439 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001440
Andrei Popescu31002712010-02-23 13:46:05 +00001441 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001442
1443 // Helper functions for generating invokes.
1444 void InvokePrologue(const ParameterCount& expected,
1445 const ParameterCount& actual,
1446 Handle<Code> code_constant,
1447 Register code_reg,
1448 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001449 bool* definitely_mismatches,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001450 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001451 const CallWrapper& call_wrapper);
Steve Blocka7e24c12009-10-30 11:49:00 +00001452
Steve Block6ded16b2010-05-10 14:33:55 +01001453 void InitializeNewString(Register string,
1454 Register length,
1455 Heap::RootListIndex map_index,
1456 Register scratch1,
1457 Register scratch2);
1458
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001459 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1460 void InNewSpace(Register object,
1461 Register scratch,
1462 Condition cond, // eq for new space, ne otherwise.
1463 Label* branch);
1464
1465 // Helper for finding the mark bits for an address. Afterwards, the
1466 // bitmap register points at the word with the mark bits and the mask
1467 // the position of the first bit. Leaves addr_reg unchanged.
1468 inline void GetMarkBits(Register addr_reg,
1469 Register bitmap_reg,
1470 Register mask_reg);
1471
1472 // Helper for throwing exceptions. Compute a handler address and jump to
1473 // it. See the implementation for register usage.
1474 void JumpToHandlerEntry();
1475
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001476 // Compute memory operands for safepoint stack slots.
1477 static int SafepointRegisterStackIndex(int reg_code);
1478 MemOperand SafepointRegisterSlot(Register reg);
1479 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1480
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001481 // Loads the constant pool pointer (pp) register.
1482 void LoadConstantPoolPointerRegister();
1483
Andrei Popescu31002712010-02-23 13:46:05 +00001484 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001485 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +00001486 // This handle will be patched with the code object on installation.
1487 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001488
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001489 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001490 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001491 friend class StandardFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001492};
1493
1494
Steve Blocka7e24c12009-10-30 11:49:00 +00001495// The code patcher is used to patch (typically) small parts of code e.g. for
1496// debugging and other types of instrumentation. When using the code patcher
1497// the exact number of bytes specified must be emitted. It is not legal to emit
1498// relocation information. If any of these constraints are violated it causes
1499// an assertion to fail.
1500class CodePatcher {
1501 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001502 enum FlushICache {
1503 FLUSH,
1504 DONT_FLUSH
1505 };
1506
1507 CodePatcher(byte* address,
1508 int instructions,
1509 FlushICache flush_cache = FLUSH);
Steve Blocka7e24c12009-10-30 11:49:00 +00001510 virtual ~CodePatcher();
1511
1512 // Macro assembler to emit code.
1513 MacroAssembler* masm() { return &masm_; }
1514
1515 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001516 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001517
1518 // Emit an address directly.
1519 void Emit(Address addr);
1520
Steve Block1e0659c2011-05-24 12:43:12 +01001521 // Emit the condition part of an instruction leaving the rest of the current
1522 // instruction unchanged.
1523 void EmitCondition(Condition cond);
1524
Steve Blocka7e24c12009-10-30 11:49:00 +00001525 private:
1526 byte* address_; // The address of the code being patched.
Steve Blocka7e24c12009-10-30 11:49:00 +00001527 int size_; // Number of bytes of the expected patch size.
1528 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001529 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Blocka7e24c12009-10-30 11:49:00 +00001530};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001531
1532
1533class FrameAndConstantPoolScope {
1534 public:
1535 FrameAndConstantPoolScope(MacroAssembler* masm, StackFrame::Type type)
1536 : masm_(masm),
1537 type_(type),
1538 old_has_frame_(masm->has_frame()),
1539 old_constant_pool_available_(masm->is_constant_pool_available()) {
1540 // We only want to enable constant pool access for non-manual frame scopes
1541 // to ensure the constant pool pointer is valid throughout the scope.
1542 DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
1543 masm->set_has_frame(true);
1544 masm->set_constant_pool_available(true);
1545 masm->EnterFrame(type, !old_constant_pool_available_);
1546 }
1547
1548 ~FrameAndConstantPoolScope() {
1549 masm_->LeaveFrame(type_);
1550 masm_->set_has_frame(old_has_frame_);
1551 masm_->set_constant_pool_available(old_constant_pool_available_);
1552 }
1553
1554 // Normally we generate the leave-frame code when this object goes
1555 // out of scope. Sometimes we may need to generate the code somewhere else
1556 // in addition. Calling this will achieve that, but the object stays in
1557 // scope, the MacroAssembler is still marked as being in a frame scope, and
1558 // the code will be generated again when it goes out of scope.
1559 void GenerateLeaveFrame() {
1560 DCHECK(type_ != StackFrame::MANUAL && type_ != StackFrame::NONE);
1561 masm_->LeaveFrame(type_);
1562 }
1563
1564 private:
1565 MacroAssembler* masm_;
1566 StackFrame::Type type_;
1567 bool old_has_frame_;
1568 bool old_constant_pool_available_;
1569
1570 DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope);
1571};
1572
1573
1574// Class for scoping the the unavailability of constant pool access.
1575class ConstantPoolUnavailableScope {
1576 public:
1577 explicit ConstantPoolUnavailableScope(MacroAssembler* masm)
1578 : masm_(masm),
1579 old_constant_pool_available_(masm->is_constant_pool_available()) {
1580 if (FLAG_enable_ool_constant_pool) {
1581 masm_->set_constant_pool_available(false);
1582 }
1583 }
1584 ~ConstantPoolUnavailableScope() {
1585 if (FLAG_enable_ool_constant_pool) {
1586 masm_->set_constant_pool_available(old_constant_pool_available_);
1587 }
1588 }
1589
1590 private:
1591 MacroAssembler* masm_;
1592 int old_constant_pool_available_;
1593
1594 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope);
1595};
Steve Blocka7e24c12009-10-30 11:49:00 +00001596
1597
1598// -----------------------------------------------------------------------------
1599// Static helper functions.
1600
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001601inline MemOperand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001602 return MemOperand(context, Context::SlotOffset(index));
1603}
1604
1605
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001606inline MemOperand GlobalObjectOperand() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001607 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001608}
1609
1610
Steve Blocka7e24c12009-10-30 11:49:00 +00001611#ifdef GENERATED_CODE_COVERAGE
1612#define CODE_COVERAGE_STRINGIFY(x) #x
1613#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1614#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1615#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1616#else
1617#define ACCESS_MASM(masm) masm->
1618#endif
1619
1620
1621} } // namespace v8::internal
1622
1623#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_