The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / mips / assembler-mips.h @ f230a1cf

History | View | Annotate | Download (41.8 KB)

1
// Copyright (c) 1994-2006 Sun Microsystems Inc.
2
// All Rights Reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
6
// met:
7
//
8
// - Redistributions of source code must retain the above copyright notice,
9
// this list of conditions and the following disclaimer.
10
//
11
// - Redistribution in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// - Neither the name of Sun Microsystems or the names of contributors may
16
// be used to endorse or promote products derived from this software without
17
// specific prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30

    
31
// The original source code covered by the above license above has been
32
// modified significantly by Google Inc.
33
// Copyright 2012 the V8 project authors. All rights reserved.
34

    
35

    
36
#ifndef V8_MIPS_ASSEMBLER_MIPS_H_
37
#define V8_MIPS_ASSEMBLER_MIPS_H_
38

    
39
#include <stdio.h>
40
#include "assembler.h"
41
#include "constants-mips.h"
42
#include "serialize.h"
43

    
44
namespace v8 {
45
namespace internal {
46

    
47
// CPU Registers.
48
//
49
// 1) We would prefer to use an enum, but enum values are assignment-
50
// compatible with int, which has caused code-generation bugs.
51
//
52
// 2) We would prefer to use a class instead of a struct but we don't like
53
// the register initialization to depend on the particular initialization
54
// order (which appears to be different on OS X, Linux, and Windows for the
55
// installed versions of C++ we tried). Using a struct permits C-style
56
// "initialization". Also, the Register objects cannot be const as this
57
// forces initialization stubs in MSVC, making us dependent on initialization
58
// order.
59
//
60
// 3) By not using an enum, we are possibly preventing the compiler from
61
// doing certain constant folds, which may significantly reduce the
62
// code generated for some assembly instructions (because they boil down
63
// to a few constants). If this is a problem, we could change the code
64
// such that we use an enum in optimized mode, and the struct in debug
65
// mode. This way we get the compile-time error checking in debug mode
66
// and best performance in optimized code.
67

    
68

    
69
// -----------------------------------------------------------------------------
70
// Implementation of Register and FPURegister.
71

    
72
// Core register.
73
struct Register {
74
  static const int kNumRegisters = v8::internal::kNumRegisters;
75
  static const int kMaxNumAllocatableRegisters = 14;  // v0 through t6 and cp.
76
  static const int kSizeInBytes = 4;
77
  static const int kCpRegister = 23;  // cp (s7) is the 23rd register.
78

    
79
  inline static int NumAllocatableRegisters();
80

    
81
  static int ToAllocationIndex(Register reg) {
82
    ASSERT((reg.code() - 2) < (kMaxNumAllocatableRegisters - 1) ||
83
           reg.is(from_code(kCpRegister)));
84
    return reg.is(from_code(kCpRegister)) ?
85
           kMaxNumAllocatableRegisters - 1 :  // Return last index for 'cp'.
86
           reg.code() - 2;  // zero_reg and 'at' are skipped.
87
  }
88

    
89
  static Register FromAllocationIndex(int index) {
90
    ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters);
91
    return index == kMaxNumAllocatableRegisters - 1 ?
92
           from_code(kCpRegister) :  // Last index is always the 'cp' register.
93
           from_code(index + 2);  // zero_reg and 'at' are skipped.
94
  }
95

    
96
  static const char* AllocationIndexToString(int index) {
97
    ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters);
98
    const char* const names[] = {
99
      "v0",
100
      "v1",
101
      "a0",
102
      "a1",
103
      "a2",
104
      "a3",
105
      "t0",
106
      "t1",
107
      "t2",
108
      "t3",
109
      "t4",
110
      "t5",
111
      "t6",
112
      "s7",
113
    };
114
    return names[index];
115
  }
116

    
117
  static Register from_code(int code) {
118
    Register r = { code };
119
    return r;
120
  }
121

    
122
  bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; }
123
  bool is(Register reg) const { return code_ == reg.code_; }
124
  int code() const {
125
    ASSERT(is_valid());
126
    return code_;
127
  }
128
  int bit() const {
129
    ASSERT(is_valid());
130
    return 1 << code_;
131
  }
132

    
133
  // Unfortunately we can't make this private in a struct.
134
  int code_;
135
};
136

    
137
#define REGISTER(N, C) \
138
  const int kRegister_ ## N ## _Code = C; \
139
  const Register N = { C }
140

    
141
REGISTER(no_reg, -1);
142
// Always zero.
143
REGISTER(zero_reg, 0);
144
// at: Reserved for synthetic instructions.
145
REGISTER(at, 1);
146
// v0, v1: Used when returning multiple values from subroutines.
147
REGISTER(v0, 2);
148
REGISTER(v1, 3);
149
// a0 - a4: Used to pass non-FP parameters.
150
REGISTER(a0, 4);
151
REGISTER(a1, 5);
152
REGISTER(a2, 6);
153
REGISTER(a3, 7);
154
// t0 - t9: Can be used without reservation, act as temporary registers and are
155
// allowed to be destroyed by subroutines.
156
REGISTER(t0, 8);
157
REGISTER(t1, 9);
158
REGISTER(t2, 10);
159
REGISTER(t3, 11);
160
REGISTER(t4, 12);
161
REGISTER(t5, 13);
162
REGISTER(t6, 14);
163
REGISTER(t7, 15);
164
// s0 - s7: Subroutine register variables. Subroutines that write to these
165
// registers must restore their values before exiting so that the caller can
166
// expect the values to be preserved.
167
REGISTER(s0, 16);
168
REGISTER(s1, 17);
169
REGISTER(s2, 18);
170
REGISTER(s3, 19);
171
REGISTER(s4, 20);
172
REGISTER(s5, 21);
173
REGISTER(s6, 22);
174
REGISTER(s7, 23);
175
REGISTER(t8, 24);
176
REGISTER(t9, 25);
177
// k0, k1: Reserved for system calls and interrupt handlers.
178
REGISTER(k0, 26);
179
REGISTER(k1, 27);
180
// gp: Reserved.
181
REGISTER(gp, 28);
182
// sp: Stack pointer.
183
REGISTER(sp, 29);
184
// fp: Frame pointer.
185
REGISTER(fp, 30);
186
// ra: Return address pointer.
187
REGISTER(ra, 31);
188

    
189
#undef REGISTER
190

    
191

    
192
int ToNumber(Register reg);
193

    
194
Register ToRegister(int num);
195

    
196
// Coprocessor register.
197
struct FPURegister {
198
  static const int kMaxNumRegisters = v8::internal::kNumFPURegisters;
199

    
200
  // TODO(plind): Warning, inconsistent numbering here. kNumFPURegisters refers
201
  // to number of 32-bit FPU regs, but kNumAllocatableRegisters refers to
202
  // number of Double regs (64-bit regs, or FPU-reg-pairs).
203

    
204
  // A few double registers are reserved: one as a scratch register and one to
205
  // hold 0.0.
206
  //  f28: 0.0
207
  //  f30: scratch register.
208
  static const int kNumReservedRegisters = 2;
209
  static const int kMaxNumAllocatableRegisters = kMaxNumRegisters / 2 -
210
      kNumReservedRegisters;
211

    
212
  inline static int NumRegisters();
213
  inline static int NumAllocatableRegisters();
214
  inline static int ToAllocationIndex(FPURegister reg);
215
  static const char* AllocationIndexToString(int index);
216

    
217
  static FPURegister FromAllocationIndex(int index) {
218
    ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters);
219
    return from_code(index * 2);
220
  }
221

    
222
  static FPURegister from_code(int code) {
223
    FPURegister r = { code };
224
    return r;
225
  }
226

    
227
  bool is_valid() const { return 0 <= code_ && code_ < kMaxNumRegisters ; }
228
  bool is(FPURegister creg) const { return code_ == creg.code_; }
229
  FPURegister low() const {
230
    // Find low reg of a Double-reg pair, which is the reg itself.
231
    ASSERT(code_ % 2 == 0);  // Specified Double reg must be even.
232
    FPURegister reg;
233
    reg.code_ = code_;
234
    ASSERT(reg.is_valid());
235
    return reg;
236
  }
237
  FPURegister high() const {
238
    // Find high reg of a Doubel-reg pair, which is reg + 1.
239
    ASSERT(code_ % 2 == 0);  // Specified Double reg must be even.
240
    FPURegister reg;
241
    reg.code_ = code_ + 1;
242
    ASSERT(reg.is_valid());
243
    return reg;
244
  }
245

    
246
  int code() const {
247
    ASSERT(is_valid());
248
    return code_;
249
  }
250
  int bit() const {
251
    ASSERT(is_valid());
252
    return 1 << code_;
253
  }
254
  void setcode(int f) {
255
    code_ = f;
256
    ASSERT(is_valid());
257
  }
258
  // Unfortunately we can't make this private in a struct.
259
  int code_;
260
};
261

    
262
// V8 now supports the O32 ABI, and the FPU Registers are organized as 32
263
// 32-bit registers, f0 through f31. When used as 'double' they are used
264
// in pairs, starting with the even numbered register. So a double operation
265
// on f0 really uses f0 and f1.
266
// (Modern mips hardware also supports 32 64-bit registers, via setting
267
// (priviledged) Status Register FR bit to 1. This is used by the N32 ABI,
268
// but it is not in common use. Someday we will want to support this in v8.)
269

    
270
// For O32 ABI, Floats and Doubles refer to same set of 32 32-bit registers.
271
typedef FPURegister DoubleRegister;
272
typedef FPURegister FloatRegister;
273

    
274
const FPURegister no_freg = { -1 };
275

    
276
const FPURegister f0 = { 0 };  // Return value in hard float mode.
277
const FPURegister f1 = { 1 };
278
const FPURegister f2 = { 2 };
279
const FPURegister f3 = { 3 };
280
const FPURegister f4 = { 4 };
281
const FPURegister f5 = { 5 };
282
const FPURegister f6 = { 6 };
283
const FPURegister f7 = { 7 };
284
const FPURegister f8 = { 8 };
285
const FPURegister f9 = { 9 };
286
const FPURegister f10 = { 10 };
287
const FPURegister f11 = { 11 };
288
const FPURegister f12 = { 12 };  // Arg 0 in hard float mode.
289
const FPURegister f13 = { 13 };
290
const FPURegister f14 = { 14 };  // Arg 1 in hard float mode.
291
const FPURegister f15 = { 15 };
292
const FPURegister f16 = { 16 };
293
const FPURegister f17 = { 17 };
294
const FPURegister f18 = { 18 };
295
const FPURegister f19 = { 19 };
296
const FPURegister f20 = { 20 };
297
const FPURegister f21 = { 21 };
298
const FPURegister f22 = { 22 };
299
const FPURegister f23 = { 23 };
300
const FPURegister f24 = { 24 };
301
const FPURegister f25 = { 25 };
302
const FPURegister f26 = { 26 };
303
const FPURegister f27 = { 27 };
304
const FPURegister f28 = { 28 };
305
const FPURegister f29 = { 29 };
306
const FPURegister f30 = { 30 };
307
const FPURegister f31 = { 31 };
308

    
309
// Register aliases.
310
// cp is assumed to be a callee saved register.
311
// Defined using #define instead of "static const Register&" because Clang
312
// complains otherwise when a compilation unit that includes this header
313
// doesn't use the variables.
314
#define kRootRegister s6
315
#define cp s7
316
#define kLithiumScratchReg s3
317
#define kLithiumScratchReg2 s4
318
#define kLithiumScratchDouble f30
319
#define kDoubleRegZero f28
320

    
321
// FPU (coprocessor 1) control registers.
322
// Currently only FCSR (#31) is implemented.
323
struct FPUControlRegister {
324
  bool is_valid() const { return code_ == kFCSRRegister; }
325
  bool is(FPUControlRegister creg) const { return code_ == creg.code_; }
326
  int code() const {
327
    ASSERT(is_valid());
328
    return code_;
329
  }
330
  int bit() const {
331
    ASSERT(is_valid());
332
    return 1 << code_;
333
  }
334
  void setcode(int f) {
335
    code_ = f;
336
    ASSERT(is_valid());
337
  }
338
  // Unfortunately we can't make this private in a struct.
339
  int code_;
340
};
341

    
342
const FPUControlRegister no_fpucreg = { kInvalidFPUControlRegister };
343
const FPUControlRegister FCSR = { kFCSRRegister };
344

    
345

    
346
// -----------------------------------------------------------------------------
347
// Machine instruction Operands.
348

    
349
// Class Operand represents a shifter operand in data processing instructions.
350
class Operand BASE_EMBEDDED {
351
 public:
352
  // Immediate.
353
  INLINE(explicit Operand(int32_t immediate,
354
         RelocInfo::Mode rmode = RelocInfo::NONE32));
355
  INLINE(explicit Operand(const ExternalReference& f));
356
  INLINE(explicit Operand(const char* s));
357
  INLINE(explicit Operand(Object** opp));
358
  INLINE(explicit Operand(Context** cpp));
359
  explicit Operand(Handle<Object> handle);
360
  INLINE(explicit Operand(Smi* value));
361

    
362
  // Register.
363
  INLINE(explicit Operand(Register rm));
364

    
365
  // Return true if this is a register operand.
366
  INLINE(bool is_reg() const);
367

    
368
  inline int32_t immediate() const {
369
    ASSERT(!is_reg());
370
    return imm32_;
371
  }
372

    
373
  Register rm() const { return rm_; }
374

    
375
 private:
376
  Register rm_;
377
  int32_t imm32_;  // Valid if rm_ == no_reg.
378
  RelocInfo::Mode rmode_;
379

    
380
  friend class Assembler;
381
  friend class MacroAssembler;
382
};
383

    
384

    
385
// On MIPS we have only one adressing mode with base_reg + offset.
386
// Class MemOperand represents a memory operand in load and store instructions.
387
class MemOperand : public Operand {
388
 public:
389
  explicit MemOperand(Register rn, int32_t offset = 0);
390
  int32_t offset() const { return offset_; }
391

    
392
  bool OffsetIsInt16Encodable() const {
393
    return is_int16(offset_);
394
  }
395

    
396
 private:
397
  int32_t offset_;
398

    
399
  friend class Assembler;
400
};
401

    
402

    
403
// CpuFeatures keeps track of which features are supported by the target CPU.
404
// Supported features must be enabled by a CpuFeatureScope before use.
405
class CpuFeatures : public AllStatic {
406
 public:
407
  // Detect features of the target CPU. Set safe defaults if the serializer
408
  // is enabled (snapshots must be portable).
409
  static void Probe();
410

    
411
  // Check whether a feature is supported by the target CPU.
412
  static bool IsSupported(CpuFeature f) {
413
    ASSERT(initialized_);
414
    return Check(f, supported_);
415
  }
416

    
417
  static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
418
    ASSERT(initialized_);
419
    return Check(f, found_by_runtime_probing_only_);
420
  }
421

    
422
  static bool IsSafeForSnapshot(CpuFeature f) {
423
    return Check(f, cross_compile_) ||
424
           (IsSupported(f) &&
425
            (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f)));
426
  }
427

    
428
  static bool VerifyCrossCompiling() {
429
    return cross_compile_ == 0;
430
  }
431

    
432
  static bool VerifyCrossCompiling(CpuFeature f) {
433
    unsigned mask = flag2set(f);
434
    return cross_compile_ == 0 ||
435
           (cross_compile_ & mask) == mask;
436
  }
437

    
438
 private:
439
  static bool Check(CpuFeature f, unsigned set) {
440
    return (set & flag2set(f)) != 0;
441
  }
442

    
443
  static unsigned flag2set(CpuFeature f) {
444
    return 1u << f;
445
  }
446

    
447
#ifdef DEBUG
448
  static bool initialized_;
449
#endif
450
  static unsigned supported_;
451
  static unsigned found_by_runtime_probing_only_;
452

    
453
  static unsigned cross_compile_;
454

    
455
  friend class ExternalReference;
456
  friend class PlatformFeatureScope;
457
  DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
458
};
459

    
460

    
461
class Assembler : public AssemblerBase {
462
 public:
463
  // Create an assembler. Instructions and relocation information are emitted
464
  // into a buffer, with the instructions starting from the beginning and the
465
  // relocation information starting from the end of the buffer. See CodeDesc
466
  // for a detailed comment on the layout (globals.h).
467
  //
468
  // If the provided buffer is NULL, the assembler allocates and grows its own
469
  // buffer, and buffer_size determines the initial buffer size. The buffer is
470
  // owned by the assembler and deallocated upon destruction of the assembler.
471
  //
472
  // If the provided buffer is not NULL, the assembler uses the provided buffer
473
  // for code generation and assumes its size to be buffer_size. If the buffer
474
  // is too small, a fatal error occurs. No deallocation of the buffer is done
475
  // upon destruction of the assembler.
476
  Assembler(Isolate* isolate, void* buffer, int buffer_size);
477
  virtual ~Assembler() { }
478

    
479
  // GetCode emits any pending (non-emitted) code and fills the descriptor
480
  // desc. GetCode() is idempotent; it returns the same result if no other
481
  // Assembler functions are invoked in between GetCode() calls.
482
  void GetCode(CodeDesc* desc);
483

    
484
  // Label operations & relative jumps (PPUM Appendix D).
485
  //
486
  // Takes a branch opcode (cc) and a label (L) and generates
487
  // either a backward branch or a forward branch and links it
488
  // to the label fixup chain. Usage:
489
  //
490
  // Label L;    // unbound label
491
  // j(cc, &L);  // forward branch to unbound label
492
  // bind(&L);   // bind label to the current pc
493
  // j(cc, &L);  // backward branch to bound label
494
  // bind(&L);   // illegal: a label may be bound only once
495
  //
496
  // Note: The same Label can be used for forward and backward branches
497
  // but it may be bound only once.
498
  void bind(Label* L);  // Binds an unbound label L to current code position.
499
  // Determines if Label is bound and near enough so that branch instruction
500
  // can be used to reach it, instead of jump instruction.
501
  bool is_near(Label* L);
502

    
503
  // Returns the branch offset to the given label from the current code
504
  // position. Links the label to the current position if it is still unbound.
505
  // Manages the jump elimination optimization if the second parameter is true.
506
  int32_t branch_offset(Label* L, bool jump_elimination_allowed);
507
  int32_t shifted_branch_offset(Label* L, bool jump_elimination_allowed) {
508
    int32_t o = branch_offset(L, jump_elimination_allowed);
509
    ASSERT((o & 3) == 0);   // Assert the offset is aligned.
510
    return o >> 2;
511
  }
512
  uint32_t jump_address(Label* L);
513

    
514
  // Puts a labels target address at the given position.
515
  // The high 8 bits are set to zero.
516
  void label_at_put(Label* L, int at_offset);
517

    
518
  // Read/Modify the code target address in the branch/call instruction at pc.
519
  static Address target_address_at(Address pc);
520
  static void set_target_address_at(Address pc, Address target);
521

    
522
  // Return the code target address at a call site from the return address
523
  // of that call in the instruction stream.
524
  inline static Address target_address_from_return_address(Address pc);
525

    
526
  static void JumpLabelToJumpRegister(Address pc);
527

    
528
  static void QuietNaN(HeapObject* nan);
529

    
530
  // This sets the branch destination (which gets loaded at the call address).
531
  // This is for calls and branches within generated code.  The serializer
532
  // has already deserialized the lui/ori instructions etc.
533
  inline static void deserialization_set_special_target_at(
534
      Address instruction_payload, Address target) {
535
    set_target_address_at(
536
        instruction_payload - kInstructionsFor32BitConstant * kInstrSize,
537
        target);
538
  }
539

    
540
  // This sets the branch destination.
541
  // This is for calls and branches to runtime code.
542
  inline static void set_external_target_at(Address instruction_payload,
543
                                            Address target) {
544
    set_target_address_at(instruction_payload, target);
545
  }
546

    
547
  // Size of an instruction.
548
  static const int kInstrSize = sizeof(Instr);
549

    
550
  // Difference between address of current opcode and target address offset.
551
  static const int kBranchPCOffset = 4;
552

    
553
  // Here we are patching the address in the LUI/ORI instruction pair.
554
  // These values are used in the serialization process and must be zero for
555
  // MIPS platform, as Code, Embedded Object or External-reference pointers
556
  // are split across two consecutive instructions and don't exist separately
557
  // in the code, so the serializer should not step forwards in memory after
558
  // a target is resolved and written.
559
  static const int kSpecialTargetSize = 0;
560

    
561
  // Number of consecutive instructions used to store 32bit constant.
562
  // Before jump-optimizations, this constant was used in
563
  // RelocInfo::target_address_address() function to tell serializer address of
564
  // the instruction that follows LUI/ORI instruction pair. Now, with new jump
565
  // optimization, where jump-through-register instruction that usually
566
  // follows LUI/ORI pair is substituted with J/JAL, this constant equals
567
  // to 3 instructions (LUI+ORI+J/JAL/JR/JALR).
568
  static const int kInstructionsFor32BitConstant = 3;
569

    
570
  // Distance between the instruction referring to the address of the call
571
  // target and the return address.
572
  static const int kCallTargetAddressOffset = 4 * kInstrSize;
573

    
574
  // Distance between start of patched return sequence and the emitted address
575
  // to jump to.
576
  static const int kPatchReturnSequenceAddressOffset = 0;
577

    
578
  // Distance between start of patched debug break slot and the emitted address
579
  // to jump to.
580
  static const int kPatchDebugBreakSlotAddressOffset =  0 * kInstrSize;
581

    
582
  // Difference between address of current opcode and value read from pc
583
  // register.
584
  static const int kPcLoadDelta = 4;
585

    
586
  static const int kPatchDebugBreakSlotReturnOffset = 4 * kInstrSize;
587

    
588
  // Number of instructions used for the JS return sequence. The constant is
589
  // used by the debugger to patch the JS return sequence.
590
  static const int kJSReturnSequenceInstructions = 7;
591
  static const int kDebugBreakSlotInstructions = 4;
592
  static const int kDebugBreakSlotLength =
593
      kDebugBreakSlotInstructions * kInstrSize;
594

    
595

    
596
  // ---------------------------------------------------------------------------
597
  // Code generation.
598

    
599
  // Insert the smallest number of nop instructions
600
  // possible to align the pc offset to a multiple
601
  // of m. m must be a power of 2 (>= 4).
602
  void Align(int m);
603
  // Aligns code to something that's optimal for a jump target for the platform.
604
  void CodeTargetAlign();
605

    
606
  // Different nop operations are used by the code generator to detect certain
607
  // states of the generated code.
608
  enum NopMarkerTypes {
609
    NON_MARKING_NOP = 0,
610
    DEBUG_BREAK_NOP,
611
    // IC markers.
612
    PROPERTY_ACCESS_INLINED,
613
    PROPERTY_ACCESS_INLINED_CONTEXT,
614
    PROPERTY_ACCESS_INLINED_CONTEXT_DONT_DELETE,
615
    // Helper values.
616
    LAST_CODE_MARKER,
617
    FIRST_IC_MARKER = PROPERTY_ACCESS_INLINED,
618
    // Code aging
619
    CODE_AGE_MARKER_NOP = 6,
620
    CODE_AGE_SEQUENCE_NOP
621
  };
622

    
623
  // Type == 0 is the default non-marking nop. For mips this is a
624
  // sll(zero_reg, zero_reg, 0). We use rt_reg == at for non-zero
625
  // marking, to avoid conflict with ssnop and ehb instructions.
626
  void nop(unsigned int type = 0) {
627
    ASSERT(type < 32);
628
    Register nop_rt_reg = (type == 0) ? zero_reg : at;
629
    sll(zero_reg, nop_rt_reg, type, true);
630
  }
631

    
632

    
633
  // --------Branch-and-jump-instructions----------
634
  // We don't use likely variant of instructions.
635
  void b(int16_t offset);
636
  void b(Label* L) { b(branch_offset(L, false)>>2); }
637
  void bal(int16_t offset);
638
  void bal(Label* L) { bal(branch_offset(L, false)>>2); }
639

    
640
  void beq(Register rs, Register rt, int16_t offset);
641
  void beq(Register rs, Register rt, Label* L) {
642
    beq(rs, rt, branch_offset(L, false) >> 2);
643
  }
644
  void bgez(Register rs, int16_t offset);
645
  void bgezal(Register rs, int16_t offset);
646
  void bgtz(Register rs, int16_t offset);
647
  void blez(Register rs, int16_t offset);
648
  void bltz(Register rs, int16_t offset);
649
  void bltzal(Register rs, int16_t offset);
650
  void bne(Register rs, Register rt, int16_t offset);
651
  void bne(Register rs, Register rt, Label* L) {
652
    bne(rs, rt, branch_offset(L, false)>>2);
653
  }
654

    
655
  // Never use the int16_t b(l)cond version with a branch offset
656
  // instead of using the Label* version.
657

    
658
  // Jump targets must be in the current 256 MB-aligned region. i.e. 28 bits.
659
  void j(int32_t target);
660
  void jal(int32_t target);
661
  void jalr(Register rs, Register rd = ra);
662
  void jr(Register target);
663
  void j_or_jr(int32_t target, Register rs);
664
  void jal_or_jalr(int32_t target, Register rs);
665

    
666

    
667
  //-------Data-processing-instructions---------
668

    
669
  // Arithmetic.
670
  void addu(Register rd, Register rs, Register rt);
671
  void subu(Register rd, Register rs, Register rt);
672
  void mult(Register rs, Register rt);
673
  void multu(Register rs, Register rt);
674
  void div(Register rs, Register rt);
675
  void divu(Register rs, Register rt);
676
  void mul(Register rd, Register rs, Register rt);
677

    
678
  void addiu(Register rd, Register rs, int32_t j);
679

    
680
  // Logical.
681
  void and_(Register rd, Register rs, Register rt);
682
  void or_(Register rd, Register rs, Register rt);
683
  void xor_(Register rd, Register rs, Register rt);
684
  void nor(Register rd, Register rs, Register rt);
685

    
686
  void andi(Register rd, Register rs, int32_t j);
687
  void ori(Register rd, Register rs, int32_t j);
688
  void xori(Register rd, Register rs, int32_t j);
689
  void lui(Register rd, int32_t j);
690

    
691
  // Shifts.
692
  // Please note: sll(zero_reg, zero_reg, x) instructions are reserved as nop
693
  // and may cause problems in normal code. coming_from_nop makes sure this
694
  // doesn't happen.
695
  void sll(Register rd, Register rt, uint16_t sa, bool coming_from_nop = false);
696
  void sllv(Register rd, Register rt, Register rs);
697
  void srl(Register rd, Register rt, uint16_t sa);
698
  void srlv(Register rd, Register rt, Register rs);
699
  void sra(Register rt, Register rd, uint16_t sa);
700
  void srav(Register rt, Register rd, Register rs);
701
  void rotr(Register rd, Register rt, uint16_t sa);
702
  void rotrv(Register rd, Register rt, Register rs);
703

    
704

    
705
  //------------Memory-instructions-------------
706

    
707
  void lb(Register rd, const MemOperand& rs);
708
  void lbu(Register rd, const MemOperand& rs);
709
  void lh(Register rd, const MemOperand& rs);
710
  void lhu(Register rd, const MemOperand& rs);
711
  void lw(Register rd, const MemOperand& rs);
712
  void lwl(Register rd, const MemOperand& rs);
713
  void lwr(Register rd, const MemOperand& rs);
714
  void sb(Register rd, const MemOperand& rs);
715
  void sh(Register rd, const MemOperand& rs);
716
  void sw(Register rd, const MemOperand& rs);
717
  void swl(Register rd, const MemOperand& rs);
718
  void swr(Register rd, const MemOperand& rs);
719

    
720

    
721
  //-------------Misc-instructions--------------
722

    
723
  // Break / Trap instructions.
724
  void break_(uint32_t code, bool break_as_stop = false);
725
  void stop(const char* msg, uint32_t code = kMaxStopCode);
726
  void tge(Register rs, Register rt, uint16_t code);
727
  void tgeu(Register rs, Register rt, uint16_t code);
728
  void tlt(Register rs, Register rt, uint16_t code);
729
  void tltu(Register rs, Register rt, uint16_t code);
730
  void teq(Register rs, Register rt, uint16_t code);
731
  void tne(Register rs, Register rt, uint16_t code);
732

    
733
  // Move from HI/LO register.
734
  void mfhi(Register rd);
735
  void mflo(Register rd);
736

    
737
  // Set on less than.
738
  void slt(Register rd, Register rs, Register rt);
739
  void sltu(Register rd, Register rs, Register rt);
740
  void slti(Register rd, Register rs, int32_t j);
741
  void sltiu(Register rd, Register rs, int32_t j);
742

    
743
  // Conditional move.
744
  void movz(Register rd, Register rs, Register rt);
745
  void movn(Register rd, Register rs, Register rt);
746
  void movt(Register rd, Register rs, uint16_t cc = 0);
747
  void movf(Register rd, Register rs, uint16_t cc = 0);
748

    
749
  // Bit twiddling.
750
  void clz(Register rd, Register rs);
751
  void ins_(Register rt, Register rs, uint16_t pos, uint16_t size);
752
  void ext_(Register rt, Register rs, uint16_t pos, uint16_t size);
753

    
754
  //--------Coprocessor-instructions----------------
755

    
756
  // Load, store, and move.
757
  void lwc1(FPURegister fd, const MemOperand& src);
758
  void ldc1(FPURegister fd, const MemOperand& src);
759

    
760
  void swc1(FPURegister fs, const MemOperand& dst);
761
  void sdc1(FPURegister fs, const MemOperand& dst);
762

    
763
  void mtc1(Register rt, FPURegister fs);
764
  void mfc1(Register rt, FPURegister fs);
765

    
766
  void ctc1(Register rt, FPUControlRegister fs);
767
  void cfc1(Register rt, FPUControlRegister fs);
768

    
769
  // Arithmetic.
770
  void add_d(FPURegister fd, FPURegister fs, FPURegister ft);
771
  void sub_d(FPURegister fd, FPURegister fs, FPURegister ft);
772
  void mul_d(FPURegister fd, FPURegister fs, FPURegister ft);
773
  void madd_d(FPURegister fd, FPURegister fr, FPURegister fs, FPURegister ft);
774
  void div_d(FPURegister fd, FPURegister fs, FPURegister ft);
775
  void abs_d(FPURegister fd, FPURegister fs);
776
  void mov_d(FPURegister fd, FPURegister fs);
777
  void neg_d(FPURegister fd, FPURegister fs);
778
  void sqrt_d(FPURegister fd, FPURegister fs);
779

    
780
  // Conversion.
781
  void cvt_w_s(FPURegister fd, FPURegister fs);
782
  void cvt_w_d(FPURegister fd, FPURegister fs);
783
  void trunc_w_s(FPURegister fd, FPURegister fs);
784
  void trunc_w_d(FPURegister fd, FPURegister fs);
785
  void round_w_s(FPURegister fd, FPURegister fs);
786
  void round_w_d(FPURegister fd, FPURegister fs);
787
  void floor_w_s(FPURegister fd, FPURegister fs);
788
  void floor_w_d(FPURegister fd, FPURegister fs);
789
  void ceil_w_s(FPURegister fd, FPURegister fs);
790
  void ceil_w_d(FPURegister fd, FPURegister fs);
791

    
792
  void cvt_l_s(FPURegister fd, FPURegister fs);
793
  void cvt_l_d(FPURegister fd, FPURegister fs);
794
  void trunc_l_s(FPURegister fd, FPURegister fs);
795
  void trunc_l_d(FPURegister fd, FPURegister fs);
796
  void round_l_s(FPURegister fd, FPURegister fs);
797
  void round_l_d(FPURegister fd, FPURegister fs);
798
  void floor_l_s(FPURegister fd, FPURegister fs);
799
  void floor_l_d(FPURegister fd, FPURegister fs);
800
  void ceil_l_s(FPURegister fd, FPURegister fs);
801
  void ceil_l_d(FPURegister fd, FPURegister fs);
802

    
803
  void cvt_s_w(FPURegister fd, FPURegister fs);
804
  void cvt_s_l(FPURegister fd, FPURegister fs);
805
  void cvt_s_d(FPURegister fd, FPURegister fs);
806

    
807
  void cvt_d_w(FPURegister fd, FPURegister fs);
808
  void cvt_d_l(FPURegister fd, FPURegister fs);
809
  void cvt_d_s(FPURegister fd, FPURegister fs);
810

    
811
  // Conditions and branches.
812
  void c(FPUCondition cond, SecondaryField fmt,
813
         FPURegister ft, FPURegister fs, uint16_t cc = 0);
814

    
815
  void bc1f(int16_t offset, uint16_t cc = 0);
816
  void bc1f(Label* L, uint16_t cc = 0) { bc1f(branch_offset(L, false)>>2, cc); }
817
  void bc1t(int16_t offset, uint16_t cc = 0);
818
  void bc1t(Label* L, uint16_t cc = 0) { bc1t(branch_offset(L, false)>>2, cc); }
819
  void fcmp(FPURegister src1, const double src2, FPUCondition cond);
820

    
821
  // Check the code size generated from label to here.
822
  int SizeOfCodeGeneratedSince(Label* label) {
823
    return pc_offset() - label->pos();
824
  }
825

    
826
  // Check the number of instructions generated from label to here.
827
  int InstructionsGeneratedSince(Label* label) {
828
    return SizeOfCodeGeneratedSince(label) / kInstrSize;
829
  }
830

    
831
  // Class for scoping postponing the trampoline pool generation.
832
  class BlockTrampolinePoolScope {
833
   public:
834
    explicit BlockTrampolinePoolScope(Assembler* assem) : assem_(assem) {
835
      assem_->StartBlockTrampolinePool();
836
    }
837
    ~BlockTrampolinePoolScope() {
838
      assem_->EndBlockTrampolinePool();
839
    }
840

    
841
   private:
842
    Assembler* assem_;
843

    
844
    DISALLOW_IMPLICIT_CONSTRUCTORS(BlockTrampolinePoolScope);
845
  };
846

    
847
  // Class for postponing the assembly buffer growth. Typically used for
848
  // sequences of instructions that must be emitted as a unit, before
849
  // buffer growth (and relocation) can occur.
850
  // This blocking scope is not nestable.
851
  class BlockGrowBufferScope {
852
   public:
853
    explicit BlockGrowBufferScope(Assembler* assem) : assem_(assem) {
854
      assem_->StartBlockGrowBuffer();
855
    }
856
    ~BlockGrowBufferScope() {
857
      assem_->EndBlockGrowBuffer();
858
    }
859

    
860
    private:
861
     Assembler* assem_;
862

    
863
     DISALLOW_IMPLICIT_CONSTRUCTORS(BlockGrowBufferScope);
864
  };
865

    
866
  // Debugging.
867

    
868
  // Mark address of the ExitJSFrame code.
869
  void RecordJSReturn();
870

    
871
  // Mark address of a debug break slot.
872
  void RecordDebugBreakSlot();
873

    
874
  // Record the AST id of the CallIC being compiled, so that it can be placed
875
  // in the relocation information.
876
  void SetRecordedAstId(TypeFeedbackId ast_id) {
877
    ASSERT(recorded_ast_id_.IsNone());
878
    recorded_ast_id_ = ast_id;
879
  }
880

    
881
  TypeFeedbackId RecordedAstId() {
882
    ASSERT(!recorded_ast_id_.IsNone());
883
    return recorded_ast_id_;
884
  }
885

    
886
  void ClearRecordedAstId() { recorded_ast_id_ = TypeFeedbackId::None(); }
887

    
888
  // Record a comment relocation entry that can be used by a disassembler.
889
  // Use --code-comments to enable.
890
  void RecordComment(const char* msg);
891

    
892
  static int RelocateInternalReference(byte* pc, intptr_t pc_delta);
893

    
894
  // Writes a single byte or word of data in the code stream.  Used for
895
  // inline tables, e.g., jump-tables.
896
  void db(uint8_t data);
897
  void dd(uint32_t data);
898

    
899
  PositionsRecorder* positions_recorder() { return &positions_recorder_; }
900

    
901
  // Postpone the generation of the trampoline pool for the specified number of
902
  // instructions.
903
  void BlockTrampolinePoolFor(int instructions);
904

    
905
  // Check if there is less than kGap bytes available in the buffer.
906
  // If this is the case, we need to grow the buffer before emitting
907
  // an instruction or relocation information.
908
  inline bool overflow() const { return pc_ >= reloc_info_writer.pos() - kGap; }
909

    
910
  // Get the number of bytes available in the buffer.
911
  inline int available_space() const { return reloc_info_writer.pos() - pc_; }
912

    
913
  // Read/patch instructions.
914
  static Instr instr_at(byte* pc) { return *reinterpret_cast<Instr*>(pc); }
915
  static void instr_at_put(byte* pc, Instr instr) {
916
    *reinterpret_cast<Instr*>(pc) = instr;
917
  }
918
  Instr instr_at(int pos) { return *reinterpret_cast<Instr*>(buffer_ + pos); }
919
  void instr_at_put(int pos, Instr instr) {
920
    *reinterpret_cast<Instr*>(buffer_ + pos) = instr;
921
  }
922

    
923
  // Check if an instruction is a branch of some kind.
924
  static bool IsBranch(Instr instr);
925
  static bool IsBeq(Instr instr);
926
  static bool IsBne(Instr instr);
927

    
928
  static bool IsJump(Instr instr);
929
  static bool IsJ(Instr instr);
930
  static bool IsLui(Instr instr);
931
  static bool IsOri(Instr instr);
932

    
933
  static bool IsJal(Instr instr);
934
  static bool IsJr(Instr instr);
935
  static bool IsJalr(Instr instr);
936

    
937
  static bool IsNop(Instr instr, unsigned int type);
938
  static bool IsPop(Instr instr);
939
  static bool IsPush(Instr instr);
940
  static bool IsLwRegFpOffset(Instr instr);
941
  static bool IsSwRegFpOffset(Instr instr);
942
  static bool IsLwRegFpNegOffset(Instr instr);
943
  static bool IsSwRegFpNegOffset(Instr instr);
944

    
945
  static Register GetRtReg(Instr instr);
946
  static Register GetRsReg(Instr instr);
947
  static Register GetRdReg(Instr instr);
948

    
949
  static uint32_t GetRt(Instr instr);
950
  static uint32_t GetRtField(Instr instr);
951
  static uint32_t GetRs(Instr instr);
952
  static uint32_t GetRsField(Instr instr);
953
  static uint32_t GetRd(Instr instr);
954
  static uint32_t GetRdField(Instr instr);
955
  static uint32_t GetSa(Instr instr);
956
  static uint32_t GetSaField(Instr instr);
957
  static uint32_t GetOpcodeField(Instr instr);
958
  static uint32_t GetFunction(Instr instr);
959
  static uint32_t GetFunctionField(Instr instr);
960
  static uint32_t GetImmediate16(Instr instr);
961
  static uint32_t GetLabelConst(Instr instr);
962

    
963
  static int32_t GetBranchOffset(Instr instr);
964
  static bool IsLw(Instr instr);
965
  static int16_t GetLwOffset(Instr instr);
966
  static Instr SetLwOffset(Instr instr, int16_t offset);
967

    
968
  static bool IsSw(Instr instr);
969
  static Instr SetSwOffset(Instr instr, int16_t offset);
970
  static bool IsAddImmediate(Instr instr);
971
  static Instr SetAddImmediateOffset(Instr instr, int16_t offset);
972

    
973
  static bool IsAndImmediate(Instr instr);
974
  static bool IsEmittedConstant(Instr instr);
975

    
976
  void CheckTrampolinePool();
977

    
978
 protected:
979
  // Relocation for a type-recording IC has the AST id added to it.  This
980
  // member variable is a way to pass the information from the call site to
981
  // the relocation info.
982
  TypeFeedbackId recorded_ast_id_;
983

    
984
  int32_t buffer_space() const { return reloc_info_writer.pos() - pc_; }
985

    
986
  // Decode branch instruction at pos and return branch target pos.
987
  int target_at(int32_t pos);
988

    
989
  // Patch branch instruction at pos to branch to given branch target pos.
990
  void target_at_put(int32_t pos, int32_t target_pos);
991

    
992
  // Say if we need to relocate with this mode.
993
  bool MustUseReg(RelocInfo::Mode rmode);
994

    
995
  // Record reloc info for current pc_.
996
  void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
997

    
998
  // Block the emission of the trampoline pool before pc_offset.
999
  void BlockTrampolinePoolBefore(int pc_offset) {
1000
    if (no_trampoline_pool_before_ < pc_offset)
1001
      no_trampoline_pool_before_ = pc_offset;
1002
  }
1003

    
1004
  void StartBlockTrampolinePool() {
1005
    trampoline_pool_blocked_nesting_++;
1006
  }
1007

    
1008
  void EndBlockTrampolinePool() {
1009
    trampoline_pool_blocked_nesting_--;
1010
  }
1011

    
1012
  bool is_trampoline_pool_blocked() const {
1013
    return trampoline_pool_blocked_nesting_ > 0;
1014
  }
1015

    
1016
  bool has_exception() const {
1017
    return internal_trampoline_exception_;
1018
  }
1019

    
1020
  void DoubleAsTwoUInt32(double d, uint32_t* lo, uint32_t* hi);
1021

    
1022
  bool is_trampoline_emitted() const {
1023
    return trampoline_emitted_;
1024
  }
1025

    
1026
  // Temporarily block automatic assembly buffer growth.
1027
  void StartBlockGrowBuffer() {
1028
    ASSERT(!block_buffer_growth_);
1029
    block_buffer_growth_ = true;
1030
  }
1031

    
1032
  void EndBlockGrowBuffer() {
1033
    ASSERT(block_buffer_growth_);
1034
    block_buffer_growth_ = false;
1035
  }
1036

    
1037
  bool is_buffer_growth_blocked() const {
1038
    return block_buffer_growth_;
1039
  }
1040

    
1041
 private:
1042
  // Buffer size and constant pool distance are checked together at regular
1043
  // intervals of kBufferCheckInterval emitted bytes.
1044
  static const int kBufferCheckInterval = 1*KB/2;
1045

    
1046
  // Code generation.
1047
  // The relocation writer's position is at least kGap bytes below the end of
1048
  // the generated instructions. This is so that multi-instruction sequences do
1049
  // not have to check for overflow. The same is true for writes of large
1050
  // relocation info entries.
1051
  static const int kGap = 32;
1052

    
1053

    
1054
  // Repeated checking whether the trampoline pool should be emitted is rather
1055
  // expensive. By default we only check again once a number of instructions
1056
  // has been generated.
1057
  static const int kCheckConstIntervalInst = 32;
1058
  static const int kCheckConstInterval = kCheckConstIntervalInst * kInstrSize;
1059

    
1060
  int next_buffer_check_;  // pc offset of next buffer check.
1061

    
1062
  // Emission of the trampoline pool may be blocked in some code sequences.
1063
  int trampoline_pool_blocked_nesting_;  // Block emission if this is not zero.
1064
  int no_trampoline_pool_before_;  // Block emission before this pc offset.
1065

    
1066
  // Keep track of the last emitted pool to guarantee a maximal distance.
1067
  int last_trampoline_pool_end_;  // pc offset of the end of the last pool.
1068

    
1069
  // Automatic growth of the assembly buffer may be blocked for some sequences.
1070
  bool block_buffer_growth_;  // Block growth when true.
1071

    
1072
  // Relocation information generation.
1073
  // Each relocation is encoded as a variable size value.
1074
  static const int kMaxRelocSize = RelocInfoWriter::kMaxSize;
1075
  RelocInfoWriter reloc_info_writer;
1076

    
1077
  // The bound position, before this we cannot do instruction elimination.
1078
  int last_bound_pos_;
1079

    
1080
  // Code emission.
1081
  inline void CheckBuffer();
1082
  void GrowBuffer();
1083
  inline void emit(Instr x);
1084
  inline void CheckTrampolinePoolQuick();
1085

    
1086
  // Instruction generation.
1087
  // We have 3 different kind of encoding layout on MIPS.
1088
  // However due to many different types of objects encoded in the same fields
1089
  // we have quite a few aliases for each mode.
1090
  // Using the same structure to refer to Register and FPURegister would spare a
1091
  // few aliases, but mixing both does not look clean to me.
1092
  // Anyway we could surely implement this differently.
1093

    
1094
  void GenInstrRegister(Opcode opcode,
1095
                        Register rs,
1096
                        Register rt,
1097
                        Register rd,
1098
                        uint16_t sa = 0,
1099
                        SecondaryField func = NULLSF);
1100

    
1101
  void GenInstrRegister(Opcode opcode,
1102
                        Register rs,
1103
                        Register rt,
1104
                        uint16_t msb,
1105
                        uint16_t lsb,
1106
                        SecondaryField func);
1107

    
1108
  void GenInstrRegister(Opcode opcode,
1109
                        SecondaryField fmt,
1110
                        FPURegister ft,
1111
                        FPURegister fs,
1112
                        FPURegister fd,
1113
                        SecondaryField func = NULLSF);
1114

    
1115
  void GenInstrRegister(Opcode opcode,
1116
                        FPURegister fr,
1117
                        FPURegister ft,
1118
                        FPURegister fs,
1119
                        FPURegister fd,
1120
                        SecondaryField func = NULLSF);
1121

    
1122
  void GenInstrRegister(Opcode opcode,
1123
                        SecondaryField fmt,
1124
                        Register rt,
1125
                        FPURegister fs,
1126
                        FPURegister fd,
1127
                        SecondaryField func = NULLSF);
1128

    
1129
  void GenInstrRegister(Opcode opcode,
1130
                        SecondaryField fmt,
1131
                        Register rt,
1132
                        FPUControlRegister fs,
1133
                        SecondaryField func = NULLSF);
1134

    
1135

    
1136
  void GenInstrImmediate(Opcode opcode,
1137
                         Register rs,
1138
                         Register rt,
1139
                         int32_t  j);
1140
  void GenInstrImmediate(Opcode opcode,
1141
                         Register rs,
1142
                         SecondaryField SF,
1143
                         int32_t  j);
1144
  void GenInstrImmediate(Opcode opcode,
1145
                         Register r1,
1146
                         FPURegister r2,
1147
                         int32_t  j);
1148

    
1149

    
1150
  void GenInstrJump(Opcode opcode,
1151
                     uint32_t address);
1152

    
1153
  // Helpers.
1154
  void LoadRegPlusOffsetToAt(const MemOperand& src);
1155

    
1156
  // Labels.
1157
  void print(Label* L);
1158
  void bind_to(Label* L, int pos);
1159
  void next(Label* L);
1160

    
1161
  // One trampoline consists of:
1162
  // - space for trampoline slots,
1163
  // - space for labels.
1164
  //
1165
  // Space for trampoline slots is equal to slot_count * 2 * kInstrSize.
1166
  // Space for trampoline slots preceeds space for labels. Each label is of one
1167
  // instruction size, so total amount for labels is equal to
1168
  // label_count *  kInstrSize.
1169
  class Trampoline {
1170
   public:
1171
    Trampoline() {
1172
      start_ = 0;
1173
      next_slot_ = 0;
1174
      free_slot_count_ = 0;
1175
      end_ = 0;
1176
    }
1177
    Trampoline(int start, int slot_count) {
1178
      start_ = start;
1179
      next_slot_ = start;
1180
      free_slot_count_ = slot_count;
1181
      end_ = start + slot_count * kTrampolineSlotsSize;
1182
    }
1183
    int start() {
1184
      return start_;
1185
    }
1186
    int end() {
1187
      return end_;
1188
    }
1189
    int take_slot() {
1190
      int trampoline_slot = kInvalidSlotPos;
1191
      if (free_slot_count_ <= 0) {
1192
        // We have run out of space on trampolines.
1193
        // Make sure we fail in debug mode, so we become aware of each case
1194
        // when this happens.
1195
        ASSERT(0);
1196
        // Internal exception will be caught.
1197
      } else {
1198
        trampoline_slot = next_slot_;
1199
        free_slot_count_--;
1200
        next_slot_ += kTrampolineSlotsSize;
1201
      }
1202
      return trampoline_slot;
1203
    }
1204

    
1205
   private:
1206
    int start_;
1207
    int end_;
1208
    int next_slot_;
1209
    int free_slot_count_;
1210
  };
1211

    
1212
  int32_t get_trampoline_entry(int32_t pos);
1213
  int unbound_labels_count_;
1214
  // If trampoline is emitted, generated code is becoming large. As this is
1215
  // already a slow case which can possibly break our code generation for the
1216
  // extreme case, we use this information to trigger different mode of
1217
  // branch instruction generation, where we use jump instructions rather
1218
  // than regular branch instructions.
1219
  bool trampoline_emitted_;
1220
  static const int kTrampolineSlotsSize = 4 * kInstrSize;
1221
  static const int kMaxBranchOffset = (1 << (18 - 1)) - 1;
1222
  static const int kInvalidSlotPos = -1;
1223

    
1224
  Trampoline trampoline_;
1225
  bool internal_trampoline_exception_;
1226

    
1227
  friend class RegExpMacroAssemblerMIPS;
1228
  friend class RelocInfo;
1229
  friend class CodePatcher;
1230
  friend class BlockTrampolinePoolScope;
1231

    
1232
  PositionsRecorder positions_recorder_;
1233
  friend class PositionsRecorder;
1234
  friend class EnsureSpace;
1235
};
1236

    
1237

    
1238
class EnsureSpace BASE_EMBEDDED {
1239
 public:
1240
  explicit EnsureSpace(Assembler* assembler) {
1241
    assembler->CheckBuffer();
1242
  }
1243
};
1244

    
1245
} }  // namespace v8::internal
1246

    
1247
#endif  // V8_ARM_ASSEMBLER_MIPS_H_