blob: 2f028658f4fb6fe1494cec6ef7fd991a3c7530ab [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
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};
Ben Murdoch097c5b22016-05-18 11:27:45 +010018const Register kReturnRegister2 = {Register::kCode_a0};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019const Register kJSFunctionRegister = {Register::kCode_a1};
20const Register kContextRegister = {Register::kCpRegister};
21const Register kInterpreterAccumulatorRegister = {Register::kCode_v0};
22const Register kInterpreterRegisterFileRegister = {Register::kCode_t3};
23const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_t4};
24const Register kInterpreterBytecodeArrayRegister = {Register::kCode_t5};
25const Register kInterpreterDispatchTableRegister = {Register::kCode_t6};
26const Register kJavaScriptCallArgCountRegister = {Register::kCode_a0};
27const Register kJavaScriptCallNewTargetRegister = {Register::kCode_a3};
28const Register kRuntimeCallFunctionRegister = {Register::kCode_a1};
29const Register kRuntimeCallArgCountRegister = {Register::kCode_a0};
30
Andrei Popescu31002712010-02-23 13:46:05 +000031// Forward declaration.
32class JumpTarget;
33
Steve Block44f0eee2011-05-26 01:26:41 +010034// Reserved Register Usage Summary.
35//
36// Registers t8, t9, and at are reserved for use by the MacroAssembler.
37//
38// The programmer should know that the MacroAssembler may clobber these three,
39// but won't touch other registers except in special cases.
40//
41// Per the MIPS ABI, register t9 must be used for indirect function call
42// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
43// trying to update gp register for position-independent-code. Whenever
44// MIPS generated code calls C code, it must be via t9 register.
Andrei Popescu31002712010-02-23 13:46:05 +000045
Ben Murdoch592a9fc2012-03-05 11:04:45 +000046
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047// Flags used for LeaveExitFrame function.
48enum LeaveExitFrameMode {
49 EMIT_RETURN = true,
50 NO_EMIT_RETURN = false
51};
52
53// Flags used for AllocateHeapNumber
54enum TaggingMode {
55 // Tag the result.
56 TAG_RESULT,
57 // Don't tag
58 DONT_TAG_RESULT
Steve Block44f0eee2011-05-26 01:26:41 +010059};
60
61// Flags used for the ObjectToDoubleFPURegister function.
62enum ObjectToDoubleFlags {
63 // No special flags.
64 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
65 // Object is known to be a non smi.
66 OBJECT_NOT_SMI = 1 << 0,
67 // Don't load NaNs or infinities, branch to the non number case instead.
68 AVOID_NANS_AND_INFINITIES = 1 << 1
69};
70
71// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
72enum BranchDelaySlot {
73 USE_DELAY_SLOT,
74 PROTECT
75};
76
Ben Murdoch3ef787d2012-04-12 10:51:47 +010077// Flags used for the li macro-assembler function.
78enum LiFlags {
79 // If the constant value can be represented in just 16 bits, then
80 // optimize the li to use a single instruction, rather than lui/ori pair.
81 OPTIMIZE_SIZE = 0,
82 // Always use 2 instructions (lui/ori pair), even if the constant could
83 // be loaded with just one, so that this value is patchable later.
84 CONSTANT_SIZE = 1
85};
86
87
88enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
89enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090enum PointersToHereCheck {
91 kPointersToHereMaybeInteresting,
92 kPointersToHereAreAlwaysInteresting
93};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010094enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
95
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096Register GetRegisterThatIsNotOneOf(Register reg1,
97 Register reg2 = no_reg,
98 Register reg3 = no_reg,
99 Register reg4 = no_reg,
100 Register reg5 = no_reg,
101 Register reg6 = no_reg);
102
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
104 Register reg4 = no_reg, Register reg5 = no_reg,
105 Register reg6 = no_reg, Register reg7 = no_reg,
106 Register reg8 = no_reg, Register reg9 = no_reg,
107 Register reg10 = no_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100108
109
110// -----------------------------------------------------------------------------
111// Static helper functions.
112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113inline MemOperand ContextMemOperand(Register context, int index) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100114 return MemOperand(context, Context::SlotOffset(index));
115}
116
117
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118inline MemOperand NativeContextMemOperand() {
119 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100120}
121
122
123// Generate a MemOperand for loading a field from an object.
124inline MemOperand FieldMemOperand(Register object, int offset) {
125 return MemOperand(object, offset - kHeapObjectTag);
126}
127
128
129// Generate a MemOperand for storing arguments 5..N on the stack
130// when calling CallCFunction().
131inline MemOperand CFunctionArgumentOperand(int index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132 DCHECK(index > kCArgSlotCount);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100133 // Argument 5 takes the slot just past the four Arg-slots.
134 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
135 return MemOperand(sp, offset);
136}
137
138
Andrei Popescu31002712010-02-23 13:46:05 +0000139// MacroAssembler implements a collection of frequently used macros.
140class MacroAssembler: public Assembler {
141 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000142 MacroAssembler(Isolate* isolate, void* buffer, int size,
143 CodeObjectRequired create_code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000144
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000145 // Arguments macros.
Steve Block44f0eee2011-05-26 01:26:41 +0100146#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
147#define COND_ARGS cond, r1, r2
148
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000149 // Cases when relocation is not needed.
Steve Block44f0eee2011-05-26 01:26:41 +0100150#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
151 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
152 inline void Name(BranchDelaySlot bd, target_type target) { \
153 Name(target, bd); \
154 } \
155 void Name(target_type target, \
156 COND_TYPED_ARGS, \
157 BranchDelaySlot bd = PROTECT); \
158 inline void Name(BranchDelaySlot bd, \
159 target_type target, \
160 COND_TYPED_ARGS) { \
161 Name(target, COND_ARGS, bd); \
162 }
163
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000164#define DECLARE_BRANCH_PROTOTYPES(Name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100165 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000166 DECLARE_NORELOC_PROTOTYPE(Name, int32_t)
Steve Block44f0eee2011-05-26 01:26:41 +0100167
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000168 DECLARE_BRANCH_PROTOTYPES(Branch)
169 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170 DECLARE_BRANCH_PROTOTYPES(BranchShort)
Steve Block44f0eee2011-05-26 01:26:41 +0100171
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000172#undef DECLARE_BRANCH_PROTOTYPES
Steve Block44f0eee2011-05-26 01:26:41 +0100173#undef COND_TYPED_ARGS
174#undef COND_ARGS
Andrei Popescu31002712010-02-23 13:46:05 +0000175
Ben Murdoch257744e2011-11-30 15:57:28 +0000176
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000177 // Jump, Call, and Ret pseudo instructions implementing inter-working.
178#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
179 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
180
181 void Jump(Register target, COND_ARGS);
182 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
183 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
184 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100185 static int CallSize(Register target, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000186 void Call(Register target, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100187 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000188 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000189 int CallSize(Handle<Code> code,
190 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
191 TypeFeedbackId ast_id = TypeFeedbackId::None(),
192 COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000193 void Call(Handle<Code> code,
194 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195 TypeFeedbackId ast_id = TypeFeedbackId::None(),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000196 COND_ARGS);
197 void Ret(COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100198 inline void Ret(BranchDelaySlot bd, Condition cond = al,
199 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
200 Ret(cond, rs, rt, bd);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000201 }
202
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000203 bool IsNear(Label* L, Condition cond, int rs_reg);
204
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100205 void Branch(Label* L,
206 Condition cond,
207 Register rs,
208 Heap::RootListIndex index,
209 BranchDelaySlot bdslot = PROTECT);
210
Ben Murdoch097c5b22016-05-18 11:27:45 +0100211 // GetLabelFunction must be lambda '[](size_t index) -> Label*' or a
212 // functor/function with 'Label *func(size_t index)' declaration.
213 template <typename Func>
214 void GenerateSwitchTable(Register index, size_t case_count,
215 Func GetLabelFunction);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000216#undef COND_ARGS
Ben Murdoch257744e2011-11-30 15:57:28 +0000217
Andrei Popescu31002712010-02-23 13:46:05 +0000218 // Emit code to discard a non-negative number of pointer-sized elements
219 // from the stack, clobbering only the sp register.
Steve Block44f0eee2011-05-26 01:26:41 +0100220 void Drop(int count,
221 Condition cond = cc_always,
222 Register reg = no_reg,
223 const Operand& op = Operand(no_reg));
224
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100225 // Trivial case of DropAndRet that utilizes the delay slot and only emits
226 // 2 instructions.
227 void DropAndRet(int drop);
228
229 void DropAndRet(int drop,
230 Condition cond,
231 Register reg,
232 const Operand& op);
Steve Block44f0eee2011-05-26 01:26:41 +0100233
234 // Swap two registers. If the scratch register is omitted then a slightly
235 // less efficient form using xor instead of mov is emitted.
236 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
Andrei Popescu31002712010-02-23 13:46:05 +0000237
238 void Call(Label* target);
Steve Block44f0eee2011-05-26 01:26:41 +0100239
Ben Murdochda12d292016-06-02 14:46:10 +0100240 inline void Move(Register dst, Handle<Object> handle) { li(dst, handle); }
241 inline void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000242
Ben Murdoch257744e2011-11-30 15:57:28 +0000243 inline void Move(Register dst, Register src) {
244 if (!dst.is(src)) {
245 mov(dst, src);
246 }
247 }
248
Ben Murdochda12d292016-06-02 14:46:10 +0100249 inline void Move_d(FPURegister dst, FPURegister src) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000250 if (!dst.is(src)) {
251 mov_d(dst, src);
252 }
253 }
254
Ben Murdochda12d292016-06-02 14:46:10 +0100255 inline void Move_s(FPURegister dst, FPURegister src) {
256 if (!dst.is(src)) {
257 mov_s(dst, src);
258 }
259 }
260
261 inline void Move(FPURegister dst, FPURegister src) { Move_d(dst, src); }
262
Ben Murdoch257744e2011-11-30 15:57:28 +0000263 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
264 mfc1(dst_low, src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000265 Mfhc1(dst_high, src);
266 }
267
268 inline void FmoveHigh(Register dst_high, FPURegister src) {
269 Mfhc1(dst_high, src);
270 }
271
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000272 inline void FmoveHigh(FPURegister dst, Register src_high) {
273 Mthc1(src_high, dst);
274 }
275
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 inline void FmoveLow(Register dst_low, FPURegister src) {
277 mfc1(dst_low, src);
Ben Murdoch257744e2011-11-30 15:57:28 +0000278 }
279
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000280 void FmoveLow(FPURegister dst, Register src_low);
281
Ben Murdoch257744e2011-11-30 15:57:28 +0000282 inline void Move(FPURegister dst, Register src_low, Register src_high) {
283 mtc1(src_low, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284 Mthc1(src_high, dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000285 }
Andrei Popescu31002712010-02-23 13:46:05 +0000286
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400287 void Move(FPURegister dst, float imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100288 void Move(FPURegister dst, double imm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400289
290 // Conditional move.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100291 void Movz(Register rd, Register rs, Register rt);
292 void Movn(Register rd, Register rs, Register rt);
293 void Movt(Register rd, Register rs, uint16_t cc = 0);
294 void Movf(Register rd, Register rs, uint16_t cc = 0);
295
Ben Murdochda12d292016-06-02 14:46:10 +0100296 // Min, Max macros.
297 // On pre-r6 these functions may modify at and t8 registers.
298 void MinNaNCheck_d(FPURegister dst, FPURegister src1, FPURegister src2,
299 Label* nan = nullptr);
300 void MaxNaNCheck_d(FPURegister dst, FPURegister src1, FPURegister src2,
301 Label* nan = nullptr);
302 void MinNaNCheck_s(FPURegister dst, FPURegister src1, FPURegister src2,
303 Label* nan = nullptr);
304 void MaxNaNCheck_s(FPURegister dst, FPURegister src1, FPURegister src2,
305 Label* nan = nullptr);
306
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100307 void Clz(Register rd, Register rs);
308
Andrei Popescu31002712010-02-23 13:46:05 +0000309 // Jump unconditionally to given label.
310 // We NEED a nop in the branch delay slot, as it used by v8, for example in
311 // CodeGenerator::ProcessDeferred().
Steve Block6ded16b2010-05-10 14:33:55 +0100312 // Currently the branch delay slot is filled by the MacroAssembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000313 // Use rather b(Label) for code generation.
314 void jmp(Label* L) {
Steve Block44f0eee2011-05-26 01:26:41 +0100315 Branch(L);
Andrei Popescu31002712010-02-23 13:46:05 +0000316 }
317
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000318 void Load(Register dst, const MemOperand& src, Representation r);
319 void Store(Register src, const MemOperand& dst, Representation r);
320
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000321 void PushRoot(Heap::RootListIndex index) {
322 LoadRoot(at, index);
323 Push(at);
324 }
325
326 // Compare the object in a register to a value and jump if they are equal.
327 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
328 LoadRoot(at, index);
329 Branch(if_equal, eq, with, Operand(at));
330 }
331
332 // Compare the object in a register to a value and jump if they are not equal.
333 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
334 Label* if_not_equal) {
335 LoadRoot(at, index);
336 Branch(if_not_equal, ne, with, Operand(at));
337 }
338
Andrei Popescu31002712010-02-23 13:46:05 +0000339 // Load an object from the root table.
340 void LoadRoot(Register destination,
341 Heap::RootListIndex index);
342 void LoadRoot(Register destination,
343 Heap::RootListIndex index,
344 Condition cond, Register src1, const Operand& src2);
345
Steve Block44f0eee2011-05-26 01:26:41 +0100346 // Store an object to the root table.
347 void StoreRoot(Register source,
348 Heap::RootListIndex index);
349 void StoreRoot(Register source,
350 Heap::RootListIndex index,
351 Condition cond, Register src1, const Operand& src2);
352
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100353 // ---------------------------------------------------------------------------
354 // GC Support
355
356 void IncrementalMarkingRecordWriteHelper(Register object,
357 Register value,
358 Register address);
359
360 enum RememberedSetFinalAction {
361 kReturnAtEnd,
362 kFallThroughAtEnd
363 };
Steve Block44f0eee2011-05-26 01:26:41 +0100364
365
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100366 // Record in the remembered set the fact that we have a pointer to new space
367 // at the address pointed to by the addr register. Only works if addr is not
368 // in new space.
369 void RememberedSetHelper(Register object, // Used for debug code.
370 Register addr,
371 Register scratch,
372 SaveFPRegsMode save_fp,
373 RememberedSetFinalAction and_then);
Steve Block44f0eee2011-05-26 01:26:41 +0100374
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100375 void CheckPageFlag(Register object,
376 Register scratch,
377 int mask,
378 Condition cc,
379 Label* condition_met);
380
381 // Check if object is in new space. Jumps if the object is not in new space.
382 // The register scratch can be object itself, but it will be clobbered.
383 void JumpIfNotInNewSpace(Register object,
384 Register scratch,
385 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100386 InNewSpace(object, scratch, eq, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100387 }
388
389 // Check if object is in new space. Jumps if the object is in new space.
390 // The register scratch can be object itself, but scratch will be clobbered.
391 void JumpIfInNewSpace(Register object,
392 Register scratch,
393 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100394 InNewSpace(object, scratch, ne, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100395 }
396
397 // Check if an object has a given incremental marking color.
398 void HasColor(Register object,
399 Register scratch0,
400 Register scratch1,
401 Label* has_color,
402 int first_bit,
403 int second_bit);
404
405 void JumpIfBlack(Register object,
Steve Block44f0eee2011-05-26 01:26:41 +0100406 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100407 Register scratch1,
408 Label* on_black);
Steve Block44f0eee2011-05-26 01:26:41 +0100409
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000410 // Checks the color of an object. If the object is white we jump to the
411 // incremental marker.
412 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
413 Register scratch3, Label* value_is_white);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100414
415 // Notify the garbage collector that we wrote a pointer into an object.
416 // |object| is the object being stored into, |value| is the object being
417 // stored. value and scratch registers are clobbered by the operation.
418 // The offset is the offset from the start of the object, not the offset from
419 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
420 void RecordWriteField(
421 Register object,
422 int offset,
423 Register value,
424 Register scratch,
425 RAStatus ra_status,
426 SaveFPRegsMode save_fp,
427 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000428 SmiCheck smi_check = INLINE_SMI_CHECK,
429 PointersToHereCheck pointers_to_here_check_for_value =
430 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100431
432 // As above, but the offset has the tag presubtracted. For use with
433 // MemOperand(reg, off).
434 inline void RecordWriteContextSlot(
435 Register context,
436 int offset,
437 Register value,
438 Register scratch,
439 RAStatus ra_status,
440 SaveFPRegsMode save_fp,
441 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000442 SmiCheck smi_check = INLINE_SMI_CHECK,
443 PointersToHereCheck pointers_to_here_check_for_value =
444 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100445 RecordWriteField(context,
446 offset + kHeapObjectTag,
447 value,
448 scratch,
449 ra_status,
450 save_fp,
451 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000452 smi_check,
453 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100454 }
455
Ben Murdoch097c5b22016-05-18 11:27:45 +0100456 // Notify the garbage collector that we wrote a code entry into a
457 // JSFunction. Only scratch is clobbered by the operation.
458 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
459 Register scratch);
460
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 void RecordWriteForMap(
462 Register object,
463 Register map,
464 Register dst,
465 RAStatus ra_status,
466 SaveFPRegsMode save_fp);
467
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100468 // For a given |object| notify the garbage collector that the slot |address|
469 // has been written. |value| is the object being stored. The value and
470 // address registers are clobbered by the operation.
471 void RecordWrite(
472 Register object,
473 Register address,
474 Register value,
475 RAStatus ra_status,
476 SaveFPRegsMode save_fp,
477 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000478 SmiCheck smi_check = INLINE_SMI_CHECK,
479 PointersToHereCheck pointers_to_here_check_for_value =
480 kPointersToHereMaybeInteresting);
Steve Block44f0eee2011-05-26 01:26:41 +0100481
482
483 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000484 // Inline caching support.
Steve Block44f0eee2011-05-26 01:26:41 +0100485
486 // Generate code for checking access rights - used for security checks
487 // on access to global objects across environments. The holder register
488 // is left untouched, whereas both scratch registers are clobbered.
489 void CheckAccessGlobalProxy(Register holder_reg,
490 Register scratch,
491 Label* miss);
492
Ben Murdochc7cc0282012-03-05 14:35:55 +0000493 void GetNumberHash(Register reg0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000494
495 void LoadFromNumberDictionary(Label* miss,
496 Register elements,
497 Register key,
498 Register result,
499 Register reg0,
500 Register reg1,
501 Register reg2);
502
503
Steve Block44f0eee2011-05-26 01:26:41 +0100504 inline void MarkCode(NopMarkerTypes type) {
505 nop(type);
Steve Block6ded16b2010-05-10 14:33:55 +0100506 }
507
Steve Block44f0eee2011-05-26 01:26:41 +0100508 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100509 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
Steve Block44f0eee2011-05-26 01:26:41 +0100510 // nop(type)). These instructions are generated to mark special location in
511 // the code, like some special IC code.
512 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Steve Block44f0eee2011-05-26 01:26:41 +0100514 return IsNop(instr, type);
515 }
Andrei Popescu31002712010-02-23 13:46:05 +0000516
517
Steve Block44f0eee2011-05-26 01:26:41 +0100518 static inline int GetCodeMarker(Instr instr) {
519 uint32_t opcode = ((instr & kOpcodeMask));
520 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
521 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
522 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
523
524 // Return <n> if we have a sll zero_reg, zero_reg, n
525 // else return -1.
526 bool sllzz = (opcode == SLL &&
527 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
528 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
529 int type =
530 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531 DCHECK((type == -1) ||
Steve Block44f0eee2011-05-26 01:26:41 +0100532 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
533 return type;
534 }
535
536
537
538 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000539 // Allocation support.
Steve Block44f0eee2011-05-26 01:26:41 +0100540
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000541 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000542 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
543 // is passed. If the space is exhausted control continues at the gc_required
544 // label. The allocated object is returned in result. If the flag
545 // tag_allocated_object is true the result is tagged as as a heap object.
546 // All registers are clobbered also when control continues at the gc_required
547 // label.
548 void Allocate(int object_size,
549 Register result,
550 Register scratch1,
551 Register scratch2,
552 Label* gc_required,
553 AllocationFlags flags);
554
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000555 void Allocate(Register object_size, Register result, Register result_new,
556 Register scratch, Label* gc_required, AllocationFlags flags);
Steve Block44f0eee2011-05-26 01:26:41 +0100557
558 void AllocateTwoByteString(Register result,
559 Register length,
560 Register scratch1,
561 Register scratch2,
562 Register scratch3,
563 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000564 void AllocateOneByteString(Register result, Register length,
565 Register scratch1, Register scratch2,
566 Register scratch3, Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100567 void AllocateTwoByteConsString(Register result,
568 Register length,
569 Register scratch1,
570 Register scratch2,
571 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000572 void AllocateOneByteConsString(Register result, Register length,
573 Register scratch1, Register scratch2,
574 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000575 void AllocateTwoByteSlicedString(Register result,
576 Register length,
577 Register scratch1,
578 Register scratch2,
579 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000580 void AllocateOneByteSlicedString(Register result, Register length,
581 Register scratch1, Register scratch2,
582 Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100583
584 // Allocates a heap number or jumps to the gc_required label if the young
585 // space is full and a scavenge is needed. All registers are clobbered also
586 // when control continues at the gc_required label.
587 void AllocateHeapNumber(Register result,
588 Register scratch1,
589 Register scratch2,
590 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000591 Label* gc_required,
592 TaggingMode tagging_mode = TAG_RESULT,
593 MutableMode mode = IMMUTABLE);
Steve Block44f0eee2011-05-26 01:26:41 +0100594 void AllocateHeapNumberWithValue(Register result,
595 FPURegister value,
596 Register scratch1,
597 Register scratch2,
598 Label* gc_required);
599
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000600 // Allocate and initialize a JSValue wrapper with the specified {constructor}
601 // and {value}.
602 void AllocateJSValue(Register result, Register constructor, Register value,
603 Register scratch1, Register scratch2,
604 Label* gc_required);
605
Andrei Popescu31002712010-02-23 13:46:05 +0000606 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000607 // Instruction macros.
Andrei Popescu31002712010-02-23 13:46:05 +0000608
Steve Block44f0eee2011-05-26 01:26:41 +0100609#define DEFINE_INSTRUCTION(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000610 void instr(Register rd, Register rs, const Operand& rt); \
611 void instr(Register rd, Register rs, Register rt) { \
612 instr(rd, rs, Operand(rt)); \
613 } \
614 void instr(Register rs, Register rt, int32_t j) { \
615 instr(rs, rt, Operand(j)); \
616 }
617
Steve Block44f0eee2011-05-26 01:26:41 +0100618#define DEFINE_INSTRUCTION2(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000619 void instr(Register rs, const Operand& rt); \
620 void instr(Register rs, Register rt) { \
621 instr(rs, Operand(rt)); \
622 } \
623 void instr(Register rs, int32_t j) { \
624 instr(rs, Operand(j)); \
625 }
626
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000627#define DEFINE_INSTRUCTION3(instr) \
628 void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \
629 void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \
630 instr(rd_hi, rd_lo, rs, Operand(rt)); \
631 } \
632 void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \
633 instr(rd_hi, rd_lo, rs, Operand(j)); \
634 }
635
Andrei Popescu31002712010-02-23 13:46:05 +0000636 DEFINE_INSTRUCTION(Addu);
Steve Block44f0eee2011-05-26 01:26:41 +0100637 DEFINE_INSTRUCTION(Subu);
Andrei Popescu31002712010-02-23 13:46:05 +0000638 DEFINE_INSTRUCTION(Mul);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400639 DEFINE_INSTRUCTION(Div);
640 DEFINE_INSTRUCTION(Divu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000641 DEFINE_INSTRUCTION(Mod);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400642 DEFINE_INSTRUCTION(Modu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000643 DEFINE_INSTRUCTION(Mulh);
Andrei Popescu31002712010-02-23 13:46:05 +0000644 DEFINE_INSTRUCTION2(Mult);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400645 DEFINE_INSTRUCTION(Mulhu);
Andrei Popescu31002712010-02-23 13:46:05 +0000646 DEFINE_INSTRUCTION2(Multu);
647 DEFINE_INSTRUCTION2(Div);
648 DEFINE_INSTRUCTION2(Divu);
649
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000650 DEFINE_INSTRUCTION3(Div);
651 DEFINE_INSTRUCTION3(Mul);
Ben Murdochda12d292016-06-02 14:46:10 +0100652 DEFINE_INSTRUCTION3(Mulu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000653
Andrei Popescu31002712010-02-23 13:46:05 +0000654 DEFINE_INSTRUCTION(And);
655 DEFINE_INSTRUCTION(Or);
656 DEFINE_INSTRUCTION(Xor);
657 DEFINE_INSTRUCTION(Nor);
Ben Murdoch257744e2011-11-30 15:57:28 +0000658 DEFINE_INSTRUCTION2(Neg);
Andrei Popescu31002712010-02-23 13:46:05 +0000659
660 DEFINE_INSTRUCTION(Slt);
661 DEFINE_INSTRUCTION(Sltu);
662
Steve Block44f0eee2011-05-26 01:26:41 +0100663 // MIPS32 R2 instruction macro.
664 DEFINE_INSTRUCTION(Ror);
665
Andrei Popescu31002712010-02-23 13:46:05 +0000666#undef DEFINE_INSTRUCTION
667#undef DEFINE_INSTRUCTION2
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000668#undef DEFINE_INSTRUCTION3
Andrei Popescu31002712010-02-23 13:46:05 +0000669
Ben Murdochda12d292016-06-02 14:46:10 +0100670 // Load Scaled Address instructions. Parameter sa (shift argument) must be
671 // between [1, 31] (inclusive). On pre-r6 architectures the scratch register
672 // may be clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000673 void Lsa(Register rd, Register rs, Register rt, uint8_t sa,
674 Register scratch = at);
Ben Murdochda12d292016-06-02 14:46:10 +0100675
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000676 void Pref(int32_t hint, const MemOperand& rs);
677
Andrei Popescu31002712010-02-23 13:46:05 +0000678
Ben Murdoch257744e2011-11-30 15:57:28 +0000679 // ---------------------------------------------------------------------------
680 // Pseudo-instructions.
Andrei Popescu31002712010-02-23 13:46:05 +0000681
682 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
Andrei Popescu31002712010-02-23 13:46:05 +0000683
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000684 void Ulw(Register rd, const MemOperand& rs);
685 void Usw(Register rd, const MemOperand& rs);
686
Ben Murdoch257744e2011-11-30 15:57:28 +0000687 // Load int32 in the rd register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100688 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
689 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
690 li(rd, Operand(j), mode);
Andrei Popescu31002712010-02-23 13:46:05 +0000691 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000692 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
Andrei Popescu31002712010-02-23 13:46:05 +0000693
Andrei Popescu31002712010-02-23 13:46:05 +0000694 // Push multiple registers on the stack.
Steve Block6ded16b2010-05-10 14:33:55 +0100695 // Registers are saved in numerical order, with higher numbered registers
Ben Murdoch257744e2011-11-30 15:57:28 +0000696 // saved in higher memory addresses.
Andrei Popescu31002712010-02-23 13:46:05 +0000697 void MultiPush(RegList regs);
698 void MultiPushReversed(RegList regs);
Steve Block44f0eee2011-05-26 01:26:41 +0100699
Ben Murdoch589d6972011-11-30 16:04:58 +0000700 void MultiPushFPU(RegList regs);
701 void MultiPushReversedFPU(RegList regs);
702
Ben Murdoch257744e2011-11-30 15:57:28 +0000703 void push(Register src) {
Andrei Popescu31002712010-02-23 13:46:05 +0000704 Addu(sp, sp, Operand(-kPointerSize));
705 sw(src, MemOperand(sp, 0));
706 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000707 void Push(Register src) { push(src); }
Steve Block44f0eee2011-05-26 01:26:41 +0100708
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000709 // Push a handle.
710 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000711 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000712
Ben Murdoch257744e2011-11-30 15:57:28 +0000713 // Push two registers. Pushes leftmost register first (to highest address).
714 void Push(Register src1, Register src2) {
Steve Block44f0eee2011-05-26 01:26:41 +0100715 Subu(sp, sp, Operand(2 * kPointerSize));
716 sw(src1, MemOperand(sp, 1 * kPointerSize));
717 sw(src2, MemOperand(sp, 0 * kPointerSize));
718 }
719
Ben Murdoch257744e2011-11-30 15:57:28 +0000720 // Push three registers. Pushes leftmost register first (to highest address).
721 void Push(Register src1, Register src2, Register src3) {
722 Subu(sp, sp, Operand(3 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100723 sw(src1, MemOperand(sp, 2 * kPointerSize));
724 sw(src2, MemOperand(sp, 1 * kPointerSize));
725 sw(src3, MemOperand(sp, 0 * kPointerSize));
726 }
727
Ben Murdoch257744e2011-11-30 15:57:28 +0000728 // Push four registers. Pushes leftmost register first (to highest address).
729 void Push(Register src1, Register src2, Register src3, Register src4) {
730 Subu(sp, sp, Operand(4 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100731 sw(src1, MemOperand(sp, 3 * kPointerSize));
732 sw(src2, MemOperand(sp, 2 * kPointerSize));
733 sw(src3, MemOperand(sp, 1 * kPointerSize));
734 sw(src4, MemOperand(sp, 0 * kPointerSize));
735 }
736
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000737 // Push five registers. Pushes leftmost register first (to highest address).
738 void Push(Register src1, Register src2, Register src3, Register src4,
739 Register src5) {
740 Subu(sp, sp, Operand(5 * kPointerSize));
741 sw(src1, MemOperand(sp, 4 * kPointerSize));
742 sw(src2, MemOperand(sp, 3 * kPointerSize));
743 sw(src3, MemOperand(sp, 2 * kPointerSize));
744 sw(src4, MemOperand(sp, 1 * kPointerSize));
745 sw(src5, MemOperand(sp, 0 * kPointerSize));
746 }
747
Andrei Popescu31002712010-02-23 13:46:05 +0000748 void Push(Register src, Condition cond, Register tst1, Register tst2) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000749 // Since we don't have conditional execution we use a Branch.
Steve Block44f0eee2011-05-26 01:26:41 +0100750 Branch(3, cond, tst1, Operand(tst2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000751 Subu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000752 sw(src, MemOperand(sp, 0));
753 }
754
755 // Pops multiple values from the stack and load them in the
756 // registers specified in regs. Pop order is the opposite as in MultiPush.
757 void MultiPop(RegList regs);
758 void MultiPopReversed(RegList regs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000759
Ben Murdoch589d6972011-11-30 16:04:58 +0000760 void MultiPopFPU(RegList regs);
761 void MultiPopReversedFPU(RegList regs);
762
Ben Murdoch257744e2011-11-30 15:57:28 +0000763 void pop(Register dst) {
Andrei Popescu31002712010-02-23 13:46:05 +0000764 lw(dst, MemOperand(sp, 0));
765 Addu(sp, sp, Operand(kPointerSize));
766 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000767 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000768
769 // Pop two registers. Pops rightmost register first (from lower address).
770 void Pop(Register src1, Register src2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000771 DCHECK(!src1.is(src2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000772 lw(src2, MemOperand(sp, 0 * kPointerSize));
773 lw(src1, MemOperand(sp, 1 * kPointerSize));
774 Addu(sp, sp, 2 * kPointerSize);
775 }
776
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100777 // Pop three registers. Pops rightmost register first (from lower address).
778 void Pop(Register src1, Register src2, Register src3) {
779 lw(src3, MemOperand(sp, 0 * kPointerSize));
780 lw(src2, MemOperand(sp, 1 * kPointerSize));
781 lw(src1, MemOperand(sp, 2 * kPointerSize));
782 Addu(sp, sp, 3 * kPointerSize);
783 }
784
Steve Block44f0eee2011-05-26 01:26:41 +0100785 void Pop(uint32_t count = 1) {
786 Addu(sp, sp, Operand(count * kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000787 }
788
Ben Murdochda12d292016-06-02 14:46:10 +0100789 // Push a fixed frame, consisting of ra, fp.
790 void PushCommonFrame(Register marker_reg = no_reg);
791
792 // Push a standard frame, consisting of ra, fp, context and JS function.
793 void PushStandardFrame(Register function_reg);
794
795 void PopCommonFrame(Register marker_reg = no_reg);
796
Steve Block44f0eee2011-05-26 01:26:41 +0100797 // Push and pop the registers that can hold pointers, as defined by the
798 // RegList constant kSafepointSavedRegisters.
Ben Murdoch257744e2011-11-30 15:57:28 +0000799 void PushSafepointRegisters();
800 void PopSafepointRegisters();
Ben Murdoch257744e2011-11-30 15:57:28 +0000801 // Store value in register src in the safepoint stack slot for
802 // register dst.
803 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000804 // Load the value of the src register from its safepoint stack slot
805 // into register dst.
806 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Steve Block44f0eee2011-05-26 01:26:41 +0100807
808 // MIPS32 R2 instruction macro.
809 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
810 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
811
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100812 // ---------------------------------------------------------------------------
813 // FPU macros. These do not handle special cases like NaN or +- inf.
814
Steve Block44f0eee2011-05-26 01:26:41 +0100815 // Convert unsigned word to double.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000816 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100817
Ben Murdoch097c5b22016-05-18 11:27:45 +0100818 // Convert single to unsigned word.
819 void Trunc_uw_s(FPURegister fd, FPURegister fs, FPURegister scratch);
820 void Trunc_uw_s(FPURegister fd, Register rs, FPURegister scratch);
821
Steve Block44f0eee2011-05-26 01:26:41 +0100822 // Convert double to unsigned word.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000823 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
824 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100825
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100826 void Trunc_w_d(FPURegister fd, FPURegister fs);
827 void Round_w_d(FPURegister fd, FPURegister fs);
828 void Floor_w_d(FPURegister fd, FPURegister fs);
829 void Ceil_w_d(FPURegister fd, FPURegister fs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000830
831 // FP32 mode: Move the general purpose register into
832 // the high part of the double-register pair.
833 // FP64 mode: Move the general-purpose register into
834 // the higher 32 bits of the 64-bit coprocessor register,
835 // while leaving the low bits unchanged.
836 void Mthc1(Register rt, FPURegister fs);
837
838 // FP32 mode: move the high part of the double-register pair into
839 // general purpose register.
840 // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
841 // general-purpose register.
842 void Mfhc1(Register rt, FPURegister fs);
843
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000844 // Wrapper functions for the different cmp/branch types.
845 inline void BranchF32(Label* target, Label* nan, Condition cc,
846 FPURegister cmp1, FPURegister cmp2,
847 BranchDelaySlot bd = PROTECT) {
848 BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
849 }
850
851 inline void BranchF64(Label* target, Label* nan, Condition cc,
852 FPURegister cmp1, FPURegister cmp2,
853 BranchDelaySlot bd = PROTECT) {
854 BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
855 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100856
857 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000858 inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
859 Condition cc, FPURegister cmp1, FPURegister cmp2) {
860 BranchF64(target, nan, cc, cmp1, cmp2, bd);
861 }
862
863 inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
864 Condition cc, FPURegister cmp1, FPURegister cmp2) {
865 BranchF32(target, nan, cc, cmp1, cmp2, bd);
866 }
867
868 // Alias functions for backward compatibility.
869 inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
870 FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
871 BranchF64(target, nan, cc, cmp1, cmp2, bd);
872 }
873
874 inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
875 Condition cc, FPURegister cmp1, FPURegister cmp2) {
876 BranchF64(bd, target, nan, cc, cmp1, cmp2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000877 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100878
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000879 // Truncates a double using a specific rounding mode, and writes the value
880 // to the result register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100881 // The except_flag will contain any exceptions caused by the instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000882 // If check_inexact is kDontCheckForInexactConversion, then the inexact
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100883 // exception is masked.
884 void EmitFPUTruncate(FPURoundingMode rounding_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000885 Register result,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100886 DoubleRegister double_input,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000887 Register scratch,
888 DoubleRegister double_scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100889 Register except_flag,
890 CheckForInexactConversion check_inexact
891 = kDontCheckForInexactConversion);
892
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000893 // Performs a truncating conversion of a floating point number as used by
894 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
895 // succeeds, otherwise falls through if result is saturated. On return
896 // 'result' either holds answer, or is clobbered on fall through.
897 //
898 // Only public for the test code in test-code-stubs-arm.cc.
899 void TryInlineTruncateDoubleToI(Register result,
900 DoubleRegister input,
901 Label* done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000902
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000903 // Performs a truncating conversion of a floating point number as used by
904 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 // Exits with 'result' holding the answer.
906 void TruncateDoubleToI(Register result, DoubleRegister double_input);
907
908 // Performs a truncating conversion of a heap number as used by
909 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
910 // must be different registers. Exits with 'result' holding the answer.
911 void TruncateHeapNumberToI(Register result, Register object);
912
913 // Converts the smi or heap number in object to an int32 using the rules
914 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
915 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
916 // different registers.
917 void TruncateNumberToI(Register object,
918 Register result,
919 Register heap_number_map,
920 Register scratch,
921 Label* not_int32);
922
923 // Loads the number from object into dst register.
924 // If |object| is neither smi nor heap number, |not_number| is jumped to
925 // with |object| still intact.
926 void LoadNumber(Register object,
927 FPURegister dst,
928 Register heap_number_map,
929 Register scratch,
930 Label* not_number);
931
932 // Loads the number from object into double_dst in the double format.
933 // Control will jump to not_int32 if the value cannot be exactly represented
934 // by a 32-bit integer.
935 // Floating point value in the 32-bit integer range that are not exact integer
936 // won't be loaded.
937 void LoadNumberAsInt32Double(Register object,
938 DoubleRegister double_dst,
939 Register heap_number_map,
940 Register scratch1,
941 Register scratch2,
942 FPURegister double_scratch,
943 Label* not_int32);
944
945 // Loads the number from object into dst as a 32-bit integer.
946 // Control will jump to not_int32 if the object cannot be exactly represented
947 // by a 32-bit integer.
948 // Floating point value in the 32-bit integer range that are not exact integer
949 // won't be converted.
950 void LoadNumberAsInt32(Register object,
951 Register dst,
952 Register heap_number_map,
953 Register scratch1,
954 Register scratch2,
955 FPURegister double_scratch0,
956 FPURegister double_scratch1,
957 Label* not_int32);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000958
Steve Block44f0eee2011-05-26 01:26:41 +0100959 // Enter exit frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000960 // argc - argument count to be dropped by LeaveExitFrame.
961 // save_doubles - saves FPU registers on stack, currently disabled.
962 // stack_space - extra stack space.
963 void EnterExitFrame(bool save_doubles,
964 int stack_space = 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100965
Ben Murdoch257744e2011-11-30 15:57:28 +0000966 // Leave the current exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000967 void LeaveExitFrame(bool save_doubles, Register arg_count,
968 bool restore_context, bool do_return = NO_EMIT_RETURN,
969 bool argument_count_is_length = false);
Steve Block6ded16b2010-05-10 14:33:55 +0100970
Steve Block44f0eee2011-05-26 01:26:41 +0100971 // Get the actual activation frame alignment for target environment.
972 static int ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +0100973
Ben Murdoch257744e2011-11-30 15:57:28 +0000974 // Make sure the stack is aligned. Only emits code in debug mode.
975 void AssertStackIsAligned();
976
Steve Block44f0eee2011-05-26 01:26:41 +0100977 void LoadContext(Register dst, int context_chain_length);
Steve Block6ded16b2010-05-10 14:33:55 +0100978
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000979 // Load the global object from the current context.
980 void LoadGlobalObject(Register dst) {
981 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
982 }
983
984 // Load the global proxy from the current context.
985 void LoadGlobalProxy(Register dst) {
986 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
987 }
988
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100989 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000990 // transitioned_kind from the native context if the map in register
991 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100992 // expected_kind.
993 void LoadTransitionedArrayMapConditional(
994 ElementsKind expected_kind,
995 ElementsKind transitioned_kind,
996 Register map_in_out,
997 Register scratch,
998 Label* no_map_match);
999
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001000 void LoadNativeContextSlot(int index, Register dst);
Steve Block44f0eee2011-05-26 01:26:41 +01001001
1002 // Load the initial map from the global function. The registers
1003 // function and map can be the same, function is then overwritten.
1004 void LoadGlobalFunctionInitialMap(Register function,
1005 Register map,
1006 Register scratch);
1007
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001008 void InitializeRootRegister() {
1009 ExternalReference roots_array_start =
1010 ExternalReference::roots_array_start(isolate());
1011 li(kRootRegister, Operand(roots_array_start));
1012 }
1013
Steve Block44f0eee2011-05-26 01:26:41 +01001014 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001015 // JavaScript invokes.
1016
Ben Murdochda12d292016-06-02 14:46:10 +01001017 // Removes current frame and its arguments from the stack preserving
1018 // the arguments and a return address pushed to the stack for the next call.
1019 // Both |callee_args_count| and |caller_args_count_reg| do not include
1020 // receiver. |callee_args_count| is not modified, |caller_args_count_reg|
1021 // is trashed.
1022 void PrepareForTailCall(const ParameterCount& callee_args_count,
1023 Register caller_args_count_reg, Register scratch0,
1024 Register scratch1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001025
Ben Murdochda12d292016-06-02 14:46:10 +01001026 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001027 void InvokeFunctionCode(Register function, Register new_target,
1028 const ParameterCount& expected,
1029 const ParameterCount& actual, InvokeFlag flag,
1030 const CallWrapper& call_wrapper);
1031
1032 void FloodFunctionIfStepping(Register fun, Register new_target,
1033 const ParameterCount& expected,
1034 const ParameterCount& actual);
Steve Block6ded16b2010-05-10 14:33:55 +01001035
1036 // Invoke the JavaScript function in the given register. Changes the
1037 // current context to the context in the function before invoking.
1038 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001039 Register new_target,
Steve Block6ded16b2010-05-10 14:33:55 +01001040 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +01001041 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001042 const CallWrapper& call_wrapper);
Steve Block44f0eee2011-05-26 01:26:41 +01001043
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001044 void InvokeFunction(Register function,
1045 const ParameterCount& expected,
Steve Block44f0eee2011-05-26 01:26:41 +01001046 const ParameterCount& actual,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001047 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001048 const CallWrapper& call_wrapper);
1049
1050 void InvokeFunction(Handle<JSFunction> function,
1051 const ParameterCount& expected,
1052 const ParameterCount& actual,
1053 InvokeFlag flag,
1054 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001055
Steve Block44f0eee2011-05-26 01:26:41 +01001056 void IsObjectJSStringType(Register object,
1057 Register scratch,
1058 Label* fail);
1059
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001060 void IsObjectNameType(Register object,
1061 Register scratch,
1062 Label* fail);
1063
Steve Block44f0eee2011-05-26 01:26:41 +01001064 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001065 // Debugger Support.
Steve Block6ded16b2010-05-10 14:33:55 +01001066
Steve Block6ded16b2010-05-10 14:33:55 +01001067 void DebugBreak();
Steve Block6ded16b2010-05-10 14:33:55 +01001068
Steve Block44f0eee2011-05-26 01:26:41 +01001069 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001070 // Exception handling.
Andrei Popescu31002712010-02-23 13:46:05 +00001071
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001072 // Push a new stack handler and link into stack handler chain.
1073 void PushStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001074
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001075 // Unlink the stack handler on top of the stack from the stack handler chain.
Andrei Popescu31002712010-02-23 13:46:05 +00001076 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001077 void PopStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001078
Ben Murdoch257744e2011-11-30 15:57:28 +00001079 // Copies a number of bytes from src to dst. All registers are clobbered. On
1080 // exit src and dst will point to the place just after where the last byte was
1081 // read or written and length will be zero.
1082 void CopyBytes(Register src,
1083 Register dst,
1084 Register length,
1085 Register scratch);
1086
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001087 // Initialize fields with filler values. Fields starting at |current_address|
1088 // not including |end_address| are overwritten with the value in |filler|. At
1089 // the end the loop, |current_address| takes the value of |end_address|.
1090 void InitializeFieldsWithFiller(Register current_address,
1091 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001092
Steve Block44f0eee2011-05-26 01:26:41 +01001093 // -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001094 // Support functions.
1095
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001096 // Machine code version of Map::GetConstructor().
1097 // |temp| holds |result|'s map when done, and |temp2| its instance type.
1098 void GetMapConstructor(Register result, Register map, Register temp,
1099 Register temp2);
1100
Steve Block44f0eee2011-05-26 01:26:41 +01001101 // Try to get function prototype of a function and puts the value in
1102 // the result register. Checks that the function really is a
1103 // function and jumps to the miss label if the fast checks fail. The
1104 // function register will be untouched; the other registers may be
1105 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001106 void TryGetFunctionPrototype(Register function, Register result,
1107 Register scratch, Label* miss);
Steve Block44f0eee2011-05-26 01:26:41 +01001108
Steve Block6ded16b2010-05-10 14:33:55 +01001109 void GetObjectType(Register function,
1110 Register map,
1111 Register type_reg);
1112
Ben Murdoch097c5b22016-05-18 11:27:45 +01001113 void GetInstanceType(Register object_map, Register object_instance_type) {
1114 lbu(object_instance_type,
1115 FieldMemOperand(object_map, Map::kInstanceTypeOffset));
1116 }
1117
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001118 // Check if a map for a JSObject indicates that the object has fast elements.
1119 // Jump to the specified label if it does not.
1120 void CheckFastElements(Register map,
1121 Register scratch,
1122 Label* fail);
1123
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001124 // Check if a map for a JSObject indicates that the object can have both smi
1125 // and HeapObject elements. Jump to the specified label if it does not.
1126 void CheckFastObjectElements(Register map,
1127 Register scratch,
1128 Label* fail);
1129
1130 // Check if a map for a JSObject indicates that the object has fast smi only
1131 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001132 void CheckFastSmiElements(Register map,
1133 Register scratch,
1134 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001135
1136 // Check to see if maybe_number can be stored as a double in
1137 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001138 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001139 void StoreNumberToDoubleElements(Register value_reg,
1140 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001141 Register elements_reg,
1142 Register scratch1,
1143 Register scratch2,
1144 Register scratch3,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001145 Label* fail,
1146 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001147
1148 // Compare an object's map with the specified map and its transitioned
1149 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1150 // "branch_to" if the result of the comparison is "cond". If multiple map
1151 // compares are required, the compare sequences branches to early_success.
1152 void CompareMapAndBranch(Register obj,
1153 Register scratch,
1154 Handle<Map> map,
1155 Label* early_success,
1156 Condition cond,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001157 Label* branch_to);
1158
1159 // As above, but the map of the object is already loaded into the register
1160 // which is preserved by the code generated.
1161 void CompareMapAndBranch(Register obj_map,
1162 Handle<Map> map,
1163 Label* early_success,
1164 Condition cond,
1165 Label* branch_to);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001166
1167 // Check if the map of an object is equal to a specified map and branch to
1168 // label if not. Skip the smi check if not required (object is known to be a
1169 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1170 // against maps that are ElementsKind transition maps of the specificed map.
Steve Block44f0eee2011-05-26 01:26:41 +01001171 void CheckMap(Register obj,
1172 Register scratch,
1173 Handle<Map> map,
1174 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001175 SmiCheckType smi_check_type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001176
Andrei Popescu31002712010-02-23 13:46:05 +00001177
Steve Block44f0eee2011-05-26 01:26:41 +01001178 void CheckMap(Register obj,
1179 Register scratch,
1180 Heap::RootListIndex index,
1181 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +00001182 SmiCheckType smi_check_type);
1183
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001184 // Check if the map of an object is equal to a specified weak map and branch
1185 // to a specified target if equal. Skip the smi check if not required
1186 // (object is known to be a heap object)
1187 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1188 Handle<WeakCell> cell, Handle<Code> success,
1189 SmiCheckType smi_check_type);
Steve Block6ded16b2010-05-10 14:33:55 +01001190
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001191 // Get value of the weak cell.
1192 void GetWeakValue(Register value, Handle<WeakCell> cell);
1193
1194 // Load the value of the weak cell in the value register. Branch to the
1195 // given miss label is the weak cell was cleared.
1196 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001197
1198 // Load and check the instance type of an object for being a string.
1199 // Loads the type into the second argument register.
1200 // Returns a condition that will be enabled if the object was a string.
1201 Condition IsObjectStringType(Register obj,
1202 Register type,
1203 Register result) {
1204 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1205 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1206 And(type, type, Operand(kIsNotStringMask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001207 DCHECK_EQ(0u, kStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001208 return eq;
1209 }
1210
1211
Steve Block44f0eee2011-05-26 01:26:41 +01001212 // Picks out an array index from the hash field.
1213 // Register use:
1214 // hash - holds the index's hash. Clobbered.
1215 // index - holds the overwritten index on exit.
1216 void IndexFromHash(Register hash, Register index);
Andrei Popescu31002712010-02-23 13:46:05 +00001217
Ben Murdoch257744e2011-11-30 15:57:28 +00001218 // Get the number of least significant bits from a register.
1219 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1220 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1221
Steve Block44f0eee2011-05-26 01:26:41 +01001222 // Load the value of a number object into a FPU double register. If the
1223 // object is not a number a jump to the label not_number is performed
1224 // and the FPU double register is unchanged.
1225 void ObjectToDoubleFPURegister(
1226 Register object,
1227 FPURegister value,
1228 Register scratch1,
1229 Register scratch2,
1230 Register heap_number_map,
1231 Label* not_number,
1232 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1233
1234 // Load the value of a smi object into a FPU double register. The register
1235 // scratch1 can be the same register as smi in which case smi will hold the
1236 // untagged value afterwards.
1237 void SmiToDoubleFPURegister(Register smi,
1238 FPURegister value,
1239 Register scratch1);
1240
1241 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001242 // Overflow handling functions.
1243 // Usage: first call the appropriate arithmetic function, then call one of the
1244 // jump functions with the overflow_dst register as the second parameter.
1245
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001246 inline void AddBranchOvf(Register dst, Register left, const Operand& right,
1247 Label* overflow_label, Register scratch = at) {
1248 AddBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001249 }
1250
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001251 inline void AddBranchNoOvf(Register dst, Register left, const Operand& right,
1252 Label* no_overflow_label, Register scratch = at) {
1253 AddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001254 }
1255
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001256 void AddBranchOvf(Register dst, Register left, const Operand& right,
1257 Label* overflow_label, Label* no_overflow_label,
1258 Register scratch = at);
1259
1260 void AddBranchOvf(Register dst, Register left, Register right,
1261 Label* overflow_label, Label* no_overflow_label,
1262 Register scratch = at);
1263
1264
1265 inline void SubBranchOvf(Register dst, Register left, const Operand& right,
1266 Label* overflow_label, Register scratch = at) {
1267 SubBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001268 }
1269
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001270 inline void SubBranchNoOvf(Register dst, Register left, const Operand& right,
1271 Label* no_overflow_label, Register scratch = at) {
1272 SubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001273 }
1274
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001275 void SubBranchOvf(Register dst, Register left, const Operand& right,
1276 Label* overflow_label, Label* no_overflow_label,
1277 Register scratch = at);
1278
1279 void SubBranchOvf(Register dst, Register left, Register right,
1280 Label* overflow_label, Label* no_overflow_label,
1281 Register scratch = at);
1282
Ben Murdoch257744e2011-11-30 15:57:28 +00001283 // -------------------------------------------------------------------------
1284 // Runtime calls.
Andrei Popescu31002712010-02-23 13:46:05 +00001285
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001286 // See comments at the beginning of CEntryStub::Generate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001287 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
Ben Murdoch85b71792012-04-11 18:30:58 +01001288
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001289 inline void PrepareCEntryFunction(const ExternalReference& ref) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001290 li(a1, Operand(ref));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001291 }
1292
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001293#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1294const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1295
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001296 // Call a code stub.
1297 void CallStub(CodeStub* stub,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001298 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1299 COND_ARGS);
Steve Block44f0eee2011-05-26 01:26:41 +01001300
1301 // Tail call a code stub (jump).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001302 void TailCallStub(CodeStub* stub, COND_ARGS);
1303
1304#undef COND_ARGS
Steve Block44f0eee2011-05-26 01:26:41 +01001305
Andrei Popescu31002712010-02-23 13:46:05 +00001306 void CallJSExitStub(CodeStub* stub);
1307
Andrei Popescu31002712010-02-23 13:46:05 +00001308 // Call a runtime routine.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001309 void CallRuntime(const Runtime::Function* f, int num_arguments,
1310 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1311 BranchDelaySlot bd = PROTECT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001312 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1313 const Runtime::Function* function = Runtime::FunctionForId(id);
1314 CallRuntime(function, function->nargs, kSaveFPRegs);
1315 }
Andrei Popescu31002712010-02-23 13:46:05 +00001316
1317 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001318 void CallRuntime(Runtime::FunctionId fid,
1319 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1320 BranchDelaySlot bd = PROTECT) {
1321 const Runtime::Function* function = Runtime::FunctionForId(fid);
1322 CallRuntime(function, function->nargs, save_doubles, bd);
1323 }
1324
1325 // Convenience function: Same as above, but takes the fid instead.
1326 void CallRuntime(Runtime::FunctionId id, int num_arguments,
1327 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1328 BranchDelaySlot bd = PROTECT) {
1329 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001330 }
Andrei Popescu31002712010-02-23 13:46:05 +00001331
Steve Block44f0eee2011-05-26 01:26:41 +01001332 // Convenience function: call an external reference.
1333 void CallExternalReference(const ExternalReference& ext,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001334 int num_arguments,
1335 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001336
Steve Block6ded16b2010-05-10 14:33:55 +01001337
1338 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001339 void TailCallRuntime(Runtime::FunctionId fid);
Andrei Popescu31002712010-02-23 13:46:05 +00001340
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001341 int CalculateStackPassedWords(int num_reg_arguments,
1342 int num_double_arguments);
1343
Steve Block44f0eee2011-05-26 01:26:41 +01001344 // Before calling a C-function from generated code, align arguments on stack
1345 // and add space for the four mips argument slots.
1346 // After aligning the frame, non-register arguments must be stored on the
1347 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1348 // The argument count assumes all arguments are word sized.
1349 // Some compilers/platforms require the stack to be aligned when calling
1350 // C++ code.
1351 // Needs a scratch register to do some arithmetic. This register will be
1352 // trashed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001353 void PrepareCallCFunction(int num_reg_arguments,
1354 int num_double_registers,
1355 Register scratch);
1356 void PrepareCallCFunction(int num_reg_arguments,
1357 Register scratch);
Steve Block44f0eee2011-05-26 01:26:41 +01001358
1359 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1360 // Arguments 5..n are stored to stack using following:
1361 // sw(t0, CFunctionArgumentOperand(5));
1362
1363 // Calls a C function and cleans up the space for arguments allocated
1364 // by PrepareCallCFunction. The called function is not allowed to trigger a
1365 // garbage collection, since that might move the code and invalidate the
1366 // return address (unless this is somehow accounted for by the called
1367 // function).
1368 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001369 void CallCFunction(Register function, int num_arguments);
1370 void CallCFunction(ExternalReference function,
1371 int num_reg_arguments,
1372 int num_double_arguments);
1373 void CallCFunction(Register function,
1374 int num_reg_arguments,
1375 int num_double_arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001376 void MovFromFloatResult(DoubleRegister dst);
1377 void MovFromFloatParameter(DoubleRegister dst);
Ben Murdoch257744e2011-11-30 15:57:28 +00001378
1379 // There are two ways of passing double arguments on MIPS, depending on
1380 // whether soft or hard floating point ABI is used. These functions
1381 // abstract parameter passing for the three different ways we call
1382 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001383 void MovToFloatParameter(DoubleRegister src);
1384 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1385 void MovToFloatResult(DoubleRegister src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001386
Andrei Popescu31002712010-02-23 13:46:05 +00001387 // Jump to the builtin routine.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001388 void JumpToExternalReference(const ExternalReference& builtin,
1389 BranchDelaySlot bd = PROTECT);
Andrei Popescu31002712010-02-23 13:46:05 +00001390
Andrei Popescu31002712010-02-23 13:46:05 +00001391 struct Unresolved {
1392 int pc;
Ben Murdoch257744e2011-11-30 15:57:28 +00001393 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
Andrei Popescu31002712010-02-23 13:46:05 +00001394 const char* name;
1395 };
Andrei Popescu31002712010-02-23 13:46:05 +00001396
Ben Murdoch257744e2011-11-30 15:57:28 +00001397 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001398 DCHECK(!code_object_.is_null());
Ben Murdoch257744e2011-11-30 15:57:28 +00001399 return code_object_;
1400 }
Andrei Popescu31002712010-02-23 13:46:05 +00001401
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001402 // Emit code for a truncating division by a constant. The dividend register is
1403 // unchanged and at gets clobbered. Dividend and result must be different.
1404 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1405
Steve Block44f0eee2011-05-26 01:26:41 +01001406 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001407 // StatsCounter support.
Andrei Popescu31002712010-02-23 13:46:05 +00001408
1409 void SetCounter(StatsCounter* counter, int value,
1410 Register scratch1, Register scratch2);
1411 void IncrementCounter(StatsCounter* counter, int value,
1412 Register scratch1, Register scratch2);
1413 void DecrementCounter(StatsCounter* counter, int value,
1414 Register scratch1, Register scratch2);
1415
1416
Steve Block44f0eee2011-05-26 01:26:41 +01001417 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001418 // Debugging.
Andrei Popescu31002712010-02-23 13:46:05 +00001419
1420 // Calls Abort(msg) if the condition cc is not satisfied.
1421 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001422 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
Steve Block44f0eee2011-05-26 01:26:41 +01001423 void AssertFastElements(Register elements);
Andrei Popescu31002712010-02-23 13:46:05 +00001424
1425 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001426 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
Andrei Popescu31002712010-02-23 13:46:05 +00001427
1428 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001429 void Abort(BailoutReason msg);
Andrei Popescu31002712010-02-23 13:46:05 +00001430
1431 // Verify restrictions about code generated in stubs.
1432 void set_generating_stub(bool value) { generating_stub_ = value; }
1433 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001434 void set_has_frame(bool value) { has_frame_ = value; }
1435 bool has_frame() { return has_frame_; }
1436 inline bool AllowThisStubCall(CodeStub* stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001437
Steve Block44f0eee2011-05-26 01:26:41 +01001438 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001439 // Number utilities.
Steve Block6ded16b2010-05-10 14:33:55 +01001440
Steve Block44f0eee2011-05-26 01:26:41 +01001441 // Check whether the value of reg is a power of two and not zero. If not
1442 // control continues at the label not_power_of_two. If reg is a power of two
1443 // the register scratch contains the value of (reg - 1) when control falls
1444 // through.
1445 void JumpIfNotPowerOfTwoOrZero(Register reg,
1446 Register scratch,
1447 Label* not_power_of_two_or_zero);
1448
1449 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001450 // Smi utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001451
Steve Block44f0eee2011-05-26 01:26:41 +01001452 void SmiTag(Register reg) {
1453 Addu(reg, reg, reg);
1454 }
1455
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001456 void SmiTag(Register dst, Register src) { Addu(dst, src, src); }
1457
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001458 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1459 void SmiTagCheckOverflow(Register reg, Register overflow);
1460 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1461
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001462 void BranchOnOverflow(Label* label, Register overflow_check,
1463 BranchDelaySlot bd = PROTECT) {
1464 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
Steve Block44f0eee2011-05-26 01:26:41 +01001465 }
1466
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001467 void BranchOnNoOverflow(Label* label, Register overflow_check,
1468 BranchDelaySlot bd = PROTECT) {
1469 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1470 }
1471
1472
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001473 // Try to convert int32 to smi. If the value is to large, preserve
1474 // the original value and jump to not_a_smi. Destroys scratch and
1475 // sets flags.
1476 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1477 TrySmiTag(reg, reg, scratch, not_a_smi);
1478 }
1479 void TrySmiTag(Register dst,
1480 Register src,
1481 Register scratch,
1482 Label* not_a_smi) {
1483 SmiTagCheckOverflow(at, src, scratch);
1484 BranchOnOverflow(not_a_smi, scratch);
1485 mov(dst, at);
1486 }
1487
Steve Block44f0eee2011-05-26 01:26:41 +01001488 void SmiUntag(Register reg) {
1489 sra(reg, reg, kSmiTagSize);
1490 }
1491
1492 void SmiUntag(Register dst, Register src) {
1493 sra(dst, src, kSmiTagSize);
1494 }
1495
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001496 // Test if the register contains a smi.
1497 inline void SmiTst(Register value, Register scratch) {
1498 And(scratch, value, Operand(kSmiTagMask));
1499 }
1500 inline void NonNegativeSmiTst(Register value, Register scratch) {
1501 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1502 }
1503
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001504 // Untag the source value into destination and jump if source is a smi.
1505 // Souce and destination can be the same register.
1506 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1507
1508 // Untag the source value into destination and jump if source is not a smi.
1509 // Souce and destination can be the same register.
1510 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1511
Steve Block44f0eee2011-05-26 01:26:41 +01001512 // Jump the register contains a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001513 void JumpIfSmi(Register value,
1514 Label* smi_label,
1515 Register scratch = at,
1516 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001517
1518 // Jump if the register contains a non-smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001519 void JumpIfNotSmi(Register value,
1520 Label* not_smi_label,
1521 Register scratch = at,
1522 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001523
1524 // Jump if either of the registers contain a non-smi.
1525 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1526 // Jump if either of the registers contain a smi.
1527 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1528
Ben Murdochda12d292016-06-02 14:46:10 +01001529 // Abort execution if argument is a number, enabled via --debug-code.
1530 void AssertNotNumber(Register object);
1531
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001532 // Abort execution if argument is a smi, enabled via --debug-code.
1533 void AssertNotSmi(Register object);
1534 void AssertSmi(Register object);
Steve Block44f0eee2011-05-26 01:26:41 +01001535
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001536 // Abort execution if argument is not a string, enabled via --debug-code.
1537 void AssertString(Register object);
Ben Murdoch257744e2011-11-30 15:57:28 +00001538
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001539 // Abort execution if argument is not a name, enabled via --debug-code.
1540 void AssertName(Register object);
1541
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001542 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1543 void AssertFunction(Register object);
1544
1545 // Abort execution if argument is not a JSBoundFunction,
1546 // enabled via --debug-code.
1547 void AssertBoundFunction(Register object);
1548
Ben Murdoch097c5b22016-05-18 11:27:45 +01001549 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1550 void AssertReceiver(Register object);
1551
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001552 // Abort execution if argument is not undefined or an AllocationSite, enabled
1553 // via --debug-code.
1554 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1555
1556 // Abort execution if reg is not the root value with the given index,
1557 // enabled via --debug-code.
1558 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block44f0eee2011-05-26 01:26:41 +01001559
1560 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001561 // HeapNumber utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001562
1563 void JumpIfNotHeapNumber(Register object,
1564 Register heap_number_map,
1565 Register scratch,
1566 Label* on_not_heap_number);
1567
1568 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001569 // String utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001570
1571 // Checks if both instance types are sequential ASCII strings and jumps to
1572 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001573 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1574 Register first_object_instance_type, Register second_object_instance_type,
1575 Register scratch1, Register scratch2, Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001576
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001577 // Check if instance type is sequential one-byte string and jump to label if
Steve Block44f0eee2011-05-26 01:26:41 +01001578 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001579 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1580 Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001581
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001582 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
Steve Block44f0eee2011-05-26 01:26:41 +01001583
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001584 void EmitSeqStringSetCharCheck(Register string,
1585 Register index,
1586 Register value,
1587 Register scratch,
1588 uint32_t encoding_mask);
1589
1590 // Checks if both objects are sequential one-byte strings and jumps to label
1591 // if either is not. Assumes that neither object is a smi.
1592 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1593 Register second,
1594 Register scratch1,
1595 Register scratch2,
1596 Label* failure);
1597
1598 // Checks if both objects are sequential one-byte strings and jumps to label
1599 // if either is not.
1600 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1601 Register scratch1,
1602 Register scratch2,
1603 Label* not_flat_one_byte_strings);
Steve Block44f0eee2011-05-26 01:26:41 +01001604
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001605 void ClampUint8(Register output_reg, Register input_reg);
1606
1607 void ClampDoubleToUint8(Register result_reg,
1608 DoubleRegister input_reg,
1609 DoubleRegister temp_double_reg);
1610
1611
Ben Murdoch257744e2011-11-30 15:57:28 +00001612 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001613 void EnumLength(Register dst, Register map);
1614 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001615 void LoadAccessor(Register dst, Register holder, int accessor_index,
1616 AccessorComponent accessor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001617
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001618 template<typename Field>
1619 void DecodeField(Register dst, Register src) {
1620 Ext(dst, src, Field::kShift, Field::kSize);
1621 }
1622
1623 template<typename Field>
1624 void DecodeField(Register reg) {
1625 DecodeField<Field>(reg, reg);
1626 }
1627
1628 template<typename Field>
1629 void DecodeFieldToSmi(Register dst, Register src) {
1630 static const int shift = Field::kShift;
1631 static const int mask = Field::kMask >> shift << kSmiTagSize;
1632 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1633 STATIC_ASSERT(kSmiTag == 0);
1634 if (shift < kSmiTagSize) {
1635 sll(dst, src, kSmiTagSize - shift);
1636 And(dst, dst, Operand(mask));
1637 } else if (shift > kSmiTagSize) {
1638 srl(dst, src, shift - kSmiTagSize);
1639 And(dst, dst, Operand(mask));
1640 } else {
1641 And(dst, src, Operand(mask));
1642 }
1643 }
1644
1645 template<typename Field>
1646 void DecodeFieldToSmi(Register reg) {
1647 DecodeField<Field>(reg, reg);
1648 }
1649
1650 // Generates function and stub prologue code.
Ben Murdochda12d292016-06-02 14:46:10 +01001651 void StubPrologue(StackFrame::Type type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001652 void Prologue(bool code_pre_aging);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001653
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001654 // Load the type feedback vector from a JavaScript frame.
1655 void EmitLoadTypeFeedbackVector(Register vector);
1656
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001657 // Activation support.
1658 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001659 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001660 void LeaveFrame(StackFrame::Type type);
1661
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001662 // Expects object in a0 and returns map with validated enum cache
1663 // in a0. Assumes that any other register can be used as a scratch.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001664 void CheckEnumCache(Label* call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001665
Ben Murdochda12d292016-06-02 14:46:10 +01001666 // AllocationMemento support. Arrays may have an associated AllocationMemento
1667 // object that can be checked for in order to pretransition to another type.
1668 // On entry, receiver_reg should point to the array object. scratch_reg gets
1669 // clobbered. If no info is present jump to no_memento_found, otherwise fall
1670 // through.
1671 void TestJSArrayForAllocationMemento(Register receiver_reg,
1672 Register scratch_reg,
1673 Label* no_memento_found);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001674
1675 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1676 Register scratch_reg,
1677 Label* memento_found) {
1678 Label no_memento_found;
1679 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
Ben Murdochda12d292016-06-02 14:46:10 +01001680 &no_memento_found);
1681 Branch(memento_found);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001682 bind(&no_memento_found);
1683 }
1684
1685 // Jumps to found label if a prototype map has dictionary elements.
1686 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1687 Register scratch1, Label* found);
1688
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001689 bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
1690
Steve Block44f0eee2011-05-26 01:26:41 +01001691 private:
1692 void CallCFunctionHelper(Register function,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001693 int num_reg_arguments,
1694 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001695
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001696 inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch);
1697 inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits);
1698 void BranchShortHelperR6(int32_t offset, Label* L);
1699 void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot);
1700 bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond,
1701 Register rs, const Operand& rt);
1702 bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs,
1703 const Operand& rt, BranchDelaySlot bdslot);
1704 bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs,
1705 const Operand& rt, BranchDelaySlot bdslot);
1706
1707 void BranchAndLinkShortHelperR6(int32_t offset, Label* L);
1708 void BranchAndLinkShortHelper(int16_t offset, Label* L,
1709 BranchDelaySlot bdslot);
1710 void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001711 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001712 bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond,
1713 Register rs, const Operand& rt);
1714 bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond,
1715 Register rs, const Operand& rt,
1716 BranchDelaySlot bdslot);
1717 bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond,
1718 Register rs, const Operand& rt,
1719 BranchDelaySlot bdslot);
1720 void BranchLong(Label* L, BranchDelaySlot bdslot);
1721 void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot);
1722
1723 // Common implementation of BranchF functions for the different formats.
1724 void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1725 Condition cc, FPURegister cmp1, FPURegister cmp2,
1726 BranchDelaySlot bd = PROTECT);
1727
1728 void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1729 FPURegister cmp1, FPURegister cmp2,
1730 BranchDelaySlot bd = PROTECT);
Steve Block6ded16b2010-05-10 14:33:55 +01001731
1732 // Helper functions for generating invokes.
1733 void InvokePrologue(const ParameterCount& expected,
1734 const ParameterCount& actual,
Steve Block6ded16b2010-05-10 14:33:55 +01001735 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001736 bool* definitely_mismatches,
Steve Block44f0eee2011-05-26 01:26:41 +01001737 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001738 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001739
Steve Block44f0eee2011-05-26 01:26:41 +01001740 void InitializeNewString(Register string,
1741 Register length,
1742 Heap::RootListIndex map_index,
1743 Register scratch1,
1744 Register scratch2);
1745
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001746 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001747 void InNewSpace(Register object, Register scratch,
1748 Condition cond, // ne for new space, eq otherwise.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001749 Label* branch);
1750
1751 // Helper for finding the mark bits for an address. Afterwards, the
1752 // bitmap register points at the word with the mark bits and the mask
1753 // the position of the first bit. Leaves addr_reg unchanged.
1754 inline void GetMarkBits(Register addr_reg,
1755 Register bitmap_reg,
1756 Register mask_reg);
1757
Ben Murdoch257744e2011-11-30 15:57:28 +00001758 // Compute memory operands for safepoint stack slots.
1759 static int SafepointRegisterStackIndex(int reg_code);
1760 MemOperand SafepointRegisterSlot(Register reg);
1761 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
Steve Block44f0eee2011-05-26 01:26:41 +01001762
1763 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001764 bool has_frame_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001765 bool has_double_zero_reg_set_;
Steve Block44f0eee2011-05-26 01:26:41 +01001766 // This handle will be patched with the code object on installation.
1767 Handle<Object> code_object_;
Ben Murdoch257744e2011-11-30 15:57:28 +00001768
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001769 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoch257744e2011-11-30 15:57:28 +00001770 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001771 friend class StandardFrame;
Steve Block44f0eee2011-05-26 01:26:41 +01001772};
1773
1774
Steve Block44f0eee2011-05-26 01:26:41 +01001775// The code patcher is used to patch (typically) small parts of code e.g. for
1776// debugging and other types of instrumentation. When using the code patcher
1777// the exact number of bytes specified must be emitted. It is not legal to emit
1778// relocation information. If any of these constraints are violated it causes
1779// an assertion to fail.
1780class CodePatcher {
1781 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001782 enum FlushICache {
1783 FLUSH,
1784 DONT_FLUSH
1785 };
1786
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001787 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001788 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001789 ~CodePatcher();
Steve Block44f0eee2011-05-26 01:26:41 +01001790
1791 // Macro assembler to emit code.
1792 MacroAssembler* masm() { return &masm_; }
1793
1794 // Emit an instruction directly.
Ben Murdoch257744e2011-11-30 15:57:28 +00001795 void Emit(Instr instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001796
1797 // Emit an address directly.
1798 void Emit(Address addr);
1799
Ben Murdoch257744e2011-11-30 15:57:28 +00001800 // Change the condition part of an instruction leaving the rest of the current
1801 // instruction unchanged.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001802 void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode);
Ben Murdoch257744e2011-11-30 15:57:28 +00001803
Steve Block44f0eee2011-05-26 01:26:41 +01001804 private:
1805 byte* address_; // The address of the code being patched.
Steve Block44f0eee2011-05-26 01:26:41 +01001806 int size_; // Number of bytes of the expected patch size.
1807 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001808 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Block44f0eee2011-05-26 01:26:41 +01001809};
Andrei Popescu31002712010-02-23 13:46:05 +00001810
Ben Murdoch097c5b22016-05-18 11:27:45 +01001811template <typename Func>
1812void MacroAssembler::GenerateSwitchTable(Register index, size_t case_count,
1813 Func GetLabelFunction) {
1814 if (kArchVariant >= kMips32r6) {
1815 BlockTrampolinePoolFor(case_count + 5);
1816 addiupc(at, 5);
Ben Murdochda12d292016-06-02 14:46:10 +01001817 Lsa(at, at, index, kPointerSizeLog2);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001818 lw(at, MemOperand(at));
1819 } else {
1820 Label here;
Ben Murdochda12d292016-06-02 14:46:10 +01001821 BlockTrampolinePoolFor(case_count + 10);
1822 push(ra);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001823 bal(&here);
1824 sll(at, index, kPointerSizeLog2); // Branch delay slot.
1825 bind(&here);
1826 addu(at, at, ra);
Ben Murdochda12d292016-06-02 14:46:10 +01001827 pop(ra);
1828 lw(at, MemOperand(at, 6 * v8::internal::Assembler::kInstrSize));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001829 }
1830 jr(at);
1831 nop(); // Branch delay slot nop.
1832 for (size_t index = 0; index < case_count; ++index) {
1833 dd(GetLabelFunction(index));
1834 }
1835}
Andrei Popescu31002712010-02-23 13:46:05 +00001836
1837#ifdef GENERATED_CODE_COVERAGE
1838#define CODE_COVERAGE_STRINGIFY(x) #x
1839#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1840#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1841#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1842#else
1843#define ACCESS_MASM(masm) masm->
1844#endif
1845
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001846} // namespace internal
1847} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +00001848
1849#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_