blob: 31ed8a32e118e0dc1c2466d49267eade9ace75a9 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
6#define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
7
8#include "src/assembler.h"
9#include "src/globals.h"
10#include "src/mips64/assembler-mips64.h"
11
12namespace v8 {
13namespace internal {
14
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000015// Give alias names to registers for calling conventions.
16const Register kReturnRegister0 = {Register::kCode_v0};
17const Register kReturnRegister1 = {Register::kCode_v1};
18const Register kJSFunctionRegister = {Register::kCode_a1};
19const Register kContextRegister = {Register::kCpRegister};
20const Register kInterpreterAccumulatorRegister = {Register::kCode_v0};
21const Register kInterpreterRegisterFileRegister = {Register::kCode_a7};
22const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_t0};
23const Register kInterpreterBytecodeArrayRegister = {Register::kCode_t1};
24const Register kInterpreterDispatchTableRegister = {Register::kCode_t2};
25const Register kJavaScriptCallArgCountRegister = {Register::kCode_a0};
26const Register kJavaScriptCallNewTargetRegister = {Register::kCode_a3};
27const Register kRuntimeCallFunctionRegister = {Register::kCode_a1};
28const Register kRuntimeCallArgCountRegister = {Register::kCode_a0};
29
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030// Forward declaration.
31class JumpTarget;
32
33// Reserved Register Usage Summary.
34//
35// Registers t8, t9, and at are reserved for use by the MacroAssembler.
36//
37// The programmer should know that the MacroAssembler may clobber these three,
38// but won't touch other registers except in special cases.
39//
40// Per the MIPS ABI, register t9 must be used for indirect function call
41// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
42// trying to update gp register for position-independent-code. Whenever
43// MIPS generated code calls C code, it must be via t9 register.
44
45
46// Flags used for LeaveExitFrame function.
47enum LeaveExitFrameMode {
48 EMIT_RETURN = true,
49 NO_EMIT_RETURN = false
50};
51
52// Flags used for AllocateHeapNumber
53enum TaggingMode {
54 // Tag the result.
55 TAG_RESULT,
56 // Don't tag
57 DONT_TAG_RESULT
58};
59
60// Flags used for the ObjectToDoubleFPURegister function.
61enum ObjectToDoubleFlags {
62 // No special flags.
63 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
64 // Object is known to be a non smi.
65 OBJECT_NOT_SMI = 1 << 0,
66 // Don't load NaNs or infinities, branch to the non number case instead.
67 AVOID_NANS_AND_INFINITIES = 1 << 1
68};
69
70// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
71enum BranchDelaySlot {
72 USE_DELAY_SLOT,
73 PROTECT
74};
75
76// Flags used for the li macro-assembler function.
77enum LiFlags {
78 // If the constant value can be represented in just 16 bits, then
79 // optimize the li to use a single instruction, rather than lui/ori/dsll
80 // sequence.
81 OPTIMIZE_SIZE = 0,
82 // Always use 6 instructions (lui/ori/dsll sequence), even if the constant
83 // could be loaded with just one, so that this value is patchable later.
84 CONSTANT_SIZE = 1,
85 // For address loads only 4 instruction are required. Used to mark
86 // constant load that will be used as address without relocation
87 // information. It ensures predictable code size, so specific sites
88 // in code are patchable.
89 ADDRESS_LOAD = 2
90};
91
92
93enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
94enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
95enum PointersToHereCheck {
96 kPointersToHereMaybeInteresting,
97 kPointersToHereAreAlwaysInteresting
98};
99enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
100
101Register GetRegisterThatIsNotOneOf(Register reg1,
102 Register reg2 = no_reg,
103 Register reg3 = no_reg,
104 Register reg4 = no_reg,
105 Register reg5 = no_reg,
106 Register reg6 = no_reg);
107
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
109 Register reg4 = no_reg, Register reg5 = no_reg,
110 Register reg6 = no_reg, Register reg7 = no_reg,
111 Register reg8 = no_reg, Register reg9 = no_reg,
112 Register reg10 = no_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113
114
115// -----------------------------------------------------------------------------
116// Static helper functions.
117
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118#if defined(V8_TARGET_LITTLE_ENDIAN)
119#define SmiWordOffset(offset) (offset + kPointerSize / 2)
120#else
121#define SmiWordOffset(offset) offset
122#endif
123
124
125inline MemOperand ContextMemOperand(Register context, int index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126 return MemOperand(context, Context::SlotOffset(index));
127}
128
129
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000130inline MemOperand NativeContextMemOperand() {
131 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132}
133
134
135// Generate a MemOperand for loading a field from an object.
136inline MemOperand FieldMemOperand(Register object, int offset) {
137 return MemOperand(object, offset - kHeapObjectTag);
138}
139
140
141inline MemOperand UntagSmiMemOperand(Register rm, int offset) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000142 // Assumes that Smis are shifted by 32 bits.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000143 STATIC_ASSERT(kSmiShift == 32);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144 return MemOperand(rm, SmiWordOffset(offset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145}
146
147
148inline MemOperand UntagSmiFieldMemOperand(Register rm, int offset) {
149 return UntagSmiMemOperand(rm, offset - kHeapObjectTag);
150}
151
152
153// Generate a MemOperand for storing arguments 5..N on the stack
154// when calling CallCFunction().
155// TODO(plind): Currently ONLY used for O32. Should be fixed for
156// n64, and used in RegExp code, and other places
157// with more than 8 arguments.
158inline MemOperand CFunctionArgumentOperand(int index) {
159 DCHECK(index > kCArgSlotCount);
160 // Argument 5 takes the slot just past the four Arg-slots.
161 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
162 return MemOperand(sp, offset);
163}
164
165
166// MacroAssembler implements a collection of frequently used macros.
167class MacroAssembler: public Assembler {
168 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000169 MacroAssembler(Isolate* isolate, void* buffer, int size,
170 CodeObjectRequired create_code_object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000171
172 // Arguments macros.
173#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
174#define COND_ARGS cond, r1, r2
175
176 // Cases when relocation is not needed.
177#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
178 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
179 inline void Name(BranchDelaySlot bd, target_type target) { \
180 Name(target, bd); \
181 } \
182 void Name(target_type target, \
183 COND_TYPED_ARGS, \
184 BranchDelaySlot bd = PROTECT); \
185 inline void Name(BranchDelaySlot bd, \
186 target_type target, \
187 COND_TYPED_ARGS) { \
188 Name(target, COND_ARGS, bd); \
189 }
190
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000191#define DECLARE_BRANCH_PROTOTYPES(Name) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000192 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000193 DECLARE_NORELOC_PROTOTYPE(Name, int32_t)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194
195 DECLARE_BRANCH_PROTOTYPES(Branch)
196 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
197 DECLARE_BRANCH_PROTOTYPES(BranchShort)
198
199#undef DECLARE_BRANCH_PROTOTYPES
200#undef COND_TYPED_ARGS
201#undef COND_ARGS
202
203
204 // Jump, Call, and Ret pseudo instructions implementing inter-working.
205#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
206 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
207
208 void Jump(Register target, COND_ARGS);
209 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
210 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
211 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
212 static int CallSize(Register target, COND_ARGS);
213 void Call(Register target, COND_ARGS);
214 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
215 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
216 int CallSize(Handle<Code> code,
217 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
218 TypeFeedbackId ast_id = TypeFeedbackId::None(),
219 COND_ARGS);
220 void Call(Handle<Code> code,
221 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
222 TypeFeedbackId ast_id = TypeFeedbackId::None(),
223 COND_ARGS);
224 void Ret(COND_ARGS);
225 inline void Ret(BranchDelaySlot bd, Condition cond = al,
226 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
227 Ret(cond, rs, rt, bd);
228 }
229
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000230 bool IsNear(Label* L, Condition cond, int rs_reg);
231
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232 void Branch(Label* L,
233 Condition cond,
234 Register rs,
235 Heap::RootListIndex index,
236 BranchDelaySlot bdslot = PROTECT);
237
238#undef COND_ARGS
239
240 // Emit code to discard a non-negative number of pointer-sized elements
241 // from the stack, clobbering only the sp register.
242 void Drop(int count,
243 Condition cond = cc_always,
244 Register reg = no_reg,
245 const Operand& op = Operand(no_reg));
246
247 // Trivial case of DropAndRet that utilizes the delay slot and only emits
248 // 2 instructions.
249 void DropAndRet(int drop);
250
251 void DropAndRet(int drop,
252 Condition cond,
253 Register reg,
254 const Operand& op);
255
256 // Swap two registers. If the scratch register is omitted then a slightly
257 // less efficient form using xor instead of mov is emitted.
258 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
259
260 void Call(Label* target);
261
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262 void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); }
263
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264 inline void Move(Register dst, Register src) {
265 if (!dst.is(src)) {
266 mov(dst, src);
267 }
268 }
269
270 inline void Move(FPURegister dst, FPURegister src) {
271 if (!dst.is(src)) {
272 mov_d(dst, src);
273 }
274 }
275
276 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
277 mfc1(dst_low, src);
278 mfhc1(dst_high, src);
279 }
280
281 inline void FmoveHigh(Register dst_high, FPURegister src) {
282 mfhc1(dst_high, src);
283 }
284
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285 inline void FmoveHigh(FPURegister dst, Register src_high) {
286 mthc1(src_high, dst);
287 }
288
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 inline void FmoveLow(Register dst_low, FPURegister src) {
290 mfc1(dst_low, src);
291 }
292
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000293 void FmoveLow(FPURegister dst, Register src_low);
294
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000295 inline void Move(FPURegister dst, Register src_low, Register src_high) {
296 mtc1(src_low, dst);
297 mthc1(src_high, dst);
298 }
299
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400300 void Move(FPURegister dst, float imm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 void Move(FPURegister dst, double imm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400302
303 // Conditional move.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000304 void Movz(Register rd, Register rs, Register rt);
305 void Movn(Register rd, Register rs, Register rt);
306 void Movt(Register rd, Register rs, uint16_t cc = 0);
307 void Movf(Register rd, Register rs, uint16_t cc = 0);
308
309 void Clz(Register rd, Register rs);
310
311 // Jump unconditionally to given label.
312 // We NEED a nop in the branch delay slot, as it used by v8, for example in
313 // CodeGenerator::ProcessDeferred().
314 // Currently the branch delay slot is filled by the MacroAssembler.
315 // Use rather b(Label) for code generation.
316 void jmp(Label* L) {
317 Branch(L);
318 }
319
320 void Load(Register dst, const MemOperand& src, Representation r);
321 void Store(Register src, const MemOperand& dst, Representation r);
322
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000323 void PushRoot(Heap::RootListIndex index) {
324 LoadRoot(at, index);
325 Push(at);
326 }
327
328 // Compare the object in a register to a value and jump if they are equal.
329 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
330 LoadRoot(at, index);
331 Branch(if_equal, eq, with, Operand(at));
332 }
333
334 // Compare the object in a register to a value and jump if they are not equal.
335 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
336 Label* if_not_equal) {
337 LoadRoot(at, index);
338 Branch(if_not_equal, ne, with, Operand(at));
339 }
340
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 // Load an object from the root table.
342 void LoadRoot(Register destination,
343 Heap::RootListIndex index);
344 void LoadRoot(Register destination,
345 Heap::RootListIndex index,
346 Condition cond, Register src1, const Operand& src2);
347
348 // Store an object to the root table.
349 void StoreRoot(Register source,
350 Heap::RootListIndex index);
351 void StoreRoot(Register source,
352 Heap::RootListIndex index,
353 Condition cond, Register src1, const Operand& src2);
354
355 // ---------------------------------------------------------------------------
356 // GC Support
357
358 void IncrementalMarkingRecordWriteHelper(Register object,
359 Register value,
360 Register address);
361
362 enum RememberedSetFinalAction {
363 kReturnAtEnd,
364 kFallThroughAtEnd
365 };
366
367
368 // Record in the remembered set the fact that we have a pointer to new space
369 // at the address pointed to by the addr register. Only works if addr is not
370 // in new space.
371 void RememberedSetHelper(Register object, // Used for debug code.
372 Register addr,
373 Register scratch,
374 SaveFPRegsMode save_fp,
375 RememberedSetFinalAction and_then);
376
377 void CheckPageFlag(Register object,
378 Register scratch,
379 int mask,
380 Condition cc,
381 Label* condition_met);
382
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 // Check if object is in new space. Jumps if the object is not in new space.
384 // The register scratch can be object itself, but it will be clobbered.
385 void JumpIfNotInNewSpace(Register object,
386 Register scratch,
387 Label* branch) {
388 InNewSpace(object, scratch, ne, branch);
389 }
390
391 // Check if object is in new space. Jumps if the object is in new space.
392 // The register scratch can be object itself, but scratch will be clobbered.
393 void JumpIfInNewSpace(Register object,
394 Register scratch,
395 Label* branch) {
396 InNewSpace(object, scratch, eq, branch);
397 }
398
399 // Check if an object has a given incremental marking color.
400 void HasColor(Register object,
401 Register scratch0,
402 Register scratch1,
403 Label* has_color,
404 int first_bit,
405 int second_bit);
406
407 void JumpIfBlack(Register object,
408 Register scratch0,
409 Register scratch1,
410 Label* on_black);
411
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412 // Checks the color of an object. If the object is white we jump to the
413 // incremental marker.
414 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
415 Register scratch3, Label* value_is_white);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000416
417 // Notify the garbage collector that we wrote a pointer into an object.
418 // |object| is the object being stored into, |value| is the object being
419 // stored. value and scratch registers are clobbered by the operation.
420 // The offset is the offset from the start of the object, not the offset from
421 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
422 void RecordWriteField(
423 Register object,
424 int offset,
425 Register value,
426 Register scratch,
427 RAStatus ra_status,
428 SaveFPRegsMode save_fp,
429 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
430 SmiCheck smi_check = INLINE_SMI_CHECK,
431 PointersToHereCheck pointers_to_here_check_for_value =
432 kPointersToHereMaybeInteresting);
433
434 // As above, but the offset has the tag presubtracted. For use with
435 // MemOperand(reg, off).
436 inline void RecordWriteContextSlot(
437 Register context,
438 int offset,
439 Register value,
440 Register scratch,
441 RAStatus ra_status,
442 SaveFPRegsMode save_fp,
443 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
444 SmiCheck smi_check = INLINE_SMI_CHECK,
445 PointersToHereCheck pointers_to_here_check_for_value =
446 kPointersToHereMaybeInteresting) {
447 RecordWriteField(context,
448 offset + kHeapObjectTag,
449 value,
450 scratch,
451 ra_status,
452 save_fp,
453 remembered_set_action,
454 smi_check,
455 pointers_to_here_check_for_value);
456 }
457
458 void RecordWriteForMap(
459 Register object,
460 Register map,
461 Register dst,
462 RAStatus ra_status,
463 SaveFPRegsMode save_fp);
464
465 // For a given |object| notify the garbage collector that the slot |address|
466 // has been written. |value| is the object being stored. The value and
467 // address registers are clobbered by the operation.
468 void RecordWrite(
469 Register object,
470 Register address,
471 Register value,
472 RAStatus ra_status,
473 SaveFPRegsMode save_fp,
474 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
475 SmiCheck smi_check = INLINE_SMI_CHECK,
476 PointersToHereCheck pointers_to_here_check_for_value =
477 kPointersToHereMaybeInteresting);
478
479
480 // ---------------------------------------------------------------------------
481 // Inline caching support.
482
483 // Generate code for checking access rights - used for security checks
484 // on access to global objects across environments. The holder register
485 // is left untouched, whereas both scratch registers are clobbered.
486 void CheckAccessGlobalProxy(Register holder_reg,
487 Register scratch,
488 Label* miss);
489
490 void GetNumberHash(Register reg0, Register scratch);
491
492 void LoadFromNumberDictionary(Label* miss,
493 Register elements,
494 Register key,
495 Register result,
496 Register reg0,
497 Register reg1,
498 Register reg2);
499
500
501 inline void MarkCode(NopMarkerTypes type) {
502 nop(type);
503 }
504
505 // Check if the given instruction is a 'type' marker.
506 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
507 // nop(type)). These instructions are generated to mark special location in
508 // the code, like some special IC code.
509 static inline bool IsMarkedCode(Instr instr, int type) {
510 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
511 return IsNop(instr, type);
512 }
513
514
515 static inline int GetCodeMarker(Instr instr) {
516 uint32_t opcode = ((instr & kOpcodeMask));
517 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
518 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
519 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
520
521 // Return <n> if we have a sll zero_reg, zero_reg, n
522 // else return -1.
523 bool sllzz = (opcode == SLL &&
524 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
525 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
526 int type =
527 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
528 DCHECK((type == -1) ||
529 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
530 return type;
531 }
532
533
534
535 // ---------------------------------------------------------------------------
536 // Allocation support.
537
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000538 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000539 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
540 // is passed. If the space is exhausted control continues at the gc_required
541 // label. The allocated object is returned in result. If the flag
542 // tag_allocated_object is true the result is tagged as as a heap object.
543 // All registers are clobbered also when control continues at the gc_required
544 // label.
545 void Allocate(int object_size,
546 Register result,
547 Register scratch1,
548 Register scratch2,
549 Label* gc_required,
550 AllocationFlags flags);
551
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000552 void Allocate(Register object_size, Register result, Register result_end,
553 Register scratch, Label* gc_required, AllocationFlags flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000554
555 void AllocateTwoByteString(Register result,
556 Register length,
557 Register scratch1,
558 Register scratch2,
559 Register scratch3,
560 Label* gc_required);
561 void AllocateOneByteString(Register result, Register length,
562 Register scratch1, Register scratch2,
563 Register scratch3, Label* gc_required);
564 void AllocateTwoByteConsString(Register result,
565 Register length,
566 Register scratch1,
567 Register scratch2,
568 Label* gc_required);
569 void AllocateOneByteConsString(Register result, Register length,
570 Register scratch1, Register scratch2,
571 Label* gc_required);
572 void AllocateTwoByteSlicedString(Register result,
573 Register length,
574 Register scratch1,
575 Register scratch2,
576 Label* gc_required);
577 void AllocateOneByteSlicedString(Register result, Register length,
578 Register scratch1, Register scratch2,
579 Label* gc_required);
580
581 // Allocates a heap number or jumps to the gc_required label if the young
582 // space is full and a scavenge is needed. All registers are clobbered also
583 // when control continues at the gc_required label.
584 void AllocateHeapNumber(Register result,
585 Register scratch1,
586 Register scratch2,
587 Register heap_number_map,
588 Label* gc_required,
589 TaggingMode tagging_mode = TAG_RESULT,
590 MutableMode mode = IMMUTABLE);
591
592 void AllocateHeapNumberWithValue(Register result,
593 FPURegister value,
594 Register scratch1,
595 Register scratch2,
596 Label* gc_required);
597
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000598 // Allocate and initialize a JSValue wrapper with the specified {constructor}
599 // and {value}.
600 void AllocateJSValue(Register result, Register constructor, Register value,
601 Register scratch1, Register scratch2,
602 Label* gc_required);
603
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000604 // ---------------------------------------------------------------------------
605 // Instruction macros.
606
607#define DEFINE_INSTRUCTION(instr) \
608 void instr(Register rd, Register rs, const Operand& rt); \
609 void instr(Register rd, Register rs, Register rt) { \
610 instr(rd, rs, Operand(rt)); \
611 } \
612 void instr(Register rs, Register rt, int32_t j) { \
613 instr(rs, rt, Operand(j)); \
614 }
615
616#define DEFINE_INSTRUCTION2(instr) \
617 void instr(Register rs, const Operand& rt); \
618 void instr(Register rs, Register rt) { \
619 instr(rs, Operand(rt)); \
620 } \
621 void instr(Register rs, int32_t j) { \
622 instr(rs, Operand(j)); \
623 }
624
625 DEFINE_INSTRUCTION(Addu);
626 DEFINE_INSTRUCTION(Daddu);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400627 DEFINE_INSTRUCTION(Div);
628 DEFINE_INSTRUCTION(Divu);
629 DEFINE_INSTRUCTION(Ddivu);
630 DEFINE_INSTRUCTION(Mod);
631 DEFINE_INSTRUCTION(Modu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000632 DEFINE_INSTRUCTION(Ddiv);
633 DEFINE_INSTRUCTION(Subu);
634 DEFINE_INSTRUCTION(Dsubu);
635 DEFINE_INSTRUCTION(Dmod);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400636 DEFINE_INSTRUCTION(Dmodu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000637 DEFINE_INSTRUCTION(Mul);
638 DEFINE_INSTRUCTION(Mulh);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400639 DEFINE_INSTRUCTION(Mulhu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640 DEFINE_INSTRUCTION(Dmul);
641 DEFINE_INSTRUCTION(Dmulh);
642 DEFINE_INSTRUCTION2(Mult);
643 DEFINE_INSTRUCTION2(Dmult);
644 DEFINE_INSTRUCTION2(Multu);
645 DEFINE_INSTRUCTION2(Dmultu);
646 DEFINE_INSTRUCTION2(Div);
647 DEFINE_INSTRUCTION2(Ddiv);
648 DEFINE_INSTRUCTION2(Divu);
649 DEFINE_INSTRUCTION2(Ddivu);
650
651 DEFINE_INSTRUCTION(And);
652 DEFINE_INSTRUCTION(Or);
653 DEFINE_INSTRUCTION(Xor);
654 DEFINE_INSTRUCTION(Nor);
655 DEFINE_INSTRUCTION2(Neg);
656
657 DEFINE_INSTRUCTION(Slt);
658 DEFINE_INSTRUCTION(Sltu);
659
660 // MIPS32 R2 instruction macro.
661 DEFINE_INSTRUCTION(Ror);
662 DEFINE_INSTRUCTION(Dror);
663
664#undef DEFINE_INSTRUCTION
665#undef DEFINE_INSTRUCTION2
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000666#undef DEFINE_INSTRUCTION3
667
668 void Lsa(Register rd, Register rs, Register rt, uint8_t sa,
669 Register scratch = at);
670 void Dlsa(Register rd, Register rs, Register rt, uint8_t sa,
671 Register scratch = at);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000672
673 void Pref(int32_t hint, const MemOperand& rs);
674
675
676 // ---------------------------------------------------------------------------
677 // Pseudo-instructions.
678
679 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
680
681 void Ulw(Register rd, const MemOperand& rs);
682 void Usw(Register rd, const MemOperand& rs);
683 void Uld(Register rd, const MemOperand& rs, Register scratch = at);
684 void Usd(Register rd, const MemOperand& rs, Register scratch = at);
685
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000686 void LoadWordPair(Register rd, const MemOperand& rs, Register scratch = at);
687 void StoreWordPair(Register rd, const MemOperand& rs, Register scratch = at);
688
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000689 // Load int32 in the rd register.
690 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
691 inline void li(Register rd, int64_t j, LiFlags mode = OPTIMIZE_SIZE) {
692 li(rd, Operand(j), mode);
693 }
694 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
695
696 // Push multiple registers on the stack.
697 // Registers are saved in numerical order, with higher numbered registers
698 // saved in higher memory addresses.
699 void MultiPush(RegList regs);
700 void MultiPushReversed(RegList regs);
701
702 void MultiPushFPU(RegList regs);
703 void MultiPushReversedFPU(RegList regs);
704
705 void push(Register src) {
706 Daddu(sp, sp, Operand(-kPointerSize));
707 sd(src, MemOperand(sp, 0));
708 }
709 void Push(Register src) { push(src); }
710
711 // Push a handle.
712 void Push(Handle<Object> handle);
713 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
714
715 // Push two registers. Pushes leftmost register first (to highest address).
716 void Push(Register src1, Register src2) {
717 Dsubu(sp, sp, Operand(2 * kPointerSize));
718 sd(src1, MemOperand(sp, 1 * kPointerSize));
719 sd(src2, MemOperand(sp, 0 * kPointerSize));
720 }
721
722 // Push three registers. Pushes leftmost register first (to highest address).
723 void Push(Register src1, Register src2, Register src3) {
724 Dsubu(sp, sp, Operand(3 * kPointerSize));
725 sd(src1, MemOperand(sp, 2 * kPointerSize));
726 sd(src2, MemOperand(sp, 1 * kPointerSize));
727 sd(src3, MemOperand(sp, 0 * kPointerSize));
728 }
729
730 // Push four registers. Pushes leftmost register first (to highest address).
731 void Push(Register src1, Register src2, Register src3, Register src4) {
732 Dsubu(sp, sp, Operand(4 * kPointerSize));
733 sd(src1, MemOperand(sp, 3 * kPointerSize));
734 sd(src2, MemOperand(sp, 2 * kPointerSize));
735 sd(src3, MemOperand(sp, 1 * kPointerSize));
736 sd(src4, MemOperand(sp, 0 * kPointerSize));
737 }
738
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000739 // Push five registers. Pushes leftmost register first (to highest address).
740 void Push(Register src1, Register src2, Register src3, Register src4,
741 Register src5) {
742 Dsubu(sp, sp, Operand(5 * kPointerSize));
743 sd(src1, MemOperand(sp, 4 * kPointerSize));
744 sd(src2, MemOperand(sp, 3 * kPointerSize));
745 sd(src3, MemOperand(sp, 2 * kPointerSize));
746 sd(src4, MemOperand(sp, 1 * kPointerSize));
747 sd(src5, MemOperand(sp, 0 * kPointerSize));
748 }
749
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000750 void Push(Register src, Condition cond, Register tst1, Register tst2) {
751 // Since we don't have conditional execution we use a Branch.
752 Branch(3, cond, tst1, Operand(tst2));
753 Dsubu(sp, sp, Operand(kPointerSize));
754 sd(src, MemOperand(sp, 0));
755 }
756
757 void PushRegisterAsTwoSmis(Register src, Register scratch = at);
758 void PopRegisterAsTwoSmis(Register dst, Register scratch = at);
759
760 // Pops multiple values from the stack and load them in the
761 // registers specified in regs. Pop order is the opposite as in MultiPush.
762 void MultiPop(RegList regs);
763 void MultiPopReversed(RegList regs);
764
765 void MultiPopFPU(RegList regs);
766 void MultiPopReversedFPU(RegList regs);
767
768 void pop(Register dst) {
769 ld(dst, MemOperand(sp, 0));
770 Daddu(sp, sp, Operand(kPointerSize));
771 }
772 void Pop(Register dst) { pop(dst); }
773
774 // Pop two registers. Pops rightmost register first (from lower address).
775 void Pop(Register src1, Register src2) {
776 DCHECK(!src1.is(src2));
777 ld(src2, MemOperand(sp, 0 * kPointerSize));
778 ld(src1, MemOperand(sp, 1 * kPointerSize));
779 Daddu(sp, sp, 2 * kPointerSize);
780 }
781
782 // Pop three registers. Pops rightmost register first (from lower address).
783 void Pop(Register src1, Register src2, Register src3) {
784 ld(src3, MemOperand(sp, 0 * kPointerSize));
785 ld(src2, MemOperand(sp, 1 * kPointerSize));
786 ld(src1, MemOperand(sp, 2 * kPointerSize));
787 Daddu(sp, sp, 3 * kPointerSize);
788 }
789
790 void Pop(uint32_t count = 1) {
791 Daddu(sp, sp, Operand(count * kPointerSize));
792 }
793
794 // Push and pop the registers that can hold pointers, as defined by the
795 // RegList constant kSafepointSavedRegisters.
796 void PushSafepointRegisters();
797 void PopSafepointRegisters();
798 // Store value in register src in the safepoint stack slot for
799 // register dst.
800 void StoreToSafepointRegisterSlot(Register src, Register dst);
801 // Load the value of the src register from its safepoint stack slot
802 // into register dst.
803 void LoadFromSafepointRegisterSlot(Register dst, Register src);
804
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000805 // MIPS64 R2 instruction macro.
806 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000807 void Dins(Register rt, Register rs, uint16_t pos, uint16_t size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000808 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400809 void Dext(Register rt, Register rs, uint16_t pos, uint16_t size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000810 void Dextm(Register rt, Register rs, uint16_t pos, uint16_t size);
811 void Dextu(Register rt, Register rs, uint16_t pos, uint16_t size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000812
813 // ---------------------------------------------------------------------------
814 // FPU macros. These do not handle special cases like NaN or +- inf.
815
816 // Convert unsigned word to double.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000817 void Cvt_d_uw(FPURegister fd, FPURegister fs);
818 void Cvt_d_uw(FPURegister fd, Register rs);
819
820 // Convert unsigned long to double.
821 void Cvt_d_ul(FPURegister fd, FPURegister fs);
822 void Cvt_d_ul(FPURegister fd, Register rs);
823
824 // Convert unsigned long to float.
825 void Cvt_s_ul(FPURegister fd, FPURegister fs);
826 void Cvt_s_ul(FPURegister fd, Register rs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000827
828 // Convert double to unsigned long.
829 void Trunc_l_ud(FPURegister fd, FPURegister fs, FPURegister scratch);
830
831 void Trunc_l_d(FPURegister fd, FPURegister fs);
832 void Round_l_d(FPURegister fd, FPURegister fs);
833 void Floor_l_d(FPURegister fd, FPURegister fs);
834 void Ceil_l_d(FPURegister fd, FPURegister fs);
835
836 // Convert double to unsigned word.
837 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
838 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
839
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000840 // Convert double to unsigned long.
841 void Trunc_ul_d(FPURegister fd, FPURegister fs, FPURegister scratch,
842 Register result = no_reg);
843 void Trunc_ul_d(FPURegister fd, Register rs, FPURegister scratch,
844 Register result = no_reg);
845
846 // Convert single to unsigned long.
847 void Trunc_ul_s(FPURegister fd, FPURegister fs, FPURegister scratch,
848 Register result = no_reg);
849 void Trunc_ul_s(FPURegister fd, Register rs, FPURegister scratch,
850 Register result = no_reg);
851
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000852 void Trunc_w_d(FPURegister fd, FPURegister fs);
853 void Round_w_d(FPURegister fd, FPURegister fs);
854 void Floor_w_d(FPURegister fd, FPURegister fs);
855 void Ceil_w_d(FPURegister fd, FPURegister fs);
856
857 void Madd_d(FPURegister fd,
858 FPURegister fr,
859 FPURegister fs,
860 FPURegister ft,
861 FPURegister scratch);
862
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000863 // Wrapper functions for the different cmp/branch types.
864 inline void BranchF32(Label* target, Label* nan, Condition cc,
865 FPURegister cmp1, FPURegister cmp2,
866 BranchDelaySlot bd = PROTECT) {
867 BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
868 }
869
870 inline void BranchF64(Label* target, Label* nan, Condition cc,
871 FPURegister cmp1, FPURegister cmp2,
872 BranchDelaySlot bd = PROTECT) {
873 BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
874 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000875
876 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000877 inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
878 Condition cc, FPURegister cmp1, FPURegister cmp2) {
879 BranchF64(target, nan, cc, cmp1, cmp2, bd);
880 }
881
882 inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
883 Condition cc, FPURegister cmp1, FPURegister cmp2) {
884 BranchF32(target, nan, cc, cmp1, cmp2, bd);
885 }
886
887 // Alias functions for backward compatibility.
888 inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
889 FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
890 BranchF64(target, nan, cc, cmp1, cmp2, bd);
891 }
892
893 inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
894 Condition cc, FPURegister cmp1, FPURegister cmp2) {
895 BranchF64(bd, target, nan, cc, cmp1, cmp2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000896 }
897
898 // Truncates a double using a specific rounding mode, and writes the value
899 // to the result register.
900 // The except_flag will contain any exceptions caused by the instruction.
901 // If check_inexact is kDontCheckForInexactConversion, then the inexact
902 // exception is masked.
903 void EmitFPUTruncate(FPURoundingMode rounding_mode,
904 Register result,
905 DoubleRegister double_input,
906 Register scratch,
907 DoubleRegister double_scratch,
908 Register except_flag,
909 CheckForInexactConversion check_inexact
910 = kDontCheckForInexactConversion);
911
912 // Performs a truncating conversion of a floating point number as used by
913 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
914 // succeeds, otherwise falls through if result is saturated. On return
915 // 'result' either holds answer, or is clobbered on fall through.
916 //
917 // Only public for the test code in test-code-stubs-arm.cc.
918 void TryInlineTruncateDoubleToI(Register result,
919 DoubleRegister input,
920 Label* done);
921
922 // Performs a truncating conversion of a floating point number as used by
923 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
924 // Exits with 'result' holding the answer.
925 void TruncateDoubleToI(Register result, DoubleRegister double_input);
926
927 // Performs a truncating conversion of a heap number as used by
928 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
929 // must be different registers. Exits with 'result' holding the answer.
930 void TruncateHeapNumberToI(Register result, Register object);
931
932 // Converts the smi or heap number in object to an int32 using the rules
933 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
934 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
935 // different registers.
936 void TruncateNumberToI(Register object,
937 Register result,
938 Register heap_number_map,
939 Register scratch,
940 Label* not_int32);
941
942 // Loads the number from object into dst register.
943 // If |object| is neither smi nor heap number, |not_number| is jumped to
944 // with |object| still intact.
945 void LoadNumber(Register object,
946 FPURegister dst,
947 Register heap_number_map,
948 Register scratch,
949 Label* not_number);
950
951 // Loads the number from object into double_dst in the double format.
952 // Control will jump to not_int32 if the value cannot be exactly represented
953 // by a 32-bit integer.
954 // Floating point value in the 32-bit integer range that are not exact integer
955 // won't be loaded.
956 void LoadNumberAsInt32Double(Register object,
957 DoubleRegister double_dst,
958 Register heap_number_map,
959 Register scratch1,
960 Register scratch2,
961 FPURegister double_scratch,
962 Label* not_int32);
963
964 // Loads the number from object into dst as a 32-bit integer.
965 // Control will jump to not_int32 if the object cannot be exactly represented
966 // by a 32-bit integer.
967 // Floating point value in the 32-bit integer range that are not exact integer
968 // won't be converted.
969 void LoadNumberAsInt32(Register object,
970 Register dst,
971 Register heap_number_map,
972 Register scratch1,
973 Register scratch2,
974 FPURegister double_scratch0,
975 FPURegister double_scratch1,
976 Label* not_int32);
977
978 // Enter exit frame.
979 // argc - argument count to be dropped by LeaveExitFrame.
980 // save_doubles - saves FPU registers on stack, currently disabled.
981 // stack_space - extra stack space.
982 void EnterExitFrame(bool save_doubles,
983 int stack_space = 0);
984
985 // Leave the current exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000986 void LeaveExitFrame(bool save_doubles, Register arg_count,
987 bool restore_context, bool do_return = NO_EMIT_RETURN,
988 bool argument_count_is_length = false);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000989
990 // Get the actual activation frame alignment for target environment.
991 static int ActivationFrameAlignment();
992
993 // Make sure the stack is aligned. Only emits code in debug mode.
994 void AssertStackIsAligned();
995
996 void LoadContext(Register dst, int context_chain_length);
997
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000998 // Load the global object from the current context.
999 void LoadGlobalObject(Register dst) {
1000 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
1001 }
1002
1003 // Load the global proxy from the current context.
1004 void LoadGlobalProxy(Register dst) {
1005 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
1006 }
1007
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001008 // Conditionally load the cached Array transitioned map of type
1009 // transitioned_kind from the native context if the map in register
1010 // map_in_out is the cached Array map in the native context of
1011 // expected_kind.
1012 void LoadTransitionedArrayMapConditional(
1013 ElementsKind expected_kind,
1014 ElementsKind transitioned_kind,
1015 Register map_in_out,
1016 Register scratch,
1017 Label* no_map_match);
1018
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001019 void LoadNativeContextSlot(int index, Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020
1021 // Load the initial map from the global function. The registers
1022 // function and map can be the same, function is then overwritten.
1023 void LoadGlobalFunctionInitialMap(Register function,
1024 Register map,
1025 Register scratch);
1026
1027 void InitializeRootRegister() {
1028 ExternalReference roots_array_start =
1029 ExternalReference::roots_array_start(isolate());
1030 li(kRootRegister, Operand(roots_array_start));
1031 }
1032
1033 // -------------------------------------------------------------------------
1034 // JavaScript invokes.
1035
1036 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001037 void InvokeFunctionCode(Register function, Register new_target,
1038 const ParameterCount& expected,
1039 const ParameterCount& actual, InvokeFlag flag,
1040 const CallWrapper& call_wrapper);
1041
1042 void FloodFunctionIfStepping(Register fun, Register new_target,
1043 const ParameterCount& expected,
1044 const ParameterCount& actual);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001045
1046 // Invoke the JavaScript function in the given register. Changes the
1047 // current context to the context in the function before invoking.
1048 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001049 Register new_target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001050 const ParameterCount& actual,
1051 InvokeFlag flag,
1052 const CallWrapper& call_wrapper);
1053
1054 void InvokeFunction(Register function,
1055 const ParameterCount& expected,
1056 const ParameterCount& actual,
1057 InvokeFlag flag,
1058 const CallWrapper& call_wrapper);
1059
1060 void InvokeFunction(Handle<JSFunction> function,
1061 const ParameterCount& expected,
1062 const ParameterCount& actual,
1063 InvokeFlag flag,
1064 const CallWrapper& call_wrapper);
1065
1066
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001067 void IsObjectJSStringType(Register object,
1068 Register scratch,
1069 Label* fail);
1070
1071 void IsObjectNameType(Register object,
1072 Register scratch,
1073 Label* fail);
1074
1075 // -------------------------------------------------------------------------
1076 // Debugger Support.
1077
1078 void DebugBreak();
1079
1080 // -------------------------------------------------------------------------
1081 // Exception handling.
1082
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001083 // Push a new stack handler and link into stack handler chain.
1084 void PushStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001085
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001086 // Unlink the stack handler on top of the stack from the stack handler chain.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001087 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001088 void PopStackHandler();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001089
1090 // Copies a number of bytes from src to dst. All registers are clobbered. On
1091 // exit src and dst will point to the place just after where the last byte was
1092 // read or written and length will be zero.
1093 void CopyBytes(Register src,
1094 Register dst,
1095 Register length,
1096 Register scratch);
1097
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001098 // Initialize fields with filler values. Fields starting at |current_address|
1099 // not including |end_address| are overwritten with the value in |filler|. At
1100 // the end the loop, |current_address| takes the value of |end_address|.
1101 void InitializeFieldsWithFiller(Register current_address,
1102 Register end_address, Register filler);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001103
1104 // -------------------------------------------------------------------------
1105 // Support functions.
1106
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001107 // Machine code version of Map::GetConstructor().
1108 // |temp| holds |result|'s map when done, and |temp2| its instance type.
1109 void GetMapConstructor(Register result, Register map, Register temp,
1110 Register temp2);
1111
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001112 // Try to get function prototype of a function and puts the value in
1113 // the result register. Checks that the function really is a
1114 // function and jumps to the miss label if the fast checks fail. The
1115 // function register will be untouched; the other registers may be
1116 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001117 void TryGetFunctionPrototype(Register function, Register result,
1118 Register scratch, Label* miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001119
1120 void GetObjectType(Register function,
1121 Register map,
1122 Register type_reg);
1123
1124 // Check if a map for a JSObject indicates that the object has fast elements.
1125 // Jump to the specified label if it does not.
1126 void CheckFastElements(Register map,
1127 Register scratch,
1128 Label* fail);
1129
1130 // Check if a map for a JSObject indicates that the object can have both smi
1131 // and HeapObject elements. Jump to the specified label if it does not.
1132 void CheckFastObjectElements(Register map,
1133 Register scratch,
1134 Label* fail);
1135
1136 // Check if a map for a JSObject indicates that the object has fast smi only
1137 // elements. Jump to the specified label if it does not.
1138 void CheckFastSmiElements(Register map,
1139 Register scratch,
1140 Label* fail);
1141
1142 // Check to see if maybe_number can be stored as a double in
1143 // FastDoubleElements. If it can, store it at the index specified by key in
1144 // the FastDoubleElements array elements. Otherwise jump to fail.
1145 void StoreNumberToDoubleElements(Register value_reg,
1146 Register key_reg,
1147 Register elements_reg,
1148 Register scratch1,
1149 Register scratch2,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001150 Label* fail,
1151 int elements_offset = 0);
1152
1153 // Compare an object's map with the specified map and its transitioned
1154 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1155 // "branch_to" if the result of the comparison is "cond". If multiple map
1156 // compares are required, the compare sequences branches to early_success.
1157 void CompareMapAndBranch(Register obj,
1158 Register scratch,
1159 Handle<Map> map,
1160 Label* early_success,
1161 Condition cond,
1162 Label* branch_to);
1163
1164 // As above, but the map of the object is already loaded into the register
1165 // which is preserved by the code generated.
1166 void CompareMapAndBranch(Register obj_map,
1167 Handle<Map> map,
1168 Label* early_success,
1169 Condition cond,
1170 Label* branch_to);
1171
1172 // Check if the map of an object is equal to a specified map and branch to
1173 // label if not. Skip the smi check if not required (object is known to be a
1174 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1175 // against maps that are ElementsKind transition maps of the specificed map.
1176 void CheckMap(Register obj,
1177 Register scratch,
1178 Handle<Map> map,
1179 Label* fail,
1180 SmiCheckType smi_check_type);
1181
1182
1183 void CheckMap(Register obj,
1184 Register scratch,
1185 Heap::RootListIndex index,
1186 Label* fail,
1187 SmiCheckType smi_check_type);
1188
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001189 // Check if the map of an object is equal to a specified weak map and branch
1190 // to a specified target if equal. Skip the smi check if not required
1191 // (object is known to be a heap object)
1192 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1193 Handle<WeakCell> cell, Handle<Code> success,
1194 SmiCheckType smi_check_type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001195
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001196 // If the value is a NaN, canonicalize the value else, do nothing.
1197 void FPUCanonicalizeNaN(const DoubleRegister dst, const DoubleRegister src);
1198
1199
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001200 // Get value of the weak cell.
1201 void GetWeakValue(Register value, Handle<WeakCell> cell);
1202
1203 // Load the value of the weak cell in the value register. Branch to the
1204 // given miss label is the weak cell was cleared.
1205 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001206
1207 // Load and check the instance type of an object for being a string.
1208 // Loads the type into the second argument register.
1209 // Returns a condition that will be enabled if the object was a string.
1210 Condition IsObjectStringType(Register obj,
1211 Register type,
1212 Register result) {
1213 ld(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1214 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1215 And(type, type, Operand(kIsNotStringMask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001216 DCHECK_EQ(0u, kStringTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001217 return eq;
1218 }
1219
1220
1221 // Picks out an array index from the hash field.
1222 // Register use:
1223 // hash - holds the index's hash. Clobbered.
1224 // index - holds the overwritten index on exit.
1225 void IndexFromHash(Register hash, Register index);
1226
1227 // Get the number of least significant bits from a register.
1228 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1229 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1230
1231 // Load the value of a number object into a FPU double register. If the
1232 // object is not a number a jump to the label not_number is performed
1233 // and the FPU double register is unchanged.
1234 void ObjectToDoubleFPURegister(
1235 Register object,
1236 FPURegister value,
1237 Register scratch1,
1238 Register scratch2,
1239 Register heap_number_map,
1240 Label* not_number,
1241 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1242
1243 // Load the value of a smi object into a FPU double register. The register
1244 // scratch1 can be the same register as smi in which case smi will hold the
1245 // untagged value afterwards.
1246 void SmiToDoubleFPURegister(Register smi,
1247 FPURegister value,
1248 Register scratch1);
1249
1250 // -------------------------------------------------------------------------
1251 // Overflow handling functions.
1252 // Usage: first call the appropriate arithmetic function, then call one of the
1253 // jump functions with the overflow_dst register as the second parameter.
1254
1255 void AdduAndCheckForOverflow(Register dst,
1256 Register left,
1257 Register right,
1258 Register overflow_dst,
1259 Register scratch = at);
1260
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001261 void AdduAndCheckForOverflow(Register dst, Register left,
1262 const Operand& right, Register overflow_dst,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001263 Register scratch);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001264
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001265 void SubuAndCheckForOverflow(Register dst,
1266 Register left,
1267 Register right,
1268 Register overflow_dst,
1269 Register scratch = at);
1270
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001271 void SubuAndCheckForOverflow(Register dst, Register left,
1272 const Operand& right, Register overflow_dst,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001273 Register scratch);
1274
1275 void DadduAndCheckForOverflow(Register dst, Register left, Register right,
1276 Register overflow_dst, Register scratch = at);
1277
1278 void DadduAndCheckForOverflow(Register dst, Register left,
1279 const Operand& right, Register overflow_dst,
1280 Register scratch);
1281
1282 inline void DaddBranchOvf(Register dst, Register left, const Operand& right,
1283 Label* overflow_label, Register scratch = at) {
1284 DaddBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
1285 }
1286
1287 inline void DaddBranchNoOvf(Register dst, Register left, const Operand& right,
1288 Label* no_overflow_label, Register scratch = at) {
1289 DaddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
1290 }
1291
1292 void DaddBranchOvf(Register dst, Register left, const Operand& right,
1293 Label* overflow_label, Label* no_overflow_label,
1294 Register scratch = at);
1295
1296 void DaddBranchOvf(Register dst, Register left, Register right,
1297 Label* overflow_label, Label* no_overflow_label,
1298 Register scratch = at);
1299
1300 void DsubuAndCheckForOverflow(Register dst, Register left, Register right,
1301 Register overflow_dst, Register scratch = at);
1302
1303 void DsubuAndCheckForOverflow(Register dst, Register left,
1304 const Operand& right, Register overflow_dst,
1305 Register scratch);
1306
1307 inline void DsubBranchOvf(Register dst, Register left, const Operand& right,
1308 Label* overflow_label, Register scratch = at) {
1309 DsubBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
1310 }
1311
1312 inline void DsubBranchNoOvf(Register dst, Register left, const Operand& right,
1313 Label* no_overflow_label, Register scratch = at) {
1314 DsubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
1315 }
1316
1317 void DsubBranchOvf(Register dst, Register left, const Operand& right,
1318 Label* overflow_label, Label* no_overflow_label,
1319 Register scratch = at);
1320
1321 void DsubBranchOvf(Register dst, Register left, Register right,
1322 Label* overflow_label, Label* no_overflow_label,
1323 Register scratch = at);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001324
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001325 void BranchOnOverflow(Label* label,
1326 Register overflow_check,
1327 BranchDelaySlot bd = PROTECT) {
1328 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1329 }
1330
1331 void BranchOnNoOverflow(Label* label,
1332 Register overflow_check,
1333 BranchDelaySlot bd = PROTECT) {
1334 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1335 }
1336
1337 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1338 Ret(lt, overflow_check, Operand(zero_reg), bd);
1339 }
1340
1341 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1342 Ret(ge, overflow_check, Operand(zero_reg), bd);
1343 }
1344
1345 // -------------------------------------------------------------------------
1346 // Runtime calls.
1347
1348 // See comments at the beginning of CEntryStub::Generate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001349 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001350
1351 inline void PrepareCEntryFunction(const ExternalReference& ref) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001352 li(a1, Operand(ref));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001353 }
1354
1355#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1356const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1357
1358 // Call a code stub.
1359 void CallStub(CodeStub* stub,
1360 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1361 COND_ARGS);
1362
1363 // Tail call a code stub (jump).
1364 void TailCallStub(CodeStub* stub, COND_ARGS);
1365
1366#undef COND_ARGS
1367
1368 void CallJSExitStub(CodeStub* stub);
1369
1370 // Call a runtime routine.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001371 void CallRuntime(const Runtime::Function* f, int num_arguments,
1372 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1373 BranchDelaySlot bd = PROTECT);
1374 void CallRuntimeSaveDoubles(Runtime::FunctionId fid) {
1375 const Runtime::Function* function = Runtime::FunctionForId(fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001376 CallRuntime(function, function->nargs, kSaveFPRegs);
1377 }
1378
1379 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001380 void CallRuntime(Runtime::FunctionId fid,
1381 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1382 BranchDelaySlot bd = PROTECT) {
1383 const Runtime::Function* function = Runtime::FunctionForId(fid);
1384 CallRuntime(function, function->nargs, save_doubles, bd);
1385 }
1386
1387 // Convenience function: Same as above, but takes the fid instead.
1388 void CallRuntime(Runtime::FunctionId fid, int num_arguments,
1389 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1390 BranchDelaySlot bd = PROTECT) {
1391 CallRuntime(Runtime::FunctionForId(fid), num_arguments, save_doubles, bd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001392 }
1393
1394 // Convenience function: call an external reference.
1395 void CallExternalReference(const ExternalReference& ext,
1396 int num_arguments,
1397 BranchDelaySlot bd = PROTECT);
1398
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001399 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001400 void TailCallRuntime(Runtime::FunctionId fid);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001401
1402 int CalculateStackPassedWords(int num_reg_arguments,
1403 int num_double_arguments);
1404
1405 // Before calling a C-function from generated code, align arguments on stack
1406 // and add space for the four mips argument slots.
1407 // After aligning the frame, non-register arguments must be stored on the
1408 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1409 // The argument count assumes all arguments are word sized.
1410 // Some compilers/platforms require the stack to be aligned when calling
1411 // C++ code.
1412 // Needs a scratch register to do some arithmetic. This register will be
1413 // trashed.
1414 void PrepareCallCFunction(int num_reg_arguments,
1415 int num_double_registers,
1416 Register scratch);
1417 void PrepareCallCFunction(int num_reg_arguments,
1418 Register scratch);
1419
1420 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1421 // Arguments 5..n are stored to stack using following:
1422 // sw(a4, CFunctionArgumentOperand(5));
1423
1424 // Calls a C function and cleans up the space for arguments allocated
1425 // by PrepareCallCFunction. The called function is not allowed to trigger a
1426 // garbage collection, since that might move the code and invalidate the
1427 // return address (unless this is somehow accounted for by the called
1428 // function).
1429 void CallCFunction(ExternalReference function, int num_arguments);
1430 void CallCFunction(Register function, int num_arguments);
1431 void CallCFunction(ExternalReference function,
1432 int num_reg_arguments,
1433 int num_double_arguments);
1434 void CallCFunction(Register function,
1435 int num_reg_arguments,
1436 int num_double_arguments);
1437 void MovFromFloatResult(DoubleRegister dst);
1438 void MovFromFloatParameter(DoubleRegister dst);
1439
1440 // There are two ways of passing double arguments on MIPS, depending on
1441 // whether soft or hard floating point ABI is used. These functions
1442 // abstract parameter passing for the three different ways we call
1443 // C functions from generated code.
1444 void MovToFloatParameter(DoubleRegister src);
1445 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1446 void MovToFloatResult(DoubleRegister src);
1447
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001448 // Jump to the builtin routine.
1449 void JumpToExternalReference(const ExternalReference& builtin,
1450 BranchDelaySlot bd = PROTECT);
1451
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001452 // Invoke specified builtin JavaScript function.
1453 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001454 const CallWrapper& call_wrapper = NullCallWrapper());
1455
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001456 struct Unresolved {
1457 int pc;
1458 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
1459 const char* name;
1460 };
1461
1462 Handle<Object> CodeObject() {
1463 DCHECK(!code_object_.is_null());
1464 return code_object_;
1465 }
1466
1467 // Emit code for a truncating division by a constant. The dividend register is
1468 // unchanged and at gets clobbered. Dividend and result must be different.
1469 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1470
1471 // -------------------------------------------------------------------------
1472 // StatsCounter support.
1473
1474 void SetCounter(StatsCounter* counter, int value,
1475 Register scratch1, Register scratch2);
1476 void IncrementCounter(StatsCounter* counter, int value,
1477 Register scratch1, Register scratch2);
1478 void DecrementCounter(StatsCounter* counter, int value,
1479 Register scratch1, Register scratch2);
1480
1481
1482 // -------------------------------------------------------------------------
1483 // Debugging.
1484
1485 // Calls Abort(msg) if the condition cc is not satisfied.
1486 // Use --debug_code to enable.
1487 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
1488 void AssertFastElements(Register elements);
1489
1490 // Like Assert(), but always enabled.
1491 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
1492
1493 // Print a message to stdout and abort execution.
1494 void Abort(BailoutReason msg);
1495
1496 // Verify restrictions about code generated in stubs.
1497 void set_generating_stub(bool value) { generating_stub_ = value; }
1498 bool generating_stub() { return generating_stub_; }
1499 void set_has_frame(bool value) { has_frame_ = value; }
1500 bool has_frame() { return has_frame_; }
1501 inline bool AllowThisStubCall(CodeStub* stub);
1502
1503 // ---------------------------------------------------------------------------
1504 // Number utilities.
1505
1506 // Check whether the value of reg is a power of two and not zero. If not
1507 // control continues at the label not_power_of_two. If reg is a power of two
1508 // the register scratch contains the value of (reg - 1) when control falls
1509 // through.
1510 void JumpIfNotPowerOfTwoOrZero(Register reg,
1511 Register scratch,
1512 Label* not_power_of_two_or_zero);
1513
1514 // -------------------------------------------------------------------------
1515 // Smi utilities.
1516
1517 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1518 void SmiTagCheckOverflow(Register reg, Register overflow);
1519 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1520
1521 void SmiTag(Register dst, Register src) {
1522 STATIC_ASSERT(kSmiTag == 0);
1523 if (SmiValuesAre32Bits()) {
1524 STATIC_ASSERT(kSmiShift == 32);
1525 dsll32(dst, src, 0);
1526 } else {
1527 Addu(dst, src, src);
1528 }
1529 }
1530
1531 void SmiTag(Register reg) {
1532 SmiTag(reg, reg);
1533 }
1534
1535 // Try to convert int32 to smi. If the value is to large, preserve
1536 // the original value and jump to not_a_smi. Destroys scratch and
1537 // sets flags.
1538 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1539 TrySmiTag(reg, reg, scratch, not_a_smi);
1540 }
1541
1542 void TrySmiTag(Register dst,
1543 Register src,
1544 Register scratch,
1545 Label* not_a_smi) {
1546 if (SmiValuesAre32Bits()) {
1547 SmiTag(dst, src);
1548 } else {
1549 SmiTagCheckOverflow(at, src, scratch);
1550 BranchOnOverflow(not_a_smi, scratch);
1551 mov(dst, at);
1552 }
1553 }
1554
1555 void SmiUntag(Register dst, Register src) {
1556 if (SmiValuesAre32Bits()) {
1557 STATIC_ASSERT(kSmiShift == 32);
1558 dsra32(dst, src, 0);
1559 } else {
1560 sra(dst, src, kSmiTagSize);
1561 }
1562 }
1563
1564 void SmiUntag(Register reg) {
1565 SmiUntag(reg, reg);
1566 }
1567
1568 // Left-shifted from int32 equivalent of Smi.
1569 void SmiScale(Register dst, Register src, int scale) {
1570 if (SmiValuesAre32Bits()) {
1571 // The int portion is upper 32-bits of 64-bit word.
1572 dsra(dst, src, kSmiShift - scale);
1573 } else {
1574 DCHECK(scale >= kSmiTagSize);
1575 sll(dst, src, scale - kSmiTagSize);
1576 }
1577 }
1578
1579 // Combine load with untagging or scaling.
1580 void SmiLoadUntag(Register dst, MemOperand src);
1581
1582 void SmiLoadScale(Register dst, MemOperand src, int scale);
1583
1584 // Returns 2 values: the Smi and a scaled version of the int within the Smi.
1585 void SmiLoadWithScale(Register d_smi,
1586 Register d_scaled,
1587 MemOperand src,
1588 int scale);
1589
1590 // Returns 2 values: the untagged Smi (int32) and scaled version of that int.
1591 void SmiLoadUntagWithScale(Register d_int,
1592 Register d_scaled,
1593 MemOperand src,
1594 int scale);
1595
1596
1597 // Test if the register contains a smi.
1598 inline void SmiTst(Register value, Register scratch) {
1599 And(scratch, value, Operand(kSmiTagMask));
1600 }
1601 inline void NonNegativeSmiTst(Register value, Register scratch) {
1602 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1603 }
1604
1605 // Untag the source value into destination and jump if source is a smi.
1606 // Source and destination can be the same register.
1607 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1608
1609 // Untag the source value into destination and jump if source is not a smi.
1610 // Source and destination can be the same register.
1611 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1612
1613 // Jump the register contains a smi.
1614 void JumpIfSmi(Register value,
1615 Label* smi_label,
1616 Register scratch = at,
1617 BranchDelaySlot bd = PROTECT);
1618
1619 // Jump if the register contains a non-smi.
1620 void JumpIfNotSmi(Register value,
1621 Label* not_smi_label,
1622 Register scratch = at,
1623 BranchDelaySlot bd = PROTECT);
1624
1625 // Jump if either of the registers contain a non-smi.
1626 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1627 // Jump if either of the registers contain a smi.
1628 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1629
1630 // Abort execution if argument is a smi, enabled via --debug-code.
1631 void AssertNotSmi(Register object);
1632 void AssertSmi(Register object);
1633
1634 // Abort execution if argument is not a string, enabled via --debug-code.
1635 void AssertString(Register object);
1636
1637 // Abort execution if argument is not a name, enabled via --debug-code.
1638 void AssertName(Register object);
1639
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001640 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1641 void AssertFunction(Register object);
1642
1643 // Abort execution if argument is not a JSBoundFunction,
1644 // enabled via --debug-code.
1645 void AssertBoundFunction(Register object);
1646
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001647 // Abort execution if argument is not undefined or an AllocationSite, enabled
1648 // via --debug-code.
1649 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1650
1651 // Abort execution if reg is not the root value with the given index,
1652 // enabled via --debug-code.
1653 void AssertIsRoot(Register reg, Heap::RootListIndex index);
1654
1655 // ---------------------------------------------------------------------------
1656 // HeapNumber utilities.
1657
1658 void JumpIfNotHeapNumber(Register object,
1659 Register heap_number_map,
1660 Register scratch,
1661 Label* on_not_heap_number);
1662
1663 // -------------------------------------------------------------------------
1664 // String utilities.
1665
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001666 // Checks if both instance types are sequential one-byte strings and jumps to
1667 // label if either is not.
1668 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1669 Register first_object_instance_type, Register second_object_instance_type,
1670 Register scratch1, Register scratch2, Label* failure);
1671
1672 // Check if instance type is sequential one-byte string and jump to label if
1673 // it is not.
1674 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1675 Label* failure);
1676
1677 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
1678
1679 void EmitSeqStringSetCharCheck(Register string,
1680 Register index,
1681 Register value,
1682 Register scratch,
1683 uint32_t encoding_mask);
1684
1685 // Checks if both objects are sequential one-byte strings and jumps to label
1686 // if either is not. Assumes that neither object is a smi.
1687 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1688 Register second,
1689 Register scratch1,
1690 Register scratch2,
1691 Label* failure);
1692
1693 // Checks if both objects are sequential one-byte strings and jumps to label
1694 // if either is not.
1695 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1696 Register scratch1,
1697 Register scratch2,
1698 Label* not_flat_one_byte_strings);
1699
1700 void ClampUint8(Register output_reg, Register input_reg);
1701
1702 void ClampDoubleToUint8(Register result_reg,
1703 DoubleRegister input_reg,
1704 DoubleRegister temp_double_reg);
1705
1706
1707 void LoadInstanceDescriptors(Register map, Register descriptors);
1708 void EnumLength(Register dst, Register map);
1709 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001710 void LoadAccessor(Register dst, Register holder, int accessor_index,
1711 AccessorComponent accessor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001712
1713 template<typename Field>
1714 void DecodeField(Register dst, Register src) {
1715 Ext(dst, src, Field::kShift, Field::kSize);
1716 }
1717
1718 template<typename Field>
1719 void DecodeField(Register reg) {
1720 DecodeField<Field>(reg, reg);
1721 }
1722
1723 template<typename Field>
1724 void DecodeFieldToSmi(Register dst, Register src) {
1725 static const int shift = Field::kShift;
1726 static const int mask = Field::kMask >> shift;
1727 dsrl(dst, src, shift);
1728 And(dst, dst, Operand(mask));
1729 dsll32(dst, dst, 0);
1730 }
1731
1732 template<typename Field>
1733 void DecodeFieldToSmi(Register reg) {
1734 DecodeField<Field>(reg, reg);
1735 }
1736 // Generates function and stub prologue code.
1737 void StubPrologue();
1738 void Prologue(bool code_pre_aging);
1739
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001740 // Load the type feedback vector from a JavaScript frame.
1741 void EmitLoadTypeFeedbackVector(Register vector);
1742
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001743 // Activation support.
1744 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001745 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001746 void LeaveFrame(StackFrame::Type type);
1747
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001748 // Expects object in a0 and returns map with validated enum cache
1749 // in a0. Assumes that any other register can be used as a scratch.
1750 void CheckEnumCache(Register null_value, Label* call_runtime);
1751
1752 // AllocationMemento support. Arrays may have an associated
1753 // AllocationMemento object that can be checked for in order to pretransition
1754 // to another type.
1755 // On entry, receiver_reg should point to the array object.
1756 // scratch_reg gets clobbered.
1757 // If allocation info is present, jump to allocation_memento_present.
1758 void TestJSArrayForAllocationMemento(
1759 Register receiver_reg,
1760 Register scratch_reg,
1761 Label* no_memento_found,
1762 Condition cond = al,
1763 Label* allocation_memento_present = NULL);
1764
1765 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1766 Register scratch_reg,
1767 Label* memento_found) {
1768 Label no_memento_found;
1769 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1770 &no_memento_found, eq, memento_found);
1771 bind(&no_memento_found);
1772 }
1773
1774 // Jumps to found label if a prototype map has dictionary elements.
1775 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1776 Register scratch1, Label* found);
1777
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001778 bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
1779
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001780 private:
1781 void CallCFunctionHelper(Register function,
1782 int num_reg_arguments,
1783 int num_double_arguments);
1784
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001785 inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch);
1786 inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits);
1787 void BranchShortHelperR6(int32_t offset, Label* L);
1788 void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot);
1789 bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond,
1790 Register rs, const Operand& rt);
1791 bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs,
1792 const Operand& rt, BranchDelaySlot bdslot);
1793 bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs,
1794 const Operand& rt, BranchDelaySlot bdslot);
1795
1796 void BranchAndLinkShortHelperR6(int32_t offset, Label* L);
1797 void BranchAndLinkShortHelper(int16_t offset, Label* L,
1798 BranchDelaySlot bdslot);
1799 void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001800 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001801 bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond,
1802 Register rs, const Operand& rt);
1803 bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond,
1804 Register rs, const Operand& rt,
1805 BranchDelaySlot bdslot);
1806 bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond,
1807 Register rs, const Operand& rt,
1808 BranchDelaySlot bdslot);
1809 void BranchLong(Label* L, BranchDelaySlot bdslot);
1810 void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001811 void Jr(Label* L, BranchDelaySlot bdslot);
1812 void Jalr(Label* L, BranchDelaySlot bdslot);
1813
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001814 // Common implementation of BranchF functions for the different formats.
1815 void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1816 Condition cc, FPURegister cmp1, FPURegister cmp2,
1817 BranchDelaySlot bd = PROTECT);
1818
1819 void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1820 FPURegister cmp1, FPURegister cmp2,
1821 BranchDelaySlot bd = PROTECT);
1822
1823
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001824 // Helper functions for generating invokes.
1825 void InvokePrologue(const ParameterCount& expected,
1826 const ParameterCount& actual,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001827 Label* done,
1828 bool* definitely_mismatches,
1829 InvokeFlag flag,
1830 const CallWrapper& call_wrapper);
1831
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001832 void InitializeNewString(Register string,
1833 Register length,
1834 Heap::RootListIndex map_index,
1835 Register scratch1,
1836 Register scratch2);
1837
1838 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1839 void InNewSpace(Register object,
1840 Register scratch,
1841 Condition cond, // eq for new space, ne otherwise.
1842 Label* branch);
1843
1844 // Helper for finding the mark bits for an address. Afterwards, the
1845 // bitmap register points at the word with the mark bits and the mask
1846 // the position of the first bit. Leaves addr_reg unchanged.
1847 inline void GetMarkBits(Register addr_reg,
1848 Register bitmap_reg,
1849 Register mask_reg);
1850
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001851 // Compute memory operands for safepoint stack slots.
1852 static int SafepointRegisterStackIndex(int reg_code);
1853 MemOperand SafepointRegisterSlot(Register reg);
1854 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1855
1856 bool generating_stub_;
1857 bool has_frame_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001858 bool has_double_zero_reg_set_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001859 // This handle will be patched with the code object on installation.
1860 Handle<Object> code_object_;
1861
1862 // Needs access to SafepointRegisterStackIndex for compiled frame
1863 // traversal.
1864 friend class StandardFrame;
1865};
1866
1867
1868// The code patcher is used to patch (typically) small parts of code e.g. for
1869// debugging and other types of instrumentation. When using the code patcher
1870// the exact number of bytes specified must be emitted. It is not legal to emit
1871// relocation information. If any of these constraints are violated it causes
1872// an assertion to fail.
1873class CodePatcher {
1874 public:
1875 enum FlushICache {
1876 FLUSH,
1877 DONT_FLUSH
1878 };
1879
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001880 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001881 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001882 ~CodePatcher();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001883
1884 // Macro assembler to emit code.
1885 MacroAssembler* masm() { return &masm_; }
1886
1887 // Emit an instruction directly.
1888 void Emit(Instr instr);
1889
1890 // Emit an address directly.
1891 void Emit(Address addr);
1892
1893 // Change the condition part of an instruction leaving the rest of the current
1894 // instruction unchanged.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001895 void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001896
1897 private:
1898 byte* address_; // The address of the code being patched.
1899 int size_; // Number of bytes of the expected patch size.
1900 MacroAssembler masm_; // Macro assembler used to generate the code.
1901 FlushICache flush_cache_; // Whether to flush the I cache after patching.
1902};
1903
1904
1905
1906#ifdef GENERATED_CODE_COVERAGE
1907#define CODE_COVERAGE_STRINGIFY(x) #x
1908#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1909#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1910#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1911#else
1912#define ACCESS_MASM(masm) masm->
1913#endif
1914
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001915} // namespace internal
1916} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001917
1918#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_