blob: db9f1a2c76d9dba76e35d82d1d07c3826c515e8e [file] [log] [blame]
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001// Copyright 2012 the V8 project authors. All rights reserved.
ager@chromium.org5c838252010-02-19 08:53:10 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
29#define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
30
31#include "assembler.h"
32#include "mips/assembler-mips.h"
danno@chromium.org40cb8782011-05-25 07:58:50 +000033#include "v8globals.h"
ager@chromium.org5c838252010-02-19 08:53:10 +000034
35namespace v8 {
36namespace internal {
37
38// Forward declaration.
39class JumpTarget;
40
lrn@chromium.org7516f052011-03-30 08:52:27 +000041// Reserved Register Usage Summary.
42//
43// Registers t8, t9, and at are reserved for use by the MacroAssembler.
44//
45// The programmer should know that the MacroAssembler may clobber these three,
46// but won't touch other registers except in special cases.
47//
48// Per the MIPS ABI, register t9 must be used for indirect function call
49// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
50// trying to update gp register for position-independent-code. Whenever
51// MIPS generated code calls C code, it must be via t9 register.
ager@chromium.org5c838252010-02-19 08:53:10 +000052
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000053
machenbach@chromium.org528ce022013-09-23 14:09:36 +000054// Flags used for LeaveExitFrame function.
55enum LeaveExitFrameMode {
56 EMIT_RETURN = true,
57 NO_EMIT_RETURN = false
58};
59
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +000060// Flags used for AllocateHeapNumber
61enum TaggingMode {
62 // Tag the result.
63 TAG_RESULT,
64 // Don't tag
65 DONT_TAG_RESULT
66};
67
lrn@chromium.org7516f052011-03-30 08:52:27 +000068// Flags used for the ObjectToDoubleFPURegister function.
69enum ObjectToDoubleFlags {
70 // No special flags.
71 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
72 // Object is known to be a non smi.
73 OBJECT_NOT_SMI = 1 << 0,
74 // Don't load NaNs or infinities, branch to the non number case instead.
75 AVOID_NANS_AND_INFINITIES = 1 << 1
76};
77
78// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
79enum BranchDelaySlot {
80 USE_DELAY_SLOT,
81 PROTECT
82};
83
danno@chromium.org88aa0582012-03-23 15:11:57 +000084// Flags used for the li macro-assembler function.
85enum LiFlags {
86 // If the constant value can be represented in just 16 bits, then
87 // optimize the li to use a single instruction, rather than lui/ori pair.
88 OPTIMIZE_SIZE = 0,
89 // Always use 2 instructions (lui/ori pair), even if the constant could
90 // be loaded with just one, so that this value is patchable later.
91 CONSTANT_SIZE = 1
92};
93
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000094
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +000095enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
96enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
97enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
98
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +000099Register GetRegisterThatIsNotOneOf(Register reg1,
100 Register reg2 = no_reg,
101 Register reg3 = no_reg,
102 Register reg4 = no_reg,
103 Register reg5 = no_reg,
104 Register reg6 = no_reg);
105
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000106bool AreAliased(Register r1, Register r2, Register r3, Register r4);
107
108
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000109// -----------------------------------------------------------------------------
110// Static helper functions.
111
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000112inline MemOperand ContextOperand(Register context, int index) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000113 return MemOperand(context, Context::SlotOffset(index));
114}
115
116
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000117inline MemOperand GlobalObjectOperand() {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000118 return ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000119}
120
121
122// Generate a MemOperand for loading a field from an object.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000123inline MemOperand FieldMemOperand(Register object, int offset) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000124 return MemOperand(object, offset - kHeapObjectTag);
125}
126
127
128// Generate a MemOperand for storing arguments 5..N on the stack
129// when calling CallCFunction().
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000130inline MemOperand CFunctionArgumentOperand(int index) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000131 ASSERT(index > kCArgSlotCount);
132 // 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
ager@chromium.org5c838252010-02-19 08:53:10 +0000138// MacroAssembler implements a collection of frequently used macros.
139class MacroAssembler: public Assembler {
140 public:
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000141 // The isolate parameter can be NULL if the macro assembler should
142 // not use isolate-dependent functionality. In this case, it's the
143 // responsibility of the caller to never invoke such function on the
144 // macro assembler.
145 MacroAssembler(Isolate* isolate, void* buffer, int size);
ager@chromium.org5c838252010-02-19 08:53:10 +0000146
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000147 // Arguments macros.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000148#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
149#define COND_ARGS cond, r1, r2
150
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000151 // Cases when relocation is not needed.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000152#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
153 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
154 inline void Name(BranchDelaySlot bd, target_type target) { \
155 Name(target, bd); \
156 } \
157 void Name(target_type target, \
158 COND_TYPED_ARGS, \
159 BranchDelaySlot bd = PROTECT); \
160 inline void Name(BranchDelaySlot bd, \
161 target_type target, \
162 COND_TYPED_ARGS) { \
163 Name(target, COND_ARGS, bd); \
164 }
165
lrn@chromium.org7516f052011-03-30 08:52:27 +0000166#define DECLARE_BRANCH_PROTOTYPES(Name) \
167 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
168 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
169
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000170 DECLARE_BRANCH_PROTOTYPES(Branch)
171 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
bmeurer@chromium.org25530ce2014-02-07 09:11:16 +0000172 DECLARE_BRANCH_PROTOTYPES(BranchShort)
lrn@chromium.org7516f052011-03-30 08:52:27 +0000173
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000174#undef DECLARE_BRANCH_PROTOTYPES
lrn@chromium.org7516f052011-03-30 08:52:27 +0000175#undef COND_TYPED_ARGS
176#undef COND_ARGS
ager@chromium.org5c838252010-02-19 08:53:10 +0000177
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000178
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000179 // Jump, Call, and Ret pseudo instructions implementing inter-working.
180#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
181 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
182
183 void Jump(Register target, COND_ARGS);
184 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
185 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
186 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000187 static int CallSize(Register target, COND_ARGS);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000188 void Call(Register target, COND_ARGS);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000189 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000190 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000191 int CallSize(Handle<Code> code,
192 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
193 TypeFeedbackId ast_id = TypeFeedbackId::None(),
194 COND_ARGS);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000195 void Call(Handle<Code> code,
196 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000197 TypeFeedbackId ast_id = TypeFeedbackId::None(),
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000198 COND_ARGS);
199 void Ret(COND_ARGS);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000200 inline void Ret(BranchDelaySlot bd, Condition cond = al,
201 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
202 Ret(cond, rs, rt, bd);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000203 }
204
danno@chromium.org88aa0582012-03-23 15:11:57 +0000205 void Branch(Label* L,
206 Condition cond,
207 Register rs,
208 Heap::RootListIndex index,
209 BranchDelaySlot bdslot = PROTECT);
210
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000211#undef COND_ARGS
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000212
ager@chromium.org5c838252010-02-19 08:53:10 +0000213 // Emit code to discard a non-negative number of pointer-sized elements
214 // from the stack, clobbering only the sp register.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000215 void Drop(int count,
216 Condition cond = cc_always,
217 Register reg = no_reg,
218 const Operand& op = Operand(no_reg));
219
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000220 // Trivial case of DropAndRet that utilizes the delay slot and only emits
221 // 2 instructions.
222 void DropAndRet(int drop);
223
224 void DropAndRet(int drop,
225 Condition cond,
226 Register reg,
227 const Operand& op);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000228
229 // Swap two registers. If the scratch register is omitted then a slightly
230 // less efficient form using xor instead of mov is emitted.
231 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
ager@chromium.org5c838252010-02-19 08:53:10 +0000232
233 void Call(Label* target);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000234
danno@chromium.org40cb8782011-05-25 07:58:50 +0000235 inline void Move(Register dst, Register src) {
236 if (!dst.is(src)) {
237 mov(dst, src);
238 }
239 }
240
241 inline void Move(FPURegister dst, FPURegister src) {
242 if (!dst.is(src)) {
243 mov_d(dst, src);
244 }
245 }
246
247 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
248 mfc1(dst_low, src);
249 mfc1(dst_high, FPURegister::from_code(src.code() + 1));
250 }
251
palfia@homejinni.comc4c71ea2013-08-15 08:05:35 +0000252 inline void FmoveHigh(Register dst_high, FPURegister src) {
253 mfc1(dst_high, FPURegister::from_code(src.code() + 1));
254 }
255
256 inline void FmoveLow(Register dst_low, FPURegister src) {
257 mfc1(dst_low, src);
258 }
259
danno@chromium.org40cb8782011-05-25 07:58:50 +0000260 inline void Move(FPURegister dst, Register src_low, Register src_high) {
261 mtc1(src_low, dst);
262 mtc1(src_high, FPURegister::from_code(dst.code() + 1));
263 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000264
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000265 // Conditional move.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000266 void Move(FPURegister dst, double imm);
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000267 void Movz(Register rd, Register rs, Register rt);
268 void Movn(Register rd, Register rs, Register rt);
269 void Movt(Register rd, Register rs, uint16_t cc = 0);
270 void Movf(Register rd, Register rs, uint16_t cc = 0);
271
272 void Clz(Register rd, Register rs);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000273
ager@chromium.org5c838252010-02-19 08:53:10 +0000274 // Jump unconditionally to given label.
275 // We NEED a nop in the branch delay slot, as it used by v8, for example in
276 // CodeGenerator::ProcessDeferred().
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000277 // Currently the branch delay slot is filled by the MacroAssembler.
ager@chromium.org5c838252010-02-19 08:53:10 +0000278 // Use rather b(Label) for code generation.
279 void jmp(Label* L) {
lrn@chromium.org7516f052011-03-30 08:52:27 +0000280 Branch(L);
ager@chromium.org5c838252010-02-19 08:53:10 +0000281 }
282
machenbach@chromium.org935a7792013-11-12 09:05:18 +0000283 void Load(Register dst, const MemOperand& src, Representation r);
284 void Store(Register src, const MemOperand& dst, Representation r);
285
ager@chromium.org5c838252010-02-19 08:53:10 +0000286 // Load an object from the root table.
287 void LoadRoot(Register destination,
288 Heap::RootListIndex index);
289 void LoadRoot(Register destination,
290 Heap::RootListIndex index,
291 Condition cond, Register src1, const Operand& src2);
292
lrn@chromium.org7516f052011-03-30 08:52:27 +0000293 // Store an object to the root table.
294 void StoreRoot(Register source,
295 Heap::RootListIndex index);
296 void StoreRoot(Register source,
297 Heap::RootListIndex index,
298 Condition cond, Register src1, const Operand& src2);
299
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000300 // ---------------------------------------------------------------------------
301 // GC Support
302
303 void IncrementalMarkingRecordWriteHelper(Register object,
304 Register value,
305 Register address);
306
307 enum RememberedSetFinalAction {
308 kReturnAtEnd,
309 kFallThroughAtEnd
310 };
lrn@chromium.org7516f052011-03-30 08:52:27 +0000311
312
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000313 // Record in the remembered set the fact that we have a pointer to new space
314 // at the address pointed to by the addr register. Only works if addr is not
315 // in new space.
316 void RememberedSetHelper(Register object, // Used for debug code.
317 Register addr,
318 Register scratch,
319 SaveFPRegsMode save_fp,
320 RememberedSetFinalAction and_then);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000321
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000322 void CheckPageFlag(Register object,
323 Register scratch,
324 int mask,
325 Condition cc,
326 Label* condition_met);
327
danno@chromium.orgf005df62013-04-30 16:36:45 +0000328 void CheckMapDeprecated(Handle<Map> map,
329 Register scratch,
330 Label* if_deprecated);
331
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000332 // Check if object is in new space. Jumps if the object is not in new space.
333 // The register scratch can be object itself, but it will be clobbered.
334 void JumpIfNotInNewSpace(Register object,
335 Register scratch,
336 Label* branch) {
337 InNewSpace(object, scratch, ne, branch);
338 }
339
340 // Check if object is in new space. Jumps if the object is in new space.
341 // The register scratch can be object itself, but scratch will be clobbered.
342 void JumpIfInNewSpace(Register object,
343 Register scratch,
344 Label* branch) {
345 InNewSpace(object, scratch, eq, branch);
346 }
347
348 // Check if an object has a given incremental marking color.
349 void HasColor(Register object,
350 Register scratch0,
351 Register scratch1,
352 Label* has_color,
353 int first_bit,
354 int second_bit);
355
356 void JumpIfBlack(Register object,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000357 Register scratch0,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000358 Register scratch1,
359 Label* on_black);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000360
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000361 // Checks the color of an object. If the object is already grey or black
362 // then we just fall through, since it is already live. If it is white and
363 // we can determine that it doesn't need to be scanned, then we just mark it
364 // black and fall through. For the rest we jump to the label so the
365 // incremental marker can fix its assumptions.
366 void EnsureNotWhite(Register object,
367 Register scratch1,
368 Register scratch2,
369 Register scratch3,
370 Label* object_is_white_and_not_data);
371
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000372 // Detects conservatively whether an object is data-only, i.e. it does need to
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000373 // be scanned by the garbage collector.
374 void JumpIfDataObject(Register value,
375 Register scratch,
376 Label* not_data_object);
377
378 // Notify the garbage collector that we wrote a pointer into an object.
379 // |object| is the object being stored into, |value| is the object being
380 // stored. value and scratch registers are clobbered by the operation.
381 // The offset is the offset from the start of the object, not the offset from
382 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
383 void RecordWriteField(
384 Register object,
385 int offset,
386 Register value,
387 Register scratch,
388 RAStatus ra_status,
389 SaveFPRegsMode save_fp,
390 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
391 SmiCheck smi_check = INLINE_SMI_CHECK);
392
393 // As above, but the offset has the tag presubtracted. For use with
394 // MemOperand(reg, off).
395 inline void RecordWriteContextSlot(
396 Register context,
397 int offset,
398 Register value,
399 Register scratch,
400 RAStatus ra_status,
401 SaveFPRegsMode save_fp,
402 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
403 SmiCheck smi_check = INLINE_SMI_CHECK) {
404 RecordWriteField(context,
405 offset + kHeapObjectTag,
406 value,
407 scratch,
408 ra_status,
409 save_fp,
410 remembered_set_action,
411 smi_check);
412 }
413
414 // For a given |object| notify the garbage collector that the slot |address|
415 // has been written. |value| is the object being stored. The value and
416 // address registers are clobbered by the operation.
417 void RecordWrite(
418 Register object,
419 Register address,
420 Register value,
421 RAStatus ra_status,
422 SaveFPRegsMode save_fp,
423 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
424 SmiCheck smi_check = INLINE_SMI_CHECK);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000425
426
427 // ---------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000428 // Inline caching support.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000429
430 // Generate code for checking access rights - used for security checks
431 // on access to global objects across environments. The holder register
432 // is left untouched, whereas both scratch registers are clobbered.
433 void CheckAccessGlobalProxy(Register holder_reg,
434 Register scratch,
435 Label* miss);
436
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000437 void GetNumberHash(Register reg0, Register scratch);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000438
439 void LoadFromNumberDictionary(Label* miss,
440 Register elements,
441 Register key,
442 Register result,
443 Register reg0,
444 Register reg1,
445 Register reg2);
446
447
lrn@chromium.org7516f052011-03-30 08:52:27 +0000448 inline void MarkCode(NopMarkerTypes type) {
449 nop(type);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000450 }
451
lrn@chromium.org7516f052011-03-30 08:52:27 +0000452 // Check if the given instruction is a 'type' marker.
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000453 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
lrn@chromium.org7516f052011-03-30 08:52:27 +0000454 // nop(type)). These instructions are generated to mark special location in
455 // the code, like some special IC code.
456 static inline bool IsMarkedCode(Instr instr, int type) {
457 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
458 return IsNop(instr, type);
459 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000460
461
lrn@chromium.org7516f052011-03-30 08:52:27 +0000462 static inline int GetCodeMarker(Instr instr) {
463 uint32_t opcode = ((instr & kOpcodeMask));
464 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
465 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
466 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
467
468 // Return <n> if we have a sll zero_reg, zero_reg, n
469 // else return -1.
470 bool sllzz = (opcode == SLL &&
471 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
472 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
473 int type =
474 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
475 ASSERT((type == -1) ||
476 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
477 return type;
478 }
479
480
481
482 // ---------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000483 // Allocation support.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000484
jkummerow@chromium.org4c54a2a2013-03-19 17:51:30 +0000485 // Allocate an object in new space or old pointer space. The object_size is
486 // specified either in bytes or in words if the allocation flag SIZE_IN_WORDS
487 // is passed. If the space is exhausted control continues at the gc_required
488 // label. The allocated object is returned in result. If the flag
489 // tag_allocated_object is true the result is tagged as as a heap object.
490 // All registers are clobbered also when control continues at the gc_required
491 // label.
492 void Allocate(int object_size,
493 Register result,
494 Register scratch1,
495 Register scratch2,
496 Label* gc_required,
497 AllocationFlags flags);
498
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000499 void Allocate(Register object_size,
500 Register result,
501 Register scratch1,
502 Register scratch2,
503 Label* gc_required,
504 AllocationFlags flags);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000505
506 // Undo allocation in new space. The object passed and objects allocated after
507 // it will no longer be allocated. The caller must make sure that no pointers
508 // are left to the object(s) no longer allocated as they would be invalid when
509 // allocation is undone.
510 void UndoAllocationInNewSpace(Register object, Register scratch);
511
512
513 void AllocateTwoByteString(Register result,
514 Register length,
515 Register scratch1,
516 Register scratch2,
517 Register scratch3,
518 Label* gc_required);
519 void AllocateAsciiString(Register result,
520 Register length,
521 Register scratch1,
522 Register scratch2,
523 Register scratch3,
524 Label* gc_required);
525 void AllocateTwoByteConsString(Register result,
526 Register length,
527 Register scratch1,
528 Register scratch2,
529 Label* gc_required);
530 void AllocateAsciiConsString(Register result,
531 Register length,
532 Register scratch1,
533 Register scratch2,
534 Label* gc_required);
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000535 void AllocateTwoByteSlicedString(Register result,
536 Register length,
537 Register scratch1,
538 Register scratch2,
539 Label* gc_required);
540 void AllocateAsciiSlicedString(Register result,
541 Register length,
542 Register scratch1,
543 Register scratch2,
544 Label* gc_required);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000545
546 // Allocates a heap number or jumps to the gc_required label if the young
547 // space is full and a scavenge is needed. All registers are clobbered also
548 // when control continues at the gc_required label.
549 void AllocateHeapNumber(Register result,
550 Register scratch1,
551 Register scratch2,
552 Register heap_number_map,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000553 Label* gc_required,
554 TaggingMode tagging_mode = TAG_RESULT);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000555 void AllocateHeapNumberWithValue(Register result,
556 FPURegister value,
557 Register scratch1,
558 Register scratch2,
559 Label* gc_required);
560
ager@chromium.org5c838252010-02-19 08:53:10 +0000561 // ---------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000562 // Instruction macros.
ager@chromium.org5c838252010-02-19 08:53:10 +0000563
lrn@chromium.org7516f052011-03-30 08:52:27 +0000564#define DEFINE_INSTRUCTION(instr) \
ager@chromium.org5c838252010-02-19 08:53:10 +0000565 void instr(Register rd, Register rs, const Operand& rt); \
566 void instr(Register rd, Register rs, Register rt) { \
567 instr(rd, rs, Operand(rt)); \
568 } \
569 void instr(Register rs, Register rt, int32_t j) { \
570 instr(rs, rt, Operand(j)); \
571 }
572
lrn@chromium.org7516f052011-03-30 08:52:27 +0000573#define DEFINE_INSTRUCTION2(instr) \
ager@chromium.org5c838252010-02-19 08:53:10 +0000574 void instr(Register rs, const Operand& rt); \
575 void instr(Register rs, Register rt) { \
576 instr(rs, Operand(rt)); \
577 } \
578 void instr(Register rs, int32_t j) { \
579 instr(rs, Operand(j)); \
580 }
581
ager@chromium.org5c838252010-02-19 08:53:10 +0000582 DEFINE_INSTRUCTION(Addu);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000583 DEFINE_INSTRUCTION(Subu);
ager@chromium.org5c838252010-02-19 08:53:10 +0000584 DEFINE_INSTRUCTION(Mul);
585 DEFINE_INSTRUCTION2(Mult);
586 DEFINE_INSTRUCTION2(Multu);
587 DEFINE_INSTRUCTION2(Div);
588 DEFINE_INSTRUCTION2(Divu);
589
590 DEFINE_INSTRUCTION(And);
591 DEFINE_INSTRUCTION(Or);
592 DEFINE_INSTRUCTION(Xor);
593 DEFINE_INSTRUCTION(Nor);
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000594 DEFINE_INSTRUCTION2(Neg);
ager@chromium.org5c838252010-02-19 08:53:10 +0000595
596 DEFINE_INSTRUCTION(Slt);
597 DEFINE_INSTRUCTION(Sltu);
598
lrn@chromium.org7516f052011-03-30 08:52:27 +0000599 // MIPS32 R2 instruction macro.
600 DEFINE_INSTRUCTION(Ror);
601
ager@chromium.org5c838252010-02-19 08:53:10 +0000602#undef DEFINE_INSTRUCTION
603#undef DEFINE_INSTRUCTION2
604
machenbach@chromium.orgafbdadc2013-12-09 16:12:18 +0000605 void Pref(int32_t hint, const MemOperand& rs);
606
ager@chromium.org5c838252010-02-19 08:53:10 +0000607
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000608 // ---------------------------------------------------------------------------
609 // Pseudo-instructions.
ager@chromium.org5c838252010-02-19 08:53:10 +0000610
611 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
ager@chromium.org5c838252010-02-19 08:53:10 +0000612
machenbach@chromium.orgafbdadc2013-12-09 16:12:18 +0000613 void Ulw(Register rd, const MemOperand& rs);
614 void Usw(Register rd, const MemOperand& rs);
615
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000616 // Load int32 in the rd register.
danno@chromium.org88aa0582012-03-23 15:11:57 +0000617 void li(Register rd, Operand j, LiFlags mode = OPTIMIZE_SIZE);
618 inline void li(Register rd, int32_t j, LiFlags mode = OPTIMIZE_SIZE) {
619 li(rd, Operand(j), mode);
ager@chromium.org5c838252010-02-19 08:53:10 +0000620 }
verwaest@chromium.org057bd502013-11-06 12:03:29 +0000621 void li(Register dst, Handle<Object> value, LiFlags mode = OPTIMIZE_SIZE);
ager@chromium.org5c838252010-02-19 08:53:10 +0000622
ager@chromium.org5c838252010-02-19 08:53:10 +0000623 // Push multiple registers on the stack.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000624 // Registers are saved in numerical order, with higher numbered registers
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000625 // saved in higher memory addresses.
ager@chromium.org5c838252010-02-19 08:53:10 +0000626 void MultiPush(RegList regs);
627 void MultiPushReversed(RegList regs);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000628
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000629 void MultiPushFPU(RegList regs);
630 void MultiPushReversedFPU(RegList regs);
631
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000632 void push(Register src) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000633 Addu(sp, sp, Operand(-kPointerSize));
634 sw(src, MemOperand(sp, 0));
635 }
danno@chromium.org59400602013-08-13 17:09:37 +0000636 void Push(Register src) { push(src); }
lrn@chromium.org7516f052011-03-30 08:52:27 +0000637
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000638 // Push a handle.
639 void Push(Handle<Object> handle);
ulan@chromium.org09d7ab52013-02-25 15:50:35 +0000640 void Push(Smi* smi) { Push(Handle<Smi>(smi, isolate())); }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000641
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000642 // Push two registers. Pushes leftmost register first (to highest address).
643 void Push(Register src1, Register src2) {
lrn@chromium.org7516f052011-03-30 08:52:27 +0000644 Subu(sp, sp, Operand(2 * kPointerSize));
645 sw(src1, MemOperand(sp, 1 * kPointerSize));
646 sw(src2, MemOperand(sp, 0 * kPointerSize));
647 }
648
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000649 // Push three registers. Pushes leftmost register first (to highest address).
650 void Push(Register src1, Register src2, Register src3) {
651 Subu(sp, sp, Operand(3 * kPointerSize));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000652 sw(src1, MemOperand(sp, 2 * kPointerSize));
653 sw(src2, MemOperand(sp, 1 * kPointerSize));
654 sw(src3, MemOperand(sp, 0 * kPointerSize));
655 }
656
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000657 // Push four registers. Pushes leftmost register first (to highest address).
658 void Push(Register src1, Register src2, Register src3, Register src4) {
659 Subu(sp, sp, Operand(4 * kPointerSize));
lrn@chromium.org7516f052011-03-30 08:52:27 +0000660 sw(src1, MemOperand(sp, 3 * kPointerSize));
661 sw(src2, MemOperand(sp, 2 * kPointerSize));
662 sw(src3, MemOperand(sp, 1 * kPointerSize));
663 sw(src4, MemOperand(sp, 0 * kPointerSize));
664 }
665
ager@chromium.org5c838252010-02-19 08:53:10 +0000666 void Push(Register src, Condition cond, Register tst1, Register tst2) {
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000667 // Since we don't have conditional execution we use a Branch.
lrn@chromium.org7516f052011-03-30 08:52:27 +0000668 Branch(3, cond, tst1, Operand(tst2));
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000669 Subu(sp, sp, Operand(kPointerSize));
ager@chromium.org5c838252010-02-19 08:53:10 +0000670 sw(src, MemOperand(sp, 0));
671 }
672
673 // Pops multiple values from the stack and load them in the
674 // registers specified in regs. Pop order is the opposite as in MultiPush.
675 void MultiPop(RegList regs);
676 void MultiPopReversed(RegList regs);
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000677
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000678 void MultiPopFPU(RegList regs);
679 void MultiPopReversedFPU(RegList regs);
680
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000681 void pop(Register dst) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000682 lw(dst, MemOperand(sp, 0));
683 Addu(sp, sp, Operand(kPointerSize));
684 }
danno@chromium.org59400602013-08-13 17:09:37 +0000685 void Pop(Register dst) { pop(dst); }
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000686
687 // Pop two registers. Pops rightmost register first (from lower address).
688 void Pop(Register src1, Register src2) {
689 ASSERT(!src1.is(src2));
690 lw(src2, MemOperand(sp, 0 * kPointerSize));
691 lw(src1, MemOperand(sp, 1 * kPointerSize));
692 Addu(sp, sp, 2 * kPointerSize);
693 }
694
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000695 // Pop three registers. Pops rightmost register first (from lower address).
696 void Pop(Register src1, Register src2, Register src3) {
697 lw(src3, MemOperand(sp, 0 * kPointerSize));
698 lw(src2, MemOperand(sp, 1 * kPointerSize));
699 lw(src1, MemOperand(sp, 2 * kPointerSize));
700 Addu(sp, sp, 3 * kPointerSize);
701 }
702
lrn@chromium.org7516f052011-03-30 08:52:27 +0000703 void Pop(uint32_t count = 1) {
704 Addu(sp, sp, Operand(count * kPointerSize));
ager@chromium.org5c838252010-02-19 08:53:10 +0000705 }
706
lrn@chromium.org7516f052011-03-30 08:52:27 +0000707 // Push and pop the registers that can hold pointers, as defined by the
708 // RegList constant kSafepointSavedRegisters.
danno@chromium.org40cb8782011-05-25 07:58:50 +0000709 void PushSafepointRegisters();
710 void PopSafepointRegisters();
711 void PushSafepointRegistersAndDoubles();
712 void PopSafepointRegistersAndDoubles();
713 // Store value in register src in the safepoint stack slot for
714 // register dst.
715 void StoreToSafepointRegisterSlot(Register src, Register dst);
716 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
717 // Load the value of the src register from its safepoint stack slot
718 // into register dst.
719 void LoadFromSafepointRegisterSlot(Register dst, Register src);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000720
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000721 // Flush the I-cache from asm code. You should use CPU::FlushICache from C.
722 // Does not handle errors.
723 void FlushICache(Register address, unsigned instructions);
724
lrn@chromium.org7516f052011-03-30 08:52:27 +0000725 // MIPS32 R2 instruction macro.
726 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
727 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
728
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000729 // ---------------------------------------------------------------------------
730 // FPU macros. These do not handle special cases like NaN or +- inf.
731
lrn@chromium.org7516f052011-03-30 08:52:27 +0000732 // Convert unsigned word to double.
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000733 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
734 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000735
736 // Convert double to unsigned word.
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000737 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
738 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000739
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000740 void Trunc_w_d(FPURegister fd, FPURegister fs);
741 void Round_w_d(FPURegister fd, FPURegister fs);
742 void Floor_w_d(FPURegister fd, FPURegister fs);
743 void Ceil_w_d(FPURegister fd, FPURegister fs);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000744 // Wrapper function for the different cmp/branch types.
745 void BranchF(Label* target,
746 Label* nan,
747 Condition cc,
748 FPURegister cmp1,
749 FPURegister cmp2,
750 BranchDelaySlot bd = PROTECT);
751
752 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
753 inline void BranchF(BranchDelaySlot bd,
754 Label* target,
755 Label* nan,
756 Condition cc,
757 FPURegister cmp1,
758 FPURegister cmp2) {
759 BranchF(target, nan, cc, cmp1, cmp2, bd);
760 };
761
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000762 // Truncates a double using a specific rounding mode, and writes the value
763 // to the result register.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000764 // The except_flag will contain any exceptions caused by the instruction.
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000765 // If check_inexact is kDontCheckForInexactConversion, then the inexact
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000766 // exception is masked.
767 void EmitFPUTruncate(FPURoundingMode rounding_mode,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000768 Register result,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000769 DoubleRegister double_input,
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000770 Register scratch,
771 DoubleRegister double_scratch,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000772 Register except_flag,
773 CheckForInexactConversion check_inexact
774 = kDontCheckForInexactConversion);
775
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000776 // Performs a truncating conversion of a floating point number as used by
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000777 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. Goes to 'done' if it
778 // succeeds, otherwise falls through if result is saturated. On return
779 // 'result' either holds answer, or is clobbered on fall through.
780 //
781 // Only public for the test code in test-code-stubs-arm.cc.
782 void TryInlineTruncateDoubleToI(Register result,
783 DoubleRegister input,
784 Label* done);
785
786 // Performs a truncating conversion of a floating point number as used by
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000787 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000788 // Exits with 'result' holding the answer.
789 void TruncateDoubleToI(Register result, DoubleRegister double_input);
790
791 // Performs a truncating conversion of a heap number as used by
792 // the JS bitwise operations. See ECMA-262 9.5: ToInt32. 'result' and 'input'
793 // must be different registers. Exits with 'result' holding the answer.
794 void TruncateHeapNumberToI(Register result, Register object);
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000795
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +0000796 // Converts the smi or heap number in object to an int32 using the rules
797 // for ToInt32 as described in ECMAScript 9.5.: the value is truncated
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000798 // and brought into the range -2^31 .. +2^31 - 1. 'result' and 'input' must be
799 // different registers.
800 void TruncateNumberToI(Register object,
801 Register result,
802 Register heap_number_map,
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +0000803 Register scratch,
jkummerow@chromium.org8fa5bd92013-09-02 11:45:09 +0000804 Label* not_int32);
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +0000805
806 // Loads the number from object into dst register.
807 // If |object| is neither smi nor heap number, |not_number| is jumped to
808 // with |object| still intact.
809 void LoadNumber(Register object,
810 FPURegister dst,
811 Register heap_number_map,
812 Register scratch,
813 Label* not_number);
814
815 // Loads the number from object into double_dst in the double format.
816 // Control will jump to not_int32 if the value cannot be exactly represented
817 // by a 32-bit integer.
818 // Floating point value in the 32-bit integer range that are not exact integer
819 // won't be loaded.
820 void LoadNumberAsInt32Double(Register object,
821 DoubleRegister double_dst,
822 Register heap_number_map,
823 Register scratch1,
824 Register scratch2,
825 FPURegister double_scratch,
826 Label* not_int32);
827
828 // Loads the number from object into dst as a 32-bit integer.
829 // Control will jump to not_int32 if the object cannot be exactly represented
830 // by a 32-bit integer.
831 // Floating point value in the 32-bit integer range that are not exact integer
832 // won't be converted.
833 void LoadNumberAsInt32(Register object,
834 Register dst,
835 Register heap_number_map,
836 Register scratch1,
837 Register scratch2,
838 FPURegister double_scratch0,
839 FPURegister double_scratch1,
840 Label* not_int32);
841
lrn@chromium.org7516f052011-03-30 08:52:27 +0000842 // Enter exit frame.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000843 // argc - argument count to be dropped by LeaveExitFrame.
844 // save_doubles - saves FPU registers on stack, currently disabled.
845 // stack_space - extra stack space.
846 void EnterExitFrame(bool save_doubles,
847 int stack_space = 0);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000848
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000849 // Leave the current exit frame.
ulan@chromium.org6ff65142012-03-21 09:52:17 +0000850 void LeaveExitFrame(bool save_doubles,
851 Register arg_count,
machenbach@chromium.org528ce022013-09-23 14:09:36 +0000852 bool restore_context,
853 bool do_return = NO_EMIT_RETURN);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000854
lrn@chromium.org7516f052011-03-30 08:52:27 +0000855 // Get the actual activation frame alignment for target environment.
856 static int ActivationFrameAlignment();
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000857
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000858 // Make sure the stack is aligned. Only emits code in debug mode.
859 void AssertStackIsAligned();
860
lrn@chromium.org7516f052011-03-30 08:52:27 +0000861 void LoadContext(Register dst, int context_chain_length);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000862
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000863 // Conditionally load the cached Array transitioned map of type
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000864 // transitioned_kind from the native context if the map in register
865 // map_in_out is the cached Array map in the native context of
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000866 // expected_kind.
867 void LoadTransitionedArrayMapConditional(
868 ElementsKind expected_kind,
869 ElementsKind transitioned_kind,
870 Register map_in_out,
871 Register scratch,
872 Label* no_map_match);
873
lrn@chromium.org7516f052011-03-30 08:52:27 +0000874 void LoadGlobalFunction(int index, Register function);
875
876 // Load the initial map from the global function. The registers
877 // function and map can be the same, function is then overwritten.
878 void LoadGlobalFunctionInitialMap(Register function,
879 Register map,
880 Register scratch);
881
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000882 void InitializeRootRegister() {
883 ExternalReference roots_array_start =
884 ExternalReference::roots_array_start(isolate());
885 li(kRootRegister, Operand(roots_array_start));
886 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000887
lrn@chromium.org7516f052011-03-30 08:52:27 +0000888 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000889 // JavaScript invokes.
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000890
891 // Invoke the JavaScript function code by either calling or jumping.
892 void InvokeCode(Register code,
893 const ParameterCount& expected,
894 const ParameterCount& actual,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000895 InvokeFlag flag,
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000896 const CallWrapper& call_wrapper);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000897
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000898 // Invoke the JavaScript function in the given register. Changes the
899 // current context to the context in the function before invoking.
900 void InvokeFunction(Register function,
901 const ParameterCount& actual,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000902 InvokeFlag flag,
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000903 const CallWrapper& call_wrapper);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000904
machenbach@chromium.org8a58f642013-12-02 10:46:30 +0000905 void InvokeFunction(Register function,
906 const ParameterCount& expected,
907 const ParameterCount& actual,
908 InvokeFlag flag,
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000909 const CallWrapper& call_wrapper);
machenbach@chromium.org8a58f642013-12-02 10:46:30 +0000910
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000911 void InvokeFunction(Handle<JSFunction> function,
ulan@chromium.org32d7dba2013-04-24 10:59:06 +0000912 const ParameterCount& expected,
lrn@chromium.org7516f052011-03-30 08:52:27 +0000913 const ParameterCount& actual,
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000914 InvokeFlag flag,
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000915 const CallWrapper& call_wrapper);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000916
917
lrn@chromium.org7516f052011-03-30 08:52:27 +0000918 void IsObjectJSObjectType(Register heap_object,
919 Register map,
920 Register scratch,
921 Label* fail);
922
923 void IsInstanceJSObjectType(Register map,
924 Register scratch,
925 Label* fail);
926
927 void IsObjectJSStringType(Register object,
928 Register scratch,
929 Label* fail);
930
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +0000931 void IsObjectNameType(Register object,
932 Register scratch,
933 Label* fail);
934
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000935#ifdef ENABLE_DEBUGGER_SUPPORT
lrn@chromium.org7516f052011-03-30 08:52:27 +0000936 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000937 // Debugger Support.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000938
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000939 void DebugBreak();
940#endif
941
942
lrn@chromium.org7516f052011-03-30 08:52:27 +0000943 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000944 // Exception handling.
ager@chromium.org5c838252010-02-19 08:53:10 +0000945
946 // Push a new try handler and link into try handler chain.
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000947 void PushTryHandler(StackHandler::Kind kind, int handler_index);
ager@chromium.org5c838252010-02-19 08:53:10 +0000948
949 // Unlink the stack handler on top of the stack from the try handler chain.
950 // Must preserve the result register.
951 void PopTryHandler();
952
ulan@chromium.org65a89c22012-02-14 11:46:07 +0000953 // Passes thrown value to the handler of top of the try handler chain.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000954 void Throw(Register value);
955
956 // Propagates an uncatchable exception to the top of the current JS stack's
957 // handler chain.
ulan@chromium.org65a89c22012-02-14 11:46:07 +0000958 void ThrowUncatchable(Register value);
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000959
machenbach@chromium.org9af454f2013-11-20 09:25:57 +0000960 // Throw a message string as an exception.
961 void Throw(BailoutReason reason);
962
963 // Throw a message string as an exception if a condition is not true.
964 void ThrowIf(Condition cc, BailoutReason reason, Register rs, Operand rt);
965
lrn@chromium.org7516f052011-03-30 08:52:27 +0000966 // Copies a fixed number of fields of heap objects from src to dst.
967 void CopyFields(Register dst, Register src, RegList temps, int field_count);
ager@chromium.org5c838252010-02-19 08:53:10 +0000968
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000969 // Copies a number of bytes from src to dst. All registers are clobbered. On
970 // exit src and dst will point to the place just after where the last byte was
971 // read or written and length will be zero.
972 void CopyBytes(Register src,
973 Register dst,
974 Register length,
975 Register scratch);
976
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000977 // Initialize fields with filler values. Fields starting at |start_offset|
978 // not including end_offset are overwritten with the value in |filler|. At
979 // the end the loop, |start_offset| takes the value of |end_offset|.
980 void InitializeFieldsWithFiller(Register start_offset,
981 Register end_offset,
982 Register filler);
983
lrn@chromium.org7516f052011-03-30 08:52:27 +0000984 // -------------------------------------------------------------------------
ager@chromium.org5c838252010-02-19 08:53:10 +0000985 // Support functions.
986
lrn@chromium.org7516f052011-03-30 08:52:27 +0000987 // Try to get function prototype of a function and puts the value in
988 // the result register. Checks that the function really is a
989 // function and jumps to the miss label if the fast checks fail. The
990 // function register will be untouched; the other registers may be
991 // clobbered.
992 void TryGetFunctionPrototype(Register function,
993 Register result,
994 Register scratch,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000995 Label* miss,
996 bool miss_on_bound_function = false);
lrn@chromium.org7516f052011-03-30 08:52:27 +0000997
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000998 void GetObjectType(Register function,
999 Register map,
1000 Register type_reg);
1001
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00001002 // Check if a map for a JSObject indicates that the object has fast elements.
1003 // Jump to the specified label if it does not.
1004 void CheckFastElements(Register map,
1005 Register scratch,
1006 Label* fail);
1007
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001008 // Check if a map for a JSObject indicates that the object can have both smi
1009 // and HeapObject elements. Jump to the specified label if it does not.
1010 void CheckFastObjectElements(Register map,
1011 Register scratch,
1012 Label* fail);
1013
1014 // Check if a map for a JSObject indicates that the object has fast smi only
1015 // elements. Jump to the specified label if it does not.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001016 void CheckFastSmiElements(Register map,
1017 Register scratch,
1018 Label* fail);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001019
1020 // Check to see if maybe_number can be stored as a double in
1021 // FastDoubleElements. If it can, store it at the index specified by key in
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +00001022 // the FastDoubleElements array elements. Otherwise jump to fail.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001023 void StoreNumberToDoubleElements(Register value_reg,
1024 Register key_reg,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001025 Register elements_reg,
1026 Register scratch1,
1027 Register scratch2,
1028 Register scratch3,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001029 Label* fail,
1030 int elements_offset = 0);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001031
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001032 // Compare an object's map with the specified map and its transitioned
1033 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
1034 // "branch_to" if the result of the comparison is "cond". If multiple map
1035 // compares are required, the compare sequences branches to early_success.
1036 void CompareMapAndBranch(Register obj,
1037 Register scratch,
1038 Handle<Map> map,
1039 Label* early_success,
1040 Condition cond,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001041 Label* branch_to);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001042
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001043 // As above, but the map of the object is already loaded into the register
1044 // which is preserved by the code generated.
1045 void CompareMapAndBranch(Register obj_map,
1046 Handle<Map> map,
1047 Label* early_success,
1048 Condition cond,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001049 Label* branch_to);
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001050
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001051 // Check if the map of an object is equal to a specified map and branch to
1052 // label if not. Skip the smi check if not required (object is known to be a
1053 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
1054 // against maps that are ElementsKind transition maps of the specificed map.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001055 void CheckMap(Register obj,
1056 Register scratch,
1057 Handle<Map> map,
1058 Label* fail,
svenpanne@chromium.orga53e8e02013-05-24 12:35:50 +00001059 SmiCheckType smi_check_type);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001060
ager@chromium.org5c838252010-02-19 08:53:10 +00001061
lrn@chromium.org7516f052011-03-30 08:52:27 +00001062 void CheckMap(Register obj,
1063 Register scratch,
1064 Heap::RootListIndex index,
1065 Label* fail,
danno@chromium.org40cb8782011-05-25 07:58:50 +00001066 SmiCheckType smi_check_type);
1067
1068 // Check if the map of an object is equal to a specified map and branch to a
1069 // specified target if equal. Skip the smi check if not required (object is
1070 // known to be a heap object)
1071 void DispatchMap(Register obj,
1072 Register scratch,
1073 Handle<Map> map,
1074 Handle<Code> success,
1075 SmiCheckType smi_check_type);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001076
1077 // Generates code for reporting that an illegal operation has
1078 // occurred.
1079 void IllegalOperation(int num_arguments);
1080
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001081
1082 // Load and check the instance type of an object for being a string.
1083 // Loads the type into the second argument register.
1084 // Returns a condition that will be enabled if the object was a string.
1085 Condition IsObjectStringType(Register obj,
1086 Register type,
1087 Register result) {
1088 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
1089 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
1090 And(type, type, Operand(kIsNotStringMask));
1091 ASSERT_EQ(0, kStringTag);
1092 return eq;
1093 }
1094
1095
lrn@chromium.org7516f052011-03-30 08:52:27 +00001096 // Picks out an array index from the hash field.
1097 // Register use:
1098 // hash - holds the index's hash. Clobbered.
1099 // index - holds the overwritten index on exit.
1100 void IndexFromHash(Register hash, Register index);
ager@chromium.org5c838252010-02-19 08:53:10 +00001101
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001102 // Get the number of least significant bits from a register.
1103 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1104 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1105
lrn@chromium.org7516f052011-03-30 08:52:27 +00001106 // Load the value of a number object into a FPU double register. If the
1107 // object is not a number a jump to the label not_number is performed
1108 // and the FPU double register is unchanged.
1109 void ObjectToDoubleFPURegister(
1110 Register object,
1111 FPURegister value,
1112 Register scratch1,
1113 Register scratch2,
1114 Register heap_number_map,
1115 Label* not_number,
1116 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1117
1118 // Load the value of a smi object into a FPU double register. The register
1119 // scratch1 can be the same register as smi in which case smi will hold the
1120 // untagged value afterwards.
1121 void SmiToDoubleFPURegister(Register smi,
1122 FPURegister value,
1123 Register scratch1);
1124
1125 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001126 // Overflow handling functions.
1127 // Usage: first call the appropriate arithmetic function, then call one of the
1128 // jump functions with the overflow_dst register as the second parameter.
1129
1130 void AdduAndCheckForOverflow(Register dst,
1131 Register left,
1132 Register right,
1133 Register overflow_dst,
1134 Register scratch = at);
1135
1136 void SubuAndCheckForOverflow(Register dst,
1137 Register left,
1138 Register right,
1139 Register overflow_dst,
1140 Register scratch = at);
1141
1142 void BranchOnOverflow(Label* label,
1143 Register overflow_check,
1144 BranchDelaySlot bd = PROTECT) {
1145 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1146 }
1147
1148 void BranchOnNoOverflow(Label* label,
1149 Register overflow_check,
1150 BranchDelaySlot bd = PROTECT) {
1151 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1152 }
1153
1154 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1155 Ret(lt, overflow_check, Operand(zero_reg), bd);
1156 }
1157
1158 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1159 Ret(ge, overflow_check, Operand(zero_reg), bd);
1160 }
1161
1162 // -------------------------------------------------------------------------
1163 // Runtime calls.
ager@chromium.org5c838252010-02-19 08:53:10 +00001164
ulan@chromium.org6ff65142012-03-21 09:52:17 +00001165 // See comments at the beginning of CEntryStub::Generate.
1166 inline void PrepareCEntryArgs(int num_args) {
1167 li(s0, num_args);
1168 li(s1, (num_args - 1) * kPointerSize);
1169 }
1170
1171 inline void PrepareCEntryFunction(const ExternalReference& ref) {
1172 li(s2, Operand(ref));
1173 }
1174
ulan@chromium.org0f13e742014-01-03 15:51:11 +00001175#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
1176const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
1177
ager@chromium.org5c838252010-02-19 08:53:10 +00001178 // Call a code stub.
ulan@chromium.org6ff65142012-03-21 09:52:17 +00001179 void CallStub(CodeStub* stub,
jkummerow@chromium.org59297c72013-01-09 16:32:23 +00001180 TypeFeedbackId ast_id = TypeFeedbackId::None(),
ulan@chromium.org0f13e742014-01-03 15:51:11 +00001181 COND_ARGS);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001182
1183 // Tail call a code stub (jump).
ulan@chromium.org0f13e742014-01-03 15:51:11 +00001184 void TailCallStub(CodeStub* stub, COND_ARGS);
1185
1186#undef COND_ARGS
lrn@chromium.org7516f052011-03-30 08:52:27 +00001187
ager@chromium.org5c838252010-02-19 08:53:10 +00001188 void CallJSExitStub(CodeStub* stub);
1189
ager@chromium.org5c838252010-02-19 08:53:10 +00001190 // Call a runtime routine.
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +00001191 void CallRuntime(const Runtime::Function* f,
1192 int num_arguments,
1193 SaveFPRegsMode save_doubles = kDontSaveFPRegs);
1194 void CallRuntimeSaveDoubles(Runtime::FunctionId id) {
1195 const Runtime::Function* function = Runtime::FunctionForId(id);
1196 CallRuntime(function, function->nargs, kSaveFPRegs);
1197 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001198
1199 // Convenience function: Same as above, but takes the fid instead.
machenbach@chromium.orgf9841892013-11-25 12:01:13 +00001200 void CallRuntime(Runtime::FunctionId id,
1201 int num_arguments,
1202 SaveFPRegsMode save_doubles = kDontSaveFPRegs) {
1203 CallRuntime(Runtime::FunctionForId(id), num_arguments, save_doubles);
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +00001204 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001205
lrn@chromium.org7516f052011-03-30 08:52:27 +00001206 // Convenience function: call an external reference.
1207 void CallExternalReference(const ExternalReference& ext,
ulan@chromium.org6ff65142012-03-21 09:52:17 +00001208 int num_arguments,
1209 BranchDelaySlot bd = PROTECT);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001210
ager@chromium.org5c838252010-02-19 08:53:10 +00001211 // Tail call of a runtime routine (jump).
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001212 // Like JumpToExternalReference, but also takes care of passing the number
ager@chromium.org5c838252010-02-19 08:53:10 +00001213 // of parameters.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001214 void TailCallExternalReference(const ExternalReference& ext,
1215 int num_arguments,
1216 int result_size);
1217
1218 // Convenience function: tail call a runtime routine (jump).
1219 void TailCallRuntime(Runtime::FunctionId fid,
ager@chromium.org5c838252010-02-19 08:53:10 +00001220 int num_arguments,
1221 int result_size);
1222
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001223 int CalculateStackPassedWords(int num_reg_arguments,
1224 int num_double_arguments);
1225
lrn@chromium.org7516f052011-03-30 08:52:27 +00001226 // Before calling a C-function from generated code, align arguments on stack
1227 // and add space for the four mips argument slots.
1228 // After aligning the frame, non-register arguments must be stored on the
1229 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1230 // The argument count assumes all arguments are word sized.
1231 // Some compilers/platforms require the stack to be aligned when calling
1232 // C++ code.
1233 // Needs a scratch register to do some arithmetic. This register will be
1234 // trashed.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001235 void PrepareCallCFunction(int num_reg_arguments,
1236 int num_double_registers,
1237 Register scratch);
1238 void PrepareCallCFunction(int num_reg_arguments,
1239 Register scratch);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001240
1241 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1242 // Arguments 5..n are stored to stack using following:
1243 // sw(t0, CFunctionArgumentOperand(5));
1244
1245 // Calls a C function and cleans up the space for arguments allocated
1246 // by PrepareCallCFunction. The called function is not allowed to trigger a
1247 // garbage collection, since that might move the code and invalidate the
1248 // return address (unless this is somehow accounted for by the called
1249 // function).
1250 void CallCFunction(ExternalReference function, int num_arguments);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001251 void CallCFunction(Register function, int num_arguments);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001252 void CallCFunction(ExternalReference function,
1253 int num_reg_arguments,
1254 int num_double_arguments);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001255 void CallCFunction(Register function,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001256 int num_reg_arguments,
1257 int num_double_arguments);
machenbach@chromium.org4ddd2f12014-01-14 08:13:44 +00001258 void MovFromFloatResult(DoubleRegister dst);
1259 void MovFromFloatParameter(DoubleRegister dst);
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001260
danno@chromium.org40cb8782011-05-25 07:58:50 +00001261 // There are two ways of passing double arguments on MIPS, depending on
1262 // whether soft or hard floating point ABI is used. These functions
1263 // abstract parameter passing for the three different ways we call
1264 // C functions from generated code.
machenbach@chromium.org4ddd2f12014-01-14 08:13:44 +00001265 void MovToFloatParameter(DoubleRegister src);
1266 void MovToFloatParameters(DoubleRegister src1, DoubleRegister src2);
1267 void MovToFloatResult(DoubleRegister src);
danno@chromium.org40cb8782011-05-25 07:58:50 +00001268
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001269 // Calls an API function. Allocates HandleScope, extracts returned value
1270 // from handle and propagates exceptions. Restores context. stack_space
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001271 // - space to be unwound on exit (includes the call JS arguments space and
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001272 // the additional space allocated for the fast call).
machenbach@chromium.orge014e5b2014-01-28 07:51:38 +00001273 void CallApiFunctionAndReturn(Register function_address,
dslomov@chromium.orgb752d402013-06-18 11:54:54 +00001274 ExternalReference thunk_ref,
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001275 int stack_space,
machenbach@chromium.org528ce022013-09-23 14:09:36 +00001276 MemOperand return_value_operand,
1277 MemOperand* context_restore_operand);
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00001278
ager@chromium.org5c838252010-02-19 08:53:10 +00001279 // Jump to the builtin routine.
ulan@chromium.org6ff65142012-03-21 09:52:17 +00001280 void JumpToExternalReference(const ExternalReference& builtin,
1281 BranchDelaySlot bd = PROTECT);
ager@chromium.org5c838252010-02-19 08:53:10 +00001282
1283 // Invoke specified builtin JavaScript function. Adds an entry to
1284 // the unresolved list if the name does not resolve.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001285 void InvokeBuiltin(Builtins::JavaScript id,
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00001286 InvokeFlag flag,
fschneider@chromium.orgfb144a02011-05-04 12:43:48 +00001287 const CallWrapper& call_wrapper = NullCallWrapper());
ager@chromium.org5c838252010-02-19 08:53:10 +00001288
1289 // Store the code object for the given builtin in the target register and
lrn@chromium.org7516f052011-03-30 08:52:27 +00001290 // setup the function in a1.
ager@chromium.org5c838252010-02-19 08:53:10 +00001291 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1292
lrn@chromium.org7516f052011-03-30 08:52:27 +00001293 // Store the function for the given builtin in the target register.
1294 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1295
ager@chromium.org5c838252010-02-19 08:53:10 +00001296 struct Unresolved {
1297 int pc;
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001298 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
ager@chromium.org5c838252010-02-19 08:53:10 +00001299 const char* name;
1300 };
ager@chromium.org5c838252010-02-19 08:53:10 +00001301
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001302 Handle<Object> CodeObject() {
1303 ASSERT(!code_object_.is_null());
1304 return code_object_;
1305 }
ager@chromium.org5c838252010-02-19 08:53:10 +00001306
machenbach@chromium.org69f64b12014-03-20 01:04:55 +00001307 // Emit code for a truncating division by a constant. The dividend register is
machenbach@chromium.orgbcc36722014-03-11 07:52:26 +00001308 // unchanged and at gets clobbered. Dividend and result must be different.
machenbach@chromium.org69f64b12014-03-20 01:04:55 +00001309 void TruncatingDiv(Register result, Register dividend, int32_t divisor);
machenbach@chromium.orgbcc36722014-03-11 07:52:26 +00001310
lrn@chromium.org7516f052011-03-30 08:52:27 +00001311 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001312 // StatsCounter support.
ager@chromium.org5c838252010-02-19 08:53:10 +00001313
1314 void SetCounter(StatsCounter* counter, int value,
1315 Register scratch1, Register scratch2);
1316 void IncrementCounter(StatsCounter* counter, int value,
1317 Register scratch1, Register scratch2);
1318 void DecrementCounter(StatsCounter* counter, int value,
1319 Register scratch1, Register scratch2);
1320
1321
lrn@chromium.org7516f052011-03-30 08:52:27 +00001322 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001323 // Debugging.
ager@chromium.org5c838252010-02-19 08:53:10 +00001324
1325 // Calls Abort(msg) if the condition cc is not satisfied.
1326 // Use --debug_code to enable.
danno@chromium.org59400602013-08-13 17:09:37 +00001327 void Assert(Condition cc, BailoutReason reason, Register rs, Operand rt);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001328 void AssertFastElements(Register elements);
ager@chromium.org5c838252010-02-19 08:53:10 +00001329
1330 // Like Assert(), but always enabled.
danno@chromium.org59400602013-08-13 17:09:37 +00001331 void Check(Condition cc, BailoutReason reason, Register rs, Operand rt);
ager@chromium.org5c838252010-02-19 08:53:10 +00001332
1333 // Print a message to stdout and abort execution.
danno@chromium.org59400602013-08-13 17:09:37 +00001334 void Abort(BailoutReason msg);
ager@chromium.org5c838252010-02-19 08:53:10 +00001335
1336 // Verify restrictions about code generated in stubs.
1337 void set_generating_stub(bool value) { generating_stub_ = value; }
1338 bool generating_stub() { return generating_stub_; }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001339 void set_has_frame(bool value) { has_frame_ = value; }
1340 bool has_frame() { return has_frame_; }
1341 inline bool AllowThisStubCall(CodeStub* stub);
ager@chromium.org5c838252010-02-19 08:53:10 +00001342
lrn@chromium.org7516f052011-03-30 08:52:27 +00001343 // ---------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001344 // Number utilities.
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001345
lrn@chromium.org7516f052011-03-30 08:52:27 +00001346 // Check whether the value of reg is a power of two and not zero. If not
1347 // control continues at the label not_power_of_two. If reg is a power of two
1348 // the register scratch contains the value of (reg - 1) when control falls
1349 // through.
1350 void JumpIfNotPowerOfTwoOrZero(Register reg,
1351 Register scratch,
1352 Label* not_power_of_two_or_zero);
1353
1354 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001355 // Smi utilities.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001356
lrn@chromium.org7516f052011-03-30 08:52:27 +00001357 void SmiTag(Register reg) {
1358 Addu(reg, reg, reg);
1359 }
1360
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001361 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001362 void SmiTagCheckOverflow(Register reg, Register overflow);
1363 void SmiTagCheckOverflow(Register dst, Register src, Register overflow);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001364
lrn@chromium.org7516f052011-03-30 08:52:27 +00001365 void SmiTag(Register dst, Register src) {
1366 Addu(dst, src, src);
1367 }
1368
machenbach@chromium.org7ff76072013-11-21 09:47:43 +00001369 // Try to convert int32 to smi. If the value is to large, preserve
1370 // the original value and jump to not_a_smi. Destroys scratch and
1371 // sets flags.
1372 void TrySmiTag(Register reg, Register scratch, Label* not_a_smi) {
1373 TrySmiTag(reg, reg, scratch, not_a_smi);
1374 }
1375 void TrySmiTag(Register dst,
1376 Register src,
1377 Register scratch,
1378 Label* not_a_smi) {
1379 SmiTagCheckOverflow(at, src, scratch);
1380 BranchOnOverflow(not_a_smi, scratch);
1381 mov(dst, at);
1382 }
1383
lrn@chromium.org7516f052011-03-30 08:52:27 +00001384 void SmiUntag(Register reg) {
1385 sra(reg, reg, kSmiTagSize);
1386 }
1387
1388 void SmiUntag(Register dst, Register src) {
1389 sra(dst, src, kSmiTagSize);
1390 }
1391
machenbach@chromium.org7ff76072013-11-21 09:47:43 +00001392 // Test if the register contains a smi.
1393 inline void SmiTst(Register value, Register scratch) {
1394 And(scratch, value, Operand(kSmiTagMask));
1395 }
1396 inline void NonNegativeSmiTst(Register value, Register scratch) {
1397 And(scratch, value, Operand(kSmiTagMask | kSmiSignMask));
1398 }
1399
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001400 // Untag the source value into destination and jump if source is a smi.
1401 // Souce and destination can be the same register.
1402 void UntagAndJumpIfSmi(Register dst, Register src, Label* smi_case);
1403
1404 // Untag the source value into destination and jump if source is not a smi.
1405 // Souce and destination can be the same register.
1406 void UntagAndJumpIfNotSmi(Register dst, Register src, Label* non_smi_case);
1407
lrn@chromium.org7516f052011-03-30 08:52:27 +00001408 // Jump the register contains a smi.
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001409 void JumpIfSmi(Register value,
1410 Label* smi_label,
1411 Register scratch = at,
1412 BranchDelaySlot bd = PROTECT);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001413
1414 // Jump if the register contains a non-smi.
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001415 void JumpIfNotSmi(Register value,
1416 Label* not_smi_label,
1417 Register scratch = at,
1418 BranchDelaySlot bd = PROTECT);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001419
1420 // Jump if either of the registers contain a non-smi.
1421 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1422 // Jump if either of the registers contain a smi.
1423 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1424
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +00001425 // Abort execution if argument is a smi, enabled via --debug-code.
1426 void AssertNotSmi(Register object);
1427 void AssertSmi(Register object);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001428
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +00001429 // Abort execution if argument is not a string, enabled via --debug-code.
1430 void AssertString(Register object);
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001431
svenpanne@chromium.org9faefa42013-03-08 13:13:16 +00001432 // Abort execution if argument is not a name, enabled via --debug-code.
1433 void AssertName(Register object);
1434
machenbach@chromium.org2904d1a2014-03-18 01:05:18 +00001435 // Abort execution if argument is not undefined or an AllocationSite, enabled
1436 // via --debug-code.
1437 void AssertUndefinedOrAllocationSite(Register object, Register scratch);
1438
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +00001439 // Abort execution if reg is not the root value with the given index,
svenpanne@chromium.orgc859c4f2012-10-15 11:51:39 +00001440 // enabled via --debug-code.
mstarzinger@chromium.org1f410f92013-08-29 08:13:16 +00001441 void AssertIsRoot(Register reg, Heap::RootListIndex index);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001442
1443 // ---------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001444 // HeapNumber utilities.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001445
1446 void JumpIfNotHeapNumber(Register object,
1447 Register heap_number_map,
1448 Register scratch,
1449 Label* on_not_heap_number);
1450
1451 // -------------------------------------------------------------------------
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001452 // String utilities.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001453
machenbach@chromium.org528ce022013-09-23 14:09:36 +00001454 // Generate code to do a lookup in the number string cache. If the number in
1455 // the register object is found in the cache the generated code falls through
1456 // with the result in the result register. The object and the result register
1457 // can be the same. If the number is not found in the cache the code jumps to
1458 // the label not_found with only the content of register object unchanged.
1459 void LookupNumberStringCache(Register object,
1460 Register result,
1461 Register scratch1,
1462 Register scratch2,
1463 Register scratch3,
1464 Label* not_found);
1465
lrn@chromium.org7516f052011-03-30 08:52:27 +00001466 // Checks if both instance types are sequential ASCII strings and jumps to
1467 // label if either is not.
1468 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1469 Register first_object_instance_type,
1470 Register second_object_instance_type,
1471 Register scratch1,
1472 Register scratch2,
1473 Label* failure);
1474
1475 // Check if instance type is sequential ASCII string and jump to label if
1476 // it is not.
1477 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1478 Register scratch,
1479 Label* failure);
1480
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001481 void JumpIfNotUniqueName(Register reg, Label* not_unique_name);
1482
machenbach@chromium.org9af454f2013-11-20 09:25:57 +00001483 void EmitSeqStringSetCharCheck(Register string,
1484 Register index,
1485 Register value,
1486 Register scratch,
1487 uint32_t encoding_mask);
1488
lrn@chromium.org7516f052011-03-30 08:52:27 +00001489 // Test that both first and second are sequential ASCII strings.
1490 // Assume that they are non-smis.
1491 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,
1492 Register second,
1493 Register scratch1,
1494 Register scratch2,
1495 Label* failure);
1496
1497 // Test that both first and second are sequential ASCII strings.
1498 // Check that they are non-smis.
1499 void JumpIfNotBothSequentialAsciiStrings(Register first,
1500 Register second,
1501 Register scratch1,
1502 Register scratch2,
1503 Label* failure);
1504
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001505 void ClampUint8(Register output_reg, Register input_reg);
1506
1507 void ClampDoubleToUint8(Register result_reg,
1508 DoubleRegister input_reg,
1509 DoubleRegister temp_double_reg);
1510
1511
rossberg@chromium.org89e18f52012-10-22 13:09:53 +00001512 void LoadInstanceDescriptors(Register map, Register descriptors);
jkummerow@chromium.org78502a92012-09-06 13:50:42 +00001513 void EnumLength(Register dst, Register map);
verwaest@chromium.org33e09c82012-10-10 17:07:22 +00001514 void NumberOfOwnDescriptors(Register dst, Register map);
danno@chromium.org40cb8782011-05-25 07:58:50 +00001515
verwaest@chromium.org33e09c82012-10-10 17:07:22 +00001516 template<typename Field>
1517 void DecodeField(Register reg) {
1518 static const int shift = Field::kShift;
1519 static const int mask = (Field::kMask >> shift) << kSmiTagSize;
1520 srl(reg, reg, shift);
1521 And(reg, reg, Operand(mask));
1522 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001523
bmeurer@chromium.orgc9913f02013-10-24 06:31:36 +00001524 // Generates function and stub prologue code.
1525 void Prologue(PrologueFrameMode frame_mode);
1526
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001527 // Activation support.
1528 void EnterFrame(StackFrame::Type type);
1529 void LeaveFrame(StackFrame::Type type);
1530
1531 // Patch the relocated value (lui/ori pair).
1532 void PatchRelocatedValue(Register li_location,
1533 Register scratch,
1534 Register new_value);
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001535 // Get the relocatad value (loaded data) from the lui/ori pair.
1536 void GetRelocatedValue(Register li_location,
1537 Register value,
1538 Register scratch);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001539
ulan@chromium.org812308e2012-02-29 15:58:45 +00001540 // Expects object in a0 and returns map with validated enum cache
1541 // in a0. Assumes that any other register can be used as a scratch.
1542 void CheckEnumCache(Register null_value, Label* call_runtime);
1543
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +00001544 // AllocationMemento support. Arrays may have an associated
1545 // AllocationMemento object that can be checked for in order to pretransition
jkummerow@chromium.org59297c72013-01-09 16:32:23 +00001546 // to another type.
1547 // On entry, receiver_reg should point to the array object.
1548 // scratch_reg gets clobbered.
mstarzinger@chromium.orgb4968be2013-10-16 09:00:56 +00001549 // If allocation info is present, jump to allocation_memento_present.
1550 void TestJSArrayForAllocationMemento(
1551 Register receiver_reg,
1552 Register scratch_reg,
1553 Label* no_memento_found,
1554 Condition cond = al,
1555 Label* allocation_memento_present = NULL);
1556
1557 void JumpIfJSArrayHasAllocationMemento(Register receiver_reg,
1558 Register scratch_reg,
1559 Label* memento_found) {
1560 Label no_memento_found;
1561 TestJSArrayForAllocationMemento(receiver_reg, scratch_reg,
1562 &no_memento_found, eq, memento_found);
1563 bind(&no_memento_found);
1564 }
jkummerow@chromium.org59297c72013-01-09 16:32:23 +00001565
machenbach@chromium.orge8412be2013-11-08 10:23:52 +00001566 // Jumps to found label if a prototype map has dictionary elements.
1567 void JumpIfDictionaryInPrototypeChain(Register object, Register scratch0,
1568 Register scratch1, Label* found);
1569
lrn@chromium.org7516f052011-03-30 08:52:27 +00001570 private:
1571 void CallCFunctionHelper(Register function,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001572 int num_reg_arguments,
1573 int num_double_arguments);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001574
vegorov@chromium.org3cf47312011-06-29 13:20:01 +00001575 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1576 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1577 const Operand& rt,
1578 BranchDelaySlot bdslot = PROTECT);
1579 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1580 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1581 const Operand& rt,
1582 BranchDelaySlot bdslot = PROTECT);
1583 void J(Label* L, BranchDelaySlot bdslot);
1584 void Jr(Label* L, BranchDelaySlot bdslot);
1585 void Jalr(Label* L, BranchDelaySlot bdslot);
1586
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001587 // Helper functions for generating invokes.
1588 void InvokePrologue(const ParameterCount& expected,
1589 const ParameterCount& actual,
1590 Handle<Code> code_constant,
1591 Register code_reg,
1592 Label* done,
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001593 bool* definitely_mismatches,
lrn@chromium.org7516f052011-03-30 08:52:27 +00001594 InvokeFlag flag,
machenbach@chromium.orge31286d2014-01-15 10:29:52 +00001595 const CallWrapper& call_wrapper);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00001596
1597 // Get the code for the given builtin. Returns if able to resolve
1598 // the function in the 'resolved' flag.
1599 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1600
lrn@chromium.org7516f052011-03-30 08:52:27 +00001601 void InitializeNewString(Register string,
1602 Register length,
1603 Heap::RootListIndex map_index,
1604 Register scratch1,
1605 Register scratch2);
1606
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00001607 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1608 void InNewSpace(Register object,
1609 Register scratch,
1610 Condition cond, // eq for new space, ne otherwise.
1611 Label* branch);
1612
1613 // Helper for finding the mark bits for an address. Afterwards, the
1614 // bitmap register points at the word with the mark bits and the mask
1615 // the position of the first bit. Leaves addr_reg unchanged.
1616 inline void GetMarkBits(Register addr_reg,
1617 Register bitmap_reg,
1618 Register mask_reg);
1619
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00001620 // Helper for throwing exceptions. Compute a handler address and jump to
1621 // it. See the implementation for register usage.
1622 void JumpToHandlerEntry();
1623
danno@chromium.org40cb8782011-05-25 07:58:50 +00001624 // Compute memory operands for safepoint stack slots.
1625 static int SafepointRegisterStackIndex(int reg_code);
1626 MemOperand SafepointRegisterSlot(Register reg);
1627 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001628
1629 bool generating_stub_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001630 bool has_frame_;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001631 // This handle will be patched with the code object on installation.
1632 Handle<Object> code_object_;
danno@chromium.org40cb8782011-05-25 07:58:50 +00001633
jkummerow@chromium.org59297c72013-01-09 16:32:23 +00001634 // Needs access to SafepointRegisterStackIndex for compiled frame
danno@chromium.org40cb8782011-05-25 07:58:50 +00001635 // traversal.
jkummerow@chromium.org59297c72013-01-09 16:32:23 +00001636 friend class StandardFrame;
lrn@chromium.org7516f052011-03-30 08:52:27 +00001637};
1638
1639
lrn@chromium.org7516f052011-03-30 08:52:27 +00001640// The code patcher is used to patch (typically) small parts of code e.g. for
1641// debugging and other types of instrumentation. When using the code patcher
1642// the exact number of bytes specified must be emitted. It is not legal to emit
1643// relocation information. If any of these constraints are violated it causes
1644// an assertion to fail.
1645class CodePatcher {
1646 public:
1647 CodePatcher(byte* address, int instructions);
1648 virtual ~CodePatcher();
1649
1650 // Macro assembler to emit code.
1651 MacroAssembler* masm() { return &masm_; }
1652
1653 // Emit an instruction directly.
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001654 void Emit(Instr instr);
lrn@chromium.org7516f052011-03-30 08:52:27 +00001655
1656 // Emit an address directly.
1657 void Emit(Address addr);
1658
karlklose@chromium.org83a47282011-05-11 11:54:09 +00001659 // Change the condition part of an instruction leaving the rest of the current
1660 // instruction unchanged.
1661 void ChangeBranchCondition(Condition cond);
1662
lrn@chromium.org7516f052011-03-30 08:52:27 +00001663 private:
1664 byte* address_; // The address of the code being patched.
lrn@chromium.org7516f052011-03-30 08:52:27 +00001665 int size_; // Number of bytes of the expected patch size.
1666 MacroAssembler masm_; // Macro assembler used to generate the code.
1667};
lrn@chromium.org7516f052011-03-30 08:52:27 +00001668
1669
ager@chromium.org5c838252010-02-19 08:53:10 +00001670
1671#ifdef GENERATED_CODE_COVERAGE
1672#define CODE_COVERAGE_STRINGIFY(x) #x
1673#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1674#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1675#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1676#else
1677#define ACCESS_MASM(masm) masm->
1678#endif
1679
1680} } // namespace v8::internal
1681
1682#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_