blob: 05a8fec6442446f026ea08580e6f9d84abbba445 [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 Murdoch4a90d5f2016-03-22 12:00:34 +0000240 void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); }
241
Ben Murdoch257744e2011-11-30 15:57:28 +0000242 inline void Move(Register dst, Register src) {
243 if (!dst.is(src)) {
244 mov(dst, src);
245 }
246 }
247
248 inline void Move(FPURegister dst, FPURegister src) {
249 if (!dst.is(src)) {
250 mov_d(dst, src);
251 }
252 }
253
254 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
255 mfc1(dst_low, src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 Mfhc1(dst_high, src);
257 }
258
259 inline void FmoveHigh(Register dst_high, FPURegister src) {
260 Mfhc1(dst_high, src);
261 }
262
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000263 inline void FmoveHigh(FPURegister dst, Register src_high) {
264 Mthc1(src_high, dst);
265 }
266
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267 inline void FmoveLow(Register dst_low, FPURegister src) {
268 mfc1(dst_low, src);
Ben Murdoch257744e2011-11-30 15:57:28 +0000269 }
270
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271 void FmoveLow(FPURegister dst, Register src_low);
272
Ben Murdoch257744e2011-11-30 15:57:28 +0000273 inline void Move(FPURegister dst, Register src_low, Register src_high) {
274 mtc1(src_low, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275 Mthc1(src_high, dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000276 }
Andrei Popescu31002712010-02-23 13:46:05 +0000277
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400278 void Move(FPURegister dst, float imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100279 void Move(FPURegister dst, double imm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400280
281 // Conditional move.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100282 void Movz(Register rd, Register rs, Register rt);
283 void Movn(Register rd, Register rs, Register rt);
284 void Movt(Register rd, Register rs, uint16_t cc = 0);
285 void Movf(Register rd, Register rs, uint16_t cc = 0);
286
287 void Clz(Register rd, Register rs);
288
Andrei Popescu31002712010-02-23 13:46:05 +0000289 // Jump unconditionally to given label.
290 // We NEED a nop in the branch delay slot, as it used by v8, for example in
291 // CodeGenerator::ProcessDeferred().
Steve Block6ded16b2010-05-10 14:33:55 +0100292 // Currently the branch delay slot is filled by the MacroAssembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000293 // Use rather b(Label) for code generation.
294 void jmp(Label* L) {
Steve Block44f0eee2011-05-26 01:26:41 +0100295 Branch(L);
Andrei Popescu31002712010-02-23 13:46:05 +0000296 }
297
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298 void Load(Register dst, const MemOperand& src, Representation r);
299 void Store(Register src, const MemOperand& dst, Representation r);
300
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000301 void PushRoot(Heap::RootListIndex index) {
302 LoadRoot(at, index);
303 Push(at);
304 }
305
306 // Compare the object in a register to a value and jump if they are equal.
307 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
308 LoadRoot(at, index);
309 Branch(if_equal, eq, with, Operand(at));
310 }
311
312 // Compare the object in a register to a value and jump if they are not equal.
313 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
314 Label* if_not_equal) {
315 LoadRoot(at, index);
316 Branch(if_not_equal, ne, with, Operand(at));
317 }
318
Andrei Popescu31002712010-02-23 13:46:05 +0000319 // Load an object from the root table.
320 void LoadRoot(Register destination,
321 Heap::RootListIndex index);
322 void LoadRoot(Register destination,
323 Heap::RootListIndex index,
324 Condition cond, Register src1, const Operand& src2);
325
Steve Block44f0eee2011-05-26 01:26:41 +0100326 // Store an object to the root table.
327 void StoreRoot(Register source,
328 Heap::RootListIndex index);
329 void StoreRoot(Register source,
330 Heap::RootListIndex index,
331 Condition cond, Register src1, const Operand& src2);
332
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100333 // ---------------------------------------------------------------------------
334 // GC Support
335
336 void IncrementalMarkingRecordWriteHelper(Register object,
337 Register value,
338 Register address);
339
340 enum RememberedSetFinalAction {
341 kReturnAtEnd,
342 kFallThroughAtEnd
343 };
Steve Block44f0eee2011-05-26 01:26:41 +0100344
345
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100346 // Record in the remembered set the fact that we have a pointer to new space
347 // at the address pointed to by the addr register. Only works if addr is not
348 // in new space.
349 void RememberedSetHelper(Register object, // Used for debug code.
350 Register addr,
351 Register scratch,
352 SaveFPRegsMode save_fp,
353 RememberedSetFinalAction and_then);
Steve Block44f0eee2011-05-26 01:26:41 +0100354
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100355 void CheckPageFlag(Register object,
356 Register scratch,
357 int mask,
358 Condition cc,
359 Label* condition_met);
360
361 // Check if object is in new space. Jumps if the object is not in new space.
362 // The register scratch can be object itself, but it will be clobbered.
363 void JumpIfNotInNewSpace(Register object,
364 Register scratch,
365 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100366 InNewSpace(object, scratch, eq, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100367 }
368
369 // Check if object is in new space. Jumps if the object is in new space.
370 // The register scratch can be object itself, but scratch will be clobbered.
371 void JumpIfInNewSpace(Register object,
372 Register scratch,
373 Label* branch) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100374 InNewSpace(object, scratch, ne, branch);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100375 }
376
377 // Check if an object has a given incremental marking color.
378 void HasColor(Register object,
379 Register scratch0,
380 Register scratch1,
381 Label* has_color,
382 int first_bit,
383 int second_bit);
384
385 void JumpIfBlack(Register object,
Steve Block44f0eee2011-05-26 01:26:41 +0100386 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100387 Register scratch1,
388 Label* on_black);
Steve Block44f0eee2011-05-26 01:26:41 +0100389
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000390 // Checks the color of an object. If the object is white we jump to the
391 // incremental marker.
392 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
393 Register scratch3, Label* value_is_white);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100394
395 // Notify the garbage collector that we wrote a pointer into an object.
396 // |object| is the object being stored into, |value| is the object being
397 // stored. value and scratch registers are clobbered by the operation.
398 // The offset is the offset from the start of the object, not the offset from
399 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
400 void RecordWriteField(
401 Register object,
402 int offset,
403 Register value,
404 Register scratch,
405 RAStatus ra_status,
406 SaveFPRegsMode save_fp,
407 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000408 SmiCheck smi_check = INLINE_SMI_CHECK,
409 PointersToHereCheck pointers_to_here_check_for_value =
410 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100411
412 // As above, but the offset has the tag presubtracted. For use with
413 // MemOperand(reg, off).
414 inline void RecordWriteContextSlot(
415 Register context,
416 int offset,
417 Register value,
418 Register scratch,
419 RAStatus ra_status,
420 SaveFPRegsMode save_fp,
421 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000422 SmiCheck smi_check = INLINE_SMI_CHECK,
423 PointersToHereCheck pointers_to_here_check_for_value =
424 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100425 RecordWriteField(context,
426 offset + kHeapObjectTag,
427 value,
428 scratch,
429 ra_status,
430 save_fp,
431 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000432 smi_check,
433 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100434 }
435
Ben Murdoch097c5b22016-05-18 11:27:45 +0100436 // Notify the garbage collector that we wrote a code entry into a
437 // JSFunction. Only scratch is clobbered by the operation.
438 void RecordWriteCodeEntryField(Register js_function, Register code_entry,
439 Register scratch);
440
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000441 void RecordWriteForMap(
442 Register object,
443 Register map,
444 Register dst,
445 RAStatus ra_status,
446 SaveFPRegsMode save_fp);
447
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100448 // For a given |object| notify the garbage collector that the slot |address|
449 // has been written. |value| is the object being stored. The value and
450 // address registers are clobbered by the operation.
451 void RecordWrite(
452 Register object,
453 Register address,
454 Register value,
455 RAStatus ra_status,
456 SaveFPRegsMode save_fp,
457 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000458 SmiCheck smi_check = INLINE_SMI_CHECK,
459 PointersToHereCheck pointers_to_here_check_for_value =
460 kPointersToHereMaybeInteresting);
Steve Block44f0eee2011-05-26 01:26:41 +0100461
462
463 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000464 // Inline caching support.
Steve Block44f0eee2011-05-26 01:26:41 +0100465
466 // Generate code for checking access rights - used for security checks
467 // on access to global objects across environments. The holder register
468 // is left untouched, whereas both scratch registers are clobbered.
469 void CheckAccessGlobalProxy(Register holder_reg,
470 Register scratch,
471 Label* miss);
472
Ben Murdochc7cc0282012-03-05 14:35:55 +0000473 void GetNumberHash(Register reg0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000474
475 void LoadFromNumberDictionary(Label* miss,
476 Register elements,
477 Register key,
478 Register result,
479 Register reg0,
480 Register reg1,
481 Register reg2);
482
483
Steve Block44f0eee2011-05-26 01:26:41 +0100484 inline void MarkCode(NopMarkerTypes type) {
485 nop(type);
Steve Block6ded16b2010-05-10 14:33:55 +0100486 }
487
Steve Block44f0eee2011-05-26 01:26:41 +0100488 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100489 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
Steve Block44f0eee2011-05-26 01:26:41 +0100490 // nop(type)). These instructions are generated to mark special location in
491 // the code, like some special IC code.
492 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000493 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Steve Block44f0eee2011-05-26 01:26:41 +0100494 return IsNop(instr, type);
495 }
Andrei Popescu31002712010-02-23 13:46:05 +0000496
497
Steve Block44f0eee2011-05-26 01:26:41 +0100498 static inline int GetCodeMarker(Instr instr) {
499 uint32_t opcode = ((instr & kOpcodeMask));
500 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
501 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
502 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
503
504 // Return <n> if we have a sll zero_reg, zero_reg, n
505 // else return -1.
506 bool sllzz = (opcode == SLL &&
507 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
508 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
509 int type =
510 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000511 DCHECK((type == -1) ||
Steve Block44f0eee2011-05-26 01:26:41 +0100512 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
513 return type;
514 }
515
516
517
518 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000519 // Allocation support.
Steve Block44f0eee2011-05-26 01:26:41 +0100520
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000521 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000522 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
523 // is passed. If the space is exhausted control continues at the gc_required
524 // label. The allocated object is returned in result. If the flag
525 // tag_allocated_object is true the result is tagged as as a heap object.
526 // All registers are clobbered also when control continues at the gc_required
527 // label.
528 void Allocate(int object_size,
529 Register result,
530 Register scratch1,
531 Register scratch2,
532 Label* gc_required,
533 AllocationFlags flags);
534
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000535 void Allocate(Register object_size, Register result, Register result_new,
536 Register scratch, Label* gc_required, AllocationFlags flags);
Steve Block44f0eee2011-05-26 01:26:41 +0100537
538 void AllocateTwoByteString(Register result,
539 Register length,
540 Register scratch1,
541 Register scratch2,
542 Register scratch3,
543 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 void AllocateOneByteString(Register result, Register length,
545 Register scratch1, Register scratch2,
546 Register scratch3, Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100547 void AllocateTwoByteConsString(Register result,
548 Register length,
549 Register scratch1,
550 Register scratch2,
551 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000552 void AllocateOneByteConsString(Register result, Register length,
553 Register scratch1, Register scratch2,
554 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000555 void AllocateTwoByteSlicedString(Register result,
556 Register length,
557 Register scratch1,
558 Register scratch2,
559 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000560 void AllocateOneByteSlicedString(Register result, Register length,
561 Register scratch1, Register scratch2,
562 Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100563
564 // Allocates a heap number or jumps to the gc_required label if the young
565 // space is full and a scavenge is needed. All registers are clobbered also
566 // when control continues at the gc_required label.
567 void AllocateHeapNumber(Register result,
568 Register scratch1,
569 Register scratch2,
570 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000571 Label* gc_required,
572 TaggingMode tagging_mode = TAG_RESULT,
573 MutableMode mode = IMMUTABLE);
Steve Block44f0eee2011-05-26 01:26:41 +0100574 void AllocateHeapNumberWithValue(Register result,
575 FPURegister value,
576 Register scratch1,
577 Register scratch2,
578 Label* gc_required);
579
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000580 // Allocate and initialize a JSValue wrapper with the specified {constructor}
581 // and {value}.
582 void AllocateJSValue(Register result, Register constructor, Register value,
583 Register scratch1, Register scratch2,
584 Label* gc_required);
585
Andrei Popescu31002712010-02-23 13:46:05 +0000586 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000587 // Instruction macros.
Andrei Popescu31002712010-02-23 13:46:05 +0000588
Steve Block44f0eee2011-05-26 01:26:41 +0100589#define DEFINE_INSTRUCTION(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000590 void instr(Register rd, Register rs, const Operand& rt); \
591 void instr(Register rd, Register rs, Register rt) { \
592 instr(rd, rs, Operand(rt)); \
593 } \
594 void instr(Register rs, Register rt, int32_t j) { \
595 instr(rs, rt, Operand(j)); \
596 }
597
Steve Block44f0eee2011-05-26 01:26:41 +0100598#define DEFINE_INSTRUCTION2(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000599 void instr(Register rs, const Operand& rt); \
600 void instr(Register rs, Register rt) { \
601 instr(rs, Operand(rt)); \
602 } \
603 void instr(Register rs, int32_t j) { \
604 instr(rs, Operand(j)); \
605 }
606
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000607#define DEFINE_INSTRUCTION3(instr) \
608 void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \
609 void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \
610 instr(rd_hi, rd_lo, rs, Operand(rt)); \
611 } \
612 void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \
613 instr(rd_hi, rd_lo, rs, Operand(j)); \
614 }
615
Andrei Popescu31002712010-02-23 13:46:05 +0000616 DEFINE_INSTRUCTION(Addu);
Steve Block44f0eee2011-05-26 01:26:41 +0100617 DEFINE_INSTRUCTION(Subu);
Andrei Popescu31002712010-02-23 13:46:05 +0000618 DEFINE_INSTRUCTION(Mul);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400619 DEFINE_INSTRUCTION(Div);
620 DEFINE_INSTRUCTION(Divu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000621 DEFINE_INSTRUCTION(Mod);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400622 DEFINE_INSTRUCTION(Modu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000623 DEFINE_INSTRUCTION(Mulh);
Andrei Popescu31002712010-02-23 13:46:05 +0000624 DEFINE_INSTRUCTION2(Mult);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400625 DEFINE_INSTRUCTION(Mulhu);
Andrei Popescu31002712010-02-23 13:46:05 +0000626 DEFINE_INSTRUCTION2(Multu);
627 DEFINE_INSTRUCTION2(Div);
628 DEFINE_INSTRUCTION2(Divu);
629
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000630 DEFINE_INSTRUCTION3(Div);
631 DEFINE_INSTRUCTION3(Mul);
632
Andrei Popescu31002712010-02-23 13:46:05 +0000633 DEFINE_INSTRUCTION(And);
634 DEFINE_INSTRUCTION(Or);
635 DEFINE_INSTRUCTION(Xor);
636 DEFINE_INSTRUCTION(Nor);
Ben Murdoch257744e2011-11-30 15:57:28 +0000637 DEFINE_INSTRUCTION2(Neg);
Andrei Popescu31002712010-02-23 13:46:05 +0000638
639 DEFINE_INSTRUCTION(Slt);
640 DEFINE_INSTRUCTION(Sltu);
641
Steve Block44f0eee2011-05-26 01:26:41 +0100642 // MIPS32 R2 instruction macro.
643 DEFINE_INSTRUCTION(Ror);
644
Andrei Popescu31002712010-02-23 13:46:05 +0000645#undef DEFINE_INSTRUCTION
646#undef DEFINE_INSTRUCTION2
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000647#undef DEFINE_INSTRUCTION3
Andrei Popescu31002712010-02-23 13:46:05 +0000648
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000649 void Lsa(Register rd, Register rs, Register rt, uint8_t sa,
650 Register scratch = at);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000651 void Pref(int32_t hint, const MemOperand& rs);
652
Andrei Popescu31002712010-02-23 13:46:05 +0000653
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 // ---------------------------------------------------------------------------
655 // Pseudo-instructions.
Andrei Popescu31002712010-02-23 13:46:05 +0000656
657 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
Andrei Popescu31002712010-02-23 13:46:05 +0000658
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000659 void Ulw(Register rd, const MemOperand& rs);
660 void Usw(Register rd, const MemOperand& rs);
661
Ben Murdoch257744e2011-11-30 15:57:28 +0000662 // Load int32 in the rd register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100663 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
664 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
665 li(rd, Operand(j), mode);
Andrei Popescu31002712010-02-23 13:46:05 +0000666 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000667 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
Andrei Popescu31002712010-02-23 13:46:05 +0000668
Andrei Popescu31002712010-02-23 13:46:05 +0000669 // Push multiple registers on the stack.
Steve Block6ded16b2010-05-10 14:33:55 +0100670 // Registers are saved in numerical order, with higher numbered registers
Ben Murdoch257744e2011-11-30 15:57:28 +0000671 // saved in higher memory addresses.
Andrei Popescu31002712010-02-23 13:46:05 +0000672 void MultiPush(RegList regs);
673 void MultiPushReversed(RegList regs);
Steve Block44f0eee2011-05-26 01:26:41 +0100674
Ben Murdoch589d6972011-11-30 16:04:58 +0000675 void MultiPushFPU(RegList regs);
676 void MultiPushReversedFPU(RegList regs);
677
Ben Murdoch257744e2011-11-30 15:57:28 +0000678 void push(Register src) {
Andrei Popescu31002712010-02-23 13:46:05 +0000679 Addu(sp, sp, Operand(-kPointerSize));
680 sw(src, MemOperand(sp, 0));
681 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000682 void Push(Register src) { push(src); }
Steve Block44f0eee2011-05-26 01:26:41 +0100683
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000684 // Push a handle.
685 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000686 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000687
Ben Murdoch257744e2011-11-30 15:57:28 +0000688 // Push two registers. Pushes leftmost register first (to highest address).
689 void Push(Register src1, Register src2) {
Steve Block44f0eee2011-05-26 01:26:41 +0100690 Subu(sp, sp, Operand(2 * kPointerSize));
691 sw(src1, MemOperand(sp, 1 * kPointerSize));
692 sw(src2, MemOperand(sp, 0 * kPointerSize));
693 }
694
Ben Murdoch257744e2011-11-30 15:57:28 +0000695 // Push three registers. Pushes leftmost register first (to highest address).
696 void Push(Register src1, Register src2, Register src3) {
697 Subu(sp, sp, Operand(3 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100698 sw(src1, MemOperand(sp, 2 * kPointerSize));
699 sw(src2, MemOperand(sp, 1 * kPointerSize));
700 sw(src3, MemOperand(sp, 0 * kPointerSize));
701 }
702
Ben Murdoch257744e2011-11-30 15:57:28 +0000703 // Push four registers. Pushes leftmost register first (to highest address).
704 void Push(Register src1, Register src2, Register src3, Register src4) {
705 Subu(sp, sp, Operand(4 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100706 sw(src1, MemOperand(sp, 3 * kPointerSize));
707 sw(src2, MemOperand(sp, 2 * kPointerSize));
708 sw(src3, MemOperand(sp, 1 * kPointerSize));
709 sw(src4, MemOperand(sp, 0 * kPointerSize));
710 }
711
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000712 // Push five registers. Pushes leftmost register first (to highest address).
713 void Push(Register src1, Register src2, Register src3, Register src4,
714 Register src5) {
715 Subu(sp, sp, Operand(5 * kPointerSize));
716 sw(src1, MemOperand(sp, 4 * kPointerSize));
717 sw(src2, MemOperand(sp, 3 * kPointerSize));
718 sw(src3, MemOperand(sp, 2 * kPointerSize));
719 sw(src4, MemOperand(sp, 1 * kPointerSize));
720 sw(src5, MemOperand(sp, 0 * kPointerSize));
721 }
722
Andrei Popescu31002712010-02-23 13:46:05 +0000723 void Push(Register src, Condition cond, Register tst1, Register tst2) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000724 // Since we don't have conditional execution we use a Branch.
Steve Block44f0eee2011-05-26 01:26:41 +0100725 Branch(3, cond, tst1, Operand(tst2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000726 Subu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000727 sw(src, MemOperand(sp, 0));
728 }
729
730 // Pops multiple values from the stack and load them in the
731 // registers specified in regs. Pop order is the opposite as in MultiPush.
732 void MultiPop(RegList regs);
733 void MultiPopReversed(RegList regs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000734
Ben Murdoch589d6972011-11-30 16:04:58 +0000735 void MultiPopFPU(RegList regs);
736 void MultiPopReversedFPU(RegList regs);
737
Ben Murdoch257744e2011-11-30 15:57:28 +0000738 void pop(Register dst) {
Andrei Popescu31002712010-02-23 13:46:05 +0000739 lw(dst, MemOperand(sp, 0));
740 Addu(sp, sp, Operand(kPointerSize));
741 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000742 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000743
744 // Pop two registers. Pops rightmost register first (from lower address).
745 void Pop(Register src1, Register src2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000746 DCHECK(!src1.is(src2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000747 lw(src2, MemOperand(sp, 0 * kPointerSize));
748 lw(src1, MemOperand(sp, 1 * kPointerSize));
749 Addu(sp, sp, 2 * kPointerSize);
750 }
751
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100752 // Pop three registers. Pops rightmost register first (from lower address).
753 void Pop(Register src1, Register src2, Register src3) {
754 lw(src3, MemOperand(sp, 0 * kPointerSize));
755 lw(src2, MemOperand(sp, 1 * kPointerSize));
756 lw(src1, MemOperand(sp, 2 * kPointerSize));
757 Addu(sp, sp, 3 * kPointerSize);
758 }
759
Steve Block44f0eee2011-05-26 01:26:41 +0100760 void Pop(uint32_t count = 1) {
761 Addu(sp, sp, Operand(count * kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000762 }
763
Steve Block44f0eee2011-05-26 01:26:41 +0100764 // Push and pop the registers that can hold pointers, as defined by the
765 // RegList constant kSafepointSavedRegisters.
Ben Murdoch257744e2011-11-30 15:57:28 +0000766 void PushSafepointRegisters();
767 void PopSafepointRegisters();
Ben Murdoch257744e2011-11-30 15:57:28 +0000768 // Store value in register src in the safepoint stack slot for
769 // register dst.
770 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000771 // Load the value of the src register from its safepoint stack slot
772 // into register dst.
773 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Steve Block44f0eee2011-05-26 01:26:41 +0100774
775 // MIPS32 R2 instruction macro.
776 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
777 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
778
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100779 // ---------------------------------------------------------------------------
780 // FPU macros. These do not handle special cases like NaN or +- inf.
781
Steve Block44f0eee2011-05-26 01:26:41 +0100782 // Convert unsigned word to double.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000783 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100784
Ben Murdoch097c5b22016-05-18 11:27:45 +0100785 // Convert single to unsigned word.
786 void Trunc_uw_s(FPURegister fd, FPURegister fs, FPURegister scratch);
787 void Trunc_uw_s(FPURegister fd, Register rs, FPURegister scratch);
788
Steve Block44f0eee2011-05-26 01:26:41 +0100789 // Convert double to unsigned word.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000790 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
791 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100792
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100793 void Trunc_w_d(FPURegister fd, FPURegister fs);
794 void Round_w_d(FPURegister fd, FPURegister fs);
795 void Floor_w_d(FPURegister fd, FPURegister fs);
796 void Ceil_w_d(FPURegister fd, FPURegister fs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797
798 // FP32 mode: Move the general purpose register into
799 // the high part of the double-register pair.
800 // FP64 mode: Move the general-purpose register into
801 // the higher 32 bits of the 64-bit coprocessor register,
802 // while leaving the low bits unchanged.
803 void Mthc1(Register rt, FPURegister fs);
804
805 // FP32 mode: move the high part of the double-register pair into
806 // general purpose register.
807 // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
808 // general-purpose register.
809 void Mfhc1(Register rt, FPURegister fs);
810
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000811 // Wrapper functions for the different cmp/branch types.
812 inline void BranchF32(Label* target, Label* nan, Condition cc,
813 FPURegister cmp1, FPURegister cmp2,
814 BranchDelaySlot bd = PROTECT) {
815 BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
816 }
817
818 inline void BranchF64(Label* target, Label* nan, Condition cc,
819 FPURegister cmp1, FPURegister cmp2,
820 BranchDelaySlot bd = PROTECT) {
821 BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
822 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100823
824 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000825 inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
826 Condition cc, FPURegister cmp1, FPURegister cmp2) {
827 BranchF64(target, nan, cc, cmp1, cmp2, bd);
828 }
829
830 inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
831 Condition cc, FPURegister cmp1, FPURegister cmp2) {
832 BranchF32(target, nan, cc, cmp1, cmp2, bd);
833 }
834
835 // Alias functions for backward compatibility.
836 inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
837 FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
838 BranchF64(target, nan, cc, cmp1, cmp2, bd);
839 }
840
841 inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
842 Condition cc, FPURegister cmp1, FPURegister cmp2) {
843 BranchF64(bd, target, nan, cc, cmp1, cmp2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000844 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100845
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000846 // Truncates a double using a specific rounding mode, and writes the value
847 // to the result register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100848 // The except_flag will contain any exceptions caused by the instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000849 // If check_inexact is kDontCheckForInexactConversion, then the inexact
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100850 // exception is masked.
851 void EmitFPUTruncate(FPURoundingMode rounding_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000852 Register result,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100853 DoubleRegister double_input,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000854 Register scratch,
855 DoubleRegister double_scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100856 Register except_flag,
857 CheckForInexactConversion check_inexact
858 = kDontCheckForInexactConversion);
859
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000860 // Performs a truncating conversion of a floating point number as used by
861 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
862 // succeeds, otherwise falls through if result is saturated. On return
863 // 'result' either holds answer, or is clobbered on fall through.
864 //
865 // Only public for the test code in test-code-stubs-arm.cc.
866 void TryInlineTruncateDoubleToI(Register result,
867 DoubleRegister input,
868 Label* done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000869
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000870 // Performs a truncating conversion of a floating point number as used by
871 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872 // Exits with 'result' holding the answer.
873 void TruncateDoubleToI(Register result, DoubleRegister double_input);
874
875 // Performs a truncating conversion of a heap number as used by
876 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
877 // must be different registers. Exits with 'result' holding the answer.
878 void TruncateHeapNumberToI(Register result, Register object);
879
880 // Converts the smi or heap number in object to an int32 using the rules
881 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
882 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
883 // different registers.
884 void TruncateNumberToI(Register object,
885 Register result,
886 Register heap_number_map,
887 Register scratch,
888 Label* not_int32);
889
890 // Loads the number from object into dst register.
891 // If |object| is neither smi nor heap number, |not_number| is jumped to
892 // with |object| still intact.
893 void LoadNumber(Register object,
894 FPURegister dst,
895 Register heap_number_map,
896 Register scratch,
897 Label* not_number);
898
899 // Loads the number from object into double_dst in the double format.
900 // Control will jump to not_int32 if the value cannot be exactly represented
901 // by a 32-bit integer.
902 // Floating point value in the 32-bit integer range that are not exact integer
903 // won't be loaded.
904 void LoadNumberAsInt32Double(Register object,
905 DoubleRegister double_dst,
906 Register heap_number_map,
907 Register scratch1,
908 Register scratch2,
909 FPURegister double_scratch,
910 Label* not_int32);
911
912 // Loads the number from object into dst as a 32-bit integer.
913 // Control will jump to not_int32 if the object cannot be exactly represented
914 // by a 32-bit integer.
915 // Floating point value in the 32-bit integer range that are not exact integer
916 // won't be converted.
917 void LoadNumberAsInt32(Register object,
918 Register dst,
919 Register heap_number_map,
920 Register scratch1,
921 Register scratch2,
922 FPURegister double_scratch0,
923 FPURegister double_scratch1,
924 Label* not_int32);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000925
Steve Block44f0eee2011-05-26 01:26:41 +0100926 // Enter exit frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000927 // argc - argument count to be dropped by LeaveExitFrame.
928 // save_doubles - saves FPU registers on stack, currently disabled.
929 // stack_space - extra stack space.
930 void EnterExitFrame(bool save_doubles,
931 int stack_space = 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100932
Ben Murdoch257744e2011-11-30 15:57:28 +0000933 // Leave the current exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000934 void LeaveExitFrame(bool save_doubles, Register arg_count,
935 bool restore_context, bool do_return = NO_EMIT_RETURN,
936 bool argument_count_is_length = false);
Steve Block6ded16b2010-05-10 14:33:55 +0100937
Steve Block44f0eee2011-05-26 01:26:41 +0100938 // Get the actual activation frame alignment for target environment.
939 static int ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +0100940
Ben Murdoch257744e2011-11-30 15:57:28 +0000941 // Make sure the stack is aligned. Only emits code in debug mode.
942 void AssertStackIsAligned();
943
Steve Block44f0eee2011-05-26 01:26:41 +0100944 void LoadContext(Register dst, int context_chain_length);
Steve Block6ded16b2010-05-10 14:33:55 +0100945
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000946 // Load the global object from the current context.
947 void LoadGlobalObject(Register dst) {
948 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
949 }
950
951 // Load the global proxy from the current context.
952 void LoadGlobalProxy(Register dst) {
953 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
954 }
955
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100956 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000957 // transitioned_kind from the native context if the map in register
958 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100959 // expected_kind.
960 void LoadTransitionedArrayMapConditional(
961 ElementsKind expected_kind,
962 ElementsKind transitioned_kind,
963 Register map_in_out,
964 Register scratch,
965 Label* no_map_match);
966
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000967 void LoadNativeContextSlot(int index, Register dst);
Steve Block44f0eee2011-05-26 01:26:41 +0100968
969 // Load the initial map from the global function. The registers
970 // function and map can be the same, function is then overwritten.
971 void LoadGlobalFunctionInitialMap(Register function,
972 Register map,
973 Register scratch);
974
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100975 void InitializeRootRegister() {
976 ExternalReference roots_array_start =
977 ExternalReference::roots_array_start(isolate());
978 li(kRootRegister, Operand(roots_array_start));
979 }
980
Steve Block44f0eee2011-05-26 01:26:41 +0100981 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000982 // JavaScript invokes.
983
Steve Block6ded16b2010-05-10 14:33:55 +0100984 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000985
986 void InvokeFunctionCode(Register function, Register new_target,
987 const ParameterCount& expected,
988 const ParameterCount& actual, InvokeFlag flag,
989 const CallWrapper& call_wrapper);
990
991 void FloodFunctionIfStepping(Register fun, Register new_target,
992 const ParameterCount& expected,
993 const ParameterCount& actual);
Steve Block6ded16b2010-05-10 14:33:55 +0100994
995 // Invoke the JavaScript function in the given register. Changes the
996 // current context to the context in the function before invoking.
997 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000998 Register new_target,
Steve Block6ded16b2010-05-10 14:33:55 +0100999 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +01001000 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001001 const CallWrapper& call_wrapper);
Steve Block44f0eee2011-05-26 01:26:41 +01001002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 void InvokeFunction(Register function,
1004 const ParameterCount& expected,
Steve Block44f0eee2011-05-26 01:26:41 +01001005 const ParameterCount& actual,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001006 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001007 const CallWrapper& call_wrapper);
1008
1009 void InvokeFunction(Handle<JSFunction> function,
1010 const ParameterCount& expected,
1011 const ParameterCount& actual,
1012 InvokeFlag flag,
1013 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001014
Steve Block44f0eee2011-05-26 01:26:41 +01001015 void IsObjectJSStringType(Register object,
1016 Register scratch,
1017 Label* fail);
1018
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001019 void IsObjectNameType(Register object,
1020 Register scratch,
1021 Label* fail);
1022
Steve Block44f0eee2011-05-26 01:26:41 +01001023 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001024 // Debugger Support.
Steve Block6ded16b2010-05-10 14:33:55 +01001025
Steve Block6ded16b2010-05-10 14:33:55 +01001026 void DebugBreak();
Steve Block6ded16b2010-05-10 14:33:55 +01001027
Steve Block44f0eee2011-05-26 01:26:41 +01001028 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001029 // Exception handling.
Andrei Popescu31002712010-02-23 13:46:05 +00001030
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031 // Push a new stack handler and link into stack handler chain.
1032 void PushStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001033
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001034 // Unlink the stack handler on top of the stack from the stack handler chain.
Andrei Popescu31002712010-02-23 13:46:05 +00001035 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001036 void PopStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001037
Ben Murdoch257744e2011-11-30 15:57:28 +00001038 // Copies a number of bytes from src to dst. All registers are clobbered. On
1039 // exit src and dst will point to the place just after where the last byte was
1040 // read or written and length will be zero.
1041 void CopyBytes(Register src,
1042 Register dst,
1043 Register length,
1044 Register scratch);
1045
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001046 // Initialize fields with filler values. Fields starting at |current_address|
1047 // not including |end_address| are overwritten with the value in |filler|. At
1048 // the end the loop, |current_address| takes the value of |end_address|.
1049 void InitializeFieldsWithFiller(Register current_address,
1050 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001051
Steve Block44f0eee2011-05-26 01:26:41 +01001052 // -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001053 // Support functions.
1054
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001055 // Machine code version of Map::GetConstructor().
1056 // |temp| holds |result|'s map when done, and |temp2| its instance type.
1057 void GetMapConstructor(Register result, Register map, Register temp,
1058 Register temp2);
1059
Steve Block44f0eee2011-05-26 01:26:41 +01001060 // Try to get function prototype of a function and puts the value in
1061 // the result register. Checks that the function really is a
1062 // function and jumps to the miss label if the fast checks fail. The
1063 // function register will be untouched; the other registers may be
1064 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001065 void TryGetFunctionPrototype(Register function, Register result,
1066 Register scratch, Label* miss);
Steve Block44f0eee2011-05-26 01:26:41 +01001067
Steve Block6ded16b2010-05-10 14:33:55 +01001068 void GetObjectType(Register function,
1069 Register map,
1070 Register type_reg);
1071
Ben Murdoch097c5b22016-05-18 11:27:45 +01001072 void GetInstanceType(Register object_map, Register object_instance_type) {
1073 lbu(object_instance_type,
1074 FieldMemOperand(object_map, Map::kInstanceTypeOffset));
1075 }
1076
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001077 // Check if a map for a JSObject indicates that the object has fast elements.
1078 // Jump to the specified label if it does not.
1079 void CheckFastElements(Register map,
1080 Register scratch,
1081 Label* fail);
1082
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001083 // Check if a map for a JSObject indicates that the object can have both smi
1084 // and HeapObject elements. Jump to the specified label if it does not.
1085 void CheckFastObjectElements(Register map,
1086 Register scratch,
1087 Label* fail);
1088
1089 // Check if a map for a JSObject indicates that the object has fast smi only
1090 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001091 void CheckFastSmiElements(Register map,
1092 Register scratch,
1093 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001094
1095 // Check to see if maybe_number can be stored as a double in
1096 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001097 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001098 void StoreNumberToDoubleElements(Register value_reg,
1099 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001100 Register elements_reg,
1101 Register scratch1,
1102 Register scratch2,
1103 Register scratch3,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001104 Label* fail,
1105 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001106
1107 // Compare an object's map with the specified map and its transitioned
1108 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1109 // "branch_to" if the result of the comparison is "cond". If multiple map
1110 // compares are required, the compare sequences branches to early_success.
1111 void CompareMapAndBranch(Register obj,
1112 Register scratch,
1113 Handle<Map> map,
1114 Label* early_success,
1115 Condition cond,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001116 Label* branch_to);
1117
1118 // As above, but the map of the object is already loaded into the register
1119 // which is preserved by the code generated.
1120 void CompareMapAndBranch(Register obj_map,
1121 Handle<Map> map,
1122 Label* early_success,
1123 Condition cond,
1124 Label* branch_to);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001125
1126 // Check if the map of an object is equal to a specified map and branch to
1127 // label if not. Skip the smi check if not required (object is known to be a
1128 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1129 // against maps that are ElementsKind transition maps of the specificed map.
Steve Block44f0eee2011-05-26 01:26:41 +01001130 void CheckMap(Register obj,
1131 Register scratch,
1132 Handle<Map> map,
1133 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001134 SmiCheckType smi_check_type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001135
Andrei Popescu31002712010-02-23 13:46:05 +00001136
Steve Block44f0eee2011-05-26 01:26:41 +01001137 void CheckMap(Register obj,
1138 Register scratch,
1139 Heap::RootListIndex index,
1140 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +00001141 SmiCheckType smi_check_type);
1142
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001143 // Check if the map of an object is equal to a specified weak map and branch
1144 // to a specified target if equal. Skip the smi check if not required
1145 // (object is known to be a heap object)
1146 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1147 Handle<WeakCell> cell, Handle<Code> success,
1148 SmiCheckType smi_check_type);
Steve Block6ded16b2010-05-10 14:33:55 +01001149
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001150 // Get value of the weak cell.
1151 void GetWeakValue(Register value, Handle<WeakCell> cell);
1152
1153 // Load the value of the weak cell in the value register. Branch to the
1154 // given miss label is the weak cell was cleared.
1155 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001156
1157 // Load and check the instance type of an object for being a string.
1158 // Loads the type into the second argument register.
1159 // Returns a condition that will be enabled if the object was a string.
1160 Condition IsObjectStringType(Register obj,
1161 Register type,
1162 Register result) {
1163 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1164 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1165 And(type, type, Operand(kIsNotStringMask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001166 DCHECK_EQ(0u, kStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001167 return eq;
1168 }
1169
1170
Steve Block44f0eee2011-05-26 01:26:41 +01001171 // Picks out an array index from the hash field.
1172 // Register use:
1173 // hash - holds the index's hash. Clobbered.
1174 // index - holds the overwritten index on exit.
1175 void IndexFromHash(Register hash, Register index);
Andrei Popescu31002712010-02-23 13:46:05 +00001176
Ben Murdoch257744e2011-11-30 15:57:28 +00001177 // Get the number of least significant bits from a register.
1178 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1179 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1180
Steve Block44f0eee2011-05-26 01:26:41 +01001181 // Load the value of a number object into a FPU double register. If the
1182 // object is not a number a jump to the label not_number is performed
1183 // and the FPU double register is unchanged.
1184 void ObjectToDoubleFPURegister(
1185 Register object,
1186 FPURegister value,
1187 Register scratch1,
1188 Register scratch2,
1189 Register heap_number_map,
1190 Label* not_number,
1191 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1192
1193 // Load the value of a smi object into a FPU double register. The register
1194 // scratch1 can be the same register as smi in which case smi will hold the
1195 // untagged value afterwards.
1196 void SmiToDoubleFPURegister(Register smi,
1197 FPURegister value,
1198 Register scratch1);
1199
1200 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001201 // Overflow handling functions.
1202 // Usage: first call the appropriate arithmetic function, then call one of the
1203 // jump functions with the overflow_dst register as the second parameter.
1204
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001205 inline void AddBranchOvf(Register dst, Register left, const Operand& right,
1206 Label* overflow_label, Register scratch = at) {
1207 AddBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001208 }
1209
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001210 inline void AddBranchNoOvf(Register dst, Register left, const Operand& right,
1211 Label* no_overflow_label, Register scratch = at) {
1212 AddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001213 }
1214
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001215 void AddBranchOvf(Register dst, Register left, const Operand& right,
1216 Label* overflow_label, Label* no_overflow_label,
1217 Register scratch = at);
1218
1219 void AddBranchOvf(Register dst, Register left, Register right,
1220 Label* overflow_label, Label* no_overflow_label,
1221 Register scratch = at);
1222
1223
1224 inline void SubBranchOvf(Register dst, Register left, const Operand& right,
1225 Label* overflow_label, Register scratch = at) {
1226 SubBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001227 }
1228
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001229 inline void SubBranchNoOvf(Register dst, Register left, const Operand& right,
1230 Label* no_overflow_label, Register scratch = at) {
1231 SubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001232 }
1233
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001234 void SubBranchOvf(Register dst, Register left, const Operand& right,
1235 Label* overflow_label, Label* no_overflow_label,
1236 Register scratch = at);
1237
1238 void SubBranchOvf(Register dst, Register left, Register right,
1239 Label* overflow_label, Label* no_overflow_label,
1240 Register scratch = at);
1241
Ben Murdoch257744e2011-11-30 15:57:28 +00001242 // -------------------------------------------------------------------------
1243 // Runtime calls.
Andrei Popescu31002712010-02-23 13:46:05 +00001244
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001245 // See comments at the beginning of CEntryStub::Generate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001246 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
Ben Murdoch85b71792012-04-11 18:30:58 +01001247
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001248 inline void PrepareCEntryFunction(const ExternalReference& ref) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001249 li(a1, Operand(ref));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001250 }
1251
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001252#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1253const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1254
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001255 // Call a code stub.
1256 void CallStub(CodeStub* stub,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001257 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1258 COND_ARGS);
Steve Block44f0eee2011-05-26 01:26:41 +01001259
1260 // Tail call a code stub (jump).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001261 void TailCallStub(CodeStub* stub, COND_ARGS);
1262
1263#undef COND_ARGS
Steve Block44f0eee2011-05-26 01:26:41 +01001264
Andrei Popescu31002712010-02-23 13:46:05 +00001265 void CallJSExitStub(CodeStub* stub);
1266
Andrei Popescu31002712010-02-23 13:46:05 +00001267 // Call a runtime routine.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001268 void CallRuntime(const Runtime::Function* f, int num_arguments,
1269 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1270 BranchDelaySlot bd = PROTECT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001271 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1272 const Runtime::Function* function = Runtime::FunctionForId(id);
1273 CallRuntime(function, function->nargs, kSaveFPRegs);
1274 }
Andrei Popescu31002712010-02-23 13:46:05 +00001275
1276 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001277 void CallRuntime(Runtime::FunctionId fid,
1278 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1279 BranchDelaySlot bd = PROTECT) {
1280 const Runtime::Function* function = Runtime::FunctionForId(fid);
1281 CallRuntime(function, function->nargs, save_doubles, bd);
1282 }
1283
1284 // Convenience function: Same as above, but takes the fid instead.
1285 void CallRuntime(Runtime::FunctionId id, int num_arguments,
1286 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1287 BranchDelaySlot bd = PROTECT) {
1288 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001289 }
Andrei Popescu31002712010-02-23 13:46:05 +00001290
Steve Block44f0eee2011-05-26 01:26:41 +01001291 // Convenience function: call an external reference.
1292 void CallExternalReference(const ExternalReference& ext,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001293 int num_arguments,
1294 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001295
Steve Block6ded16b2010-05-10 14:33:55 +01001296
1297 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001298 void TailCallRuntime(Runtime::FunctionId fid);
Andrei Popescu31002712010-02-23 13:46:05 +00001299
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001300 int CalculateStackPassedWords(int num_reg_arguments,
1301 int num_double_arguments);
1302
Steve Block44f0eee2011-05-26 01:26:41 +01001303 // Before calling a C-function from generated code, align arguments on stack
1304 // and add space for the four mips argument slots.
1305 // After aligning the frame, non-register arguments must be stored on the
1306 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1307 // The argument count assumes all arguments are word sized.
1308 // Some compilers/platforms require the stack to be aligned when calling
1309 // C++ code.
1310 // Needs a scratch register to do some arithmetic. This register will be
1311 // trashed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001312 void PrepareCallCFunction(int num_reg_arguments,
1313 int num_double_registers,
1314 Register scratch);
1315 void PrepareCallCFunction(int num_reg_arguments,
1316 Register scratch);
Steve Block44f0eee2011-05-26 01:26:41 +01001317
1318 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1319 // Arguments 5..n are stored to stack using following:
1320 // sw(t0, CFunctionArgumentOperand(5));
1321
1322 // Calls a C function and cleans up the space for arguments allocated
1323 // by PrepareCallCFunction. The called function is not allowed to trigger a
1324 // garbage collection, since that might move the code and invalidate the
1325 // return address (unless this is somehow accounted for by the called
1326 // function).
1327 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001328 void CallCFunction(Register function, int num_arguments);
1329 void CallCFunction(ExternalReference function,
1330 int num_reg_arguments,
1331 int num_double_arguments);
1332 void CallCFunction(Register function,
1333 int num_reg_arguments,
1334 int num_double_arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001335 void MovFromFloatResult(DoubleRegister dst);
1336 void MovFromFloatParameter(DoubleRegister dst);
Ben Murdoch257744e2011-11-30 15:57:28 +00001337
1338 // There are two ways of passing double arguments on MIPS, depending on
1339 // whether soft or hard floating point ABI is used. These functions
1340 // abstract parameter passing for the three different ways we call
1341 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001342 void MovToFloatParameter(DoubleRegister src);
1343 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1344 void MovToFloatResult(DoubleRegister src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001345
Andrei Popescu31002712010-02-23 13:46:05 +00001346 // Jump to the builtin routine.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001347 void JumpToExternalReference(const ExternalReference& builtin,
1348 BranchDelaySlot bd = PROTECT);
Andrei Popescu31002712010-02-23 13:46:05 +00001349
Andrei Popescu31002712010-02-23 13:46:05 +00001350 struct Unresolved {
1351 int pc;
Ben Murdoch257744e2011-11-30 15:57:28 +00001352 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
Andrei Popescu31002712010-02-23 13:46:05 +00001353 const char* name;
1354 };
Andrei Popescu31002712010-02-23 13:46:05 +00001355
Ben Murdoch257744e2011-11-30 15:57:28 +00001356 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001357 DCHECK(!code_object_.is_null());
Ben Murdoch257744e2011-11-30 15:57:28 +00001358 return code_object_;
1359 }
Andrei Popescu31002712010-02-23 13:46:05 +00001360
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001361 // Emit code for a truncating division by a constant. The dividend register is
1362 // unchanged and at gets clobbered. Dividend and result must be different.
1363 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1364
Steve Block44f0eee2011-05-26 01:26:41 +01001365 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001366 // StatsCounter support.
Andrei Popescu31002712010-02-23 13:46:05 +00001367
1368 void SetCounter(StatsCounter* counter, int value,
1369 Register scratch1, Register scratch2);
1370 void IncrementCounter(StatsCounter* counter, int value,
1371 Register scratch1, Register scratch2);
1372 void DecrementCounter(StatsCounter* counter, int value,
1373 Register scratch1, Register scratch2);
1374
1375
Steve Block44f0eee2011-05-26 01:26:41 +01001376 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001377 // Debugging.
Andrei Popescu31002712010-02-23 13:46:05 +00001378
1379 // Calls Abort(msg) if the condition cc is not satisfied.
1380 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001381 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
Steve Block44f0eee2011-05-26 01:26:41 +01001382 void AssertFastElements(Register elements);
Andrei Popescu31002712010-02-23 13:46:05 +00001383
1384 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001385 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
Andrei Popescu31002712010-02-23 13:46:05 +00001386
1387 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001388 void Abort(BailoutReason msg);
Andrei Popescu31002712010-02-23 13:46:05 +00001389
1390 // Verify restrictions about code generated in stubs.
1391 void set_generating_stub(bool value) { generating_stub_ = value; }
1392 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001393 void set_has_frame(bool value) { has_frame_ = value; }
1394 bool has_frame() { return has_frame_; }
1395 inline bool AllowThisStubCall(CodeStub* stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001396
Steve Block44f0eee2011-05-26 01:26:41 +01001397 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001398 // Number utilities.
Steve Block6ded16b2010-05-10 14:33:55 +01001399
Steve Block44f0eee2011-05-26 01:26:41 +01001400 // Check whether the value of reg is a power of two and not zero. If not
1401 // control continues at the label not_power_of_two. If reg is a power of two
1402 // the register scratch contains the value of (reg - 1) when control falls
1403 // through.
1404 void JumpIfNotPowerOfTwoOrZero(Register reg,
1405 Register scratch,
1406 Label* not_power_of_two_or_zero);
1407
1408 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001409 // Smi utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001410
Steve Block44f0eee2011-05-26 01:26:41 +01001411 void SmiTag(Register reg) {
1412 Addu(reg, reg, reg);
1413 }
1414
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001415 void SmiTag(Register dst, Register src) { Addu(dst, src, src); }
1416
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001417 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1418 void SmiTagCheckOverflow(Register reg, Register overflow);
1419 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1420
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001421 void BranchOnOverflow(Label* label, Register overflow_check,
1422 BranchDelaySlot bd = PROTECT) {
1423 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
Steve Block44f0eee2011-05-26 01:26:41 +01001424 }
1425
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426 void BranchOnNoOverflow(Label* label, Register overflow_check,
1427 BranchDelaySlot bd = PROTECT) {
1428 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1429 }
1430
1431
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001432 // Try to convert int32 to smi. If the value is to large, preserve
1433 // the original value and jump to not_a_smi. Destroys scratch and
1434 // sets flags.
1435 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1436 TrySmiTag(reg, reg, scratch, not_a_smi);
1437 }
1438 void TrySmiTag(Register dst,
1439 Register src,
1440 Register scratch,
1441 Label* not_a_smi) {
1442 SmiTagCheckOverflow(at, src, scratch);
1443 BranchOnOverflow(not_a_smi, scratch);
1444 mov(dst, at);
1445 }
1446
Steve Block44f0eee2011-05-26 01:26:41 +01001447 void SmiUntag(Register reg) {
1448 sra(reg, reg, kSmiTagSize);
1449 }
1450
1451 void SmiUntag(Register dst, Register src) {
1452 sra(dst, src, kSmiTagSize);
1453 }
1454
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001455 // Test if the register contains a smi.
1456 inline void SmiTst(Register value, Register scratch) {
1457 And(scratch, value, Operand(kSmiTagMask));
1458 }
1459 inline void NonNegativeSmiTst(Register value, Register scratch) {
1460 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1461 }
1462
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001463 // Untag the source value into destination and jump if source is a smi.
1464 // Souce and destination can be the same register.
1465 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1466
1467 // Untag the source value into destination and jump if source is not a smi.
1468 // Souce and destination can be the same register.
1469 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1470
Steve Block44f0eee2011-05-26 01:26:41 +01001471 // Jump the register contains a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001472 void JumpIfSmi(Register value,
1473 Label* smi_label,
1474 Register scratch = at,
1475 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001476
1477 // Jump if the register contains a non-smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001478 void JumpIfNotSmi(Register value,
1479 Label* not_smi_label,
1480 Register scratch = at,
1481 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001482
1483 // Jump if either of the registers contain a non-smi.
1484 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1485 // Jump if either of the registers contain a smi.
1486 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1487
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001488 // Abort execution if argument is a smi, enabled via --debug-code.
1489 void AssertNotSmi(Register object);
1490 void AssertSmi(Register object);
Steve Block44f0eee2011-05-26 01:26:41 +01001491
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001492 // Abort execution if argument is not a string, enabled via --debug-code.
1493 void AssertString(Register object);
Ben Murdoch257744e2011-11-30 15:57:28 +00001494
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001495 // Abort execution if argument is not a name, enabled via --debug-code.
1496 void AssertName(Register object);
1497
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001498 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1499 void AssertFunction(Register object);
1500
1501 // Abort execution if argument is not a JSBoundFunction,
1502 // enabled via --debug-code.
1503 void AssertBoundFunction(Register object);
1504
Ben Murdoch097c5b22016-05-18 11:27:45 +01001505 // Abort execution if argument is not a JSReceiver, enabled via --debug-code.
1506 void AssertReceiver(Register object);
1507
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001508 // Abort execution if argument is not undefined or an AllocationSite, enabled
1509 // via --debug-code.
1510 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1511
1512 // Abort execution if reg is not the root value with the given index,
1513 // enabled via --debug-code.
1514 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block44f0eee2011-05-26 01:26:41 +01001515
1516 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001517 // HeapNumber utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001518
1519 void JumpIfNotHeapNumber(Register object,
1520 Register heap_number_map,
1521 Register scratch,
1522 Label* on_not_heap_number);
1523
1524 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001525 // String utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001526
1527 // Checks if both instance types are sequential ASCII strings and jumps to
1528 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001529 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1530 Register first_object_instance_type, Register second_object_instance_type,
1531 Register scratch1, Register scratch2, Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001532
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001533 // Check if instance type is sequential one-byte string and jump to label if
Steve Block44f0eee2011-05-26 01:26:41 +01001534 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001535 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1536 Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001537
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001538 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
Steve Block44f0eee2011-05-26 01:26:41 +01001539
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001540 void EmitSeqStringSetCharCheck(Register string,
1541 Register index,
1542 Register value,
1543 Register scratch,
1544 uint32_t encoding_mask);
1545
1546 // Checks if both objects are sequential one-byte strings and jumps to label
1547 // if either is not. Assumes that neither object is a smi.
1548 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1549 Register second,
1550 Register scratch1,
1551 Register scratch2,
1552 Label* failure);
1553
1554 // Checks if both objects are sequential one-byte strings and jumps to label
1555 // if either is not.
1556 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1557 Register scratch1,
1558 Register scratch2,
1559 Label* not_flat_one_byte_strings);
Steve Block44f0eee2011-05-26 01:26:41 +01001560
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001561 void ClampUint8(Register output_reg, Register input_reg);
1562
1563 void ClampDoubleToUint8(Register result_reg,
1564 DoubleRegister input_reg,
1565 DoubleRegister temp_double_reg);
1566
1567
Ben Murdoch257744e2011-11-30 15:57:28 +00001568 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001569 void EnumLength(Register dst, Register map);
1570 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001571 void LoadAccessor(Register dst, Register holder, int accessor_index,
1572 AccessorComponent accessor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001573
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001574 template<typename Field>
1575 void DecodeField(Register dst, Register src) {
1576 Ext(dst, src, Field::kShift, Field::kSize);
1577 }
1578
1579 template<typename Field>
1580 void DecodeField(Register reg) {
1581 DecodeField<Field>(reg, reg);
1582 }
1583
1584 template<typename Field>
1585 void DecodeFieldToSmi(Register dst, Register src) {
1586 static const int shift = Field::kShift;
1587 static const int mask = Field::kMask >> shift << kSmiTagSize;
1588 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1589 STATIC_ASSERT(kSmiTag == 0);
1590 if (shift < kSmiTagSize) {
1591 sll(dst, src, kSmiTagSize - shift);
1592 And(dst, dst, Operand(mask));
1593 } else if (shift > kSmiTagSize) {
1594 srl(dst, src, shift - kSmiTagSize);
1595 And(dst, dst, Operand(mask));
1596 } else {
1597 And(dst, src, Operand(mask));
1598 }
1599 }
1600
1601 template<typename Field>
1602 void DecodeFieldToSmi(Register reg) {
1603 DecodeField<Field>(reg, reg);
1604 }
1605
1606 // Generates function and stub prologue code.
1607 void StubPrologue();
1608 void Prologue(bool code_pre_aging);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001609
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001610 // Load the type feedback vector from a JavaScript frame.
1611 void EmitLoadTypeFeedbackVector(Register vector);
1612
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001613 // Activation support.
1614 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001615 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001616 void LeaveFrame(StackFrame::Type type);
1617
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001618 // Expects object in a0 and returns map with validated enum cache
1619 // in a0. Assumes that any other register can be used as a scratch.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001620 void CheckEnumCache(Label* call_runtime);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001621
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001622 // AllocationMemento support. Arrays may have an associated
1623 // AllocationMemento object that can be checked for in order to pretransition
1624 // to another type.
1625 // On entry, receiver_reg should point to the array object.
1626 // scratch_reg gets clobbered.
1627 // If allocation info is present, jump to allocation_memento_present.
1628 void TestJSArrayForAllocationMemento(
1629 Register receiver_reg,
1630 Register scratch_reg,
1631 Label* no_memento_found,
1632 Condition cond = al,
1633 Label* allocation_memento_present = NULL);
1634
1635 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1636 Register scratch_reg,
1637 Label* memento_found) {
1638 Label no_memento_found;
1639 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1640 &no_memento_found, eq, memento_found);
1641 bind(&no_memento_found);
1642 }
1643
1644 // Jumps to found label if a prototype map has dictionary elements.
1645 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1646 Register scratch1, Label* found);
1647
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001648 bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
1649
Steve Block44f0eee2011-05-26 01:26:41 +01001650 private:
1651 void CallCFunctionHelper(Register function,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001652 int num_reg_arguments,
1653 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001654
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001655 inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch);
1656 inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits);
1657 void BranchShortHelperR6(int32_t offset, Label* L);
1658 void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot);
1659 bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond,
1660 Register rs, const Operand& rt);
1661 bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs,
1662 const Operand& rt, BranchDelaySlot bdslot);
1663 bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs,
1664 const Operand& rt, BranchDelaySlot bdslot);
1665
1666 void BranchAndLinkShortHelperR6(int32_t offset, Label* L);
1667 void BranchAndLinkShortHelper(int16_t offset, Label* L,
1668 BranchDelaySlot bdslot);
1669 void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001670 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001671 bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond,
1672 Register rs, const Operand& rt);
1673 bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond,
1674 Register rs, const Operand& rt,
1675 BranchDelaySlot bdslot);
1676 bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond,
1677 Register rs, const Operand& rt,
1678 BranchDelaySlot bdslot);
1679 void BranchLong(Label* L, BranchDelaySlot bdslot);
1680 void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot);
1681
1682 // Common implementation of BranchF functions for the different formats.
1683 void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1684 Condition cc, FPURegister cmp1, FPURegister cmp2,
1685 BranchDelaySlot bd = PROTECT);
1686
1687 void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1688 FPURegister cmp1, FPURegister cmp2,
1689 BranchDelaySlot bd = PROTECT);
Steve Block6ded16b2010-05-10 14:33:55 +01001690
1691 // Helper functions for generating invokes.
1692 void InvokePrologue(const ParameterCount& expected,
1693 const ParameterCount& actual,
Steve Block6ded16b2010-05-10 14:33:55 +01001694 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001695 bool* definitely_mismatches,
Steve Block44f0eee2011-05-26 01:26:41 +01001696 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001697 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001698
Steve Block44f0eee2011-05-26 01:26:41 +01001699 void InitializeNewString(Register string,
1700 Register length,
1701 Heap::RootListIndex map_index,
1702 Register scratch1,
1703 Register scratch2);
1704
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001705 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001706 void InNewSpace(Register object, Register scratch,
1707 Condition cond, // ne for new space, eq otherwise.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001708 Label* branch);
1709
1710 // Helper for finding the mark bits for an address. Afterwards, the
1711 // bitmap register points at the word with the mark bits and the mask
1712 // the position of the first bit. Leaves addr_reg unchanged.
1713 inline void GetMarkBits(Register addr_reg,
1714 Register bitmap_reg,
1715 Register mask_reg);
1716
Ben Murdoch257744e2011-11-30 15:57:28 +00001717 // Compute memory operands for safepoint stack slots.
1718 static int SafepointRegisterStackIndex(int reg_code);
1719 MemOperand SafepointRegisterSlot(Register reg);
1720 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
Steve Block44f0eee2011-05-26 01:26:41 +01001721
1722 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001723 bool has_frame_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001724 bool has_double_zero_reg_set_;
Steve Block44f0eee2011-05-26 01:26:41 +01001725 // This handle will be patched with the code object on installation.
1726 Handle<Object> code_object_;
Ben Murdoch257744e2011-11-30 15:57:28 +00001727
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001728 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoch257744e2011-11-30 15:57:28 +00001729 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001730 friend class StandardFrame;
Steve Block44f0eee2011-05-26 01:26:41 +01001731};
1732
1733
Steve Block44f0eee2011-05-26 01:26:41 +01001734// The code patcher is used to patch (typically) small parts of code e.g. for
1735// debugging and other types of instrumentation. When using the code patcher
1736// the exact number of bytes specified must be emitted. It is not legal to emit
1737// relocation information. If any of these constraints are violated it causes
1738// an assertion to fail.
1739class CodePatcher {
1740 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001741 enum FlushICache {
1742 FLUSH,
1743 DONT_FLUSH
1744 };
1745
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001746 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001747 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001748 ~CodePatcher();
Steve Block44f0eee2011-05-26 01:26:41 +01001749
1750 // Macro assembler to emit code.
1751 MacroAssembler* masm() { return &masm_; }
1752
1753 // Emit an instruction directly.
Ben Murdoch257744e2011-11-30 15:57:28 +00001754 void Emit(Instr instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001755
1756 // Emit an address directly.
1757 void Emit(Address addr);
1758
Ben Murdoch257744e2011-11-30 15:57:28 +00001759 // Change the condition part of an instruction leaving the rest of the current
1760 // instruction unchanged.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001761 void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode);
Ben Murdoch257744e2011-11-30 15:57:28 +00001762
Steve Block44f0eee2011-05-26 01:26:41 +01001763 private:
1764 byte* address_; // The address of the code being patched.
Steve Block44f0eee2011-05-26 01:26:41 +01001765 int size_; // Number of bytes of the expected patch size.
1766 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001767 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Block44f0eee2011-05-26 01:26:41 +01001768};
Andrei Popescu31002712010-02-23 13:46:05 +00001769
Ben Murdoch097c5b22016-05-18 11:27:45 +01001770template <typename Func>
1771void MacroAssembler::GenerateSwitchTable(Register index, size_t case_count,
1772 Func GetLabelFunction) {
1773 if (kArchVariant >= kMips32r6) {
1774 BlockTrampolinePoolFor(case_count + 5);
1775 addiupc(at, 5);
1776 lsa(at, at, index, kPointerSizeLog2);
1777 lw(at, MemOperand(at));
1778 } else {
1779 Label here;
1780 BlockTrampolinePoolFor(case_count + 6);
1781 bal(&here);
1782 sll(at, index, kPointerSizeLog2); // Branch delay slot.
1783 bind(&here);
1784 addu(at, at, ra);
1785 lw(at, MemOperand(at, 4 * v8::internal::Assembler::kInstrSize));
1786 }
1787 jr(at);
1788 nop(); // Branch delay slot nop.
1789 for (size_t index = 0; index < case_count; ++index) {
1790 dd(GetLabelFunction(index));
1791 }
1792}
Andrei Popescu31002712010-02-23 13:46:05 +00001793
1794#ifdef GENERATED_CODE_COVERAGE
1795#define CODE_COVERAGE_STRINGIFY(x) #x
1796#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1797#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1798#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1799#else
1800#define ACCESS_MASM(masm) masm->
1801#endif
1802
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001803} // namespace internal
1804} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +00001805
1806#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_