1
// Copyright 2011 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
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.
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.
28
#ifndef V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
29
#define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
31
#include "assembler.h"
32
#include "mips/assembler-mips.h"
33
#include "v8globals.h"
38
// Forward declaration.
41
// Reserved Register Usage Summary.
43
// Registers t8, t9, and at are reserved for use by the MacroAssembler.
45
// The programmer should know that the MacroAssembler may clobber these three,
46
// but won't touch other registers except in special cases.
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.
54
// cp is assumed to be a callee saved register.
55
const Register roots = s6; // Roots array pointer.
56
const Register cp = s7; // JavaScript context pointer.
57
const Register fp = s8_fp; // Alias for fp.
58
// Registers used for condition evaluation.
59
const Register condReg1 = s4;
60
const Register condReg2 = s5;
63
// Flags used for the AllocateInNewSpace functions.
64
enum AllocationFlags {
66
NO_ALLOCATION_FLAGS = 0,
67
// Return the pointer to the allocated already tagged as a heap object.
69
// The content of the result register already contains the allocation top in
71
RESULT_CONTAINS_TOP = 1 << 1,
72
// Specify that the requested size of the space to allocate is specified in
73
// words instead of bytes.
74
SIZE_IN_WORDS = 1 << 2
77
// Flags used for the ObjectToDoubleFPURegister function.
78
enum ObjectToDoubleFlags {
80
NO_OBJECT_TO_DOUBLE_FLAGS = 0,
81
// Object is known to be a non smi.
82
OBJECT_NOT_SMI = 1 << 0,
83
// Don't load NaNs or infinities, branch to the non number case instead.
84
AVOID_NANS_AND_INFINITIES = 1 << 1
87
// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
88
enum BranchDelaySlot {
93
// MacroAssembler implements a collection of frequently used macros.
94
class MacroAssembler: public Assembler {
96
// The isolate parameter can be NULL if the macro assembler should
97
// not use isolate-dependent functionality. In this case, it's the
98
// responsibility of the caller to never invoke such function on the
100
MacroAssembler(Isolate* isolate, void* buffer, int size);
103
#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
104
#define COND_ARGS cond, r1, r2
106
// Cases when relocation is not needed.
107
#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
108
void Name(target_type target, BranchDelaySlot bd = PROTECT); \
109
inline void Name(BranchDelaySlot bd, target_type target) { \
112
void Name(target_type target, \
114
BranchDelaySlot bd = PROTECT); \
115
inline void Name(BranchDelaySlot bd, \
116
target_type target, \
118
Name(target, COND_ARGS, bd); \
121
#define DECLARE_BRANCH_PROTOTYPES(Name) \
122
DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
123
DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
125
DECLARE_BRANCH_PROTOTYPES(Branch)
126
DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
128
#undef DECLARE_BRANCH_PROTOTYPES
129
#undef COND_TYPED_ARGS
133
// Jump, Call, and Ret pseudo instructions implementing inter-working.
134
#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
135
const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
137
void Jump(Register target, COND_ARGS);
138
void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
139
void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
140
void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
141
int CallSize(Register target, COND_ARGS);
142
void Call(Register target, COND_ARGS);
143
int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
144
void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
145
int CallSize(Handle<Code> code,
146
RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
147
unsigned ast_id = kNoASTId,
149
void Call(Handle<Code> code,
150
RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
151
unsigned ast_id = kNoASTId,
154
inline void Ret(BranchDelaySlot bd) {
155
Ret(al, zero_reg, Operand(zero_reg), bd);
160
// Emit code to discard a non-negative number of pointer-sized elements
161
// from the stack, clobbering only the sp register.
163
Condition cond = cc_always,
164
Register reg = no_reg,
165
const Operand& op = Operand(no_reg));
167
void DropAndRet(int drop = 0,
168
Condition cond = cc_always,
169
Register reg = no_reg,
170
const Operand& op = Operand(no_reg));
172
// Swap two registers. If the scratch register is omitted then a slightly
173
// less efficient form using xor instead of mov is emitted.
174
void Swap(Register reg1, Register reg2, Register scratch = no_reg);
176
void Call(Label* target);
178
inline void Move(Register dst, Register src) {
184
inline void Move(FPURegister dst, FPURegister src) {
190
inline void Move(Register dst_low, Register dst_high, FPURegister src) {
192
mfc1(dst_high, FPURegister::from_code(src.code() + 1));
195
inline void Move(FPURegister dst, Register src_low, Register src_high) {
197
mtc1(src_high, FPURegister::from_code(dst.code() + 1));
200
// Jump unconditionally to given label.
201
// We NEED a nop in the branch delay slot, as it used by v8, for example in
202
// CodeGenerator::ProcessDeferred().
203
// Currently the branch delay slot is filled by the MacroAssembler.
204
// Use rather b(Label) for code generation.
209
// Load an object from the root table.
210
void LoadRoot(Register destination,
211
Heap::RootListIndex index);
212
void LoadRoot(Register destination,
213
Heap::RootListIndex index,
214
Condition cond, Register src1, const Operand& src2);
216
// Store an object to the root table.
217
void StoreRoot(Register source,
218
Heap::RootListIndex index);
219
void StoreRoot(Register source,
220
Heap::RootListIndex index,
221
Condition cond, Register src1, const Operand& src2);
224
// Check if object is in new space.
225
// scratch can be object itself, but it will be clobbered.
226
void InNewSpace(Register object,
228
Condition cc, // eq for new space, ne otherwise.
232
// For the page containing |object| mark the region covering [address]
233
// dirty. The object address must be in the first 8K of an allocated page.
234
void RecordWriteHelper(Register object,
238
// For the page containing |object| mark the region covering
239
// [object+offset] dirty. The object address must be in the first 8K
240
// of an allocated page. The 'scratch' registers are used in the
241
// implementation and all 3 registers are clobbered by the
242
// operation, as well as the 'at' register. RecordWrite updates the
243
// write barrier even when storing smis.
244
void RecordWrite(Register object,
249
// For the page containing |object| mark the region covering
250
// [address] dirty. The object address must be in the first 8K of an
251
// allocated page. All 3 registers are clobbered by the operation,
252
// as well as the ip register. RecordWrite updates the write barrier
253
// even when storing smis.
254
void RecordWrite(Register object,
259
// ---------------------------------------------------------------------------
260
// Inline caching support.
262
// Generate code for checking access rights - used for security checks
263
// on access to global objects across environments. The holder register
264
// is left untouched, whereas both scratch registers are clobbered.
265
void CheckAccessGlobalProxy(Register holder_reg,
270
void LoadFromNumberDictionary(Label* miss,
279
inline void MarkCode(NopMarkerTypes type) {
283
// Check if the given instruction is a 'type' marker.
284
// ie. check if it is a sll zero_reg, zero_reg, <type> (referenced as
285
// nop(type)). These instructions are generated to mark special location in
286
// the code, like some special IC code.
287
static inline bool IsMarkedCode(Instr instr, int type) {
288
ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
289
return IsNop(instr, type);
293
static inline int GetCodeMarker(Instr instr) {
294
uint32_t opcode = ((instr & kOpcodeMask));
295
uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
296
uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
297
uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
299
// Return <n> if we have a sll zero_reg, zero_reg, n
301
bool sllzz = (opcode == SLL &&
302
rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
303
rs == static_cast<uint32_t>(ToNumber(zero_reg)));
305
(sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
306
ASSERT((type == -1) ||
307
((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
313
// ---------------------------------------------------------------------------
314
// Allocation support.
316
// Allocate an object in new space. The object_size is specified
317
// either in bytes or in words if the allocation flag SIZE_IN_WORDS
318
// is passed. If the new space is exhausted control continues at the
319
// gc_required label. The allocated object is returned in result. If
320
// the flag tag_allocated_object is true the result is tagged as as
321
// a heap object. All registers are clobbered also when control
322
// continues at the gc_required label.
323
void AllocateInNewSpace(int object_size,
328
AllocationFlags flags);
329
void AllocateInNewSpace(Register object_size,
334
AllocationFlags flags);
336
// Undo allocation in new space. The object passed and objects allocated after
337
// it will no longer be allocated. The caller must make sure that no pointers
338
// are left to the object(s) no longer allocated as they would be invalid when
339
// allocation is undone.
340
void UndoAllocationInNewSpace(Register object, Register scratch);
343
void AllocateTwoByteString(Register result,
349
void AllocateAsciiString(Register result,
355
void AllocateTwoByteConsString(Register result,
360
void AllocateAsciiConsString(Register result,
365
void AllocateTwoByteSlicedString(Register result,
370
void AllocateAsciiSlicedString(Register result,
376
// Allocates a heap number or jumps to the gc_required label if the young
377
// space is full and a scavenge is needed. All registers are clobbered also
378
// when control continues at the gc_required label.
379
void AllocateHeapNumber(Register result,
382
Register heap_number_map,
384
void AllocateHeapNumberWithValue(Register result,
390
// ---------------------------------------------------------------------------
391
// Instruction macros.
393
#define DEFINE_INSTRUCTION(instr) \
394
void instr(Register rd, Register rs, const Operand& rt); \
395
void instr(Register rd, Register rs, Register rt) { \
396
instr(rd, rs, Operand(rt)); \
398
void instr(Register rs, Register rt, int32_t j) { \
399
instr(rs, rt, Operand(j)); \
402
#define DEFINE_INSTRUCTION2(instr) \
403
void instr(Register rs, const Operand& rt); \
404
void instr(Register rs, Register rt) { \
405
instr(rs, Operand(rt)); \
407
void instr(Register rs, int32_t j) { \
408
instr(rs, Operand(j)); \
411
DEFINE_INSTRUCTION(Addu);
412
DEFINE_INSTRUCTION(Subu);
413
DEFINE_INSTRUCTION(Mul);
414
DEFINE_INSTRUCTION2(Mult);
415
DEFINE_INSTRUCTION2(Multu);
416
DEFINE_INSTRUCTION2(Div);
417
DEFINE_INSTRUCTION2(Divu);
419
DEFINE_INSTRUCTION(And);
420
DEFINE_INSTRUCTION(Or);
421
DEFINE_INSTRUCTION(Xor);
422
DEFINE_INSTRUCTION(Nor);
423
DEFINE_INSTRUCTION2(Neg);
425
DEFINE_INSTRUCTION(Slt);
426
DEFINE_INSTRUCTION(Sltu);
428
// MIPS32 R2 instruction macro.
429
DEFINE_INSTRUCTION(Ror);
431
#undef DEFINE_INSTRUCTION
432
#undef DEFINE_INSTRUCTION2
435
// ---------------------------------------------------------------------------
436
// Pseudo-instructions.
438
void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
440
// Load int32 in the rd register.
441
void li(Register rd, Operand j, bool gen2instr = false);
442
inline void li(Register rd, int32_t j, bool gen2instr = false) {
443
li(rd, Operand(j), gen2instr);
445
inline void li(Register dst, Handle<Object> value, bool gen2instr = false) {
446
li(dst, Operand(value), gen2instr);
449
// Push multiple registers on the stack.
450
// Registers are saved in numerical order, with higher numbered registers
451
// saved in higher memory addresses.
452
void MultiPush(RegList regs);
453
void MultiPushReversed(RegList regs);
455
void MultiPushFPU(RegList regs);
456
void MultiPushReversedFPU(RegList regs);
458
// Lower case push() for compatibility with arch-independent code.
459
void push(Register src) {
460
Addu(sp, sp, Operand(-kPointerSize));
461
sw(src, MemOperand(sp, 0));
465
void Push(Handle<Object> handle);
467
// Push two registers. Pushes leftmost register first (to highest address).
468
void Push(Register src1, Register src2) {
469
Subu(sp, sp, Operand(2 * kPointerSize));
470
sw(src1, MemOperand(sp, 1 * kPointerSize));
471
sw(src2, MemOperand(sp, 0 * kPointerSize));
474
// Push three registers. Pushes leftmost register first (to highest address).
475
void Push(Register src1, Register src2, Register src3) {
476
Subu(sp, sp, Operand(3 * kPointerSize));
477
sw(src1, MemOperand(sp, 2 * kPointerSize));
478
sw(src2, MemOperand(sp, 1 * kPointerSize));
479
sw(src3, MemOperand(sp, 0 * kPointerSize));
482
// Push four registers. Pushes leftmost register first (to highest address).
483
void Push(Register src1, Register src2, Register src3, Register src4) {
484
Subu(sp, sp, Operand(4 * kPointerSize));
485
sw(src1, MemOperand(sp, 3 * kPointerSize));
486
sw(src2, MemOperand(sp, 2 * kPointerSize));
487
sw(src3, MemOperand(sp, 1 * kPointerSize));
488
sw(src4, MemOperand(sp, 0 * kPointerSize));
491
void Push(Register src, Condition cond, Register tst1, Register tst2) {
492
// Since we don't have conditional execution we use a Branch.
493
Branch(3, cond, tst1, Operand(tst2));
494
Subu(sp, sp, Operand(kPointerSize));
495
sw(src, MemOperand(sp, 0));
498
// Pops multiple values from the stack and load them in the
499
// registers specified in regs. Pop order is the opposite as in MultiPush.
500
void MultiPop(RegList regs);
501
void MultiPopReversed(RegList regs);
503
void MultiPopFPU(RegList regs);
504
void MultiPopReversedFPU(RegList regs);
506
// Lower case pop() for compatibility with arch-independent code.
507
void pop(Register dst) {
508
lw(dst, MemOperand(sp, 0));
509
Addu(sp, sp, Operand(kPointerSize));
512
// Pop two registers. Pops rightmost register first (from lower address).
513
void Pop(Register src1, Register src2) {
514
ASSERT(!src1.is(src2));
515
lw(src2, MemOperand(sp, 0 * kPointerSize));
516
lw(src1, MemOperand(sp, 1 * kPointerSize));
517
Addu(sp, sp, 2 * kPointerSize);
520
void Pop(uint32_t count = 1) {
521
Addu(sp, sp, Operand(count * kPointerSize));
524
// Push and pop the registers that can hold pointers, as defined by the
525
// RegList constant kSafepointSavedRegisters.
526
void PushSafepointRegisters();
527
void PopSafepointRegisters();
528
void PushSafepointRegistersAndDoubles();
529
void PopSafepointRegistersAndDoubles();
530
// Store value in register src in the safepoint stack slot for
532
void StoreToSafepointRegisterSlot(Register src, Register dst);
533
void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
534
// Load the value of the src register from its safepoint stack slot
535
// into register dst.
536
void LoadFromSafepointRegisterSlot(Register dst, Register src);
538
// MIPS32 R2 instruction macro.
539
void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
540
void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
542
// Convert unsigned word to double.
543
void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
544
void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
546
// Convert double to unsigned word.
547
void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
548
void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
550
// Convert the HeapNumber pointed to by source to a 32bits signed integer
551
// dest. If the HeapNumber does not fit into a 32bits signed integer branch
552
// to not_int32 label. If FPU is available double_scratch is used but not
554
void ConvertToInt32(Register source,
558
FPURegister double_scratch,
561
// Helper for EmitECMATruncate.
562
// This will truncate a floating-point value outside of the singed 32bit
563
// integer range to a 32bit signed integer.
564
// Expects the double value loaded in input_high and input_low.
565
// Exits with the answer in 'result'.
566
// Note that this code does not work for values in the 32bit range!
567
void EmitOutOfInt32RangeTruncate(Register result,
572
// Performs a truncating conversion of a floating point number as used by
573
// the JS bitwise operations. See ECMA-262 9.5: ToInt32.
574
// Exits with 'result' holding the answer and all other registers clobbered.
575
void EmitECMATruncate(Register result,
576
FPURegister double_input,
577
FPURegister single_scratch,
582
// -------------------------------------------------------------------------
583
// Activation frames.
585
void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
586
void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
588
void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
589
void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
592
// argc - argument count to be dropped by LeaveExitFrame.
593
// save_doubles - saves FPU registers on stack, currently disabled.
594
// stack_space - extra stack space.
595
void EnterExitFrame(bool save_doubles,
596
int stack_space = 0);
598
// Leave the current exit frame.
599
void LeaveExitFrame(bool save_doubles, Register arg_count);
601
// Get the actual activation frame alignment for target environment.
602
static int ActivationFrameAlignment();
604
// Make sure the stack is aligned. Only emits code in debug mode.
605
void AssertStackIsAligned();
607
void LoadContext(Register dst, int context_chain_length);
609
void LoadGlobalFunction(int index, Register function);
611
// Load the initial map from the global function. The registers
612
// function and map can be the same, function is then overwritten.
613
void LoadGlobalFunctionInitialMap(Register function,
617
// -------------------------------------------------------------------------
618
// JavaScript invokes.
620
// Setup call kind marking in t1. The method takes t1 as an
621
// explicit first parameter to make the code more readable at the
623
void SetCallKind(Register dst, CallKind kind);
625
// Invoke the JavaScript function code by either calling or jumping.
626
void InvokeCode(Register code,
627
const ParameterCount& expected,
628
const ParameterCount& actual,
630
const CallWrapper& call_wrapper,
633
void InvokeCode(Handle<Code> code,
634
const ParameterCount& expected,
635
const ParameterCount& actual,
636
RelocInfo::Mode rmode,
640
// Invoke the JavaScript function in the given register. Changes the
641
// current context to the context in the function before invoking.
642
void InvokeFunction(Register function,
643
const ParameterCount& actual,
645
const CallWrapper& call_wrapper,
648
void InvokeFunction(JSFunction* function,
649
const ParameterCount& actual,
654
void IsObjectJSObjectType(Register heap_object,
659
void IsInstanceJSObjectType(Register map,
663
void IsObjectJSStringType(Register object,
667
#ifdef ENABLE_DEBUGGER_SUPPORT
668
// -------------------------------------------------------------------------
675
// -------------------------------------------------------------------------
676
// Exception handling.
678
// Push a new try handler and link into try handler chain.
679
// The return address must be passed in register ra.
680
// Clobber t0, t1, t2.
681
void PushTryHandler(CodeLocation try_location, HandlerType type);
683
// Unlink the stack handler on top of the stack from the try handler chain.
684
// Must preserve the result register.
685
void PopTryHandler();
687
// Passes thrown value (in v0) to the handler of top of the try handler chain.
688
void Throw(Register value);
690
// Propagates an uncatchable exception to the top of the current JS stack's
692
void ThrowUncatchable(UncatchableExceptionType type, Register value);
694
// Copies a fixed number of fields of heap objects from src to dst.
695
void CopyFields(Register dst, Register src, RegList temps, int field_count);
697
// Copies a number of bytes from src to dst. All registers are clobbered. On
698
// exit src and dst will point to the place just after where the last byte was
699
// read or written and length will be zero.
700
void CopyBytes(Register src,
705
// -------------------------------------------------------------------------
706
// Support functions.
708
// Try to get function prototype of a function and puts the value in
709
// the result register. Checks that the function really is a
710
// function and jumps to the miss label if the fast checks fail. The
711
// function register will be untouched; the other registers may be
713
void TryGetFunctionPrototype(Register function,
718
void GetObjectType(Register function,
722
// Check if a map for a JSObject indicates that the object has fast elements.
723
// Jump to the specified label if it does not.
724
void CheckFastElements(Register map,
728
// Check if the map of an object is equal to a specified map (either
729
// given directly or as an index into the root list) and branch to
730
// label if not. Skip the smi check if not required (object is known
731
// to be a heap object).
732
void CheckMap(Register obj,
736
SmiCheckType smi_check_type);
738
void CheckMap(Register obj,
740
Heap::RootListIndex index,
742
SmiCheckType smi_check_type);
744
// Check if the map of an object is equal to a specified map and branch to a
745
// specified target if equal. Skip the smi check if not required (object is
746
// known to be a heap object)
747
void DispatchMap(Register obj,
750
Handle<Code> success,
751
SmiCheckType smi_check_type);
753
// Generates code for reporting that an illegal operation has
755
void IllegalOperation(int num_arguments);
757
// Picks out an array index from the hash field.
759
// hash - holds the index's hash. Clobbered.
760
// index - holds the overwritten index on exit.
761
void IndexFromHash(Register hash, Register index);
763
// Get the number of least significant bits from a register.
764
void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
765
void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
767
// Load the value of a number object into a FPU double register. If the
768
// object is not a number a jump to the label not_number is performed
769
// and the FPU double register is unchanged.
770
void ObjectToDoubleFPURegister(
775
Register heap_number_map,
777
ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
779
// Load the value of a smi object into a FPU double register. The register
780
// scratch1 can be the same register as smi in which case smi will hold the
781
// untagged value afterwards.
782
void SmiToDoubleFPURegister(Register smi,
786
// -------------------------------------------------------------------------
787
// Overflow handling functions.
788
// Usage: first call the appropriate arithmetic function, then call one of the
789
// jump functions with the overflow_dst register as the second parameter.
791
void AdduAndCheckForOverflow(Register dst,
794
Register overflow_dst,
795
Register scratch = at);
797
void SubuAndCheckForOverflow(Register dst,
800
Register overflow_dst,
801
Register scratch = at);
803
void BranchOnOverflow(Label* label,
804
Register overflow_check,
805
BranchDelaySlot bd = PROTECT) {
806
Branch(label, lt, overflow_check, Operand(zero_reg), bd);
809
void BranchOnNoOverflow(Label* label,
810
Register overflow_check,
811
BranchDelaySlot bd = PROTECT) {
812
Branch(label, ge, overflow_check, Operand(zero_reg), bd);
815
void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
816
Ret(lt, overflow_check, Operand(zero_reg), bd);
819
void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
820
Ret(ge, overflow_check, Operand(zero_reg), bd);
823
// -------------------------------------------------------------------------
827
void CallStub(CodeStub* stub, Condition cond = cc_always,
828
Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
830
// Call a code stub and return the code object called. Try to generate
831
// the code if necessary. Do not perform a GC but instead return a retry
833
MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub,
834
Condition cond = cc_always,
835
Register r1 = zero_reg,
839
// Tail call a code stub (jump).
840
void TailCallStub(CodeStub* stub);
842
// Tail call a code stub (jump) and return the code object called. Try to
843
// generate the code if necessary. Do not perform a GC but instead return
844
// a retry after GC failure.
845
MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub,
846
Condition cond = cc_always,
847
Register r1 = zero_reg,
851
void CallJSExitStub(CodeStub* stub);
853
// Call a runtime routine.
854
void CallRuntime(const Runtime::Function* f, int num_arguments);
855
void CallRuntimeSaveDoubles(Runtime::FunctionId id);
857
// Convenience function: Same as above, but takes the fid instead.
858
void CallRuntime(Runtime::FunctionId fid, int num_arguments);
860
// Convenience function: call an external reference.
861
void CallExternalReference(const ExternalReference& ext,
864
// Tail call of a runtime routine (jump).
865
// Like JumpToExternalReference, but also takes care of passing the number
867
void TailCallExternalReference(const ExternalReference& ext,
871
// Tail call of a runtime routine (jump). Try to generate the code if
872
// necessary. Do not perform a GC but instead return a retry after GC
874
MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
875
const ExternalReference& ext, int num_arguments, int result_size);
877
// Convenience function: tail call a runtime routine (jump).
878
void TailCallRuntime(Runtime::FunctionId fid,
882
// Before calling a C-function from generated code, align arguments on stack
883
// and add space for the four mips argument slots.
884
// After aligning the frame, non-register arguments must be stored on the
885
// stack, after the argument-slots using helper: CFunctionArgumentOperand().
886
// The argument count assumes all arguments are word sized.
887
// Some compilers/platforms require the stack to be aligned when calling
889
// Needs a scratch register to do some arithmetic. This register will be
891
void PrepareCallCFunction(int num_arguments, Register scratch);
893
// Arguments 1-4 are placed in registers a0 thru a3 respectively.
894
// Arguments 5..n are stored to stack using following:
895
// sw(t0, CFunctionArgumentOperand(5));
897
// Calls a C function and cleans up the space for arguments allocated
898
// by PrepareCallCFunction. The called function is not allowed to trigger a
899
// garbage collection, since that might move the code and invalidate the
900
// return address (unless this is somehow accounted for by the called
902
void CallCFunction(ExternalReference function, int num_arguments);
903
void CallCFunction(Register function, Register scratch, int num_arguments);
904
void GetCFunctionDoubleResult(const DoubleRegister dst);
906
// There are two ways of passing double arguments on MIPS, depending on
907
// whether soft or hard floating point ABI is used. These functions
908
// abstract parameter passing for the three different ways we call
909
// C functions from generated code.
910
void SetCallCDoubleArguments(DoubleRegister dreg);
911
void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2);
912
void SetCallCDoubleArguments(DoubleRegister dreg, Register reg);
914
// Calls an API function. Allocates HandleScope, extracts returned value
915
// from handle and propagates exceptions. Restores context.
916
MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function,
919
// Jump to the builtin routine.
920
void JumpToExternalReference(const ExternalReference& builtin);
922
MaybeObject* TryJumpToExternalReference(const ExternalReference& ext);
924
// Invoke specified builtin JavaScript function. Adds an entry to
925
// the unresolved list if the name does not resolve.
926
void InvokeBuiltin(Builtins::JavaScript id,
928
const CallWrapper& call_wrapper = NullCallWrapper());
930
// Store the code object for the given builtin in the target register and
931
// setup the function in a1.
932
void GetBuiltinEntry(Register target, Builtins::JavaScript id);
934
// Store the function for the given builtin in the target register.
935
void GetBuiltinFunction(Register target, Builtins::JavaScript id);
939
uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
943
Handle<Object> CodeObject() {
944
ASSERT(!code_object_.is_null());
948
// -------------------------------------------------------------------------
949
// StatsCounter support.
951
void SetCounter(StatsCounter* counter, int value,
952
Register scratch1, Register scratch2);
953
void IncrementCounter(StatsCounter* counter, int value,
954
Register scratch1, Register scratch2);
955
void DecrementCounter(StatsCounter* counter, int value,
956
Register scratch1, Register scratch2);
959
// -------------------------------------------------------------------------
962
// Calls Abort(msg) if the condition cc is not satisfied.
963
// Use --debug_code to enable.
964
void Assert(Condition cc, const char* msg, Register rs, Operand rt);
965
void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
966
void AssertFastElements(Register elements);
968
// Like Assert(), but always enabled.
969
void Check(Condition cc, const char* msg, Register rs, Operand rt);
971
// Print a message to stdout and abort execution.
972
void Abort(const char* msg);
974
// Verify restrictions about code generated in stubs.
975
void set_generating_stub(bool value) { generating_stub_ = value; }
976
bool generating_stub() { return generating_stub_; }
977
void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
978
bool allow_stub_calls() { return allow_stub_calls_; }
980
// ---------------------------------------------------------------------------
983
// Check whether the value of reg is a power of two and not zero. If not
984
// control continues at the label not_power_of_two. If reg is a power of two
985
// the register scratch contains the value of (reg - 1) when control falls
987
void JumpIfNotPowerOfTwoOrZero(Register reg,
989
Label* not_power_of_two_or_zero);
991
// -------------------------------------------------------------------------
994
// Try to convert int32 to smi. If the value is to large, preserve
995
// the original value and jump to not_a_smi. Destroys scratch and
997
// This is only used by crankshaft atm so it is unimplemented on MIPS.
998
void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
999
UNIMPLEMENTED_MIPS();
1002
void SmiTag(Register reg) {
1003
Addu(reg, reg, reg);
1006
void SmiTag(Register dst, Register src) {
1007
Addu(dst, src, src);
1010
void SmiUntag(Register reg) {
1011
sra(reg, reg, kSmiTagSize);
1014
void SmiUntag(Register dst, Register src) {
1015
sra(dst, src, kSmiTagSize);
1018
// Jump the register contains a smi.
1019
inline void JumpIfSmi(Register value, Label* smi_label,
1020
Register scratch = at) {
1021
ASSERT_EQ(0, kSmiTag);
1022
andi(scratch, value, kSmiTagMask);
1023
Branch(smi_label, eq, scratch, Operand(zero_reg));
1026
// Jump if the register contains a non-smi.
1027
inline void JumpIfNotSmi(Register value, Label* not_smi_label,
1028
Register scratch = at) {
1029
ASSERT_EQ(0, kSmiTag);
1030
andi(scratch, value, kSmiTagMask);
1031
Branch(not_smi_label, ne, scratch, Operand(zero_reg));
1034
// Jump if either of the registers contain a non-smi.
1035
void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1036
// Jump if either of the registers contain a smi.
1037
void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1039
// Abort execution if argument is a smi. Used in debug code.
1040
void AbortIfSmi(Register object);
1041
void AbortIfNotSmi(Register object);
1043
// Abort execution if argument is a string. Used in debug code.
1044
void AbortIfNotString(Register object);
1046
// Abort execution if argument is not the root value with the given index.
1047
void AbortIfNotRootValue(Register src,
1048
Heap::RootListIndex root_value_index,
1049
const char* message);
1051
// ---------------------------------------------------------------------------
1052
// HeapNumber utilities.
1054
void JumpIfNotHeapNumber(Register object,
1055
Register heap_number_map,
1057
Label* on_not_heap_number);
1059
// -------------------------------------------------------------------------
1060
// String utilities.
1062
// Checks if both instance types are sequential ASCII strings and jumps to
1063
// label if either is not.
1064
void JumpIfBothInstanceTypesAreNotSequentialAscii(
1065
Register first_object_instance_type,
1066
Register second_object_instance_type,
1071
// Check if instance type is sequential ASCII string and jump to label if
1073
void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1077
// Test that both first and second are sequential ASCII strings.
1078
// Assume that they are non-smis.
1079
void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,
1085
// Test that both first and second are sequential ASCII strings.
1086
// Check that they are non-smis.
1087
void JumpIfNotBothSequentialAsciiStrings(Register first,
1093
void LoadInstanceDescriptors(Register map, Register descriptors);
1096
void CallCFunctionHelper(Register function,
1097
ExternalReference function_reference,
1101
void BranchShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1102
void BranchShort(int16_t offset, Condition cond, Register rs,
1104
BranchDelaySlot bdslot = PROTECT);
1105
void BranchShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1106
void BranchShort(Label* L, Condition cond, Register rs,
1108
BranchDelaySlot bdslot = PROTECT);
1109
void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1110
void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1112
BranchDelaySlot bdslot = PROTECT);
1113
void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1114
void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1116
BranchDelaySlot bdslot = PROTECT);
1117
void J(Label* L, BranchDelaySlot bdslot);
1118
void Jr(Label* L, BranchDelaySlot bdslot);
1119
void Jalr(Label* L, BranchDelaySlot bdslot);
1121
// Helper functions for generating invokes.
1122
void InvokePrologue(const ParameterCount& expected,
1123
const ParameterCount& actual,
1124
Handle<Code> code_constant,
1128
const CallWrapper& call_wrapper,
1129
CallKind call_kind);
1131
// Get the code for the given builtin. Returns if able to resolve
1132
// the function in the 'resolved' flag.
1133
Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1135
// Activation support.
1136
void EnterFrame(StackFrame::Type type);
1137
void LeaveFrame(StackFrame::Type type);
1139
void InitializeNewString(Register string,
1141
Heap::RootListIndex map_index,
1145
// Compute memory operands for safepoint stack slots.
1146
static int SafepointRegisterStackIndex(int reg_code);
1147
MemOperand SafepointRegisterSlot(Register reg);
1148
MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1150
bool UseAbsoluteCodePointers();
1152
bool generating_stub_;
1153
bool allow_stub_calls_;
1154
// This handle will be patched with the code object on installation.
1155
Handle<Object> code_object_;
1157
// Needs access to SafepointRegisterStackIndex for optimized frame
1159
friend class OptimizedFrame;
1163
// The code patcher is used to patch (typically) small parts of code e.g. for
1164
// debugging and other types of instrumentation. When using the code patcher
1165
// the exact number of bytes specified must be emitted. It is not legal to emit
1166
// relocation information. If any of these constraints are violated it causes
1167
// an assertion to fail.
1170
CodePatcher(byte* address, int instructions);
1171
virtual ~CodePatcher();
1173
// Macro assembler to emit code.
1174
MacroAssembler* masm() { return &masm_; }
1176
// Emit an instruction directly.
1177
void Emit(Instr instr);
1179
// Emit an address directly.
1180
void Emit(Address addr);
1182
// Change the condition part of an instruction leaving the rest of the current
1183
// instruction unchanged.
1184
void ChangeBranchCondition(Condition cond);
1187
byte* address_; // The address of the code being patched.
1188
int instructions_; // Number of instructions of the expected patch size.
1189
int size_; // Number of bytes of the expected patch size.
1190
MacroAssembler masm_; // Macro assembler used to generate the code.
1194
// -----------------------------------------------------------------------------
1195
// Static helper functions.
1197
static MemOperand ContextOperand(Register context, int index) {
1198
return MemOperand(context, Context::SlotOffset(index));
1202
static inline MemOperand GlobalObjectOperand() {
1203
return ContextOperand(cp, Context::GLOBAL_INDEX);
1207
// Generate a MemOperand for loading a field from an object.
1208
static inline MemOperand FieldMemOperand(Register object, int offset) {
1209
return MemOperand(object, offset - kHeapObjectTag);
1213
// Generate a MemOperand for storing arguments 5..N on the stack
1214
// when calling CallCFunction().
1215
static inline MemOperand CFunctionArgumentOperand(int index) {
1216
ASSERT(index > kCArgSlotCount);
1217
// Argument 5 takes the slot just past the four Arg-slots.
1218
int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
1219
return MemOperand(sp, offset);
1223
#ifdef GENERATED_CODE_COVERAGE
1224
#define CODE_COVERAGE_STRINGIFY(x) #x
1225
#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1226
#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1227
#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1229
#define ACCESS_MASM(masm) masm->
1232
} } // namespace v8::internal
1234
#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_