blob: 0bc1e15aa829ab81a578751a0ea2028a08113c7d [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.
Andrei Popescu31002712010-02-23 13:46:05 +00004
5#ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
6#define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/assembler.h"
9#include "src/globals.h"
10#include "src/mips/assembler-mips.h"
Andrei Popescu31002712010-02-23 13:46:05 +000011
12namespace v8 {
13namespace internal {
14
15// Forward declaration.
16class JumpTarget;
17
Steve Block44f0eee2011-05-26 01:26:41 +010018// Reserved Register Usage Summary.
19//
20// Registers t8, t9, and at are reserved for use by the MacroAssembler.
21//
22// The programmer should know that the MacroAssembler may clobber these three,
23// but won't touch other registers except in special cases.
24//
25// Per the MIPS ABI, register t9 must be used for indirect function call
26// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
27// trying to update gp register for position-independent-code. Whenever
28// MIPS generated code calls C code, it must be via t9 register.
Andrei Popescu31002712010-02-23 13:46:05 +000029
Ben Murdoch592a9fc2012-03-05 11:04:45 +000030
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031// Flags used for LeaveExitFrame function.
32enum LeaveExitFrameMode {
33 EMIT_RETURN = true,
34 NO_EMIT_RETURN = false
35};
36
37// Flags used for AllocateHeapNumber
38enum TaggingMode {
39 // Tag the result.
40 TAG_RESULT,
41 // Don't tag
42 DONT_TAG_RESULT
Steve Block44f0eee2011-05-26 01:26:41 +010043};
44
45// Flags used for the ObjectToDoubleFPURegister function.
46enum ObjectToDoubleFlags {
47 // No special flags.
48 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
49 // Object is known to be a non smi.
50 OBJECT_NOT_SMI = 1 << 0,
51 // Don't load NaNs or infinities, branch to the non number case instead.
52 AVOID_NANS_AND_INFINITIES = 1 << 1
53};
54
55// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
56enum BranchDelaySlot {
57 USE_DELAY_SLOT,
58 PROTECT
59};
60
Ben Murdoch3ef787d2012-04-12 10:51:47 +010061// Flags used for the li macro-assembler function.
62enum LiFlags {
63 // If the constant value can be represented in just 16 bits, then
64 // optimize the li to use a single instruction, rather than lui/ori pair.
65 OPTIMIZE_SIZE = 0,
66 // Always use 2 instructions (lui/ori pair), even if the constant could
67 // be loaded with just one, so that this value is patchable later.
68 CONSTANT_SIZE = 1
69};
70
71
72enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
73enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074enum PointersToHereCheck {
75 kPointersToHereMaybeInteresting,
76 kPointersToHereAreAlwaysInteresting
77};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010078enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
79
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080Register GetRegisterThatIsNotOneOf(Register reg1,
81 Register reg2 = no_reg,
82 Register reg3 = no_reg,
83 Register reg4 = no_reg,
84 Register reg5 = no_reg,
85 Register reg6 = no_reg);
86
87bool AreAliased(Register reg1,
88 Register reg2,
89 Register reg3 = no_reg,
90 Register reg4 = no_reg,
91 Register reg5 = no_reg,
92 Register reg6 = no_reg,
93 Register reg7 = no_reg,
94 Register reg8 = no_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010095
96
97// -----------------------------------------------------------------------------
98// Static helper functions.
99
100inline MemOperand ContextOperand(Register context, int index) {
101 return MemOperand(context, Context::SlotOffset(index));
102}
103
104
105inline MemOperand GlobalObjectOperand() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100107}
108
109
110// Generate a MemOperand for loading a field from an object.
111inline MemOperand FieldMemOperand(Register object, int offset) {
112 return MemOperand(object, offset - kHeapObjectTag);
113}
114
115
116// Generate a MemOperand for storing arguments 5..N on the stack
117// when calling CallCFunction().
118inline MemOperand CFunctionArgumentOperand(int index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000119 DCHECK(index > kCArgSlotCount);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100120 // Argument 5 takes the slot just past the four Arg-slots.
121 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
122 return MemOperand(sp, offset);
123}
124
125
Andrei Popescu31002712010-02-23 13:46:05 +0000126// MacroAssembler implements a collection of frequently used macros.
127class MacroAssembler: public Assembler {
128 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000129 // The isolate parameter can be NULL if the macro assembler should
130 // not use isolate-dependent functionality. In this case, it's the
131 // responsibility of the caller to never invoke such function on the
132 // macro assembler.
133 MacroAssembler(Isolate* isolate, void* buffer, int size);
Andrei Popescu31002712010-02-23 13:46:05 +0000134
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000135 // Arguments macros.
Steve Block44f0eee2011-05-26 01:26:41 +0100136#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
137#define COND_ARGS cond, r1, r2
138
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000139 // Cases when relocation is not needed.
Steve Block44f0eee2011-05-26 01:26:41 +0100140#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
141 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
142 inline void Name(BranchDelaySlot bd, target_type target) { \
143 Name(target, bd); \
144 } \
145 void Name(target_type target, \
146 COND_TYPED_ARGS, \
147 BranchDelaySlot bd = PROTECT); \
148 inline void Name(BranchDelaySlot bd, \
149 target_type target, \
150 COND_TYPED_ARGS) { \
151 Name(target, COND_ARGS, bd); \
152 }
153
Steve Block44f0eee2011-05-26 01:26:41 +0100154#define DECLARE_BRANCH_PROTOTYPES(Name) \
155 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
156 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
157
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000158 DECLARE_BRANCH_PROTOTYPES(Branch)
159 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160 DECLARE_BRANCH_PROTOTYPES(BranchShort)
Steve Block44f0eee2011-05-26 01:26:41 +0100161
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000162#undef DECLARE_BRANCH_PROTOTYPES
Steve Block44f0eee2011-05-26 01:26:41 +0100163#undef COND_TYPED_ARGS
164#undef COND_ARGS
Andrei Popescu31002712010-02-23 13:46:05 +0000165
Ben Murdoch257744e2011-11-30 15:57:28 +0000166
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000167 // Jump, Call, and Ret pseudo instructions implementing inter-working.
168#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
169 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
170
171 void Jump(Register target, COND_ARGS);
172 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
173 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
174 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100175 static int CallSize(Register target, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000176 void Call(Register target, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100177 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000178 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000179 int CallSize(Handle<Code> code,
180 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
181 TypeFeedbackId ast_id = TypeFeedbackId::None(),
182 COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000183 void Call(Handle<Code> code,
184 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185 TypeFeedbackId ast_id = TypeFeedbackId::None(),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000186 COND_ARGS);
187 void Ret(COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100188 inline void Ret(BranchDelaySlot bd, Condition cond = al,
189 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
190 Ret(cond, rs, rt, bd);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000191 }
192
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100193 void Branch(Label* L,
194 Condition cond,
195 Register rs,
196 Heap::RootListIndex index,
197 BranchDelaySlot bdslot = PROTECT);
198
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000199#undef COND_ARGS
Ben Murdoch257744e2011-11-30 15:57:28 +0000200
Andrei Popescu31002712010-02-23 13:46:05 +0000201 // Emit code to discard a non-negative number of pointer-sized elements
202 // from the stack, clobbering only the sp register.
Steve Block44f0eee2011-05-26 01:26:41 +0100203 void Drop(int count,
204 Condition cond = cc_always,
205 Register reg = no_reg,
206 const Operand& op = Operand(no_reg));
207
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100208 // Trivial case of DropAndRet that utilizes the delay slot and only emits
209 // 2 instructions.
210 void DropAndRet(int drop);
211
212 void DropAndRet(int drop,
213 Condition cond,
214 Register reg,
215 const Operand& op);
Steve Block44f0eee2011-05-26 01:26:41 +0100216
217 // Swap two registers. If the scratch register is omitted then a slightly
218 // less efficient form using xor instead of mov is emitted.
219 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
Andrei Popescu31002712010-02-23 13:46:05 +0000220
221 void Call(Label* target);
Steve Block44f0eee2011-05-26 01:26:41 +0100222
Ben Murdoch257744e2011-11-30 15:57:28 +0000223 inline void Move(Register dst, Register src) {
224 if (!dst.is(src)) {
225 mov(dst, src);
226 }
227 }
228
229 inline void Move(FPURegister dst, FPURegister src) {
230 if (!dst.is(src)) {
231 mov_d(dst, src);
232 }
233 }
234
235 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
236 mfc1(dst_low, src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 Mfhc1(dst_high, src);
238 }
239
240 inline void FmoveHigh(Register dst_high, FPURegister src) {
241 Mfhc1(dst_high, src);
242 }
243
244 inline void FmoveLow(Register dst_low, FPURegister src) {
245 mfc1(dst_low, src);
Ben Murdoch257744e2011-11-30 15:57:28 +0000246 }
247
248 inline void Move(FPURegister dst, Register src_low, Register src_high) {
249 mtc1(src_low, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 Mthc1(src_high, dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000251 }
Andrei Popescu31002712010-02-23 13:46:05 +0000252
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400253 void Move(FPURegister dst, float imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100254 void Move(FPURegister dst, double imm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400255
256 // Conditional move.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100257 void Movz(Register rd, Register rs, Register rt);
258 void Movn(Register rd, Register rs, Register rt);
259 void Movt(Register rd, Register rs, uint16_t cc = 0);
260 void Movf(Register rd, Register rs, uint16_t cc = 0);
261
262 void Clz(Register rd, Register rs);
263
Andrei Popescu31002712010-02-23 13:46:05 +0000264 // Jump unconditionally to given label.
265 // We NEED a nop in the branch delay slot, as it used by v8, for example in
266 // CodeGenerator::ProcessDeferred().
Steve Block6ded16b2010-05-10 14:33:55 +0100267 // Currently the branch delay slot is filled by the MacroAssembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000268 // Use rather b(Label) for code generation.
269 void jmp(Label* L) {
Steve Block44f0eee2011-05-26 01:26:41 +0100270 Branch(L);
Andrei Popescu31002712010-02-23 13:46:05 +0000271 }
272
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 void Load(Register dst, const MemOperand& src, Representation r);
274 void Store(Register src, const MemOperand& dst, Representation r);
275
Andrei Popescu31002712010-02-23 13:46:05 +0000276 // Load an object from the root table.
277 void LoadRoot(Register destination,
278 Heap::RootListIndex index);
279 void LoadRoot(Register destination,
280 Heap::RootListIndex index,
281 Condition cond, Register src1, const Operand& src2);
282
Steve Block44f0eee2011-05-26 01:26:41 +0100283 // Store an object to the root table.
284 void StoreRoot(Register source,
285 Heap::RootListIndex index);
286 void StoreRoot(Register source,
287 Heap::RootListIndex index,
288 Condition cond, Register src1, const Operand& src2);
289
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100290 // ---------------------------------------------------------------------------
291 // GC Support
292
293 void IncrementalMarkingRecordWriteHelper(Register object,
294 Register value,
295 Register address);
296
297 enum RememberedSetFinalAction {
298 kReturnAtEnd,
299 kFallThroughAtEnd
300 };
Steve Block44f0eee2011-05-26 01:26:41 +0100301
302
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100303 // Record in the remembered set the fact that we have a pointer to new space
304 // at the address pointed to by the addr register. Only works if addr is not
305 // in new space.
306 void RememberedSetHelper(Register object, // Used for debug code.
307 Register addr,
308 Register scratch,
309 SaveFPRegsMode save_fp,
310 RememberedSetFinalAction and_then);
Steve Block44f0eee2011-05-26 01:26:41 +0100311
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100312 void CheckPageFlag(Register object,
313 Register scratch,
314 int mask,
315 Condition cc,
316 Label* condition_met);
317
318 // Check if object is in new space. Jumps if the object is not in new space.
319 // The register scratch can be object itself, but it will be clobbered.
320 void JumpIfNotInNewSpace(Register object,
321 Register scratch,
322 Label* branch) {
323 InNewSpace(object, scratch, ne, branch);
324 }
325
326 // Check if object is in new space. Jumps if the object is in new space.
327 // The register scratch can be object itself, but scratch will be clobbered.
328 void JumpIfInNewSpace(Register object,
329 Register scratch,
330 Label* branch) {
331 InNewSpace(object, scratch, eq, branch);
332 }
333
334 // Check if an object has a given incremental marking color.
335 void HasColor(Register object,
336 Register scratch0,
337 Register scratch1,
338 Label* has_color,
339 int first_bit,
340 int second_bit);
341
342 void JumpIfBlack(Register object,
Steve Block44f0eee2011-05-26 01:26:41 +0100343 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100344 Register scratch1,
345 Label* on_black);
Steve Block44f0eee2011-05-26 01:26:41 +0100346
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100347 // Checks the color of an object. If the object is already grey or black
348 // then we just fall through, since it is already live. If it is white and
349 // we can determine that it doesn't need to be scanned, then we just mark it
350 // black and fall through. For the rest we jump to the label so the
351 // incremental marker can fix its assumptions.
352 void EnsureNotWhite(Register object,
353 Register scratch1,
354 Register scratch2,
355 Register scratch3,
356 Label* object_is_white_and_not_data);
357
358 // Detects conservatively whether an object is data-only, i.e. it does need to
359 // be scanned by the garbage collector.
360 void JumpIfDataObject(Register value,
361 Register scratch,
362 Label* not_data_object);
363
364 // Notify the garbage collector that we wrote a pointer into an object.
365 // |object| is the object being stored into, |value| is the object being
366 // stored. value and scratch registers are clobbered by the operation.
367 // The offset is the offset from the start of the object, not the offset from
368 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
369 void RecordWriteField(
370 Register object,
371 int offset,
372 Register value,
373 Register scratch,
374 RAStatus ra_status,
375 SaveFPRegsMode save_fp,
376 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000377 SmiCheck smi_check = INLINE_SMI_CHECK,
378 PointersToHereCheck pointers_to_here_check_for_value =
379 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100380
381 // As above, but the offset has the tag presubtracted. For use with
382 // MemOperand(reg, off).
383 inline void RecordWriteContextSlot(
384 Register context,
385 int offset,
386 Register value,
387 Register scratch,
388 RAStatus ra_status,
389 SaveFPRegsMode save_fp,
390 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000391 SmiCheck smi_check = INLINE_SMI_CHECK,
392 PointersToHereCheck pointers_to_here_check_for_value =
393 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100394 RecordWriteField(context,
395 offset + kHeapObjectTag,
396 value,
397 scratch,
398 ra_status,
399 save_fp,
400 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000401 smi_check,
402 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100403 }
404
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 void RecordWriteForMap(
406 Register object,
407 Register map,
408 Register dst,
409 RAStatus ra_status,
410 SaveFPRegsMode save_fp);
411
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100412 // For a given |object| notify the garbage collector that the slot |address|
413 // has been written. |value| is the object being stored. The value and
414 // address registers are clobbered by the operation.
415 void RecordWrite(
416 Register object,
417 Register address,
418 Register value,
419 RAStatus ra_status,
420 SaveFPRegsMode save_fp,
421 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000422 SmiCheck smi_check = INLINE_SMI_CHECK,
423 PointersToHereCheck pointers_to_here_check_for_value =
424 kPointersToHereMaybeInteresting);
Steve Block44f0eee2011-05-26 01:26:41 +0100425
426
427 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000428 // Inline caching support.
Steve Block44f0eee2011-05-26 01:26:41 +0100429
430 // Generate code for checking access rights - used for security checks
431 // on access to global objects across environments. The holder register
432 // is left untouched, whereas both scratch registers are clobbered.
433 void CheckAccessGlobalProxy(Register holder_reg,
434 Register scratch,
435 Label* miss);
436
Ben Murdochc7cc0282012-03-05 14:35:55 +0000437 void GetNumberHash(Register reg0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000438
439 void LoadFromNumberDictionary(Label* miss,
440 Register elements,
441 Register key,
442 Register result,
443 Register reg0,
444 Register reg1,
445 Register reg2);
446
447
Steve Block44f0eee2011-05-26 01:26:41 +0100448 inline void MarkCode(NopMarkerTypes type) {
449 nop(type);
Steve Block6ded16b2010-05-10 14:33:55 +0100450 }
451
Steve Block44f0eee2011-05-26 01:26:41 +0100452 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100453 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
Steve Block44f0eee2011-05-26 01:26:41 +0100454 // nop(type)). These instructions are generated to mark special location in
455 // the code, like some special IC code.
456 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000457 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Steve Block44f0eee2011-05-26 01:26:41 +0100458 return IsNop(instr, type);
459 }
Andrei Popescu31002712010-02-23 13:46:05 +0000460
461
Steve Block44f0eee2011-05-26 01:26:41 +0100462 static inline int GetCodeMarker(Instr instr) {
463 uint32_t opcode = ((instr & kOpcodeMask));
464 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
465 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
466 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
467
468 // Return <n> if we have a sll zero_reg, zero_reg, n
469 // else return -1.
470 bool sllzz = (opcode == SLL &&
471 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
472 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
473 int type =
474 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000475 DCHECK((type == -1) ||
Steve Block44f0eee2011-05-26 01:26:41 +0100476 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
477 return type;
478 }
479
480
481
482 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000483 // Allocation support.
Steve Block44f0eee2011-05-26 01:26:41 +0100484
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000485 // Allocate an object in new space or old pointer space. The object_size is
486 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
487 // is passed. If the space is exhausted control continues at the gc_required
488 // label. The allocated object is returned in result. If the flag
489 // tag_allocated_object is true the result is tagged as as a heap object.
490 // All registers are clobbered also when control continues at the gc_required
491 // label.
492 void Allocate(int object_size,
493 Register result,
494 Register scratch1,
495 Register scratch2,
496 Label* gc_required,
497 AllocationFlags flags);
498
499 void Allocate(Register object_size,
500 Register result,
501 Register scratch1,
502 Register scratch2,
503 Label* gc_required,
504 AllocationFlags flags);
Steve Block44f0eee2011-05-26 01:26:41 +0100505
506 // Undo allocation in new space. The object passed and objects allocated after
507 // it will no longer be allocated. The caller must make sure that no pointers
508 // are left to the object(s) no longer allocated as they would be invalid when
509 // allocation is undone.
510 void UndoAllocationInNewSpace(Register object, Register scratch);
511
512
513 void AllocateTwoByteString(Register result,
514 Register length,
515 Register scratch1,
516 Register scratch2,
517 Register scratch3,
518 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519 void AllocateOneByteString(Register result, Register length,
520 Register scratch1, Register scratch2,
521 Register scratch3, Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100522 void AllocateTwoByteConsString(Register result,
523 Register length,
524 Register scratch1,
525 Register scratch2,
526 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000527 void AllocateOneByteConsString(Register result, Register length,
528 Register scratch1, Register scratch2,
529 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000530 void AllocateTwoByteSlicedString(Register result,
531 Register length,
532 Register scratch1,
533 Register scratch2,
534 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535 void AllocateOneByteSlicedString(Register result, Register length,
536 Register scratch1, Register scratch2,
537 Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100538
539 // Allocates a heap number or jumps to the gc_required label if the young
540 // space is full and a scavenge is needed. All registers are clobbered also
541 // when control continues at the gc_required label.
542 void AllocateHeapNumber(Register result,
543 Register scratch1,
544 Register scratch2,
545 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 Label* gc_required,
547 TaggingMode tagging_mode = TAG_RESULT,
548 MutableMode mode = IMMUTABLE);
Steve Block44f0eee2011-05-26 01:26:41 +0100549 void AllocateHeapNumberWithValue(Register result,
550 FPURegister value,
551 Register scratch1,
552 Register scratch2,
553 Label* gc_required);
554
Andrei Popescu31002712010-02-23 13:46:05 +0000555 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000556 // Instruction macros.
Andrei Popescu31002712010-02-23 13:46:05 +0000557
Steve Block44f0eee2011-05-26 01:26:41 +0100558#define DEFINE_INSTRUCTION(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000559 void instr(Register rd, Register rs, const Operand& rt); \
560 void instr(Register rd, Register rs, Register rt) { \
561 instr(rd, rs, Operand(rt)); \
562 } \
563 void instr(Register rs, Register rt, int32_t j) { \
564 instr(rs, rt, Operand(j)); \
565 }
566
Steve Block44f0eee2011-05-26 01:26:41 +0100567#define DEFINE_INSTRUCTION2(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000568 void instr(Register rs, const Operand& rt); \
569 void instr(Register rs, Register rt) { \
570 instr(rs, Operand(rt)); \
571 } \
572 void instr(Register rs, int32_t j) { \
573 instr(rs, Operand(j)); \
574 }
575
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000576#define DEFINE_INSTRUCTION3(instr) \
577 void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \
578 void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \
579 instr(rd_hi, rd_lo, rs, Operand(rt)); \
580 } \
581 void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \
582 instr(rd_hi, rd_lo, rs, Operand(j)); \
583 }
584
Andrei Popescu31002712010-02-23 13:46:05 +0000585 DEFINE_INSTRUCTION(Addu);
Steve Block44f0eee2011-05-26 01:26:41 +0100586 DEFINE_INSTRUCTION(Subu);
Andrei Popescu31002712010-02-23 13:46:05 +0000587 DEFINE_INSTRUCTION(Mul);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400588 DEFINE_INSTRUCTION(Div);
589 DEFINE_INSTRUCTION(Divu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000590 DEFINE_INSTRUCTION(Mod);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400591 DEFINE_INSTRUCTION(Modu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000592 DEFINE_INSTRUCTION(Mulh);
Andrei Popescu31002712010-02-23 13:46:05 +0000593 DEFINE_INSTRUCTION2(Mult);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400594 DEFINE_INSTRUCTION(Mulhu);
Andrei Popescu31002712010-02-23 13:46:05 +0000595 DEFINE_INSTRUCTION2(Multu);
596 DEFINE_INSTRUCTION2(Div);
597 DEFINE_INSTRUCTION2(Divu);
598
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599 DEFINE_INSTRUCTION3(Div);
600 DEFINE_INSTRUCTION3(Mul);
601
Andrei Popescu31002712010-02-23 13:46:05 +0000602 DEFINE_INSTRUCTION(And);
603 DEFINE_INSTRUCTION(Or);
604 DEFINE_INSTRUCTION(Xor);
605 DEFINE_INSTRUCTION(Nor);
Ben Murdoch257744e2011-11-30 15:57:28 +0000606 DEFINE_INSTRUCTION2(Neg);
Andrei Popescu31002712010-02-23 13:46:05 +0000607
608 DEFINE_INSTRUCTION(Slt);
609 DEFINE_INSTRUCTION(Sltu);
610
Steve Block44f0eee2011-05-26 01:26:41 +0100611 // MIPS32 R2 instruction macro.
612 DEFINE_INSTRUCTION(Ror);
613
Andrei Popescu31002712010-02-23 13:46:05 +0000614#undef DEFINE_INSTRUCTION
615#undef DEFINE_INSTRUCTION2
616
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000617 void Pref(int32_t hint, const MemOperand& rs);
618
Andrei Popescu31002712010-02-23 13:46:05 +0000619
Ben Murdoch257744e2011-11-30 15:57:28 +0000620 // ---------------------------------------------------------------------------
621 // Pseudo-instructions.
Andrei Popescu31002712010-02-23 13:46:05 +0000622
623 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
Andrei Popescu31002712010-02-23 13:46:05 +0000624
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000625 void Ulw(Register rd, const MemOperand& rs);
626 void Usw(Register rd, const MemOperand& rs);
627
Ben Murdoch257744e2011-11-30 15:57:28 +0000628 // Load int32 in the rd register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100629 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
630 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
631 li(rd, Operand(j), mode);
Andrei Popescu31002712010-02-23 13:46:05 +0000632 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000633 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
Andrei Popescu31002712010-02-23 13:46:05 +0000634
Andrei Popescu31002712010-02-23 13:46:05 +0000635 // Push multiple registers on the stack.
Steve Block6ded16b2010-05-10 14:33:55 +0100636 // Registers are saved in numerical order, with higher numbered registers
Ben Murdoch257744e2011-11-30 15:57:28 +0000637 // saved in higher memory addresses.
Andrei Popescu31002712010-02-23 13:46:05 +0000638 void MultiPush(RegList regs);
639 void MultiPushReversed(RegList regs);
Steve Block44f0eee2011-05-26 01:26:41 +0100640
Ben Murdoch589d6972011-11-30 16:04:58 +0000641 void MultiPushFPU(RegList regs);
642 void MultiPushReversedFPU(RegList regs);
643
Ben Murdoch257744e2011-11-30 15:57:28 +0000644 void push(Register src) {
Andrei Popescu31002712010-02-23 13:46:05 +0000645 Addu(sp, sp, Operand(-kPointerSize));
646 sw(src, MemOperand(sp, 0));
647 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648 void Push(Register src) { push(src); }
Steve Block44f0eee2011-05-26 01:26:41 +0100649
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000650 // Push a handle.
651 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000652 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000653
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 // Push two registers. Pushes leftmost register first (to highest address).
655 void Push(Register src1, Register src2) {
Steve Block44f0eee2011-05-26 01:26:41 +0100656 Subu(sp, sp, Operand(2 * kPointerSize));
657 sw(src1, MemOperand(sp, 1 * kPointerSize));
658 sw(src2, MemOperand(sp, 0 * kPointerSize));
659 }
660
Ben Murdoch257744e2011-11-30 15:57:28 +0000661 // Push three registers. Pushes leftmost register first (to highest address).
662 void Push(Register src1, Register src2, Register src3) {
663 Subu(sp, sp, Operand(3 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100664 sw(src1, MemOperand(sp, 2 * kPointerSize));
665 sw(src2, MemOperand(sp, 1 * kPointerSize));
666 sw(src3, MemOperand(sp, 0 * kPointerSize));
667 }
668
Ben Murdoch257744e2011-11-30 15:57:28 +0000669 // Push four registers. Pushes leftmost register first (to highest address).
670 void Push(Register src1, Register src2, Register src3, Register src4) {
671 Subu(sp, sp, Operand(4 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100672 sw(src1, MemOperand(sp, 3 * kPointerSize));
673 sw(src2, MemOperand(sp, 2 * kPointerSize));
674 sw(src3, MemOperand(sp, 1 * kPointerSize));
675 sw(src4, MemOperand(sp, 0 * kPointerSize));
676 }
677
Andrei Popescu31002712010-02-23 13:46:05 +0000678 void Push(Register src, Condition cond, Register tst1, Register tst2) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000679 // Since we don't have conditional execution we use a Branch.
Steve Block44f0eee2011-05-26 01:26:41 +0100680 Branch(3, cond, tst1, Operand(tst2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000681 Subu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000682 sw(src, MemOperand(sp, 0));
683 }
684
685 // Pops multiple values from the stack and load them in the
686 // registers specified in regs. Pop order is the opposite as in MultiPush.
687 void MultiPop(RegList regs);
688 void MultiPopReversed(RegList regs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000689
Ben Murdoch589d6972011-11-30 16:04:58 +0000690 void MultiPopFPU(RegList regs);
691 void MultiPopReversedFPU(RegList regs);
692
Ben Murdoch257744e2011-11-30 15:57:28 +0000693 void pop(Register dst) {
Andrei Popescu31002712010-02-23 13:46:05 +0000694 lw(dst, MemOperand(sp, 0));
695 Addu(sp, sp, Operand(kPointerSize));
696 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000697 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000698
699 // Pop two registers. Pops rightmost register first (from lower address).
700 void Pop(Register src1, Register src2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000701 DCHECK(!src1.is(src2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000702 lw(src2, MemOperand(sp, 0 * kPointerSize));
703 lw(src1, MemOperand(sp, 1 * kPointerSize));
704 Addu(sp, sp, 2 * kPointerSize);
705 }
706
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100707 // Pop three registers. Pops rightmost register first (from lower address).
708 void Pop(Register src1, Register src2, Register src3) {
709 lw(src3, MemOperand(sp, 0 * kPointerSize));
710 lw(src2, MemOperand(sp, 1 * kPointerSize));
711 lw(src1, MemOperand(sp, 2 * kPointerSize));
712 Addu(sp, sp, 3 * kPointerSize);
713 }
714
Steve Block44f0eee2011-05-26 01:26:41 +0100715 void Pop(uint32_t count = 1) {
716 Addu(sp, sp, Operand(count * kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000717 }
718
Steve Block44f0eee2011-05-26 01:26:41 +0100719 // Push and pop the registers that can hold pointers, as defined by the
720 // RegList constant kSafepointSavedRegisters.
Ben Murdoch257744e2011-11-30 15:57:28 +0000721 void PushSafepointRegisters();
722 void PopSafepointRegisters();
Ben Murdoch257744e2011-11-30 15:57:28 +0000723 // Store value in register src in the safepoint stack slot for
724 // register dst.
725 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000726 // Load the value of the src register from its safepoint stack slot
727 // into register dst.
728 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Steve Block44f0eee2011-05-26 01:26:41 +0100729
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000730 // Flush the I-cache from asm code. You should use CpuFeatures::FlushICache
731 // from C.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100732 // Does not handle errors.
733 void FlushICache(Register address, unsigned instructions);
734
Steve Block44f0eee2011-05-26 01:26:41 +0100735 // MIPS32 R2 instruction macro.
736 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
737 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
738
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100739 // ---------------------------------------------------------------------------
740 // FPU macros. These do not handle special cases like NaN or +- inf.
741
Steve Block44f0eee2011-05-26 01:26:41 +0100742 // Convert unsigned word to double.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000743 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
744 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100745
746 // Convert double to unsigned word.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000747 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
748 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100749
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100750 void Trunc_w_d(FPURegister fd, FPURegister fs);
751 void Round_w_d(FPURegister fd, FPURegister fs);
752 void Floor_w_d(FPURegister fd, FPURegister fs);
753 void Ceil_w_d(FPURegister fd, FPURegister fs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000754
755 // FP32 mode: Move the general purpose register into
756 // the high part of the double-register pair.
757 // FP64 mode: Move the general-purpose register into
758 // the higher 32 bits of the 64-bit coprocessor register,
759 // while leaving the low bits unchanged.
760 void Mthc1(Register rt, FPURegister fs);
761
762 // FP32 mode: move the high part of the double-register pair into
763 // general purpose register.
764 // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
765 // general-purpose register.
766 void Mfhc1(Register rt, FPURegister fs);
767
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100768 // Wrapper function for the different cmp/branch types.
769 void BranchF(Label* target,
770 Label* nan,
771 Condition cc,
772 FPURegister cmp1,
773 FPURegister cmp2,
774 BranchDelaySlot bd = PROTECT);
775
776 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
777 inline void BranchF(BranchDelaySlot bd,
778 Label* target,
779 Label* nan,
780 Condition cc,
781 FPURegister cmp1,
782 FPURegister cmp2) {
783 BranchF(target, nan, cc, cmp1, cmp2, bd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100785
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000786 // Truncates a double using a specific rounding mode, and writes the value
787 // to the result register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100788 // The except_flag will contain any exceptions caused by the instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000789 // If check_inexact is kDontCheckForInexactConversion, then the inexact
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100790 // exception is masked.
791 void EmitFPUTruncate(FPURoundingMode rounding_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000792 Register result,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100793 DoubleRegister double_input,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000794 Register scratch,
795 DoubleRegister double_scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100796 Register except_flag,
797 CheckForInexactConversion check_inexact
798 = kDontCheckForInexactConversion);
799
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000800 // Performs a truncating conversion of a floating point number as used by
801 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
802 // succeeds, otherwise falls through if result is saturated. On return
803 // 'result' either holds answer, or is clobbered on fall through.
804 //
805 // Only public for the test code in test-code-stubs-arm.cc.
806 void TryInlineTruncateDoubleToI(Register result,
807 DoubleRegister input,
808 Label* done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000809
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000810 // Performs a truncating conversion of a floating point number as used by
811 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000812 // Exits with 'result' holding the answer.
813 void TruncateDoubleToI(Register result, DoubleRegister double_input);
814
815 // Performs a truncating conversion of a heap number as used by
816 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
817 // must be different registers. Exits with 'result' holding the answer.
818 void TruncateHeapNumberToI(Register result, Register object);
819
820 // Converts the smi or heap number in object to an int32 using the rules
821 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
822 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
823 // different registers.
824 void TruncateNumberToI(Register object,
825 Register result,
826 Register heap_number_map,
827 Register scratch,
828 Label* not_int32);
829
830 // Loads the number from object into dst register.
831 // If |object| is neither smi nor heap number, |not_number| is jumped to
832 // with |object| still intact.
833 void LoadNumber(Register object,
834 FPURegister dst,
835 Register heap_number_map,
836 Register scratch,
837 Label* not_number);
838
839 // Loads the number from object into double_dst in the double format.
840 // Control will jump to not_int32 if the value cannot be exactly represented
841 // by a 32-bit integer.
842 // Floating point value in the 32-bit integer range that are not exact integer
843 // won't be loaded.
844 void LoadNumberAsInt32Double(Register object,
845 DoubleRegister double_dst,
846 Register heap_number_map,
847 Register scratch1,
848 Register scratch2,
849 FPURegister double_scratch,
850 Label* not_int32);
851
852 // Loads the number from object into dst as a 32-bit integer.
853 // Control will jump to not_int32 if the object cannot be exactly represented
854 // by a 32-bit integer.
855 // Floating point value in the 32-bit integer range that are not exact integer
856 // won't be converted.
857 void LoadNumberAsInt32(Register object,
858 Register dst,
859 Register heap_number_map,
860 Register scratch1,
861 Register scratch2,
862 FPURegister double_scratch0,
863 FPURegister double_scratch1,
864 Label* not_int32);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000865
Steve Block44f0eee2011-05-26 01:26:41 +0100866 // Enter exit frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000867 // argc - argument count to be dropped by LeaveExitFrame.
868 // save_doubles - saves FPU registers on stack, currently disabled.
869 // stack_space - extra stack space.
870 void EnterExitFrame(bool save_doubles,
871 int stack_space = 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100872
Ben Murdoch257744e2011-11-30 15:57:28 +0000873 // Leave the current exit frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100874 void LeaveExitFrame(bool save_doubles,
875 Register arg_count,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000876 bool restore_context,
877 bool do_return = NO_EMIT_RETURN);
Steve Block6ded16b2010-05-10 14:33:55 +0100878
Steve Block44f0eee2011-05-26 01:26:41 +0100879 // Get the actual activation frame alignment for target environment.
880 static int ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +0100881
Ben Murdoch257744e2011-11-30 15:57:28 +0000882 // Make sure the stack is aligned. Only emits code in debug mode.
883 void AssertStackIsAligned();
884
Steve Block44f0eee2011-05-26 01:26:41 +0100885 void LoadContext(Register dst, int context_chain_length);
Steve Block6ded16b2010-05-10 14:33:55 +0100886
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100887 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000888 // transitioned_kind from the native context if the map in register
889 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100890 // expected_kind.
891 void LoadTransitionedArrayMapConditional(
892 ElementsKind expected_kind,
893 ElementsKind transitioned_kind,
894 Register map_in_out,
895 Register scratch,
896 Label* no_map_match);
897
Steve Block44f0eee2011-05-26 01:26:41 +0100898 void LoadGlobalFunction(int index, Register function);
899
900 // Load the initial map from the global function. The registers
901 // function and map can be the same, function is then overwritten.
902 void LoadGlobalFunctionInitialMap(Register function,
903 Register map,
904 Register scratch);
905
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100906 void InitializeRootRegister() {
907 ExternalReference roots_array_start =
908 ExternalReference::roots_array_start(isolate());
909 li(kRootRegister, Operand(roots_array_start));
910 }
911
Steve Block44f0eee2011-05-26 01:26:41 +0100912 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000913 // JavaScript invokes.
914
Steve Block6ded16b2010-05-10 14:33:55 +0100915 // Invoke the JavaScript function code by either calling or jumping.
916 void InvokeCode(Register code,
917 const ParameterCount& expected,
918 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +0100919 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000920 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +0100921
922 // Invoke the JavaScript function in the given register. Changes the
923 // current context to the context in the function before invoking.
924 void InvokeFunction(Register function,
925 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +0100926 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000927 const CallWrapper& call_wrapper);
Steve Block44f0eee2011-05-26 01:26:41 +0100928
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000929 void InvokeFunction(Register function,
930 const ParameterCount& expected,
Steve Block44f0eee2011-05-26 01:26:41 +0100931 const ParameterCount& actual,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000932 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000933 const CallWrapper& call_wrapper);
934
935 void InvokeFunction(Handle<JSFunction> function,
936 const ParameterCount& expected,
937 const ParameterCount& actual,
938 InvokeFlag flag,
939 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +0100940
941
Steve Block44f0eee2011-05-26 01:26:41 +0100942 void IsObjectJSObjectType(Register heap_object,
943 Register map,
944 Register scratch,
945 Label* fail);
946
947 void IsInstanceJSObjectType(Register map,
948 Register scratch,
949 Label* fail);
950
951 void IsObjectJSStringType(Register object,
952 Register scratch,
953 Label* fail);
954
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000955 void IsObjectNameType(Register object,
956 Register scratch,
957 Label* fail);
958
Steve Block44f0eee2011-05-26 01:26:41 +0100959 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000960 // Debugger Support.
Steve Block6ded16b2010-05-10 14:33:55 +0100961
Steve Block6ded16b2010-05-10 14:33:55 +0100962 void DebugBreak();
Steve Block6ded16b2010-05-10 14:33:55 +0100963
Steve Block44f0eee2011-05-26 01:26:41 +0100964 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000965 // Exception handling.
Andrei Popescu31002712010-02-23 13:46:05 +0000966
967 // Push a new try handler and link into try handler chain.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100968 void PushTryHandler(StackHandler::Kind kind, int handler_index);
Andrei Popescu31002712010-02-23 13:46:05 +0000969
970 // Unlink the stack handler on top of the stack from the try handler chain.
971 // Must preserve the result register.
972 void PopTryHandler();
973
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100974 // Passes thrown value to the handler of top of the try handler chain.
Ben Murdoch257744e2011-11-30 15:57:28 +0000975 void Throw(Register value);
976
977 // Propagates an uncatchable exception to the top of the current JS stack's
978 // handler chain.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100979 void ThrowUncatchable(Register value);
Ben Murdoch257744e2011-11-30 15:57:28 +0000980
Steve Block44f0eee2011-05-26 01:26:41 +0100981 // Copies a fixed number of fields of heap objects from src to dst.
982 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000983
Ben Murdoch257744e2011-11-30 15:57:28 +0000984 // Copies a number of bytes from src to dst. All registers are clobbered. On
985 // exit src and dst will point to the place just after where the last byte was
986 // read or written and length will be zero.
987 void CopyBytes(Register src,
988 Register dst,
989 Register length,
990 Register scratch);
991
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100992 // Initialize fields with filler values. Fields starting at |start_offset|
993 // not including end_offset are overwritten with the value in |filler|. At
994 // the end the loop, |start_offset| takes the value of |end_offset|.
995 void InitializeFieldsWithFiller(Register start_offset,
996 Register end_offset,
997 Register filler);
998
Steve Block44f0eee2011-05-26 01:26:41 +0100999 // -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001000 // Support functions.
1001
Steve Block44f0eee2011-05-26 01:26:41 +01001002 // Try to get function prototype of a function and puts the value in
1003 // the result register. Checks that the function really is a
1004 // function and jumps to the miss label if the fast checks fail. The
1005 // function register will be untouched; the other registers may be
1006 // clobbered.
1007 void TryGetFunctionPrototype(Register function,
1008 Register result,
1009 Register scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001010 Label* miss,
1011 bool miss_on_bound_function = false);
Steve Block44f0eee2011-05-26 01:26:41 +01001012
Steve Block6ded16b2010-05-10 14:33:55 +01001013 void GetObjectType(Register function,
1014 Register map,
1015 Register type_reg);
1016
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001017 // Check if a map for a JSObject indicates that the object has fast elements.
1018 // Jump to the specified label if it does not.
1019 void CheckFastElements(Register map,
1020 Register scratch,
1021 Label* fail);
1022
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001023 // Check if a map for a JSObject indicates that the object can have both smi
1024 // and HeapObject elements. Jump to the specified label if it does not.
1025 void CheckFastObjectElements(Register map,
1026 Register scratch,
1027 Label* fail);
1028
1029 // Check if a map for a JSObject indicates that the object has fast smi only
1030 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001031 void CheckFastSmiElements(Register map,
1032 Register scratch,
1033 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001034
1035 // Check to see if maybe_number can be stored as a double in
1036 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001037 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001038 void StoreNumberToDoubleElements(Register value_reg,
1039 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001040 Register elements_reg,
1041 Register scratch1,
1042 Register scratch2,
1043 Register scratch3,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001044 Label* fail,
1045 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001046
1047 // Compare an object's map with the specified map and its transitioned
1048 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1049 // "branch_to" if the result of the comparison is "cond". If multiple map
1050 // compares are required, the compare sequences branches to early_success.
1051 void CompareMapAndBranch(Register obj,
1052 Register scratch,
1053 Handle<Map> map,
1054 Label* early_success,
1055 Condition cond,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001056 Label* branch_to);
1057
1058 // As above, but the map of the object is already loaded into the register
1059 // which is preserved by the code generated.
1060 void CompareMapAndBranch(Register obj_map,
1061 Handle<Map> map,
1062 Label* early_success,
1063 Condition cond,
1064 Label* branch_to);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001065
1066 // Check if the map of an object is equal to a specified map and branch to
1067 // label if not. Skip the smi check if not required (object is known to be a
1068 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1069 // against maps that are ElementsKind transition maps of the specificed map.
Steve Block44f0eee2011-05-26 01:26:41 +01001070 void CheckMap(Register obj,
1071 Register scratch,
1072 Handle<Map> map,
1073 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074 SmiCheckType smi_check_type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001075
Andrei Popescu31002712010-02-23 13:46:05 +00001076
Steve Block44f0eee2011-05-26 01:26:41 +01001077 void CheckMap(Register obj,
1078 Register scratch,
1079 Heap::RootListIndex index,
1080 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +00001081 SmiCheckType smi_check_type);
1082
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001083 // Check if the map of an object is equal to a specified weak map and branch
1084 // to a specified target if equal. Skip the smi check if not required
1085 // (object is known to be a heap object)
1086 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1087 Handle<WeakCell> cell, Handle<Code> success,
1088 SmiCheckType smi_check_type);
Steve Block6ded16b2010-05-10 14:33:55 +01001089
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001090 // Get value of the weak cell.
1091 void GetWeakValue(Register value, Handle<WeakCell> cell);
1092
1093 // Load the value of the weak cell in the value register. Branch to the
1094 // given miss label is the weak cell was cleared.
1095 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001096
1097 // Load and check the instance type of an object for being a string.
1098 // Loads the type into the second argument register.
1099 // Returns a condition that will be enabled if the object was a string.
1100 Condition IsObjectStringType(Register obj,
1101 Register type,
1102 Register result) {
1103 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1104 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1105 And(type, type, Operand(kIsNotStringMask));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001106 DCHECK_EQ(0, kStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001107 return eq;
1108 }
1109
1110
Steve Block44f0eee2011-05-26 01:26:41 +01001111 // Picks out an array index from the hash field.
1112 // Register use:
1113 // hash - holds the index's hash. Clobbered.
1114 // index - holds the overwritten index on exit.
1115 void IndexFromHash(Register hash, Register index);
Andrei Popescu31002712010-02-23 13:46:05 +00001116
Ben Murdoch257744e2011-11-30 15:57:28 +00001117 // Get the number of least significant bits from a register.
1118 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1119 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1120
Steve Block44f0eee2011-05-26 01:26:41 +01001121 // Load the value of a number object into a FPU double register. If the
1122 // object is not a number a jump to the label not_number is performed
1123 // and the FPU double register is unchanged.
1124 void ObjectToDoubleFPURegister(
1125 Register object,
1126 FPURegister value,
1127 Register scratch1,
1128 Register scratch2,
1129 Register heap_number_map,
1130 Label* not_number,
1131 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1132
1133 // Load the value of a smi object into a FPU double register. The register
1134 // scratch1 can be the same register as smi in which case smi will hold the
1135 // untagged value afterwards.
1136 void SmiToDoubleFPURegister(Register smi,
1137 FPURegister value,
1138 Register scratch1);
1139
1140 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001141 // Overflow handling functions.
1142 // Usage: first call the appropriate arithmetic function, then call one of the
1143 // jump functions with the overflow_dst register as the second parameter.
1144
1145 void AdduAndCheckForOverflow(Register dst,
1146 Register left,
1147 Register right,
1148 Register overflow_dst,
1149 Register scratch = at);
1150
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001151 void AdduAndCheckForOverflow(Register dst, Register left,
1152 const Operand& right, Register overflow_dst,
1153 Register scratch = at);
1154
Ben Murdoch257744e2011-11-30 15:57:28 +00001155 void SubuAndCheckForOverflow(Register dst,
1156 Register left,
1157 Register right,
1158 Register overflow_dst,
1159 Register scratch = at);
1160
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001161 void SubuAndCheckForOverflow(Register dst, Register left,
1162 const Operand& right, Register overflow_dst,
1163 Register scratch = at);
1164
Ben Murdoch257744e2011-11-30 15:57:28 +00001165 void BranchOnOverflow(Label* label,
1166 Register overflow_check,
1167 BranchDelaySlot bd = PROTECT) {
1168 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1169 }
1170
1171 void BranchOnNoOverflow(Label* label,
1172 Register overflow_check,
1173 BranchDelaySlot bd = PROTECT) {
1174 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1175 }
1176
1177 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1178 Ret(lt, overflow_check, Operand(zero_reg), bd);
1179 }
1180
1181 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1182 Ret(ge, overflow_check, Operand(zero_reg), bd);
1183 }
1184
1185 // -------------------------------------------------------------------------
1186 // Runtime calls.
Andrei Popescu31002712010-02-23 13:46:05 +00001187
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001188 // See comments at the beginning of CEntryStub::Generate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001189 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
Ben Murdoch85b71792012-04-11 18:30:58 +01001190
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001191 inline void PrepareCEntryFunction(const ExternalReference& ref) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001192 li(a1, Operand(ref));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001193 }
1194
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001195#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1196const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1197
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001198 // Call a code stub.
1199 void CallStub(CodeStub* stub,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001200 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1201 COND_ARGS);
Steve Block44f0eee2011-05-26 01:26:41 +01001202
1203 // Tail call a code stub (jump).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001204 void TailCallStub(CodeStub* stub, COND_ARGS);
1205
1206#undef COND_ARGS
Steve Block44f0eee2011-05-26 01:26:41 +01001207
Andrei Popescu31002712010-02-23 13:46:05 +00001208 void CallJSExitStub(CodeStub* stub);
1209
Andrei Popescu31002712010-02-23 13:46:05 +00001210 // Call a runtime routine.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001211 void CallRuntime(const Runtime::Function* f,
1212 int num_arguments,
1213 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1214 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1215 const Runtime::Function* function = Runtime::FunctionForId(id);
1216 CallRuntime(function, function->nargs, kSaveFPRegs);
1217 }
Andrei Popescu31002712010-02-23 13:46:05 +00001218
1219 // Convenience function: Same as above, but takes the fid instead.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001220 void CallRuntime(Runtime::FunctionId id,
1221 int num_arguments,
1222 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1223 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
1224 }
Andrei Popescu31002712010-02-23 13:46:05 +00001225
Steve Block44f0eee2011-05-26 01:26:41 +01001226 // Convenience function: call an external reference.
1227 void CallExternalReference(const ExternalReference& ext,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001228 int num_arguments,
1229 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001230
Andrei Popescu31002712010-02-23 13:46:05 +00001231 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +01001232 // Like JumpToExternalReference, but also takes care of passing the number
Andrei Popescu31002712010-02-23 13:46:05 +00001233 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +01001234 void TailCallExternalReference(const ExternalReference& ext,
1235 int num_arguments,
1236 int result_size);
1237
1238 // Convenience function: tail call a runtime routine (jump).
1239 void TailCallRuntime(Runtime::FunctionId fid,
Andrei Popescu31002712010-02-23 13:46:05 +00001240 int num_arguments,
1241 int result_size);
1242
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001243 int CalculateStackPassedWords(int num_reg_arguments,
1244 int num_double_arguments);
1245
Steve Block44f0eee2011-05-26 01:26:41 +01001246 // Before calling a C-function from generated code, align arguments on stack
1247 // and add space for the four mips argument slots.
1248 // After aligning the frame, non-register arguments must be stored on the
1249 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1250 // The argument count assumes all arguments are word sized.
1251 // Some compilers/platforms require the stack to be aligned when calling
1252 // C++ code.
1253 // Needs a scratch register to do some arithmetic. This register will be
1254 // trashed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001255 void PrepareCallCFunction(int num_reg_arguments,
1256 int num_double_registers,
1257 Register scratch);
1258 void PrepareCallCFunction(int num_reg_arguments,
1259 Register scratch);
Steve Block44f0eee2011-05-26 01:26:41 +01001260
1261 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1262 // Arguments 5..n are stored to stack using following:
1263 // sw(t0, CFunctionArgumentOperand(5));
1264
1265 // Calls a C function and cleans up the space for arguments allocated
1266 // by PrepareCallCFunction. The called function is not allowed to trigger a
1267 // garbage collection, since that might move the code and invalidate the
1268 // return address (unless this is somehow accounted for by the called
1269 // function).
1270 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001271 void CallCFunction(Register function, int num_arguments);
1272 void CallCFunction(ExternalReference function,
1273 int num_reg_arguments,
1274 int num_double_arguments);
1275 void CallCFunction(Register function,
1276 int num_reg_arguments,
1277 int num_double_arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001278 void MovFromFloatResult(DoubleRegister dst);
1279 void MovFromFloatParameter(DoubleRegister dst);
Ben Murdoch257744e2011-11-30 15:57:28 +00001280
1281 // There are two ways of passing double arguments on MIPS, depending on
1282 // whether soft or hard floating point ABI is used. These functions
1283 // abstract parameter passing for the three different ways we call
1284 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001285 void MovToFloatParameter(DoubleRegister src);
1286 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1287 void MovToFloatResult(DoubleRegister src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001288
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001289 // Calls an API function. Allocates HandleScope, extracts returned value
1290 // from handle and propagates exceptions. Restores context. stack_space
1291 // - space to be unwound on exit (includes the call JS arguments space and
1292 // the additional space allocated for the fast call).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001293 void CallApiFunctionAndReturn(Register function_address,
1294 ExternalReference thunk_ref,
1295 int stack_space,
1296 MemOperand return_value_operand,
1297 MemOperand* context_restore_operand);
Steve Block44f0eee2011-05-26 01:26:41 +01001298
Andrei Popescu31002712010-02-23 13:46:05 +00001299 // Jump to the builtin routine.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001300 void JumpToExternalReference(const ExternalReference& builtin,
1301 BranchDelaySlot bd = PROTECT);
Andrei Popescu31002712010-02-23 13:46:05 +00001302
1303 // Invoke specified builtin JavaScript function. Adds an entry to
1304 // the unresolved list if the name does not resolve.
Steve Block44f0eee2011-05-26 01:26:41 +01001305 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +00001306 InvokeFlag flag,
1307 const CallWrapper& call_wrapper = NullCallWrapper());
Andrei Popescu31002712010-02-23 13:46:05 +00001308
1309 // Store the code object for the given builtin in the target register and
Steve Block44f0eee2011-05-26 01:26:41 +01001310 // setup the function in a1.
Andrei Popescu31002712010-02-23 13:46:05 +00001311 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1312
Steve Block44f0eee2011-05-26 01:26:41 +01001313 // Store the function for the given builtin in the target register.
1314 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1315
Andrei Popescu31002712010-02-23 13:46:05 +00001316 struct Unresolved {
1317 int pc;
Ben Murdoch257744e2011-11-30 15:57:28 +00001318 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
Andrei Popescu31002712010-02-23 13:46:05 +00001319 const char* name;
1320 };
Andrei Popescu31002712010-02-23 13:46:05 +00001321
Ben Murdoch257744e2011-11-30 15:57:28 +00001322 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001323 DCHECK(!code_object_.is_null());
Ben Murdoch257744e2011-11-30 15:57:28 +00001324 return code_object_;
1325 }
Andrei Popescu31002712010-02-23 13:46:05 +00001326
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001327 // Emit code for a truncating division by a constant. The dividend register is
1328 // unchanged and at gets clobbered. Dividend and result must be different.
1329 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1330
Steve Block44f0eee2011-05-26 01:26:41 +01001331 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001332 // StatsCounter support.
Andrei Popescu31002712010-02-23 13:46:05 +00001333
1334 void SetCounter(StatsCounter* counter, int value,
1335 Register scratch1, Register scratch2);
1336 void IncrementCounter(StatsCounter* counter, int value,
1337 Register scratch1, Register scratch2);
1338 void DecrementCounter(StatsCounter* counter, int value,
1339 Register scratch1, Register scratch2);
1340
1341
Steve Block44f0eee2011-05-26 01:26:41 +01001342 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001343 // Debugging.
Andrei Popescu31002712010-02-23 13:46:05 +00001344
1345 // Calls Abort(msg) if the condition cc is not satisfied.
1346 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001347 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
Steve Block44f0eee2011-05-26 01:26:41 +01001348 void AssertFastElements(Register elements);
Andrei Popescu31002712010-02-23 13:46:05 +00001349
1350 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001351 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
Andrei Popescu31002712010-02-23 13:46:05 +00001352
1353 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001354 void Abort(BailoutReason msg);
Andrei Popescu31002712010-02-23 13:46:05 +00001355
1356 // Verify restrictions about code generated in stubs.
1357 void set_generating_stub(bool value) { generating_stub_ = value; }
1358 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001359 void set_has_frame(bool value) { has_frame_ = value; }
1360 bool has_frame() { return has_frame_; }
1361 inline bool AllowThisStubCall(CodeStub* stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001362
Steve Block44f0eee2011-05-26 01:26:41 +01001363 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001364 // Number utilities.
Steve Block6ded16b2010-05-10 14:33:55 +01001365
Steve Block44f0eee2011-05-26 01:26:41 +01001366 // Check whether the value of reg is a power of two and not zero. If not
1367 // control continues at the label not_power_of_two. If reg is a power of two
1368 // the register scratch contains the value of (reg - 1) when control falls
1369 // through.
1370 void JumpIfNotPowerOfTwoOrZero(Register reg,
1371 Register scratch,
1372 Label* not_power_of_two_or_zero);
1373
1374 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001375 // Smi utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001376
Steve Block44f0eee2011-05-26 01:26:41 +01001377 void SmiTag(Register reg) {
1378 Addu(reg, reg, reg);
1379 }
1380
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001381 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1382 void SmiTagCheckOverflow(Register reg, Register overflow);
1383 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1384
Steve Block44f0eee2011-05-26 01:26:41 +01001385 void SmiTag(Register dst, Register src) {
1386 Addu(dst, src, src);
1387 }
1388
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001389 // Try to convert int32 to smi. If the value is to large, preserve
1390 // the original value and jump to not_a_smi. Destroys scratch and
1391 // sets flags.
1392 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1393 TrySmiTag(reg, reg, scratch, not_a_smi);
1394 }
1395 void TrySmiTag(Register dst,
1396 Register src,
1397 Register scratch,
1398 Label* not_a_smi) {
1399 SmiTagCheckOverflow(at, src, scratch);
1400 BranchOnOverflow(not_a_smi, scratch);
1401 mov(dst, at);
1402 }
1403
Steve Block44f0eee2011-05-26 01:26:41 +01001404 void SmiUntag(Register reg) {
1405 sra(reg, reg, kSmiTagSize);
1406 }
1407
1408 void SmiUntag(Register dst, Register src) {
1409 sra(dst, src, kSmiTagSize);
1410 }
1411
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001412 // Test if the register contains a smi.
1413 inline void SmiTst(Register value, Register scratch) {
1414 And(scratch, value, Operand(kSmiTagMask));
1415 }
1416 inline void NonNegativeSmiTst(Register value, Register scratch) {
1417 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1418 }
1419
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001420 // Untag the source value into destination and jump if source is a smi.
1421 // Souce and destination can be the same register.
1422 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1423
1424 // Untag the source value into destination and jump if source is not a smi.
1425 // Souce and destination can be the same register.
1426 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1427
Steve Block44f0eee2011-05-26 01:26:41 +01001428 // Jump the register contains a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001429 void JumpIfSmi(Register value,
1430 Label* smi_label,
1431 Register scratch = at,
1432 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001433
1434 // Jump if the register contains a non-smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001435 void JumpIfNotSmi(Register value,
1436 Label* not_smi_label,
1437 Register scratch = at,
1438 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001439
1440 // Jump if either of the registers contain a non-smi.
1441 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1442 // Jump if either of the registers contain a smi.
1443 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1444
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001445 // Abort execution if argument is a smi, enabled via --debug-code.
1446 void AssertNotSmi(Register object);
1447 void AssertSmi(Register object);
Steve Block44f0eee2011-05-26 01:26:41 +01001448
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001449 // Abort execution if argument is not a string, enabled via --debug-code.
1450 void AssertString(Register object);
Ben Murdoch257744e2011-11-30 15:57:28 +00001451
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001452 // Abort execution if argument is not a name, enabled via --debug-code.
1453 void AssertName(Register object);
1454
1455 // Abort execution if argument is not undefined or an AllocationSite, enabled
1456 // via --debug-code.
1457 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1458
1459 // Abort execution if reg is not the root value with the given index,
1460 // enabled via --debug-code.
1461 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block44f0eee2011-05-26 01:26:41 +01001462
1463 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001464 // HeapNumber utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001465
1466 void JumpIfNotHeapNumber(Register object,
1467 Register heap_number_map,
1468 Register scratch,
1469 Label* on_not_heap_number);
1470
1471 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001472 // String utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001473
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001474 // Generate code to do a lookup in the number string cache. If the number in
1475 // the register object is found in the cache the generated code falls through
1476 // with the result in the result register. The object and the result register
1477 // can be the same. If the number is not found in the cache the code jumps to
1478 // the label not_found with only the content of register object unchanged.
1479 void LookupNumberStringCache(Register object,
1480 Register result,
1481 Register scratch1,
1482 Register scratch2,
1483 Register scratch3,
1484 Label* not_found);
1485
Steve Block44f0eee2011-05-26 01:26:41 +01001486 // Checks if both instance types are sequential ASCII strings and jumps to
1487 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001488 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1489 Register first_object_instance_type, Register second_object_instance_type,
1490 Register scratch1, Register scratch2, Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001491
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001492 // Check if instance type is sequential one-byte string and jump to label if
Steve Block44f0eee2011-05-26 01:26:41 +01001493 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001494 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1495 Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001496
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001497 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
Steve Block44f0eee2011-05-26 01:26:41 +01001498
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001499 void EmitSeqStringSetCharCheck(Register string,
1500 Register index,
1501 Register value,
1502 Register scratch,
1503 uint32_t encoding_mask);
1504
1505 // Checks if both objects are sequential one-byte strings and jumps to label
1506 // if either is not. Assumes that neither object is a smi.
1507 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1508 Register second,
1509 Register scratch1,
1510 Register scratch2,
1511 Label* failure);
1512
1513 // Checks if both objects are sequential one-byte strings and jumps to label
1514 // if either is not.
1515 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1516 Register scratch1,
1517 Register scratch2,
1518 Label* not_flat_one_byte_strings);
Steve Block44f0eee2011-05-26 01:26:41 +01001519
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001520 void ClampUint8(Register output_reg, Register input_reg);
1521
1522 void ClampDoubleToUint8(Register result_reg,
1523 DoubleRegister input_reg,
1524 DoubleRegister temp_double_reg);
1525
1526
Ben Murdoch257744e2011-11-30 15:57:28 +00001527 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528 void EnumLength(Register dst, Register map);
1529 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch257744e2011-11-30 15:57:28 +00001530
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001531 template<typename Field>
1532 void DecodeField(Register dst, Register src) {
1533 Ext(dst, src, Field::kShift, Field::kSize);
1534 }
1535
1536 template<typename Field>
1537 void DecodeField(Register reg) {
1538 DecodeField<Field>(reg, reg);
1539 }
1540
1541 template<typename Field>
1542 void DecodeFieldToSmi(Register dst, Register src) {
1543 static const int shift = Field::kShift;
1544 static const int mask = Field::kMask >> shift << kSmiTagSize;
1545 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1546 STATIC_ASSERT(kSmiTag == 0);
1547 if (shift < kSmiTagSize) {
1548 sll(dst, src, kSmiTagSize - shift);
1549 And(dst, dst, Operand(mask));
1550 } else if (shift > kSmiTagSize) {
1551 srl(dst, src, shift - kSmiTagSize);
1552 And(dst, dst, Operand(mask));
1553 } else {
1554 And(dst, src, Operand(mask));
1555 }
1556 }
1557
1558 template<typename Field>
1559 void DecodeFieldToSmi(Register reg) {
1560 DecodeField<Field>(reg, reg);
1561 }
1562
1563 // Generates function and stub prologue code.
1564 void StubPrologue();
1565 void Prologue(bool code_pre_aging);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001566
1567 // Activation support.
1568 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001569 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001570 void LeaveFrame(StackFrame::Type type);
1571
1572 // Patch the relocated value (lui/ori pair).
1573 void PatchRelocatedValue(Register li_location,
1574 Register scratch,
1575 Register new_value);
1576 // Get the relocatad value (loaded data) from the lui/ori pair.
1577 void GetRelocatedValue(Register li_location,
1578 Register value,
1579 Register scratch);
1580
1581 // Expects object in a0 and returns map with validated enum cache
1582 // in a0. Assumes that any other register can be used as a scratch.
1583 void CheckEnumCache(Register null_value, Label* call_runtime);
1584
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001585 // AllocationMemento support. Arrays may have an associated
1586 // AllocationMemento object that can be checked for in order to pretransition
1587 // to another type.
1588 // On entry, receiver_reg should point to the array object.
1589 // scratch_reg gets clobbered.
1590 // If allocation info is present, jump to allocation_memento_present.
1591 void TestJSArrayForAllocationMemento(
1592 Register receiver_reg,
1593 Register scratch_reg,
1594 Label* no_memento_found,
1595 Condition cond = al,
1596 Label* allocation_memento_present = NULL);
1597
1598 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1599 Register scratch_reg,
1600 Label* memento_found) {
1601 Label no_memento_found;
1602 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1603 &no_memento_found, eq, memento_found);
1604 bind(&no_memento_found);
1605 }
1606
1607 // Jumps to found label if a prototype map has dictionary elements.
1608 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1609 Register scratch1, Label* found);
1610
Steve Block44f0eee2011-05-26 01:26:41 +01001611 private:
1612 void CallCFunctionHelper(Register function,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001613 int num_reg_arguments,
1614 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001615
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001616 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1617 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1618 const Operand& rt,
1619 BranchDelaySlot bdslot = PROTECT);
1620 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1621 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1622 const Operand& rt,
1623 BranchDelaySlot bdslot = PROTECT);
1624 void J(Label* L, BranchDelaySlot bdslot);
1625 void Jr(Label* L, BranchDelaySlot bdslot);
1626 void Jalr(Label* L, BranchDelaySlot bdslot);
Steve Block6ded16b2010-05-10 14:33:55 +01001627
1628 // Helper functions for generating invokes.
1629 void InvokePrologue(const ParameterCount& expected,
1630 const ParameterCount& actual,
1631 Handle<Code> code_constant,
1632 Register code_reg,
1633 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001634 bool* definitely_mismatches,
Steve Block44f0eee2011-05-26 01:26:41 +01001635 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001636 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001637
1638 // Get the code for the given builtin. Returns if able to resolve
1639 // the function in the 'resolved' flag.
1640 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1641
Steve Block44f0eee2011-05-26 01:26:41 +01001642 void InitializeNewString(Register string,
1643 Register length,
1644 Heap::RootListIndex map_index,
1645 Register scratch1,
1646 Register scratch2);
1647
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001648 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1649 void InNewSpace(Register object,
1650 Register scratch,
1651 Condition cond, // eq for new space, ne otherwise.
1652 Label* branch);
1653
1654 // Helper for finding the mark bits for an address. Afterwards, the
1655 // bitmap register points at the word with the mark bits and the mask
1656 // the position of the first bit. Leaves addr_reg unchanged.
1657 inline void GetMarkBits(Register addr_reg,
1658 Register bitmap_reg,
1659 Register mask_reg);
1660
1661 // Helper for throwing exceptions. Compute a handler address and jump to
1662 // it. See the implementation for register usage.
1663 void JumpToHandlerEntry();
1664
Ben Murdoch257744e2011-11-30 15:57:28 +00001665 // Compute memory operands for safepoint stack slots.
1666 static int SafepointRegisterStackIndex(int reg_code);
1667 MemOperand SafepointRegisterSlot(Register reg);
1668 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
Steve Block44f0eee2011-05-26 01:26:41 +01001669
1670 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001671 bool has_frame_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001672 bool has_double_zero_reg_set_;
Steve Block44f0eee2011-05-26 01:26:41 +01001673 // This handle will be patched with the code object on installation.
1674 Handle<Object> code_object_;
Ben Murdoch257744e2011-11-30 15:57:28 +00001675
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001676 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoch257744e2011-11-30 15:57:28 +00001677 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001678 friend class StandardFrame;
Steve Block44f0eee2011-05-26 01:26:41 +01001679};
1680
1681
Steve Block44f0eee2011-05-26 01:26:41 +01001682// The code patcher is used to patch (typically) small parts of code e.g. for
1683// debugging and other types of instrumentation. When using the code patcher
1684// the exact number of bytes specified must be emitted. It is not legal to emit
1685// relocation information. If any of these constraints are violated it causes
1686// an assertion to fail.
1687class CodePatcher {
1688 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001689 enum FlushICache {
1690 FLUSH,
1691 DONT_FLUSH
1692 };
1693
1694 CodePatcher(byte* address,
1695 int instructions,
1696 FlushICache flush_cache = FLUSH);
Steve Block44f0eee2011-05-26 01:26:41 +01001697 virtual ~CodePatcher();
1698
1699 // Macro assembler to emit code.
1700 MacroAssembler* masm() { return &masm_; }
1701
1702 // Emit an instruction directly.
Ben Murdoch257744e2011-11-30 15:57:28 +00001703 void Emit(Instr instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001704
1705 // Emit an address directly.
1706 void Emit(Address addr);
1707
Ben Murdoch257744e2011-11-30 15:57:28 +00001708 // Change the condition part of an instruction leaving the rest of the current
1709 // instruction unchanged.
1710 void ChangeBranchCondition(Condition cond);
1711
Steve Block44f0eee2011-05-26 01:26:41 +01001712 private:
1713 byte* address_; // The address of the code being patched.
Steve Block44f0eee2011-05-26 01:26:41 +01001714 int size_; // Number of bytes of the expected patch size.
1715 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001716 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Block44f0eee2011-05-26 01:26:41 +01001717};
Andrei Popescu31002712010-02-23 13:46:05 +00001718
1719
Andrei Popescu31002712010-02-23 13:46:05 +00001720
1721#ifdef GENERATED_CODE_COVERAGE
1722#define CODE_COVERAGE_STRINGIFY(x) #x
1723#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1724#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1725#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1726#else
1727#define ACCESS_MASM(masm) masm->
1728#endif
1729
1730} } // namespace v8::internal
1731
1732#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_