blob: c276af51064b240c5b74d188e64a2bf610fb83a9 [file] [log] [blame]
Andrei Popescu31002712010-02-23 13:46:05 +00001// Copyright 2010 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
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
29
30#include "v8.h"
31
32#include "bootstrapper.h"
33#include "codegen-inl.h"
34#include "debug.h"
35#include "runtime.h"
36
37namespace v8 {
38namespace internal {
39
40MacroAssembler::MacroAssembler(void* buffer, int size)
41 : Assembler(buffer, size),
42 unresolved_(0),
43 generating_stub_(false),
44 allow_stub_calls_(true),
45 code_object_(Heap::undefined_value()) {
46}
47
48
49
50void MacroAssembler::Jump(Register target, Condition cond,
51 Register r1, const Operand& r2) {
52 Jump(Operand(target), cond, r1, r2);
53}
54
55
56void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
57 Condition cond, Register r1, const Operand& r2) {
Steve Block6ded16b2010-05-10 14:33:55 +010058 Jump(Operand(target, rmode), cond, r1, r2);
Andrei Popescu31002712010-02-23 13:46:05 +000059}
60
61
62void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode,
63 Condition cond, Register r1, const Operand& r2) {
64 ASSERT(!RelocInfo::IsCodeTarget(rmode));
65 Jump(reinterpret_cast<intptr_t>(target), rmode, cond, r1, r2);
66}
67
68
69void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
70 Condition cond, Register r1, const Operand& r2) {
71 ASSERT(RelocInfo::IsCodeTarget(rmode));
72 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
73}
74
75
76void MacroAssembler::Call(Register target,
77 Condition cond, Register r1, const Operand& r2) {
78 Call(Operand(target), cond, r1, r2);
79}
80
81
82void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode,
83 Condition cond, Register r1, const Operand& r2) {
Steve Block6ded16b2010-05-10 14:33:55 +010084 Call(Operand(target, rmode), cond, r1, r2);
Andrei Popescu31002712010-02-23 13:46:05 +000085}
86
87
88void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode,
89 Condition cond, Register r1, const Operand& r2) {
90 ASSERT(!RelocInfo::IsCodeTarget(rmode));
91 Call(reinterpret_cast<intptr_t>(target), rmode, cond, r1, r2);
92}
93
94
95void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
96 Condition cond, Register r1, const Operand& r2) {
97 ASSERT(RelocInfo::IsCodeTarget(rmode));
98 Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond, r1, r2);
99}
100
101
102void MacroAssembler::Ret(Condition cond, Register r1, const Operand& r2) {
103 Jump(Operand(ra), cond, r1, r2);
104}
105
106
107void MacroAssembler::LoadRoot(Register destination,
108 Heap::RootListIndex index) {
Steve Block6ded16b2010-05-10 14:33:55 +0100109 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
Andrei Popescu31002712010-02-23 13:46:05 +0000110}
111
112void MacroAssembler::LoadRoot(Register destination,
113 Heap::RootListIndex index,
114 Condition cond,
115 Register src1, const Operand& src2) {
116 Branch(NegateCondition(cond), 2, src1, src2);
Steve Block6ded16b2010-05-10 14:33:55 +0100117 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
Andrei Popescu31002712010-02-23 13:46:05 +0000118}
119
120
121void MacroAssembler::RecordWrite(Register object, Register offset,
122 Register scratch) {
123 UNIMPLEMENTED_MIPS();
124}
125
126
127// ---------------------------------------------------------------------------
128// Instruction macros
129
130void MacroAssembler::Add(Register rd, Register rs, const Operand& rt) {
131 if (rt.is_reg()) {
132 add(rd, rs, rt.rm());
133 } else {
134 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
135 addi(rd, rs, rt.imm32_);
136 } else {
137 // li handles the relocation.
138 ASSERT(!rs.is(at));
139 li(at, rt);
140 add(rd, rs, at);
141 }
142 }
143}
144
145
146void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) {
147 if (rt.is_reg()) {
148 addu(rd, rs, rt.rm());
149 } else {
150 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
151 addiu(rd, rs, rt.imm32_);
152 } else {
153 // li handles the relocation.
154 ASSERT(!rs.is(at));
155 li(at, rt);
156 addu(rd, rs, at);
157 }
158 }
159}
160
161
162void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) {
163 if (rt.is_reg()) {
164 mul(rd, rs, rt.rm());
165 } else {
166 // li handles the relocation.
167 ASSERT(!rs.is(at));
168 li(at, rt);
169 mul(rd, rs, at);
170 }
171}
172
173
174void MacroAssembler::Mult(Register rs, const Operand& rt) {
175 if (rt.is_reg()) {
176 mult(rs, rt.rm());
177 } else {
178 // li handles the relocation.
179 ASSERT(!rs.is(at));
180 li(at, rt);
181 mult(rs, at);
182 }
183}
184
185
186void MacroAssembler::Multu(Register rs, const Operand& rt) {
187 if (rt.is_reg()) {
188 multu(rs, rt.rm());
189 } else {
190 // li handles the relocation.
191 ASSERT(!rs.is(at));
192 li(at, rt);
193 multu(rs, at);
194 }
195}
196
197
198void MacroAssembler::Div(Register rs, const Operand& rt) {
199 if (rt.is_reg()) {
200 div(rs, rt.rm());
201 } else {
202 // li handles the relocation.
203 ASSERT(!rs.is(at));
204 li(at, rt);
205 div(rs, at);
206 }
207}
208
209
210void MacroAssembler::Divu(Register rs, const Operand& rt) {
211 if (rt.is_reg()) {
212 divu(rs, rt.rm());
213 } else {
214 // li handles the relocation.
215 ASSERT(!rs.is(at));
216 li(at, rt);
217 divu(rs, at);
218 }
219}
220
221
222void MacroAssembler::And(Register rd, Register rs, const Operand& rt) {
223 if (rt.is_reg()) {
224 and_(rd, rs, rt.rm());
225 } else {
226 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
227 andi(rd, rs, rt.imm32_);
228 } else {
229 // li handles the relocation.
230 ASSERT(!rs.is(at));
231 li(at, rt);
232 and_(rd, rs, at);
233 }
234 }
235}
236
237
238void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) {
239 if (rt.is_reg()) {
240 or_(rd, rs, rt.rm());
241 } else {
242 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
243 ori(rd, rs, rt.imm32_);
244 } else {
245 // li handles the relocation.
246 ASSERT(!rs.is(at));
247 li(at, rt);
248 or_(rd, rs, at);
249 }
250 }
251}
252
253
254void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) {
255 if (rt.is_reg()) {
256 xor_(rd, rs, rt.rm());
257 } else {
258 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
259 xori(rd, rs, rt.imm32_);
260 } else {
261 // li handles the relocation.
262 ASSERT(!rs.is(at));
263 li(at, rt);
264 xor_(rd, rs, at);
265 }
266 }
267}
268
269
270void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) {
271 if (rt.is_reg()) {
272 nor(rd, rs, rt.rm());
273 } else {
274 // li handles the relocation.
275 ASSERT(!rs.is(at));
276 li(at, rt);
277 nor(rd, rs, at);
278 }
279}
280
281
282void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) {
283 if (rt.is_reg()) {
284 slt(rd, rs, rt.rm());
285 } else {
286 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
287 slti(rd, rs, rt.imm32_);
288 } else {
289 // li handles the relocation.
290 ASSERT(!rs.is(at));
291 li(at, rt);
292 slt(rd, rs, at);
293 }
294 }
295}
296
297
298void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) {
299 if (rt.is_reg()) {
300 sltu(rd, rs, rt.rm());
301 } else {
302 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
303 sltiu(rd, rs, rt.imm32_);
304 } else {
305 // li handles the relocation.
306 ASSERT(!rs.is(at));
307 li(at, rt);
308 sltu(rd, rs, at);
309 }
310 }
311}
312
313
314//------------Pseudo-instructions-------------
315
316void MacroAssembler::movn(Register rd, Register rt) {
317 addiu(at, zero_reg, -1); // Fill at with ones.
318 xor_(rd, rt, at);
319}
320
321
Andrei Popescu31002712010-02-23 13:46:05 +0000322void MacroAssembler::li(Register rd, Operand j, bool gen2instr) {
323 ASSERT(!j.is_reg());
324
325 if (!MustUseAt(j.rmode_) && !gen2instr) {
326 // Normal load of an immediate value which does not need Relocation Info.
327 if (is_int16(j.imm32_)) {
328 addiu(rd, zero_reg, j.imm32_);
329 } else if (!(j.imm32_ & HIMask)) {
330 ori(rd, zero_reg, j.imm32_);
331 } else if (!(j.imm32_ & LOMask)) {
332 lui(rd, (HIMask & j.imm32_) >> 16);
333 } else {
334 lui(rd, (HIMask & j.imm32_) >> 16);
335 ori(rd, rd, (LOMask & j.imm32_));
336 }
337 } else if (MustUseAt(j.rmode_) || gen2instr) {
338 if (MustUseAt(j.rmode_)) {
339 RecordRelocInfo(j.rmode_, j.imm32_);
340 }
341 // We need always the same number of instructions as we may need to patch
342 // this code to load another value which may need 2 instructions to load.
343 if (is_int16(j.imm32_)) {
344 nop();
345 addiu(rd, zero_reg, j.imm32_);
346 } else if (!(j.imm32_ & HIMask)) {
347 nop();
348 ori(rd, zero_reg, j.imm32_);
349 } else if (!(j.imm32_ & LOMask)) {
350 nop();
351 lui(rd, (HIMask & j.imm32_) >> 16);
352 } else {
353 lui(rd, (HIMask & j.imm32_) >> 16);
354 ori(rd, rd, (LOMask & j.imm32_));
355 }
356 }
357}
358
359
360// Exception-generating instructions and debugging support
361void MacroAssembler::stop(const char* msg) {
362 // TO_UPGRADE: Just a break for now. Maybe we could upgrade it.
363 // We use the 0x54321 value to be able to find it easily when reading memory.
364 break_(0x54321);
365}
366
367
368void MacroAssembler::MultiPush(RegList regs) {
369 int16_t NumSaved = 0;
370 int16_t NumToPush = NumberOfBitsSet(regs);
371
372 addiu(sp, sp, -4 * NumToPush);
Steve Block6ded16b2010-05-10 14:33:55 +0100373 for (int16_t i = kNumRegisters; i > 0; i--) {
Andrei Popescu31002712010-02-23 13:46:05 +0000374 if ((regs & (1 << i)) != 0) {
375 sw(ToRegister(i), MemOperand(sp, 4 * (NumToPush - ++NumSaved)));
376 }
377 }
378}
379
380
381void MacroAssembler::MultiPushReversed(RegList regs) {
382 int16_t NumSaved = 0;
383 int16_t NumToPush = NumberOfBitsSet(regs);
384
385 addiu(sp, sp, -4 * NumToPush);
Steve Block6ded16b2010-05-10 14:33:55 +0100386 for (int16_t i = 0; i < kNumRegisters; i++) {
Andrei Popescu31002712010-02-23 13:46:05 +0000387 if ((regs & (1 << i)) != 0) {
388 sw(ToRegister(i), MemOperand(sp, 4 * (NumToPush - ++NumSaved)));
389 }
390 }
391}
392
393
394void MacroAssembler::MultiPop(RegList regs) {
395 int16_t NumSaved = 0;
396
Steve Block6ded16b2010-05-10 14:33:55 +0100397 for (int16_t i = 0; i < kNumRegisters; i++) {
Andrei Popescu31002712010-02-23 13:46:05 +0000398 if ((regs & (1 << i)) != 0) {
399 lw(ToRegister(i), MemOperand(sp, 4 * (NumSaved++)));
400 }
401 }
402 addiu(sp, sp, 4 * NumSaved);
403}
404
405
406void MacroAssembler::MultiPopReversed(RegList regs) {
407 int16_t NumSaved = 0;
408
Steve Block6ded16b2010-05-10 14:33:55 +0100409 for (int16_t i = kNumRegisters; i > 0; i--) {
Andrei Popescu31002712010-02-23 13:46:05 +0000410 if ((regs & (1 << i)) != 0) {
411 lw(ToRegister(i), MemOperand(sp, 4 * (NumSaved++)));
412 }
413 }
414 addiu(sp, sp, 4 * NumSaved);
415}
416
417
418// Emulated condtional branches do not emit a nop in the branch delay slot.
419
420// Trashes the at register if no scratch register is provided.
421void MacroAssembler::Branch(Condition cond, int16_t offset, Register rs,
422 const Operand& rt, Register scratch) {
Steve Block6ded16b2010-05-10 14:33:55 +0100423 Register r2 = no_reg;
Andrei Popescu31002712010-02-23 13:46:05 +0000424 if (rt.is_reg()) {
425 // We don't want any other register but scratch clobbered.
426 ASSERT(!scratch.is(rs) && !scratch.is(rt.rm_));
427 r2 = rt.rm_;
428 } else if (cond != cc_always) {
429 // We don't want any other register but scratch clobbered.
430 ASSERT(!scratch.is(rs));
431 r2 = scratch;
432 li(r2, rt);
433 }
434
435 switch (cond) {
436 case cc_always:
437 b(offset);
438 break;
439 case eq:
440 beq(rs, r2, offset);
441 break;
442 case ne:
443 bne(rs, r2, offset);
444 break;
445
446 // Signed comparison
447 case greater:
448 slt(scratch, r2, rs);
449 bne(scratch, zero_reg, offset);
450 break;
451 case greater_equal:
452 slt(scratch, rs, r2);
453 beq(scratch, zero_reg, offset);
454 break;
455 case less:
456 slt(scratch, rs, r2);
457 bne(scratch, zero_reg, offset);
458 break;
459 case less_equal:
460 slt(scratch, r2, rs);
461 beq(scratch, zero_reg, offset);
462 break;
463
464 // Unsigned comparison.
465 case Ugreater:
466 sltu(scratch, r2, rs);
467 bne(scratch, zero_reg, offset);
468 break;
469 case Ugreater_equal:
470 sltu(scratch, rs, r2);
471 beq(scratch, zero_reg, offset);
472 break;
473 case Uless:
474 sltu(scratch, rs, r2);
475 bne(scratch, zero_reg, offset);
476 break;
477 case Uless_equal:
478 sltu(scratch, r2, rs);
479 beq(scratch, zero_reg, offset);
480 break;
481
482 default:
483 UNREACHABLE();
484 }
Steve Block6ded16b2010-05-10 14:33:55 +0100485 // Emit a nop in the branch delay slot.
486 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000487}
488
489
490void MacroAssembler::Branch(Condition cond, Label* L, Register rs,
491 const Operand& rt, Register scratch) {
Steve Block6ded16b2010-05-10 14:33:55 +0100492 Register r2 = no_reg;
Andrei Popescu31002712010-02-23 13:46:05 +0000493 if (rt.is_reg()) {
494 r2 = rt.rm_;
495 } else if (cond != cc_always) {
496 r2 = scratch;
497 li(r2, rt);
498 }
499
500 // We use branch_offset as an argument for the branch instructions to be sure
501 // it is called just before generating the branch instruction, as needed.
502
503 switch (cond) {
504 case cc_always:
505 b(shifted_branch_offset(L, false));
506 break;
507 case eq:
508 beq(rs, r2, shifted_branch_offset(L, false));
509 break;
510 case ne:
511 bne(rs, r2, shifted_branch_offset(L, false));
512 break;
513
514 // Signed comparison
515 case greater:
516 slt(scratch, r2, rs);
517 bne(scratch, zero_reg, shifted_branch_offset(L, false));
518 break;
519 case greater_equal:
520 slt(scratch, rs, r2);
521 beq(scratch, zero_reg, shifted_branch_offset(L, false));
522 break;
523 case less:
524 slt(scratch, rs, r2);
525 bne(scratch, zero_reg, shifted_branch_offset(L, false));
526 break;
527 case less_equal:
528 slt(scratch, r2, rs);
529 beq(scratch, zero_reg, shifted_branch_offset(L, false));
530 break;
531
532 // Unsigned comparison.
533 case Ugreater:
534 sltu(scratch, r2, rs);
535 bne(scratch, zero_reg, shifted_branch_offset(L, false));
536 break;
537 case Ugreater_equal:
538 sltu(scratch, rs, r2);
539 beq(scratch, zero_reg, shifted_branch_offset(L, false));
540 break;
541 case Uless:
542 sltu(scratch, rs, r2);
543 bne(scratch, zero_reg, shifted_branch_offset(L, false));
544 break;
545 case Uless_equal:
546 sltu(scratch, r2, rs);
547 beq(scratch, zero_reg, shifted_branch_offset(L, false));
548 break;
549
550 default:
551 UNREACHABLE();
552 }
Steve Block6ded16b2010-05-10 14:33:55 +0100553 // Emit a nop in the branch delay slot.
554 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000555}
556
557
558// Trashes the at register if no scratch register is provided.
559// We need to use a bgezal or bltzal, but they can't be used directly with the
560// slt instructions. We could use sub or add instead but we would miss overflow
561// cases, so we keep slt and add an intermediate third instruction.
562void MacroAssembler::BranchAndLink(Condition cond, int16_t offset, Register rs,
563 const Operand& rt, Register scratch) {
Steve Block6ded16b2010-05-10 14:33:55 +0100564 Register r2 = no_reg;
Andrei Popescu31002712010-02-23 13:46:05 +0000565 if (rt.is_reg()) {
566 r2 = rt.rm_;
567 } else if (cond != cc_always) {
568 r2 = scratch;
569 li(r2, rt);
570 }
571
572 switch (cond) {
573 case cc_always:
574 bal(offset);
575 break;
576 case eq:
577 bne(rs, r2, 2);
578 nop();
579 bal(offset);
580 break;
581 case ne:
582 beq(rs, r2, 2);
583 nop();
584 bal(offset);
585 break;
586
587 // Signed comparison
588 case greater:
589 slt(scratch, r2, rs);
590 addiu(scratch, scratch, -1);
591 bgezal(scratch, offset);
592 break;
593 case greater_equal:
594 slt(scratch, rs, r2);
595 addiu(scratch, scratch, -1);
596 bltzal(scratch, offset);
597 break;
598 case less:
599 slt(scratch, rs, r2);
600 addiu(scratch, scratch, -1);
601 bgezal(scratch, offset);
602 break;
603 case less_equal:
604 slt(scratch, r2, rs);
605 addiu(scratch, scratch, -1);
606 bltzal(scratch, offset);
607 break;
608
609 // Unsigned comparison.
610 case Ugreater:
611 sltu(scratch, r2, rs);
612 addiu(scratch, scratch, -1);
613 bgezal(scratch, offset);
614 break;
615 case Ugreater_equal:
616 sltu(scratch, rs, r2);
617 addiu(scratch, scratch, -1);
618 bltzal(scratch, offset);
619 break;
620 case Uless:
621 sltu(scratch, rs, r2);
622 addiu(scratch, scratch, -1);
623 bgezal(scratch, offset);
624 break;
625 case Uless_equal:
626 sltu(scratch, r2, rs);
627 addiu(scratch, scratch, -1);
628 bltzal(scratch, offset);
629 break;
630
631 default:
632 UNREACHABLE();
633 }
Steve Block6ded16b2010-05-10 14:33:55 +0100634 // Emit a nop in the branch delay slot.
635 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000636}
637
638
639void MacroAssembler::BranchAndLink(Condition cond, Label* L, Register rs,
640 const Operand& rt, Register scratch) {
Steve Block6ded16b2010-05-10 14:33:55 +0100641 Register r2 = no_reg;
Andrei Popescu31002712010-02-23 13:46:05 +0000642 if (rt.is_reg()) {
643 r2 = rt.rm_;
644 } else if (cond != cc_always) {
645 r2 = scratch;
646 li(r2, rt);
647 }
648
649 switch (cond) {
650 case cc_always:
651 bal(shifted_branch_offset(L, false));
652 break;
653 case eq:
654 bne(rs, r2, 2);
655 nop();
656 bal(shifted_branch_offset(L, false));
657 break;
658 case ne:
659 beq(rs, r2, 2);
660 nop();
661 bal(shifted_branch_offset(L, false));
662 break;
663
664 // Signed comparison
665 case greater:
666 slt(scratch, r2, rs);
667 addiu(scratch, scratch, -1);
668 bgezal(scratch, shifted_branch_offset(L, false));
669 break;
670 case greater_equal:
671 slt(scratch, rs, r2);
672 addiu(scratch, scratch, -1);
673 bltzal(scratch, shifted_branch_offset(L, false));
674 break;
675 case less:
676 slt(scratch, rs, r2);
677 addiu(scratch, scratch, -1);
678 bgezal(scratch, shifted_branch_offset(L, false));
679 break;
680 case less_equal:
681 slt(scratch, r2, rs);
682 addiu(scratch, scratch, -1);
683 bltzal(scratch, shifted_branch_offset(L, false));
684 break;
685
686 // Unsigned comparison.
687 case Ugreater:
688 sltu(scratch, r2, rs);
689 addiu(scratch, scratch, -1);
690 bgezal(scratch, shifted_branch_offset(L, false));
691 break;
692 case Ugreater_equal:
693 sltu(scratch, rs, r2);
694 addiu(scratch, scratch, -1);
695 bltzal(scratch, shifted_branch_offset(L, false));
696 break;
697 case Uless:
698 sltu(scratch, rs, r2);
699 addiu(scratch, scratch, -1);
700 bgezal(scratch, shifted_branch_offset(L, false));
701 break;
702 case Uless_equal:
703 sltu(scratch, r2, rs);
704 addiu(scratch, scratch, -1);
705 bltzal(scratch, shifted_branch_offset(L, false));
706 break;
707
708 default:
709 UNREACHABLE();
710 }
Steve Block6ded16b2010-05-10 14:33:55 +0100711 // Emit a nop in the branch delay slot.
712 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000713}
714
715
716void MacroAssembler::Jump(const Operand& target,
717 Condition cond, Register rs, const Operand& rt) {
718 if (target.is_reg()) {
719 if (cond == cc_always) {
720 jr(target.rm());
721 } else {
722 Branch(NegateCondition(cond), 2, rs, rt);
Andrei Popescu31002712010-02-23 13:46:05 +0000723 jr(target.rm());
724 }
725 } else { // !target.is_reg()
726 if (!MustUseAt(target.rmode_)) {
727 if (cond == cc_always) {
728 j(target.imm32_);
729 } else {
730 Branch(NegateCondition(cond), 2, rs, rt);
Steve Block6ded16b2010-05-10 14:33:55 +0100731 j(target.imm32_); // Will generate only one instruction.
Andrei Popescu31002712010-02-23 13:46:05 +0000732 }
733 } else { // MustUseAt(target)
Steve Block6ded16b2010-05-10 14:33:55 +0100734 li(at, target);
Andrei Popescu31002712010-02-23 13:46:05 +0000735 if (cond == cc_always) {
736 jr(at);
737 } else {
738 Branch(NegateCondition(cond), 2, rs, rt);
Steve Block6ded16b2010-05-10 14:33:55 +0100739 jr(at); // Will generate only one instruction.
Andrei Popescu31002712010-02-23 13:46:05 +0000740 }
741 }
742 }
Steve Block6ded16b2010-05-10 14:33:55 +0100743 // Emit a nop in the branch delay slot.
744 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000745}
746
747
748void MacroAssembler::Call(const Operand& target,
749 Condition cond, Register rs, const Operand& rt) {
750 if (target.is_reg()) {
751 if (cond == cc_always) {
752 jalr(target.rm());
753 } else {
754 Branch(NegateCondition(cond), 2, rs, rt);
Andrei Popescu31002712010-02-23 13:46:05 +0000755 jalr(target.rm());
756 }
757 } else { // !target.is_reg()
758 if (!MustUseAt(target.rmode_)) {
759 if (cond == cc_always) {
760 jal(target.imm32_);
761 } else {
762 Branch(NegateCondition(cond), 2, rs, rt);
Steve Block6ded16b2010-05-10 14:33:55 +0100763 jal(target.imm32_); // Will generate only one instruction.
Andrei Popescu31002712010-02-23 13:46:05 +0000764 }
765 } else { // MustUseAt(target)
Steve Block6ded16b2010-05-10 14:33:55 +0100766 li(at, target);
Andrei Popescu31002712010-02-23 13:46:05 +0000767 if (cond == cc_always) {
768 jalr(at);
769 } else {
770 Branch(NegateCondition(cond), 2, rs, rt);
Steve Block6ded16b2010-05-10 14:33:55 +0100771 jalr(at); // Will generate only one instruction.
Andrei Popescu31002712010-02-23 13:46:05 +0000772 }
773 }
774 }
Steve Block6ded16b2010-05-10 14:33:55 +0100775 // Emit a nop in the branch delay slot.
776 nop();
Andrei Popescu31002712010-02-23 13:46:05 +0000777}
778
779void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) {
780 UNIMPLEMENTED_MIPS();
781}
782
783
784void MacroAssembler::Drop(int count, Condition cond) {
785 UNIMPLEMENTED_MIPS();
786}
787
788
789void MacroAssembler::Call(Label* target) {
790 UNIMPLEMENTED_MIPS();
791}
792
793
Steve Block6ded16b2010-05-10 14:33:55 +0100794#ifdef ENABLE_DEBUGGER_SUPPORT
795 // ---------------------------------------------------------------------------
796 // Debugger Support
797
798 void MacroAssembler::DebugBreak() {
799 UNIMPLEMENTED_MIPS();
800 }
801#endif
802
803
Andrei Popescu31002712010-02-23 13:46:05 +0000804// ---------------------------------------------------------------------------
805// Exception handling
806
807void MacroAssembler::PushTryHandler(CodeLocation try_location,
808 HandlerType type) {
Steve Block6ded16b2010-05-10 14:33:55 +0100809 // Adjust this code if not the case.
810 ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize);
811 // The return address is passed in register ra.
812 if (try_location == IN_JAVASCRIPT) {
813 if (type == TRY_CATCH_HANDLER) {
814 li(t0, Operand(StackHandler::TRY_CATCH));
815 } else {
816 li(t0, Operand(StackHandler::TRY_FINALLY));
817 }
818 ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
819 && StackHandlerConstants::kFPOffset == 2 * kPointerSize
820 && StackHandlerConstants::kPCOffset == 3 * kPointerSize
821 && StackHandlerConstants::kNextOffset == 0 * kPointerSize);
822 // Save the current handler as the next handler.
823 LoadExternalReference(t2, ExternalReference(Top::k_handler_address));
824 lw(t1, MemOperand(t2));
825
826 addiu(sp, sp, -StackHandlerConstants::kSize);
827 sw(ra, MemOperand(sp, 12));
828 sw(fp, MemOperand(sp, 8));
829 sw(t0, MemOperand(sp, 4));
830 sw(t1, MemOperand(sp, 0));
831
832 // Link this handler as the new current one.
833 sw(sp, MemOperand(t2));
834
835 } else {
836 // Must preserve a0-a3, and s0 (argv).
837 ASSERT(try_location == IN_JS_ENTRY);
838 ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
839 && StackHandlerConstants::kFPOffset == 2 * kPointerSize
840 && StackHandlerConstants::kPCOffset == 3 * kPointerSize
841 && StackHandlerConstants::kNextOffset == 0 * kPointerSize);
842
843 // The frame pointer does not point to a JS frame so we save NULL
844 // for fp. We expect the code throwing an exception to check fp
845 // before dereferencing it to restore the context.
846 li(t0, Operand(StackHandler::ENTRY));
847
848 // Save the current handler as the next handler.
849 LoadExternalReference(t2, ExternalReference(Top::k_handler_address));
850 lw(t1, MemOperand(t2));
851
852 addiu(sp, sp, -StackHandlerConstants::kSize);
853 sw(ra, MemOperand(sp, 12));
854 sw(zero_reg, MemOperand(sp, 8));
855 sw(t0, MemOperand(sp, 4));
856 sw(t1, MemOperand(sp, 0));
857
858 // Link this handler as the new current one.
859 sw(sp, MemOperand(t2));
860 }
Andrei Popescu31002712010-02-23 13:46:05 +0000861}
862
863
864void MacroAssembler::PopTryHandler() {
865 UNIMPLEMENTED_MIPS();
866}
867
868
869
Steve Block6ded16b2010-05-10 14:33:55 +0100870// -----------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000871// Activation frames
872
Steve Block6ded16b2010-05-10 14:33:55 +0100873void MacroAssembler::SetupAlignedCall(Register scratch, int arg_count) {
874 Label extra_push, end;
875
876 andi(scratch, sp, 7);
877
878 // We check for args and receiver size on the stack, all of them word sized.
879 // We add one for sp, that we also want to store on the stack.
880 if (((arg_count + 1) % kPointerSizeLog2) == 0) {
881 Branch(ne, &extra_push, at, Operand(zero_reg));
882 } else { // ((arg_count + 1) % 2) == 1
883 Branch(eq, &extra_push, at, Operand(zero_reg));
884 }
885
886 // Save sp on the stack.
887 mov(scratch, sp);
888 Push(scratch);
889 b(&end);
890
891 // Align before saving sp on the stack.
892 bind(&extra_push);
893 mov(scratch, sp);
894 addiu(sp, sp, -8);
895 sw(scratch, MemOperand(sp));
896
897 // The stack is aligned and sp is stored on the top.
898 bind(&end);
899}
900
901
902void MacroAssembler::ReturnFromAlignedCall() {
903 lw(sp, MemOperand(sp));
904}
905
906
907// -----------------------------------------------------------------------------
908// JavaScript invokes
909
910void MacroAssembler::InvokePrologue(const ParameterCount& expected,
911 const ParameterCount& actual,
912 Handle<Code> code_constant,
913 Register code_reg,
914 Label* done,
915 InvokeFlag flag) {
916 bool definitely_matches = false;
917 Label regular_invoke;
918
919 // Check whether the expected and actual arguments count match. If not,
920 // setup registers according to contract with ArgumentsAdaptorTrampoline:
921 // a0: actual arguments count
922 // a1: function (passed through to callee)
923 // a2: expected arguments count
924 // a3: callee code entry
925
926 // The code below is made a lot easier because the calling code already sets
927 // up actual and expected registers according to the contract if values are
928 // passed in registers.
929 ASSERT(actual.is_immediate() || actual.reg().is(a0));
930 ASSERT(expected.is_immediate() || expected.reg().is(a2));
931 ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(a3));
932
933 if (expected.is_immediate()) {
934 ASSERT(actual.is_immediate());
935 if (expected.immediate() == actual.immediate()) {
936 definitely_matches = true;
937 } else {
938 li(a0, Operand(actual.immediate()));
939 const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
940 if (expected.immediate() == sentinel) {
941 // Don't worry about adapting arguments for builtins that
942 // don't want that done. Skip adaption code by making it look
943 // like we have a match between expected and actual number of
944 // arguments.
945 definitely_matches = true;
946 } else {
947 li(a2, Operand(expected.immediate()));
948 }
949 }
950 } else if (actual.is_immediate()) {
951 Branch(eq, &regular_invoke, expected.reg(), Operand(actual.immediate()));
952 li(a0, Operand(actual.immediate()));
953 } else {
954 Branch(eq, &regular_invoke, expected.reg(), Operand(actual.reg()));
955 }
956
957 if (!definitely_matches) {
958 if (!code_constant.is_null()) {
959 li(a3, Operand(code_constant));
960 addiu(a3, a3, Code::kHeaderSize - kHeapObjectTag);
961 }
962
963 ExternalReference adaptor(Builtins::ArgumentsAdaptorTrampoline);
964 if (flag == CALL_FUNCTION) {
965 CallBuiltin(adaptor);
966 b(done);
967 nop();
968 } else {
969 JumpToBuiltin(adaptor);
970 }
971 bind(&regular_invoke);
972 }
973}
974
975void MacroAssembler::InvokeCode(Register code,
976 const ParameterCount& expected,
977 const ParameterCount& actual,
978 InvokeFlag flag) {
979 Label done;
980
981 InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag);
982 if (flag == CALL_FUNCTION) {
983 Call(code);
984 } else {
985 ASSERT(flag == JUMP_FUNCTION);
986 Jump(code);
987 }
988 // Continue here if InvokePrologue does handle the invocation due to
989 // mismatched parameter counts.
990 bind(&done);
991}
992
993
994void MacroAssembler::InvokeCode(Handle<Code> code,
995 const ParameterCount& expected,
996 const ParameterCount& actual,
997 RelocInfo::Mode rmode,
998 InvokeFlag flag) {
999 Label done;
1000
1001 InvokePrologue(expected, actual, code, no_reg, &done, flag);
1002 if (flag == CALL_FUNCTION) {
1003 Call(code, rmode);
1004 } else {
1005 Jump(code, rmode);
1006 }
1007 // Continue here if InvokePrologue does handle the invocation due to
1008 // mismatched parameter counts.
1009 bind(&done);
1010}
1011
1012
1013void MacroAssembler::InvokeFunction(Register function,
1014 const ParameterCount& actual,
1015 InvokeFlag flag) {
1016 // Contract with called JS functions requires that function is passed in a1.
1017 ASSERT(function.is(a1));
1018 Register expected_reg = a2;
1019 Register code_reg = a3;
1020
1021 lw(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1022 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
1023 lw(expected_reg,
1024 FieldMemOperand(code_reg,
1025 SharedFunctionInfo::kFormalParameterCountOffset));
1026 lw(code_reg,
1027 MemOperand(code_reg, SharedFunctionInfo::kCodeOffset - kHeapObjectTag));
1028 addiu(code_reg, code_reg, Code::kHeaderSize - kHeapObjectTag);
1029
1030 ParameterCount expected(expected_reg);
1031 InvokeCode(code_reg, expected, actual, flag);
1032}
1033
1034
1035// ---------------------------------------------------------------------------
1036// Support functions.
1037
1038 void MacroAssembler::GetObjectType(Register function,
1039 Register map,
1040 Register type_reg) {
1041 lw(map, FieldMemOperand(function, HeapObject::kMapOffset));
1042 lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
1043 }
1044
1045
1046 void MacroAssembler::CallBuiltin(ExternalReference builtin_entry) {
1047 // Load builtin address.
1048 LoadExternalReference(t9, builtin_entry);
1049 lw(t9, MemOperand(t9)); // Deref address.
1050 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1051 // Call and allocate arguments slots.
1052 jalr(t9);
1053 // Use the branch delay slot to allocated argument slots.
1054 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1055 addiu(sp, sp, StandardFrameConstants::kRArgsSlotsSize);
1056 }
1057
1058
1059 void MacroAssembler::CallBuiltin(Register target) {
1060 // Target already holds target address.
1061 // Call and allocate arguments slots.
1062 jalr(target);
1063 // Use the branch delay slot to allocated argument slots.
1064 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1065 addiu(sp, sp, StandardFrameConstants::kRArgsSlotsSize);
1066 }
1067
1068
1069 void MacroAssembler::JumpToBuiltin(ExternalReference builtin_entry) {
1070 // Load builtin address.
1071 LoadExternalReference(t9, builtin_entry);
1072 lw(t9, MemOperand(t9)); // Deref address.
1073 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1074 // Call and allocate arguments slots.
1075 jr(t9);
1076 // Use the branch delay slot to allocated argument slots.
1077 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1078 }
1079
1080
1081 void MacroAssembler::JumpToBuiltin(Register target) {
1082 // t9 already holds target address.
1083 // Call and allocate arguments slots.
1084 jr(t9);
1085 // Use the branch delay slot to allocated argument slots.
1086 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1087 }
1088
1089
1090// -----------------------------------------------------------------------------
1091// Runtime calls
1092
Andrei Popescu31002712010-02-23 13:46:05 +00001093void MacroAssembler::CallStub(CodeStub* stub, Condition cond,
1094 Register r1, const Operand& r2) {
Steve Block6ded16b2010-05-10 14:33:55 +01001095 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs.
1096 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond, r1, r2);
Andrei Popescu31002712010-02-23 13:46:05 +00001097}
1098
1099
1100void MacroAssembler::StubReturn(int argc) {
1101 UNIMPLEMENTED_MIPS();
1102}
1103
1104
Steve Block6ded16b2010-05-10 14:33:55 +01001105void MacroAssembler::IllegalOperation(int num_arguments) {
1106 if (num_arguments > 0) {
1107 addiu(sp, sp, num_arguments * kPointerSize);
1108 }
1109 LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1110}
1111
1112
Andrei Popescu31002712010-02-23 13:46:05 +00001113void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) {
Steve Block6ded16b2010-05-10 14:33:55 +01001114 // All parameters are on the stack. v0 has the return value after call.
1115
1116 // If the expected number of arguments of the runtime function is
1117 // constant, we check that the actual number of arguments match the
1118 // expectation.
1119 if (f->nargs >= 0 && f->nargs != num_arguments) {
1120 IllegalOperation(num_arguments);
1121 return;
1122 }
1123
1124 // TODO(1236192): Most runtime routines don't need the number of
1125 // arguments passed in because it is constant. At some point we
1126 // should remove this need and make the runtime routine entry code
1127 // smarter.
1128 li(a0, num_arguments);
1129 LoadExternalReference(a1, ExternalReference(f));
1130 CEntryStub stub(1);
1131 CallStub(&stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001132}
1133
1134
1135void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) {
Steve Block6ded16b2010-05-10 14:33:55 +01001136 CallRuntime(Runtime::FunctionForId(fid), num_arguments);
1137}
1138
1139
1140void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
1141 int num_arguments,
1142 int result_size) {
Andrei Popescu31002712010-02-23 13:46:05 +00001143 UNIMPLEMENTED_MIPS();
1144}
1145
1146
Steve Block6ded16b2010-05-10 14:33:55 +01001147void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
Andrei Popescu31002712010-02-23 13:46:05 +00001148 int num_arguments,
1149 int result_size) {
Steve Block6ded16b2010-05-10 14:33:55 +01001150 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size);
Andrei Popescu31002712010-02-23 13:46:05 +00001151}
1152
1153
Steve Block6ded16b2010-05-10 14:33:55 +01001154void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) {
Andrei Popescu31002712010-02-23 13:46:05 +00001155 UNIMPLEMENTED_MIPS();
1156}
1157
1158
1159Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id,
1160 bool* resolved) {
1161 UNIMPLEMENTED_MIPS();
1162 return Handle<Code>(reinterpret_cast<Code*>(NULL)); // UNIMPLEMENTED RETURN
1163}
1164
1165
1166void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
1167 InvokeJSFlags flags) {
1168 UNIMPLEMENTED_MIPS();
1169}
1170
1171
1172void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
1173 UNIMPLEMENTED_MIPS();
1174}
1175
1176
1177void MacroAssembler::SetCounter(StatsCounter* counter, int value,
1178 Register scratch1, Register scratch2) {
1179 UNIMPLEMENTED_MIPS();
1180}
1181
1182
1183void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
1184 Register scratch1, Register scratch2) {
1185 UNIMPLEMENTED_MIPS();
1186}
1187
1188
1189void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
1190 Register scratch1, Register scratch2) {
1191 UNIMPLEMENTED_MIPS();
1192}
1193
1194
Steve Block6ded16b2010-05-10 14:33:55 +01001195// -----------------------------------------------------------------------------
1196// Debugging
Andrei Popescu31002712010-02-23 13:46:05 +00001197
1198void MacroAssembler::Assert(Condition cc, const char* msg,
1199 Register rs, Operand rt) {
1200 UNIMPLEMENTED_MIPS();
1201}
1202
1203
1204void MacroAssembler::Check(Condition cc, const char* msg,
1205 Register rs, Operand rt) {
1206 UNIMPLEMENTED_MIPS();
1207}
1208
1209
1210void MacroAssembler::Abort(const char* msg) {
1211 UNIMPLEMENTED_MIPS();
1212}
1213
Steve Block6ded16b2010-05-10 14:33:55 +01001214
1215void MacroAssembler::EnterFrame(StackFrame::Type type) {
1216 addiu(sp, sp, -5 * kPointerSize);
1217 li(t0, Operand(Smi::FromInt(type)));
1218 li(t1, Operand(CodeObject()));
1219 sw(ra, MemOperand(sp, 4 * kPointerSize));
1220 sw(fp, MemOperand(sp, 3 * kPointerSize));
1221 sw(cp, MemOperand(sp, 2 * kPointerSize));
1222 sw(t0, MemOperand(sp, 1 * kPointerSize));
1223 sw(t1, MemOperand(sp, 0 * kPointerSize));
1224 addiu(fp, sp, 3 * kPointerSize);
1225}
1226
1227
1228void MacroAssembler::LeaveFrame(StackFrame::Type type) {
1229 mov(sp, fp);
1230 lw(fp, MemOperand(sp, 0 * kPointerSize));
1231 lw(ra, MemOperand(sp, 1 * kPointerSize));
1232 addiu(sp, sp, 2 * kPointerSize);
1233}
1234
1235
1236void MacroAssembler::EnterExitFrame(ExitFrame::Mode mode,
1237 Register hold_argc,
1238 Register hold_argv,
1239 Register hold_function) {
1240 // Compute the argv pointer and keep it in a callee-saved register.
1241 // a0 is argc.
1242 sll(t0, a0, kPointerSizeLog2);
1243 add(hold_argv, sp, t0);
1244 addi(hold_argv, hold_argv, -kPointerSize);
1245
1246 // Compute callee's stack pointer before making changes and save it as
1247 // t1 register so that it is restored as sp register on exit, thereby
1248 // popping the args.
1249 // t1 = sp + kPointerSize * #args
1250 add(t1, sp, t0);
1251
1252 // Align the stack at this point.
1253 AlignStack(0);
1254
1255 // Save registers.
1256 addiu(sp, sp, -12);
1257 sw(t1, MemOperand(sp, 8));
1258 sw(ra, MemOperand(sp, 4));
1259 sw(fp, MemOperand(sp, 0));
1260 mov(fp, sp); // Setup new frame pointer.
1261
1262 // Push debug marker.
1263 if (mode == ExitFrame::MODE_DEBUG) {
1264 Push(zero_reg);
1265 } else {
1266 li(t0, Operand(CodeObject()));
1267 Push(t0);
1268 }
1269
1270 // Save the frame pointer and the context in top.
1271 LoadExternalReference(t0, ExternalReference(Top::k_c_entry_fp_address));
1272 sw(fp, MemOperand(t0));
1273 LoadExternalReference(t0, ExternalReference(Top::k_context_address));
1274 sw(cp, MemOperand(t0));
1275
1276 // Setup argc and the builtin function in callee-saved registers.
1277 mov(hold_argc, a0);
1278 mov(hold_function, a1);
1279}
1280
1281
1282void MacroAssembler::LeaveExitFrame(ExitFrame::Mode mode) {
1283 // Clear top frame.
1284 LoadExternalReference(t0, ExternalReference(Top::k_c_entry_fp_address));
1285 sw(zero_reg, MemOperand(t0));
1286
1287 // Restore current context from top and clear it in debug mode.
1288 LoadExternalReference(t0, ExternalReference(Top::k_context_address));
1289 lw(cp, MemOperand(t0));
1290#ifdef DEBUG
1291 sw(a3, MemOperand(t0));
1292#endif
1293
1294 // Pop the arguments, restore registers, and return.
1295 mov(sp, fp); // Respect ABI stack constraint.
1296 lw(fp, MemOperand(sp, 0));
1297 lw(ra, MemOperand(sp, 4));
1298 lw(sp, MemOperand(sp, 8));
1299 jr(ra);
1300 nop(); // Branch delay slot nop.
1301}
1302
1303
1304void MacroAssembler::AlignStack(int offset) {
1305 // On MIPS an offset of 0 aligns to 0 modulo 8 bytes,
1306 // and an offset of 1 aligns to 4 modulo 8 bytes.
1307 int activation_frame_alignment = OS::ActivationFrameAlignment();
1308 if (activation_frame_alignment != kPointerSize) {
1309 // This code needs to be made more general if this assert doesn't hold.
1310 ASSERT(activation_frame_alignment == 2 * kPointerSize);
1311 if (offset == 0) {
1312 andi(t0, sp, activation_frame_alignment - 1);
1313 Push(zero_reg, eq, t0, zero_reg);
1314 } else {
1315 andi(t0, sp, activation_frame_alignment - 1);
1316 addiu(t0, t0, -4);
1317 Push(zero_reg, eq, t0, zero_reg);
1318 }
1319 }
1320}
1321
Andrei Popescu31002712010-02-23 13:46:05 +00001322} } // namespace v8::internal
1323