blob: 4f6a3c868b7a52c0363e61b21c971ee7e3a5e764 [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};
18const Register kJSFunctionRegister = {Register::kCode_a1};
19const Register kContextRegister = {Register::kCpRegister};
20const Register kInterpreterAccumulatorRegister = {Register::kCode_v0};
21const Register kInterpreterRegisterFileRegister = {Register::kCode_t3};
22const Register kInterpreterBytecodeOffsetRegister = {Register::kCode_t4};
23const Register kInterpreterBytecodeArrayRegister = {Register::kCode_t5};
24const Register kInterpreterDispatchTableRegister = {Register::kCode_t6};
25const Register kJavaScriptCallArgCountRegister = {Register::kCode_a0};
26const Register kJavaScriptCallNewTargetRegister = {Register::kCode_a3};
27const Register kRuntimeCallFunctionRegister = {Register::kCode_a1};
28const Register kRuntimeCallArgCountRegister = {Register::kCode_a0};
29
Andrei Popescu31002712010-02-23 13:46:05 +000030// Forward declaration.
31class JumpTarget;
32
Steve Block44f0eee2011-05-26 01:26:41 +010033// Reserved Register Usage Summary.
34//
35// Registers t8, t9, and at are reserved for use by the MacroAssembler.
36//
37// The programmer should know that the MacroAssembler may clobber these three,
38// but won't touch other registers except in special cases.
39//
40// Per the MIPS ABI, register t9 must be used for indirect function call
41// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
42// trying to update gp register for position-independent-code. Whenever
43// MIPS generated code calls C code, it must be via t9 register.
Andrei Popescu31002712010-02-23 13:46:05 +000044
Ben Murdoch592a9fc2012-03-05 11:04:45 +000045
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046// Flags used for LeaveExitFrame function.
47enum LeaveExitFrameMode {
48 EMIT_RETURN = true,
49 NO_EMIT_RETURN = false
50};
51
52// Flags used for AllocateHeapNumber
53enum TaggingMode {
54 // Tag the result.
55 TAG_RESULT,
56 // Don't tag
57 DONT_TAG_RESULT
Steve Block44f0eee2011-05-26 01:26:41 +010058};
59
60// Flags used for the ObjectToDoubleFPURegister function.
61enum ObjectToDoubleFlags {
62 // No special flags.
63 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
64 // Object is known to be a non smi.
65 OBJECT_NOT_SMI = 1 << 0,
66 // Don't load NaNs or infinities, branch to the non number case instead.
67 AVOID_NANS_AND_INFINITIES = 1 << 1
68};
69
70// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
71enum BranchDelaySlot {
72 USE_DELAY_SLOT,
73 PROTECT
74};
75
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076// Flags used for the li macro-assembler function.
77enum LiFlags {
78 // If the constant value can be represented in just 16 bits, then
79 // optimize the li to use a single instruction, rather than lui/ori pair.
80 OPTIMIZE_SIZE = 0,
81 // Always use 2 instructions (lui/ori pair), even if the constant could
82 // be loaded with just one, so that this value is patchable later.
83 CONSTANT_SIZE = 1
84};
85
86
87enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
88enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089enum PointersToHereCheck {
90 kPointersToHereMaybeInteresting,
91 kPointersToHereAreAlwaysInteresting
92};
Ben Murdoch3ef787d2012-04-12 10:51:47 +010093enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
94
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095Register GetRegisterThatIsNotOneOf(Register reg1,
96 Register reg2 = no_reg,
97 Register reg3 = no_reg,
98 Register reg4 = no_reg,
99 Register reg5 = no_reg,
100 Register reg6 = no_reg);
101
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000102bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg,
103 Register reg4 = no_reg, Register reg5 = no_reg,
104 Register reg6 = no_reg, Register reg7 = no_reg,
105 Register reg8 = no_reg, Register reg9 = no_reg,
106 Register reg10 = no_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100107
108
109// -----------------------------------------------------------------------------
110// Static helper functions.
111
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112inline MemOperand ContextMemOperand(Register context, int index) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100113 return MemOperand(context, Context::SlotOffset(index));
114}
115
116
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117inline MemOperand NativeContextMemOperand() {
118 return ContextMemOperand(cp, Context::NATIVE_CONTEXT_INDEX);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100119}
120
121
122// Generate a MemOperand for loading a field from an object.
123inline MemOperand FieldMemOperand(Register object, int offset) {
124 return MemOperand(object, offset - kHeapObjectTag);
125}
126
127
128// Generate a MemOperand for storing arguments 5..N on the stack
129// when calling CallCFunction().
130inline MemOperand CFunctionArgumentOperand(int index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 DCHECK(index > kCArgSlotCount);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100132 // Argument 5 takes the slot just past the four Arg-slots.
133 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
134 return MemOperand(sp, offset);
135}
136
137
Andrei Popescu31002712010-02-23 13:46:05 +0000138// MacroAssembler implements a collection of frequently used macros.
139class MacroAssembler: public Assembler {
140 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 MacroAssembler(Isolate* isolate, void* buffer, int size,
142 CodeObjectRequired create_code_object);
Andrei Popescu31002712010-02-23 13:46:05 +0000143
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000144 // Arguments macros.
Steve Block44f0eee2011-05-26 01:26:41 +0100145#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
146#define COND_ARGS cond, r1, r2
147
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000148 // Cases when relocation is not needed.
Steve Block44f0eee2011-05-26 01:26:41 +0100149#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
150 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
151 inline void Name(BranchDelaySlot bd, target_type target) { \
152 Name(target, bd); \
153 } \
154 void Name(target_type target, \
155 COND_TYPED_ARGS, \
156 BranchDelaySlot bd = PROTECT); \
157 inline void Name(BranchDelaySlot bd, \
158 target_type target, \
159 COND_TYPED_ARGS) { \
160 Name(target, COND_ARGS, bd); \
161 }
162
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000163#define DECLARE_BRANCH_PROTOTYPES(Name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100164 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000165 DECLARE_NORELOC_PROTOTYPE(Name, int32_t)
Steve Block44f0eee2011-05-26 01:26:41 +0100166
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000167 DECLARE_BRANCH_PROTOTYPES(Branch)
168 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 DECLARE_BRANCH_PROTOTYPES(BranchShort)
Steve Block44f0eee2011-05-26 01:26:41 +0100170
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000171#undef DECLARE_BRANCH_PROTOTYPES
Steve Block44f0eee2011-05-26 01:26:41 +0100172#undef COND_TYPED_ARGS
173#undef COND_ARGS
Andrei Popescu31002712010-02-23 13:46:05 +0000174
Ben Murdoch257744e2011-11-30 15:57:28 +0000175
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000176 // Jump, Call, and Ret pseudo instructions implementing inter-working.
177#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
178 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
179
180 void Jump(Register target, COND_ARGS);
181 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
182 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
183 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100184 static int CallSize(Register target, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000185 void Call(Register target, COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100186 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000187 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000188 int CallSize(Handle<Code> code,
189 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
190 TypeFeedbackId ast_id = TypeFeedbackId::None(),
191 COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000192 void Call(Handle<Code> code,
193 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194 TypeFeedbackId ast_id = TypeFeedbackId::None(),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000195 COND_ARGS);
196 void Ret(COND_ARGS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100197 inline void Ret(BranchDelaySlot bd, Condition cond = al,
198 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
199 Ret(cond, rs, rt, bd);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000200 }
201
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000202 bool IsNear(Label* L, Condition cond, int rs_reg);
203
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100204 void Branch(Label* L,
205 Condition cond,
206 Register rs,
207 Heap::RootListIndex index,
208 BranchDelaySlot bdslot = PROTECT);
209
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000210#undef COND_ARGS
Ben Murdoch257744e2011-11-30 15:57:28 +0000211
Andrei Popescu31002712010-02-23 13:46:05 +0000212 // Emit code to discard a non-negative number of pointer-sized elements
213 // from the stack, clobbering only the sp register.
Steve Block44f0eee2011-05-26 01:26:41 +0100214 void Drop(int count,
215 Condition cond = cc_always,
216 Register reg = no_reg,
217 const Operand& op = Operand(no_reg));
218
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100219 // Trivial case of DropAndRet that utilizes the delay slot and only emits
220 // 2 instructions.
221 void DropAndRet(int drop);
222
223 void DropAndRet(int drop,
224 Condition cond,
225 Register reg,
226 const Operand& op);
Steve Block44f0eee2011-05-26 01:26:41 +0100227
228 // Swap two registers. If the scratch register is omitted then a slightly
229 // less efficient form using xor instead of mov is emitted.
230 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
Andrei Popescu31002712010-02-23 13:46:05 +0000231
232 void Call(Label* target);
Steve Block44f0eee2011-05-26 01:26:41 +0100233
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000234 void Move(Register dst, Smi* smi) { li(dst, Operand(smi)); }
235
Ben Murdoch257744e2011-11-30 15:57:28 +0000236 inline void Move(Register dst, Register src) {
237 if (!dst.is(src)) {
238 mov(dst, src);
239 }
240 }
241
242 inline void Move(FPURegister dst, FPURegister src) {
243 if (!dst.is(src)) {
244 mov_d(dst, src);
245 }
246 }
247
248 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
249 mfc1(dst_low, src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 Mfhc1(dst_high, src);
251 }
252
253 inline void FmoveHigh(Register dst_high, FPURegister src) {
254 Mfhc1(dst_high, src);
255 }
256
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000257 inline void FmoveHigh(FPURegister dst, Register src_high) {
258 Mthc1(src_high, dst);
259 }
260
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000261 inline void FmoveLow(Register dst_low, FPURegister src) {
262 mfc1(dst_low, src);
Ben Murdoch257744e2011-11-30 15:57:28 +0000263 }
264
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000265 void FmoveLow(FPURegister dst, Register src_low);
266
Ben Murdoch257744e2011-11-30 15:57:28 +0000267 inline void Move(FPURegister dst, Register src_low, Register src_high) {
268 mtc1(src_low, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000269 Mthc1(src_high, dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000270 }
Andrei Popescu31002712010-02-23 13:46:05 +0000271
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400272 void Move(FPURegister dst, float imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100273 void Move(FPURegister dst, double imm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400274
275 // Conditional move.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100276 void Movz(Register rd, Register rs, Register rt);
277 void Movn(Register rd, Register rs, Register rt);
278 void Movt(Register rd, Register rs, uint16_t cc = 0);
279 void Movf(Register rd, Register rs, uint16_t cc = 0);
280
281 void Clz(Register rd, Register rs);
282
Andrei Popescu31002712010-02-23 13:46:05 +0000283 // Jump unconditionally to given label.
284 // We NEED a nop in the branch delay slot, as it used by v8, for example in
285 // CodeGenerator::ProcessDeferred().
Steve Block6ded16b2010-05-10 14:33:55 +0100286 // Currently the branch delay slot is filled by the MacroAssembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000287 // Use rather b(Label) for code generation.
288 void jmp(Label* L) {
Steve Block44f0eee2011-05-26 01:26:41 +0100289 Branch(L);
Andrei Popescu31002712010-02-23 13:46:05 +0000290 }
291
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000292 void Load(Register dst, const MemOperand& src, Representation r);
293 void Store(Register src, const MemOperand& dst, Representation r);
294
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000295 void PushRoot(Heap::RootListIndex index) {
296 LoadRoot(at, index);
297 Push(at);
298 }
299
300 // Compare the object in a register to a value and jump if they are equal.
301 void JumpIfRoot(Register with, Heap::RootListIndex index, Label* if_equal) {
302 LoadRoot(at, index);
303 Branch(if_equal, eq, with, Operand(at));
304 }
305
306 // Compare the object in a register to a value and jump if they are not equal.
307 void JumpIfNotRoot(Register with, Heap::RootListIndex index,
308 Label* if_not_equal) {
309 LoadRoot(at, index);
310 Branch(if_not_equal, ne, with, Operand(at));
311 }
312
Andrei Popescu31002712010-02-23 13:46:05 +0000313 // Load an object from the root table.
314 void LoadRoot(Register destination,
315 Heap::RootListIndex index);
316 void LoadRoot(Register destination,
317 Heap::RootListIndex index,
318 Condition cond, Register src1, const Operand& src2);
319
Steve Block44f0eee2011-05-26 01:26:41 +0100320 // Store an object to the root table.
321 void StoreRoot(Register source,
322 Heap::RootListIndex index);
323 void StoreRoot(Register source,
324 Heap::RootListIndex index,
325 Condition cond, Register src1, const Operand& src2);
326
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100327 // ---------------------------------------------------------------------------
328 // GC Support
329
330 void IncrementalMarkingRecordWriteHelper(Register object,
331 Register value,
332 Register address);
333
334 enum RememberedSetFinalAction {
335 kReturnAtEnd,
336 kFallThroughAtEnd
337 };
Steve Block44f0eee2011-05-26 01:26:41 +0100338
339
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100340 // Record in the remembered set the fact that we have a pointer to new space
341 // at the address pointed to by the addr register. Only works if addr is not
342 // in new space.
343 void RememberedSetHelper(Register object, // Used for debug code.
344 Register addr,
345 Register scratch,
346 SaveFPRegsMode save_fp,
347 RememberedSetFinalAction and_then);
Steve Block44f0eee2011-05-26 01:26:41 +0100348
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100349 void CheckPageFlag(Register object,
350 Register scratch,
351 int mask,
352 Condition cc,
353 Label* condition_met);
354
355 // Check if object is in new space. Jumps if the object is not in new space.
356 // The register scratch can be object itself, but it will be clobbered.
357 void JumpIfNotInNewSpace(Register object,
358 Register scratch,
359 Label* branch) {
360 InNewSpace(object, scratch, ne, branch);
361 }
362
363 // Check if object is in new space. Jumps if the object is in new space.
364 // The register scratch can be object itself, but scratch will be clobbered.
365 void JumpIfInNewSpace(Register object,
366 Register scratch,
367 Label* branch) {
368 InNewSpace(object, scratch, eq, branch);
369 }
370
371 // Check if an object has a given incremental marking color.
372 void HasColor(Register object,
373 Register scratch0,
374 Register scratch1,
375 Label* has_color,
376 int first_bit,
377 int second_bit);
378
379 void JumpIfBlack(Register object,
Steve Block44f0eee2011-05-26 01:26:41 +0100380 Register scratch0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100381 Register scratch1,
382 Label* on_black);
Steve Block44f0eee2011-05-26 01:26:41 +0100383
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000384 // Checks the color of an object. If the object is white we jump to the
385 // incremental marker.
386 void JumpIfWhite(Register value, Register scratch1, Register scratch2,
387 Register scratch3, Label* value_is_white);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100388
389 // Notify the garbage collector that we wrote a pointer into an object.
390 // |object| is the object being stored into, |value| is the object being
391 // stored. value and scratch registers are clobbered by the operation.
392 // The offset is the offset from the start of the object, not the offset from
393 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
394 void RecordWriteField(
395 Register object,
396 int offset,
397 Register value,
398 Register scratch,
399 RAStatus ra_status,
400 SaveFPRegsMode save_fp,
401 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000402 SmiCheck smi_check = INLINE_SMI_CHECK,
403 PointersToHereCheck pointers_to_here_check_for_value =
404 kPointersToHereMaybeInteresting);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100405
406 // As above, but the offset has the tag presubtracted. For use with
407 // MemOperand(reg, off).
408 inline void RecordWriteContextSlot(
409 Register context,
410 int offset,
411 Register value,
412 Register scratch,
413 RAStatus ra_status,
414 SaveFPRegsMode save_fp,
415 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000416 SmiCheck smi_check = INLINE_SMI_CHECK,
417 PointersToHereCheck pointers_to_here_check_for_value =
418 kPointersToHereMaybeInteresting) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100419 RecordWriteField(context,
420 offset + kHeapObjectTag,
421 value,
422 scratch,
423 ra_status,
424 save_fp,
425 remembered_set_action,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000426 smi_check,
427 pointers_to_here_check_for_value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100428 }
429
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000430 void RecordWriteForMap(
431 Register object,
432 Register map,
433 Register dst,
434 RAStatus ra_status,
435 SaveFPRegsMode save_fp);
436
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100437 // For a given |object| notify the garbage collector that the slot |address|
438 // has been written. |value| is the object being stored. The value and
439 // address registers are clobbered by the operation.
440 void RecordWrite(
441 Register object,
442 Register address,
443 Register value,
444 RAStatus ra_status,
445 SaveFPRegsMode save_fp,
446 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000447 SmiCheck smi_check = INLINE_SMI_CHECK,
448 PointersToHereCheck pointers_to_here_check_for_value =
449 kPointersToHereMaybeInteresting);
Steve Block44f0eee2011-05-26 01:26:41 +0100450
451
452 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000453 // Inline caching support.
Steve Block44f0eee2011-05-26 01:26:41 +0100454
455 // Generate code for checking access rights - used for security checks
456 // on access to global objects across environments. The holder register
457 // is left untouched, whereas both scratch registers are clobbered.
458 void CheckAccessGlobalProxy(Register holder_reg,
459 Register scratch,
460 Label* miss);
461
Ben Murdochc7cc0282012-03-05 14:35:55 +0000462 void GetNumberHash(Register reg0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000463
464 void LoadFromNumberDictionary(Label* miss,
465 Register elements,
466 Register key,
467 Register result,
468 Register reg0,
469 Register reg1,
470 Register reg2);
471
472
Steve Block44f0eee2011-05-26 01:26:41 +0100473 inline void MarkCode(NopMarkerTypes type) {
474 nop(type);
Steve Block6ded16b2010-05-10 14:33:55 +0100475 }
476
Steve Block44f0eee2011-05-26 01:26:41 +0100477 // Check if the given instruction is a 'type' marker.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100478 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
Steve Block44f0eee2011-05-26 01:26:41 +0100479 // nop(type)). These instructions are generated to mark special location in
480 // the code, like some special IC code.
481 static inline bool IsMarkedCode(Instr instr, int type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000482 DCHECK((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
Steve Block44f0eee2011-05-26 01:26:41 +0100483 return IsNop(instr, type);
484 }
Andrei Popescu31002712010-02-23 13:46:05 +0000485
486
Steve Block44f0eee2011-05-26 01:26:41 +0100487 static inline int GetCodeMarker(Instr instr) {
488 uint32_t opcode = ((instr & kOpcodeMask));
489 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
490 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
491 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
492
493 // Return <n> if we have a sll zero_reg, zero_reg, n
494 // else return -1.
495 bool sllzz = (opcode == SLL &&
496 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
497 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
498 int type =
499 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000500 DCHECK((type == -1) ||
Steve Block44f0eee2011-05-26 01:26:41 +0100501 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
502 return type;
503 }
504
505
506
507 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000508 // Allocation support.
Steve Block44f0eee2011-05-26 01:26:41 +0100509
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000510 // Allocate an object in new space or old space. The object_size is
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000511 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
512 // is passed. If the space is exhausted control continues at the gc_required
513 // label. The allocated object is returned in result. If the flag
514 // tag_allocated_object is true the result is tagged as as a heap object.
515 // All registers are clobbered also when control continues at the gc_required
516 // label.
517 void Allocate(int object_size,
518 Register result,
519 Register scratch1,
520 Register scratch2,
521 Label* gc_required,
522 AllocationFlags flags);
523
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 void Allocate(Register object_size, Register result, Register result_new,
525 Register scratch, Label* gc_required, AllocationFlags flags);
Steve Block44f0eee2011-05-26 01:26:41 +0100526
527 void AllocateTwoByteString(Register result,
528 Register length,
529 Register scratch1,
530 Register scratch2,
531 Register scratch3,
532 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000533 void AllocateOneByteString(Register result, Register length,
534 Register scratch1, Register scratch2,
535 Register scratch3, Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100536 void AllocateTwoByteConsString(Register result,
537 Register length,
538 Register scratch1,
539 Register scratch2,
540 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000541 void AllocateOneByteConsString(Register result, Register length,
542 Register scratch1, Register scratch2,
543 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000544 void AllocateTwoByteSlicedString(Register result,
545 Register length,
546 Register scratch1,
547 Register scratch2,
548 Label* gc_required);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000549 void AllocateOneByteSlicedString(Register result, Register length,
550 Register scratch1, Register scratch2,
551 Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100552
553 // Allocates a heap number or jumps to the gc_required label if the young
554 // space is full and a scavenge is needed. All registers are clobbered also
555 // when control continues at the gc_required label.
556 void AllocateHeapNumber(Register result,
557 Register scratch1,
558 Register scratch2,
559 Register heap_number_map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000560 Label* gc_required,
561 TaggingMode tagging_mode = TAG_RESULT,
562 MutableMode mode = IMMUTABLE);
Steve Block44f0eee2011-05-26 01:26:41 +0100563 void AllocateHeapNumberWithValue(Register result,
564 FPURegister value,
565 Register scratch1,
566 Register scratch2,
567 Label* gc_required);
568
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000569 // Allocate and initialize a JSValue wrapper with the specified {constructor}
570 // and {value}.
571 void AllocateJSValue(Register result, Register constructor, Register value,
572 Register scratch1, Register scratch2,
573 Label* gc_required);
574
Andrei Popescu31002712010-02-23 13:46:05 +0000575 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000576 // Instruction macros.
Andrei Popescu31002712010-02-23 13:46:05 +0000577
Steve Block44f0eee2011-05-26 01:26:41 +0100578#define DEFINE_INSTRUCTION(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000579 void instr(Register rd, Register rs, const Operand& rt); \
580 void instr(Register rd, Register rs, Register rt) { \
581 instr(rd, rs, Operand(rt)); \
582 } \
583 void instr(Register rs, Register rt, int32_t j) { \
584 instr(rs, rt, Operand(j)); \
585 }
586
Steve Block44f0eee2011-05-26 01:26:41 +0100587#define DEFINE_INSTRUCTION2(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000588 void instr(Register rs, const Operand& rt); \
589 void instr(Register rs, Register rt) { \
590 instr(rs, Operand(rt)); \
591 } \
592 void instr(Register rs, int32_t j) { \
593 instr(rs, Operand(j)); \
594 }
595
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000596#define DEFINE_INSTRUCTION3(instr) \
597 void instr(Register rd_hi, Register rd_lo, Register rs, const Operand& rt); \
598 void instr(Register rd_hi, Register rd_lo, Register rs, Register rt) { \
599 instr(rd_hi, rd_lo, rs, Operand(rt)); \
600 } \
601 void instr(Register rd_hi, Register rd_lo, Register rs, int32_t j) { \
602 instr(rd_hi, rd_lo, rs, Operand(j)); \
603 }
604
Andrei Popescu31002712010-02-23 13:46:05 +0000605 DEFINE_INSTRUCTION(Addu);
Steve Block44f0eee2011-05-26 01:26:41 +0100606 DEFINE_INSTRUCTION(Subu);
Andrei Popescu31002712010-02-23 13:46:05 +0000607 DEFINE_INSTRUCTION(Mul);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400608 DEFINE_INSTRUCTION(Div);
609 DEFINE_INSTRUCTION(Divu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000610 DEFINE_INSTRUCTION(Mod);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400611 DEFINE_INSTRUCTION(Modu);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000612 DEFINE_INSTRUCTION(Mulh);
Andrei Popescu31002712010-02-23 13:46:05 +0000613 DEFINE_INSTRUCTION2(Mult);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400614 DEFINE_INSTRUCTION(Mulhu);
Andrei Popescu31002712010-02-23 13:46:05 +0000615 DEFINE_INSTRUCTION2(Multu);
616 DEFINE_INSTRUCTION2(Div);
617 DEFINE_INSTRUCTION2(Divu);
618
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000619 DEFINE_INSTRUCTION3(Div);
620 DEFINE_INSTRUCTION3(Mul);
621
Andrei Popescu31002712010-02-23 13:46:05 +0000622 DEFINE_INSTRUCTION(And);
623 DEFINE_INSTRUCTION(Or);
624 DEFINE_INSTRUCTION(Xor);
625 DEFINE_INSTRUCTION(Nor);
Ben Murdoch257744e2011-11-30 15:57:28 +0000626 DEFINE_INSTRUCTION2(Neg);
Andrei Popescu31002712010-02-23 13:46:05 +0000627
628 DEFINE_INSTRUCTION(Slt);
629 DEFINE_INSTRUCTION(Sltu);
630
Steve Block44f0eee2011-05-26 01:26:41 +0100631 // MIPS32 R2 instruction macro.
632 DEFINE_INSTRUCTION(Ror);
633
Andrei Popescu31002712010-02-23 13:46:05 +0000634#undef DEFINE_INSTRUCTION
635#undef DEFINE_INSTRUCTION2
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000636#undef DEFINE_INSTRUCTION3
Andrei Popescu31002712010-02-23 13:46:05 +0000637
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000638 void Lsa(Register rd, Register rs, Register rt, uint8_t sa,
639 Register scratch = at);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640 void Pref(int32_t hint, const MemOperand& rs);
641
Andrei Popescu31002712010-02-23 13:46:05 +0000642
Ben Murdoch257744e2011-11-30 15:57:28 +0000643 // ---------------------------------------------------------------------------
644 // Pseudo-instructions.
Andrei Popescu31002712010-02-23 13:46:05 +0000645
646 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
Andrei Popescu31002712010-02-23 13:46:05 +0000647
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648 void Ulw(Register rd, const MemOperand& rs);
649 void Usw(Register rd, const MemOperand& rs);
650
Ben Murdoch257744e2011-11-30 15:57:28 +0000651 // Load int32 in the rd register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100652 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
653 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
654 li(rd, Operand(j), mode);
Andrei Popescu31002712010-02-23 13:46:05 +0000655 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
Andrei Popescu31002712010-02-23 13:46:05 +0000657
Andrei Popescu31002712010-02-23 13:46:05 +0000658 // Push multiple registers on the stack.
Steve Block6ded16b2010-05-10 14:33:55 +0100659 // Registers are saved in numerical order, with higher numbered registers
Ben Murdoch257744e2011-11-30 15:57:28 +0000660 // saved in higher memory addresses.
Andrei Popescu31002712010-02-23 13:46:05 +0000661 void MultiPush(RegList regs);
662 void MultiPushReversed(RegList regs);
Steve Block44f0eee2011-05-26 01:26:41 +0100663
Ben Murdoch589d6972011-11-30 16:04:58 +0000664 void MultiPushFPU(RegList regs);
665 void MultiPushReversedFPU(RegList regs);
666
Ben Murdoch257744e2011-11-30 15:57:28 +0000667 void push(Register src) {
Andrei Popescu31002712010-02-23 13:46:05 +0000668 Addu(sp, sp, Operand(-kPointerSize));
669 sw(src, MemOperand(sp, 0));
670 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000671 void Push(Register src) { push(src); }
Steve Block44f0eee2011-05-26 01:26:41 +0100672
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000673 // Push a handle.
674 void Push(Handle<Object> handle);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000675 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000676
Ben Murdoch257744e2011-11-30 15:57:28 +0000677 // Push two registers. Pushes leftmost register first (to highest address).
678 void Push(Register src1, Register src2) {
Steve Block44f0eee2011-05-26 01:26:41 +0100679 Subu(sp, sp, Operand(2 * kPointerSize));
680 sw(src1, MemOperand(sp, 1 * kPointerSize));
681 sw(src2, MemOperand(sp, 0 * kPointerSize));
682 }
683
Ben Murdoch257744e2011-11-30 15:57:28 +0000684 // Push three registers. Pushes leftmost register first (to highest address).
685 void Push(Register src1, Register src2, Register src3) {
686 Subu(sp, sp, Operand(3 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100687 sw(src1, MemOperand(sp, 2 * kPointerSize));
688 sw(src2, MemOperand(sp, 1 * kPointerSize));
689 sw(src3, MemOperand(sp, 0 * kPointerSize));
690 }
691
Ben Murdoch257744e2011-11-30 15:57:28 +0000692 // Push four registers. Pushes leftmost register first (to highest address).
693 void Push(Register src1, Register src2, Register src3, Register src4) {
694 Subu(sp, sp, Operand(4 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100695 sw(src1, MemOperand(sp, 3 * kPointerSize));
696 sw(src2, MemOperand(sp, 2 * kPointerSize));
697 sw(src3, MemOperand(sp, 1 * kPointerSize));
698 sw(src4, MemOperand(sp, 0 * kPointerSize));
699 }
700
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000701 // Push five registers. Pushes leftmost register first (to highest address).
702 void Push(Register src1, Register src2, Register src3, Register src4,
703 Register src5) {
704 Subu(sp, sp, Operand(5 * kPointerSize));
705 sw(src1, MemOperand(sp, 4 * kPointerSize));
706 sw(src2, MemOperand(sp, 3 * kPointerSize));
707 sw(src3, MemOperand(sp, 2 * kPointerSize));
708 sw(src4, MemOperand(sp, 1 * kPointerSize));
709 sw(src5, MemOperand(sp, 0 * kPointerSize));
710 }
711
Andrei Popescu31002712010-02-23 13:46:05 +0000712 void Push(Register src, Condition cond, Register tst1, Register tst2) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000713 // Since we don't have conditional execution we use a Branch.
Steve Block44f0eee2011-05-26 01:26:41 +0100714 Branch(3, cond, tst1, Operand(tst2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000715 Subu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000716 sw(src, MemOperand(sp, 0));
717 }
718
719 // Pops multiple values from the stack and load them in the
720 // registers specified in regs. Pop order is the opposite as in MultiPush.
721 void MultiPop(RegList regs);
722 void MultiPopReversed(RegList regs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000723
Ben Murdoch589d6972011-11-30 16:04:58 +0000724 void MultiPopFPU(RegList regs);
725 void MultiPopReversedFPU(RegList regs);
726
Ben Murdoch257744e2011-11-30 15:57:28 +0000727 void pop(Register dst) {
Andrei Popescu31002712010-02-23 13:46:05 +0000728 lw(dst, MemOperand(sp, 0));
729 Addu(sp, sp, Operand(kPointerSize));
730 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000731 void Pop(Register dst) { pop(dst); }
Ben Murdoch257744e2011-11-30 15:57:28 +0000732
733 // Pop two registers. Pops rightmost register first (from lower address).
734 void Pop(Register src1, Register src2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000735 DCHECK(!src1.is(src2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000736 lw(src2, MemOperand(sp, 0 * kPointerSize));
737 lw(src1, MemOperand(sp, 1 * kPointerSize));
738 Addu(sp, sp, 2 * kPointerSize);
739 }
740
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100741 // Pop three registers. Pops rightmost register first (from lower address).
742 void Pop(Register src1, Register src2, Register src3) {
743 lw(src3, MemOperand(sp, 0 * kPointerSize));
744 lw(src2, MemOperand(sp, 1 * kPointerSize));
745 lw(src1, MemOperand(sp, 2 * kPointerSize));
746 Addu(sp, sp, 3 * kPointerSize);
747 }
748
Steve Block44f0eee2011-05-26 01:26:41 +0100749 void Pop(uint32_t count = 1) {
750 Addu(sp, sp, Operand(count * kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000751 }
752
Steve Block44f0eee2011-05-26 01:26:41 +0100753 // Push and pop the registers that can hold pointers, as defined by the
754 // RegList constant kSafepointSavedRegisters.
Ben Murdoch257744e2011-11-30 15:57:28 +0000755 void PushSafepointRegisters();
756 void PopSafepointRegisters();
Ben Murdoch257744e2011-11-30 15:57:28 +0000757 // Store value in register src in the safepoint stack slot for
758 // register dst.
759 void StoreToSafepointRegisterSlot(Register src, Register dst);
Ben Murdoch257744e2011-11-30 15:57:28 +0000760 // Load the value of the src register from its safepoint stack slot
761 // into register dst.
762 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Steve Block44f0eee2011-05-26 01:26:41 +0100763
764 // MIPS32 R2 instruction macro.
765 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
766 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
767
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100768 // ---------------------------------------------------------------------------
769 // FPU macros. These do not handle special cases like NaN or +- inf.
770
Steve Block44f0eee2011-05-26 01:26:41 +0100771 // Convert unsigned word to double.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000772 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100773
774 // Convert double to unsigned word.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000775 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
776 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100777
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100778 void Trunc_w_d(FPURegister fd, FPURegister fs);
779 void Round_w_d(FPURegister fd, FPURegister fs);
780 void Floor_w_d(FPURegister fd, FPURegister fs);
781 void Ceil_w_d(FPURegister fd, FPURegister fs);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000782
783 // FP32 mode: Move the general purpose register into
784 // the high part of the double-register pair.
785 // FP64 mode: Move the general-purpose register into
786 // the higher 32 bits of the 64-bit coprocessor register,
787 // while leaving the low bits unchanged.
788 void Mthc1(Register rt, FPURegister fs);
789
790 // FP32 mode: move the high part of the double-register pair into
791 // general purpose register.
792 // FP64 mode: Move the higher 32 bits of the 64-bit coprocessor register into
793 // general-purpose register.
794 void Mfhc1(Register rt, FPURegister fs);
795
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000796 // Wrapper functions for the different cmp/branch types.
797 inline void BranchF32(Label* target, Label* nan, Condition cc,
798 FPURegister cmp1, FPURegister cmp2,
799 BranchDelaySlot bd = PROTECT) {
800 BranchFCommon(S, target, nan, cc, cmp1, cmp2, bd);
801 }
802
803 inline void BranchF64(Label* target, Label* nan, Condition cc,
804 FPURegister cmp1, FPURegister cmp2,
805 BranchDelaySlot bd = PROTECT) {
806 BranchFCommon(D, target, nan, cc, cmp1, cmp2, bd);
807 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100808
809 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000810 inline void BranchF64(BranchDelaySlot bd, Label* target, Label* nan,
811 Condition cc, FPURegister cmp1, FPURegister cmp2) {
812 BranchF64(target, nan, cc, cmp1, cmp2, bd);
813 }
814
815 inline void BranchF32(BranchDelaySlot bd, Label* target, Label* nan,
816 Condition cc, FPURegister cmp1, FPURegister cmp2) {
817 BranchF32(target, nan, cc, cmp1, cmp2, bd);
818 }
819
820 // Alias functions for backward compatibility.
821 inline void BranchF(Label* target, Label* nan, Condition cc, FPURegister cmp1,
822 FPURegister cmp2, BranchDelaySlot bd = PROTECT) {
823 BranchF64(target, nan, cc, cmp1, cmp2, bd);
824 }
825
826 inline void BranchF(BranchDelaySlot bd, Label* target, Label* nan,
827 Condition cc, FPURegister cmp1, FPURegister cmp2) {
828 BranchF64(bd, target, nan, cc, cmp1, cmp2);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000829 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100830
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000831 // Truncates a double using a specific rounding mode, and writes the value
832 // to the result register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100833 // The except_flag will contain any exceptions caused by the instruction.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834 // If check_inexact is kDontCheckForInexactConversion, then the inexact
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100835 // exception is masked.
836 void EmitFPUTruncate(FPURoundingMode rounding_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000837 Register result,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100838 DoubleRegister double_input,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000839 Register scratch,
840 DoubleRegister double_scratch,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100841 Register except_flag,
842 CheckForInexactConversion check_inexact
843 = kDontCheckForInexactConversion);
844
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000845 // Performs a truncating conversion of a floating point number as used by
846 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
847 // succeeds, otherwise falls through if result is saturated. On return
848 // 'result' either holds answer, or is clobbered on fall through.
849 //
850 // Only public for the test code in test-code-stubs-arm.cc.
851 void TryInlineTruncateDoubleToI(Register result,
852 DoubleRegister input,
853 Label* done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000854
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000855 // Performs a truncating conversion of a floating point number as used by
856 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000857 // Exits with 'result' holding the answer.
858 void TruncateDoubleToI(Register result, DoubleRegister double_input);
859
860 // Performs a truncating conversion of a heap number as used by
861 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
862 // must be different registers. Exits with 'result' holding the answer.
863 void TruncateHeapNumberToI(Register result, Register object);
864
865 // Converts the smi or heap number in object to an int32 using the rules
866 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
867 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
868 // different registers.
869 void TruncateNumberToI(Register object,
870 Register result,
871 Register heap_number_map,
872 Register scratch,
873 Label* not_int32);
874
875 // Loads the number from object into dst register.
876 // If |object| is neither smi nor heap number, |not_number| is jumped to
877 // with |object| still intact.
878 void LoadNumber(Register object,
879 FPURegister dst,
880 Register heap_number_map,
881 Register scratch,
882 Label* not_number);
883
884 // Loads the number from object into double_dst in the double format.
885 // Control will jump to not_int32 if the value cannot be exactly represented
886 // by a 32-bit integer.
887 // Floating point value in the 32-bit integer range that are not exact integer
888 // won't be loaded.
889 void LoadNumberAsInt32Double(Register object,
890 DoubleRegister double_dst,
891 Register heap_number_map,
892 Register scratch1,
893 Register scratch2,
894 FPURegister double_scratch,
895 Label* not_int32);
896
897 // Loads the number from object into dst as a 32-bit integer.
898 // Control will jump to not_int32 if the object cannot be exactly represented
899 // by a 32-bit integer.
900 // Floating point value in the 32-bit integer range that are not exact integer
901 // won't be converted.
902 void LoadNumberAsInt32(Register object,
903 Register dst,
904 Register heap_number_map,
905 Register scratch1,
906 Register scratch2,
907 FPURegister double_scratch0,
908 FPURegister double_scratch1,
909 Label* not_int32);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000910
Steve Block44f0eee2011-05-26 01:26:41 +0100911 // Enter exit frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000912 // argc - argument count to be dropped by LeaveExitFrame.
913 // save_doubles - saves FPU registers on stack, currently disabled.
914 // stack_space - extra stack space.
915 void EnterExitFrame(bool save_doubles,
916 int stack_space = 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100917
Ben Murdoch257744e2011-11-30 15:57:28 +0000918 // Leave the current exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000919 void LeaveExitFrame(bool save_doubles, Register arg_count,
920 bool restore_context, bool do_return = NO_EMIT_RETURN,
921 bool argument_count_is_length = false);
Steve Block6ded16b2010-05-10 14:33:55 +0100922
Steve Block44f0eee2011-05-26 01:26:41 +0100923 // Get the actual activation frame alignment for target environment.
924 static int ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +0100925
Ben Murdoch257744e2011-11-30 15:57:28 +0000926 // Make sure the stack is aligned. Only emits code in debug mode.
927 void AssertStackIsAligned();
928
Steve Block44f0eee2011-05-26 01:26:41 +0100929 void LoadContext(Register dst, int context_chain_length);
Steve Block6ded16b2010-05-10 14:33:55 +0100930
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000931 // Load the global object from the current context.
932 void LoadGlobalObject(Register dst) {
933 LoadNativeContextSlot(Context::EXTENSION_INDEX, dst);
934 }
935
936 // Load the global proxy from the current context.
937 void LoadGlobalProxy(Register dst) {
938 LoadNativeContextSlot(Context::GLOBAL_PROXY_INDEX, dst);
939 }
940
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100941 // Conditionally load the cached Array transitioned map of type
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 // transitioned_kind from the native context if the map in register
943 // map_in_out is the cached Array map in the native context of
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100944 // expected_kind.
945 void LoadTransitionedArrayMapConditional(
946 ElementsKind expected_kind,
947 ElementsKind transitioned_kind,
948 Register map_in_out,
949 Register scratch,
950 Label* no_map_match);
951
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000952 void LoadNativeContextSlot(int index, Register dst);
Steve Block44f0eee2011-05-26 01:26:41 +0100953
954 // Load the initial map from the global function. The registers
955 // function and map can be the same, function is then overwritten.
956 void LoadGlobalFunctionInitialMap(Register function,
957 Register map,
958 Register scratch);
959
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100960 void InitializeRootRegister() {
961 ExternalReference roots_array_start =
962 ExternalReference::roots_array_start(isolate());
963 li(kRootRegister, Operand(roots_array_start));
964 }
965
Steve Block44f0eee2011-05-26 01:26:41 +0100966 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000967 // JavaScript invokes.
968
Steve Block6ded16b2010-05-10 14:33:55 +0100969 // Invoke the JavaScript function code by either calling or jumping.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000970
971 void InvokeFunctionCode(Register function, Register new_target,
972 const ParameterCount& expected,
973 const ParameterCount& actual, InvokeFlag flag,
974 const CallWrapper& call_wrapper);
975
976 void FloodFunctionIfStepping(Register fun, Register new_target,
977 const ParameterCount& expected,
978 const ParameterCount& actual);
Steve Block6ded16b2010-05-10 14:33:55 +0100979
980 // Invoke the JavaScript function in the given register. Changes the
981 // current context to the context in the function before invoking.
982 void InvokeFunction(Register function,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000983 Register new_target,
Steve Block6ded16b2010-05-10 14:33:55 +0100984 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +0100985 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 const CallWrapper& call_wrapper);
Steve Block44f0eee2011-05-26 01:26:41 +0100987
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000988 void InvokeFunction(Register function,
989 const ParameterCount& expected,
Steve Block44f0eee2011-05-26 01:26:41 +0100990 const ParameterCount& actual,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000991 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000992 const CallWrapper& call_wrapper);
993
994 void InvokeFunction(Handle<JSFunction> function,
995 const ParameterCount& expected,
996 const ParameterCount& actual,
997 InvokeFlag flag,
998 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +0100999
Steve Block44f0eee2011-05-26 01:26:41 +01001000 void IsObjectJSStringType(Register object,
1001 Register scratch,
1002 Label* fail);
1003
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001004 void IsObjectNameType(Register object,
1005 Register scratch,
1006 Label* fail);
1007
Steve Block44f0eee2011-05-26 01:26:41 +01001008 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001009 // Debugger Support.
Steve Block6ded16b2010-05-10 14:33:55 +01001010
Steve Block6ded16b2010-05-10 14:33:55 +01001011 void DebugBreak();
Steve Block6ded16b2010-05-10 14:33:55 +01001012
Steve Block44f0eee2011-05-26 01:26:41 +01001013 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001014 // Exception handling.
Andrei Popescu31002712010-02-23 13:46:05 +00001015
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001016 // Push a new stack handler and link into stack handler chain.
1017 void PushStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001018
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001019 // Unlink the stack handler on top of the stack from the stack handler chain.
Andrei Popescu31002712010-02-23 13:46:05 +00001020 // Must preserve the result register.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001021 void PopStackHandler();
Andrei Popescu31002712010-02-23 13:46:05 +00001022
Ben Murdoch257744e2011-11-30 15:57:28 +00001023 // Copies a number of bytes from src to dst. All registers are clobbered. On
1024 // exit src and dst will point to the place just after where the last byte was
1025 // read or written and length will be zero.
1026 void CopyBytes(Register src,
1027 Register dst,
1028 Register length,
1029 Register scratch);
1030
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031 // Initialize fields with filler values. Fields starting at |current_address|
1032 // not including |end_address| are overwritten with the value in |filler|. At
1033 // the end the loop, |current_address| takes the value of |end_address|.
1034 void InitializeFieldsWithFiller(Register current_address,
1035 Register end_address, Register filler);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001036
Steve Block44f0eee2011-05-26 01:26:41 +01001037 // -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001038 // Support functions.
1039
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001040 // Machine code version of Map::GetConstructor().
1041 // |temp| holds |result|'s map when done, and |temp2| its instance type.
1042 void GetMapConstructor(Register result, Register map, Register temp,
1043 Register temp2);
1044
Steve Block44f0eee2011-05-26 01:26:41 +01001045 // Try to get function prototype of a function and puts the value in
1046 // the result register. Checks that the function really is a
1047 // function and jumps to the miss label if the fast checks fail. The
1048 // function register will be untouched; the other registers may be
1049 // clobbered.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001050 void TryGetFunctionPrototype(Register function, Register result,
1051 Register scratch, Label* miss);
Steve Block44f0eee2011-05-26 01:26:41 +01001052
Steve Block6ded16b2010-05-10 14:33:55 +01001053 void GetObjectType(Register function,
1054 Register map,
1055 Register type_reg);
1056
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001057 // Check if a map for a JSObject indicates that the object has fast elements.
1058 // Jump to the specified label if it does not.
1059 void CheckFastElements(Register map,
1060 Register scratch,
1061 Label* fail);
1062
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001063 // Check if a map for a JSObject indicates that the object can have both smi
1064 // and HeapObject elements. Jump to the specified label if it does not.
1065 void CheckFastObjectElements(Register map,
1066 Register scratch,
1067 Label* fail);
1068
1069 // Check if a map for a JSObject indicates that the object has fast smi only
1070 // elements. Jump to the specified label if it does not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001071 void CheckFastSmiElements(Register map,
1072 Register scratch,
1073 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001074
1075 // Check to see if maybe_number can be stored as a double in
1076 // FastDoubleElements. If it can, store it at the index specified by key in
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001077 // the FastDoubleElements array elements. Otherwise jump to fail.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001078 void StoreNumberToDoubleElements(Register value_reg,
1079 Register key_reg,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001080 Register elements_reg,
1081 Register scratch1,
1082 Register scratch2,
1083 Register scratch3,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001084 Label* fail,
1085 int elements_offset = 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001086
1087 // Compare an object's map with the specified map and its transitioned
1088 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1089 // "branch_to" if the result of the comparison is "cond". If multiple map
1090 // compares are required, the compare sequences branches to early_success.
1091 void CompareMapAndBranch(Register obj,
1092 Register scratch,
1093 Handle<Map> map,
1094 Label* early_success,
1095 Condition cond,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001096 Label* branch_to);
1097
1098 // As above, but the map of the object is already loaded into the register
1099 // which is preserved by the code generated.
1100 void CompareMapAndBranch(Register obj_map,
1101 Handle<Map> map,
1102 Label* early_success,
1103 Condition cond,
1104 Label* branch_to);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001105
1106 // Check if the map of an object is equal to a specified map and branch to
1107 // label if not. Skip the smi check if not required (object is known to be a
1108 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1109 // against maps that are ElementsKind transition maps of the specificed map.
Steve Block44f0eee2011-05-26 01:26:41 +01001110 void CheckMap(Register obj,
1111 Register scratch,
1112 Handle<Map> map,
1113 Label* fail,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001114 SmiCheckType smi_check_type);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001115
Andrei Popescu31002712010-02-23 13:46:05 +00001116
Steve Block44f0eee2011-05-26 01:26:41 +01001117 void CheckMap(Register obj,
1118 Register scratch,
1119 Heap::RootListIndex index,
1120 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +00001121 SmiCheckType smi_check_type);
1122
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001123 // Check if the map of an object is equal to a specified weak map and branch
1124 // to a specified target if equal. Skip the smi check if not required
1125 // (object is known to be a heap object)
1126 void DispatchWeakMap(Register obj, Register scratch1, Register scratch2,
1127 Handle<WeakCell> cell, Handle<Code> success,
1128 SmiCheckType smi_check_type);
Steve Block6ded16b2010-05-10 14:33:55 +01001129
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001130 // Get value of the weak cell.
1131 void GetWeakValue(Register value, Handle<WeakCell> cell);
1132
1133 // Load the value of the weak cell in the value register. Branch to the
1134 // given miss label is the weak cell was cleared.
1135 void LoadWeakValue(Register value, Handle<WeakCell> cell, Label* miss);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001136
1137 // Load and check the instance type of an object for being a string.
1138 // Loads the type into the second argument register.
1139 // Returns a condition that will be enabled if the object was a string.
1140 Condition IsObjectStringType(Register obj,
1141 Register type,
1142 Register result) {
1143 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1144 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1145 And(type, type, Operand(kIsNotStringMask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001146 DCHECK_EQ(0u, kStringTag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001147 return eq;
1148 }
1149
1150
Steve Block44f0eee2011-05-26 01:26:41 +01001151 // Picks out an array index from the hash field.
1152 // Register use:
1153 // hash - holds the index's hash. Clobbered.
1154 // index - holds the overwritten index on exit.
1155 void IndexFromHash(Register hash, Register index);
Andrei Popescu31002712010-02-23 13:46:05 +00001156
Ben Murdoch257744e2011-11-30 15:57:28 +00001157 // Get the number of least significant bits from a register.
1158 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1159 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1160
Steve Block44f0eee2011-05-26 01:26:41 +01001161 // Load the value of a number object into a FPU double register. If the
1162 // object is not a number a jump to the label not_number is performed
1163 // and the FPU double register is unchanged.
1164 void ObjectToDoubleFPURegister(
1165 Register object,
1166 FPURegister value,
1167 Register scratch1,
1168 Register scratch2,
1169 Register heap_number_map,
1170 Label* not_number,
1171 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1172
1173 // Load the value of a smi object into a FPU double register. The register
1174 // scratch1 can be the same register as smi in which case smi will hold the
1175 // untagged value afterwards.
1176 void SmiToDoubleFPURegister(Register smi,
1177 FPURegister value,
1178 Register scratch1);
1179
1180 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001181 // Overflow handling functions.
1182 // Usage: first call the appropriate arithmetic function, then call one of the
1183 // jump functions with the overflow_dst register as the second parameter.
1184
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001185 inline void AddBranchOvf(Register dst, Register left, const Operand& right,
1186 Label* overflow_label, Register scratch = at) {
1187 AddBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001188 }
1189
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001190 inline void AddBranchNoOvf(Register dst, Register left, const Operand& right,
1191 Label* no_overflow_label, Register scratch = at) {
1192 AddBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001193 }
1194
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001195 void AddBranchOvf(Register dst, Register left, const Operand& right,
1196 Label* overflow_label, Label* no_overflow_label,
1197 Register scratch = at);
1198
1199 void AddBranchOvf(Register dst, Register left, Register right,
1200 Label* overflow_label, Label* no_overflow_label,
1201 Register scratch = at);
1202
1203
1204 inline void SubBranchOvf(Register dst, Register left, const Operand& right,
1205 Label* overflow_label, Register scratch = at) {
1206 SubBranchOvf(dst, left, right, overflow_label, nullptr, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001207 }
1208
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001209 inline void SubBranchNoOvf(Register dst, Register left, const Operand& right,
1210 Label* no_overflow_label, Register scratch = at) {
1211 SubBranchOvf(dst, left, right, nullptr, no_overflow_label, scratch);
Ben Murdoch257744e2011-11-30 15:57:28 +00001212 }
1213
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001214 void SubBranchOvf(Register dst, Register left, const Operand& right,
1215 Label* overflow_label, Label* no_overflow_label,
1216 Register scratch = at);
1217
1218 void SubBranchOvf(Register dst, Register left, Register right,
1219 Label* overflow_label, Label* no_overflow_label,
1220 Register scratch = at);
1221
Ben Murdoch257744e2011-11-30 15:57:28 +00001222 // -------------------------------------------------------------------------
1223 // Runtime calls.
Andrei Popescu31002712010-02-23 13:46:05 +00001224
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001225 // See comments at the beginning of CEntryStub::Generate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001226 inline void PrepareCEntryArgs(int num_args) { li(a0, num_args); }
Ben Murdoch85b71792012-04-11 18:30:58 +01001227
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001228 inline void PrepareCEntryFunction(const ExternalReference& ref) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001229 li(a1, Operand(ref));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001230 }
1231
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001232#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1233const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1234
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001235 // Call a code stub.
1236 void CallStub(CodeStub* stub,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001237 TypeFeedbackId ast_id = TypeFeedbackId::None(),
1238 COND_ARGS);
Steve Block44f0eee2011-05-26 01:26:41 +01001239
1240 // Tail call a code stub (jump).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001241 void TailCallStub(CodeStub* stub, COND_ARGS);
1242
1243#undef COND_ARGS
Steve Block44f0eee2011-05-26 01:26:41 +01001244
Andrei Popescu31002712010-02-23 13:46:05 +00001245 void CallJSExitStub(CodeStub* stub);
1246
Andrei Popescu31002712010-02-23 13:46:05 +00001247 // Call a runtime routine.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001248 void CallRuntime(const Runtime::Function* f, int num_arguments,
1249 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1250 BranchDelaySlot bd = PROTECT);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001251 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1252 const Runtime::Function* function = Runtime::FunctionForId(id);
1253 CallRuntime(function, function->nargs, kSaveFPRegs);
1254 }
Andrei Popescu31002712010-02-23 13:46:05 +00001255
1256 // Convenience function: Same as above, but takes the fid instead.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001257 void CallRuntime(Runtime::FunctionId fid,
1258 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1259 BranchDelaySlot bd = PROTECT) {
1260 const Runtime::Function* function = Runtime::FunctionForId(fid);
1261 CallRuntime(function, function->nargs, save_doubles, bd);
1262 }
1263
1264 // Convenience function: Same as above, but takes the fid instead.
1265 void CallRuntime(Runtime::FunctionId id, int num_arguments,
1266 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
1267 BranchDelaySlot bd = PROTECT) {
1268 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles, bd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001269 }
Andrei Popescu31002712010-02-23 13:46:05 +00001270
Steve Block44f0eee2011-05-26 01:26:41 +01001271 // Convenience function: call an external reference.
1272 void CallExternalReference(const ExternalReference& ext,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001273 int num_arguments,
1274 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001275
Steve Block6ded16b2010-05-10 14:33:55 +01001276
1277 // Convenience function: tail call a runtime routine (jump).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001278 void TailCallRuntime(Runtime::FunctionId fid);
Andrei Popescu31002712010-02-23 13:46:05 +00001279
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001280 int CalculateStackPassedWords(int num_reg_arguments,
1281 int num_double_arguments);
1282
Steve Block44f0eee2011-05-26 01:26:41 +01001283 // Before calling a C-function from generated code, align arguments on stack
1284 // and add space for the four mips argument slots.
1285 // After aligning the frame, non-register arguments must be stored on the
1286 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1287 // The argument count assumes all arguments are word sized.
1288 // Some compilers/platforms require the stack to be aligned when calling
1289 // C++ code.
1290 // Needs a scratch register to do some arithmetic. This register will be
1291 // trashed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001292 void PrepareCallCFunction(int num_reg_arguments,
1293 int num_double_registers,
1294 Register scratch);
1295 void PrepareCallCFunction(int num_reg_arguments,
1296 Register scratch);
Steve Block44f0eee2011-05-26 01:26:41 +01001297
1298 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1299 // Arguments 5..n are stored to stack using following:
1300 // sw(t0, CFunctionArgumentOperand(5));
1301
1302 // Calls a C function and cleans up the space for arguments allocated
1303 // by PrepareCallCFunction. The called function is not allowed to trigger a
1304 // garbage collection, since that might move the code and invalidate the
1305 // return address (unless this is somehow accounted for by the called
1306 // function).
1307 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001308 void CallCFunction(Register function, int num_arguments);
1309 void CallCFunction(ExternalReference function,
1310 int num_reg_arguments,
1311 int num_double_arguments);
1312 void CallCFunction(Register function,
1313 int num_reg_arguments,
1314 int num_double_arguments);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001315 void MovFromFloatResult(DoubleRegister dst);
1316 void MovFromFloatParameter(DoubleRegister dst);
Ben Murdoch257744e2011-11-30 15:57:28 +00001317
1318 // There are two ways of passing double arguments on MIPS, depending on
1319 // whether soft or hard floating point ABI is used. These functions
1320 // abstract parameter passing for the three different ways we call
1321 // C functions from generated code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001322 void MovToFloatParameter(DoubleRegister src);
1323 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1324 void MovToFloatResult(DoubleRegister src);
Ben Murdoch257744e2011-11-30 15:57:28 +00001325
Andrei Popescu31002712010-02-23 13:46:05 +00001326 // Jump to the builtin routine.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001327 void JumpToExternalReference(const ExternalReference& builtin,
1328 BranchDelaySlot bd = PROTECT);
Andrei Popescu31002712010-02-23 13:46:05 +00001329
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001330 // Invoke specified builtin JavaScript function.
1331 void InvokeBuiltin(int native_context_index, InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +00001332 const CallWrapper& call_wrapper = NullCallWrapper());
Andrei Popescu31002712010-02-23 13:46:05 +00001333
Andrei Popescu31002712010-02-23 13:46:05 +00001334 struct Unresolved {
1335 int pc;
Ben Murdoch257744e2011-11-30 15:57:28 +00001336 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
Andrei Popescu31002712010-02-23 13:46:05 +00001337 const char* name;
1338 };
Andrei Popescu31002712010-02-23 13:46:05 +00001339
Ben Murdoch257744e2011-11-30 15:57:28 +00001340 Handle<Object> CodeObject() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001341 DCHECK(!code_object_.is_null());
Ben Murdoch257744e2011-11-30 15:57:28 +00001342 return code_object_;
1343 }
Andrei Popescu31002712010-02-23 13:46:05 +00001344
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001345 // Emit code for a truncating division by a constant. The dividend register is
1346 // unchanged and at gets clobbered. Dividend and result must be different.
1347 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
1348
Steve Block44f0eee2011-05-26 01:26:41 +01001349 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001350 // StatsCounter support.
Andrei Popescu31002712010-02-23 13:46:05 +00001351
1352 void SetCounter(StatsCounter* counter, int value,
1353 Register scratch1, Register scratch2);
1354 void IncrementCounter(StatsCounter* counter, int value,
1355 Register scratch1, Register scratch2);
1356 void DecrementCounter(StatsCounter* counter, int value,
1357 Register scratch1, Register scratch2);
1358
1359
Steve Block44f0eee2011-05-26 01:26:41 +01001360 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001361 // Debugging.
Andrei Popescu31002712010-02-23 13:46:05 +00001362
1363 // Calls Abort(msg) if the condition cc is not satisfied.
1364 // Use --debug_code to enable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001365 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
Steve Block44f0eee2011-05-26 01:26:41 +01001366 void AssertFastElements(Register elements);
Andrei Popescu31002712010-02-23 13:46:05 +00001367
1368 // Like Assert(), but always enabled.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001369 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
Andrei Popescu31002712010-02-23 13:46:05 +00001370
1371 // Print a message to stdout and abort execution.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001372 void Abort(BailoutReason msg);
Andrei Popescu31002712010-02-23 13:46:05 +00001373
1374 // Verify restrictions about code generated in stubs.
1375 void set_generating_stub(bool value) { generating_stub_ = value; }
1376 bool generating_stub() { return generating_stub_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001377 void set_has_frame(bool value) { has_frame_ = value; }
1378 bool has_frame() { return has_frame_; }
1379 inline bool AllowThisStubCall(CodeStub* stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001380
Steve Block44f0eee2011-05-26 01:26:41 +01001381 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001382 // Number utilities.
Steve Block6ded16b2010-05-10 14:33:55 +01001383
Steve Block44f0eee2011-05-26 01:26:41 +01001384 // Check whether the value of reg is a power of two and not zero. If not
1385 // control continues at the label not_power_of_two. If reg is a power of two
1386 // the register scratch contains the value of (reg - 1) when control falls
1387 // through.
1388 void JumpIfNotPowerOfTwoOrZero(Register reg,
1389 Register scratch,
1390 Label* not_power_of_two_or_zero);
1391
1392 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001393 // Smi utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001394
Steve Block44f0eee2011-05-26 01:26:41 +01001395 void SmiTag(Register reg) {
1396 Addu(reg, reg, reg);
1397 }
1398
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001399 void SmiTag(Register dst, Register src) { Addu(dst, src, src); }
1400
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001401 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1402 void SmiTagCheckOverflow(Register reg, Register overflow);
1403 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
1404
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001405 void BranchOnOverflow(Label* label, Register overflow_check,
1406 BranchDelaySlot bd = PROTECT) {
1407 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
Steve Block44f0eee2011-05-26 01:26:41 +01001408 }
1409
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001410 void BranchOnNoOverflow(Label* label, Register overflow_check,
1411 BranchDelaySlot bd = PROTECT) {
1412 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1413 }
1414
1415
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001416 // Try to convert int32 to smi. If the value is to large, preserve
1417 // the original value and jump to not_a_smi. Destroys scratch and
1418 // sets flags.
1419 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1420 TrySmiTag(reg, reg, scratch, not_a_smi);
1421 }
1422 void TrySmiTag(Register dst,
1423 Register src,
1424 Register scratch,
1425 Label* not_a_smi) {
1426 SmiTagCheckOverflow(at, src, scratch);
1427 BranchOnOverflow(not_a_smi, scratch);
1428 mov(dst, at);
1429 }
1430
Steve Block44f0eee2011-05-26 01:26:41 +01001431 void SmiUntag(Register reg) {
1432 sra(reg, reg, kSmiTagSize);
1433 }
1434
1435 void SmiUntag(Register dst, Register src) {
1436 sra(dst, src, kSmiTagSize);
1437 }
1438
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001439 // Test if the register contains a smi.
1440 inline void SmiTst(Register value, Register scratch) {
1441 And(scratch, value, Operand(kSmiTagMask));
1442 }
1443 inline void NonNegativeSmiTst(Register value, Register scratch) {
1444 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1445 }
1446
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001447 // Untag the source value into destination and jump if source is a smi.
1448 // Souce and destination can be the same register.
1449 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1450
1451 // Untag the source value into destination and jump if source is not a smi.
1452 // Souce and destination can be the same register.
1453 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1454
Steve Block44f0eee2011-05-26 01:26:41 +01001455 // Jump the register contains a smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001456 void JumpIfSmi(Register value,
1457 Label* smi_label,
1458 Register scratch = at,
1459 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001460
1461 // Jump if the register contains a non-smi.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001462 void JumpIfNotSmi(Register value,
1463 Label* not_smi_label,
1464 Register scratch = at,
1465 BranchDelaySlot bd = PROTECT);
Steve Block44f0eee2011-05-26 01:26:41 +01001466
1467 // Jump if either of the registers contain a non-smi.
1468 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1469 // Jump if either of the registers contain a smi.
1470 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1471
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001472 // Abort execution if argument is a smi, enabled via --debug-code.
1473 void AssertNotSmi(Register object);
1474 void AssertSmi(Register object);
Steve Block44f0eee2011-05-26 01:26:41 +01001475
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001476 // Abort execution if argument is not a string, enabled via --debug-code.
1477 void AssertString(Register object);
Ben Murdoch257744e2011-11-30 15:57:28 +00001478
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001479 // Abort execution if argument is not a name, enabled via --debug-code.
1480 void AssertName(Register object);
1481
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001482 // Abort execution if argument is not a JSFunction, enabled via --debug-code.
1483 void AssertFunction(Register object);
1484
1485 // Abort execution if argument is not a JSBoundFunction,
1486 // enabled via --debug-code.
1487 void AssertBoundFunction(Register object);
1488
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001489 // Abort execution if argument is not undefined or an AllocationSite, enabled
1490 // via --debug-code.
1491 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1492
1493 // Abort execution if reg is not the root value with the given index,
1494 // enabled via --debug-code.
1495 void AssertIsRoot(Register reg, Heap::RootListIndex index);
Steve Block44f0eee2011-05-26 01:26:41 +01001496
1497 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001498 // HeapNumber utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001499
1500 void JumpIfNotHeapNumber(Register object,
1501 Register heap_number_map,
1502 Register scratch,
1503 Label* on_not_heap_number);
1504
1505 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001506 // String utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001507
1508 // Checks if both instance types are sequential ASCII strings and jumps to
1509 // label if either is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001510 void JumpIfBothInstanceTypesAreNotSequentialOneByte(
1511 Register first_object_instance_type, Register second_object_instance_type,
1512 Register scratch1, Register scratch2, Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001513
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001514 // Check if instance type is sequential one-byte string and jump to label if
Steve Block44f0eee2011-05-26 01:26:41 +01001515 // it is not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516 void JumpIfInstanceTypeIsNotSequentialOneByte(Register type, Register scratch,
1517 Label* failure);
Steve Block44f0eee2011-05-26 01:26:41 +01001518
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001519 void JumpIfNotUniqueNameInstanceType(Register reg, Label* not_unique_name);
Steve Block44f0eee2011-05-26 01:26:41 +01001520
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001521 void EmitSeqStringSetCharCheck(Register string,
1522 Register index,
1523 Register value,
1524 Register scratch,
1525 uint32_t encoding_mask);
1526
1527 // Checks if both objects are sequential one-byte strings and jumps to label
1528 // if either is not. Assumes that neither object is a smi.
1529 void JumpIfNonSmisNotBothSequentialOneByteStrings(Register first,
1530 Register second,
1531 Register scratch1,
1532 Register scratch2,
1533 Label* failure);
1534
1535 // Checks if both objects are sequential one-byte strings and jumps to label
1536 // if either is not.
1537 void JumpIfNotBothSequentialOneByteStrings(Register first, Register second,
1538 Register scratch1,
1539 Register scratch2,
1540 Label* not_flat_one_byte_strings);
Steve Block44f0eee2011-05-26 01:26:41 +01001541
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001542 void ClampUint8(Register output_reg, Register input_reg);
1543
1544 void ClampDoubleToUint8(Register result_reg,
1545 DoubleRegister input_reg,
1546 DoubleRegister temp_double_reg);
1547
1548
Ben Murdoch257744e2011-11-30 15:57:28 +00001549 void LoadInstanceDescriptors(Register map, Register descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001550 void EnumLength(Register dst, Register map);
1551 void NumberOfOwnDescriptors(Register dst, Register map);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001552 void LoadAccessor(Register dst, Register holder, int accessor_index,
1553 AccessorComponent accessor);
Ben Murdoch257744e2011-11-30 15:57:28 +00001554
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555 template<typename Field>
1556 void DecodeField(Register dst, Register src) {
1557 Ext(dst, src, Field::kShift, Field::kSize);
1558 }
1559
1560 template<typename Field>
1561 void DecodeField(Register reg) {
1562 DecodeField<Field>(reg, reg);
1563 }
1564
1565 template<typename Field>
1566 void DecodeFieldToSmi(Register dst, Register src) {
1567 static const int shift = Field::kShift;
1568 static const int mask = Field::kMask >> shift << kSmiTagSize;
1569 STATIC_ASSERT((mask & (0x80000000u >> (kSmiTagSize - 1))) == 0);
1570 STATIC_ASSERT(kSmiTag == 0);
1571 if (shift < kSmiTagSize) {
1572 sll(dst, src, kSmiTagSize - shift);
1573 And(dst, dst, Operand(mask));
1574 } else if (shift > kSmiTagSize) {
1575 srl(dst, src, shift - kSmiTagSize);
1576 And(dst, dst, Operand(mask));
1577 } else {
1578 And(dst, src, Operand(mask));
1579 }
1580 }
1581
1582 template<typename Field>
1583 void DecodeFieldToSmi(Register reg) {
1584 DecodeField<Field>(reg, reg);
1585 }
1586
1587 // Generates function and stub prologue code.
1588 void StubPrologue();
1589 void Prologue(bool code_pre_aging);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001590
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001591 // Load the type feedback vector from a JavaScript frame.
1592 void EmitLoadTypeFeedbackVector(Register vector);
1593
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001594 // Activation support.
1595 void EnterFrame(StackFrame::Type type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001596 void EnterFrame(StackFrame::Type type, bool load_constant_pool_pointer_reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001597 void LeaveFrame(StackFrame::Type type);
1598
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001599 // Expects object in a0 and returns map with validated enum cache
1600 // in a0. Assumes that any other register can be used as a scratch.
1601 void CheckEnumCache(Register null_value, Label* call_runtime);
1602
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001603 // AllocationMemento support. Arrays may have an associated
1604 // AllocationMemento object that can be checked for in order to pretransition
1605 // to another type.
1606 // On entry, receiver_reg should point to the array object.
1607 // scratch_reg gets clobbered.
1608 // If allocation info is present, jump to allocation_memento_present.
1609 void TestJSArrayForAllocationMemento(
1610 Register receiver_reg,
1611 Register scratch_reg,
1612 Label* no_memento_found,
1613 Condition cond = al,
1614 Label* allocation_memento_present = NULL);
1615
1616 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1617 Register scratch_reg,
1618 Label* memento_found) {
1619 Label no_memento_found;
1620 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1621 &no_memento_found, eq, memento_found);
1622 bind(&no_memento_found);
1623 }
1624
1625 // Jumps to found label if a prototype map has dictionary elements.
1626 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1627 Register scratch1, Label* found);
1628
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001629 bool IsDoubleZeroRegSet() { return has_double_zero_reg_set_; }
1630
Steve Block44f0eee2011-05-26 01:26:41 +01001631 private:
1632 void CallCFunctionHelper(Register function,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001633 int num_reg_arguments,
1634 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001635
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001636 inline Register GetRtAsRegisterHelper(const Operand& rt, Register scratch);
1637 inline int32_t GetOffset(int32_t offset, Label* L, OffsetSize bits);
1638 void BranchShortHelperR6(int32_t offset, Label* L);
1639 void BranchShortHelper(int16_t offset, Label* L, BranchDelaySlot bdslot);
1640 bool BranchShortHelperR6(int32_t offset, Label* L, Condition cond,
1641 Register rs, const Operand& rt);
1642 bool BranchShortHelper(int16_t offset, Label* L, Condition cond, Register rs,
1643 const Operand& rt, BranchDelaySlot bdslot);
1644 bool BranchShortCheck(int32_t offset, Label* L, Condition cond, Register rs,
1645 const Operand& rt, BranchDelaySlot bdslot);
1646
1647 void BranchAndLinkShortHelperR6(int32_t offset, Label* L);
1648 void BranchAndLinkShortHelper(int16_t offset, Label* L,
1649 BranchDelaySlot bdslot);
1650 void BranchAndLinkShort(int32_t offset, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001651 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001652 bool BranchAndLinkShortHelperR6(int32_t offset, Label* L, Condition cond,
1653 Register rs, const Operand& rt);
1654 bool BranchAndLinkShortHelper(int16_t offset, Label* L, Condition cond,
1655 Register rs, const Operand& rt,
1656 BranchDelaySlot bdslot);
1657 bool BranchAndLinkShortCheck(int32_t offset, Label* L, Condition cond,
1658 Register rs, const Operand& rt,
1659 BranchDelaySlot bdslot);
1660 void BranchLong(Label* L, BranchDelaySlot bdslot);
1661 void BranchAndLinkLong(Label* L, BranchDelaySlot bdslot);
1662
1663 // Common implementation of BranchF functions for the different formats.
1664 void BranchFCommon(SecondaryField sizeField, Label* target, Label* nan,
1665 Condition cc, FPURegister cmp1, FPURegister cmp2,
1666 BranchDelaySlot bd = PROTECT);
1667
1668 void BranchShortF(SecondaryField sizeField, Label* target, Condition cc,
1669 FPURegister cmp1, FPURegister cmp2,
1670 BranchDelaySlot bd = PROTECT);
Steve Block6ded16b2010-05-10 14:33:55 +01001671
1672 // Helper functions for generating invokes.
1673 void InvokePrologue(const ParameterCount& expected,
1674 const ParameterCount& actual,
Steve Block6ded16b2010-05-10 14:33:55 +01001675 Label* done,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001676 bool* definitely_mismatches,
Steve Block44f0eee2011-05-26 01:26:41 +01001677 InvokeFlag flag,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001678 const CallWrapper& call_wrapper);
Steve Block6ded16b2010-05-10 14:33:55 +01001679
Steve Block44f0eee2011-05-26 01:26:41 +01001680 void InitializeNewString(Register string,
1681 Register length,
1682 Heap::RootListIndex map_index,
1683 Register scratch1,
1684 Register scratch2);
1685
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001686 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1687 void InNewSpace(Register object,
1688 Register scratch,
1689 Condition cond, // eq for new space, ne otherwise.
1690 Label* branch);
1691
1692 // Helper for finding the mark bits for an address. Afterwards, the
1693 // bitmap register points at the word with the mark bits and the mask
1694 // the position of the first bit. Leaves addr_reg unchanged.
1695 inline void GetMarkBits(Register addr_reg,
1696 Register bitmap_reg,
1697 Register mask_reg);
1698
Ben Murdoch257744e2011-11-30 15:57:28 +00001699 // Compute memory operands for safepoint stack slots.
1700 static int SafepointRegisterStackIndex(int reg_code);
1701 MemOperand SafepointRegisterSlot(Register reg);
1702 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
Steve Block44f0eee2011-05-26 01:26:41 +01001703
1704 bool generating_stub_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001705 bool has_frame_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001706 bool has_double_zero_reg_set_;
Steve Block44f0eee2011-05-26 01:26:41 +01001707 // This handle will be patched with the code object on installation.
1708 Handle<Object> code_object_;
Ben Murdoch257744e2011-11-30 15:57:28 +00001709
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001710 // Needs access to SafepointRegisterStackIndex for compiled frame
Ben Murdoch257744e2011-11-30 15:57:28 +00001711 // traversal.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001712 friend class StandardFrame;
Steve Block44f0eee2011-05-26 01:26:41 +01001713};
1714
1715
Steve Block44f0eee2011-05-26 01:26:41 +01001716// The code patcher is used to patch (typically) small parts of code e.g. for
1717// debugging and other types of instrumentation. When using the code patcher
1718// the exact number of bytes specified must be emitted. It is not legal to emit
1719// relocation information. If any of these constraints are violated it causes
1720// an assertion to fail.
1721class CodePatcher {
1722 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001723 enum FlushICache {
1724 FLUSH,
1725 DONT_FLUSH
1726 };
1727
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001728 CodePatcher(Isolate* isolate, byte* address, int instructions,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001729 FlushICache flush_cache = FLUSH);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001730 ~CodePatcher();
Steve Block44f0eee2011-05-26 01:26:41 +01001731
1732 // Macro assembler to emit code.
1733 MacroAssembler* masm() { return &masm_; }
1734
1735 // Emit an instruction directly.
Ben Murdoch257744e2011-11-30 15:57:28 +00001736 void Emit(Instr instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001737
1738 // Emit an address directly.
1739 void Emit(Address addr);
1740
Ben Murdoch257744e2011-11-30 15:57:28 +00001741 // Change the condition part of an instruction leaving the rest of the current
1742 // instruction unchanged.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001743 void ChangeBranchCondition(Instr current_instr, uint32_t new_opcode);
Ben Murdoch257744e2011-11-30 15:57:28 +00001744
Steve Block44f0eee2011-05-26 01:26:41 +01001745 private:
1746 byte* address_; // The address of the code being patched.
Steve Block44f0eee2011-05-26 01:26:41 +01001747 int size_; // Number of bytes of the expected patch size.
1748 MacroAssembler masm_; // Macro assembler used to generate the code.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001749 FlushICache flush_cache_; // Whether to flush the I cache after patching.
Steve Block44f0eee2011-05-26 01:26:41 +01001750};
Andrei Popescu31002712010-02-23 13:46:05 +00001751
1752
Andrei Popescu31002712010-02-23 13:46:05 +00001753
1754#ifdef GENERATED_CODE_COVERAGE
1755#define CODE_COVERAGE_STRINGIFY(x) #x
1756#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1757#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1758#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1759#else
1760#define ACCESS_MASM(masm) masm->
1761#endif
1762
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001763} // namespace internal
1764} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +00001765
1766#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_