Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/mips/macro-assembler-mips.cc

Issue 6709022: Re-establish mips basic infrastructure. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 28 #include <limits.h> // For LONG_MIN, LONG_MAX
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #if defined(V8_TARGET_ARCH_MIPS) 32 #if defined(V8_TARGET_ARCH_MIPS)
33 33
34 #include "bootstrapper.h" 34 #include "bootstrapper.h"
35 #include "codegen-inl.h" 35 #include "codegen-inl.h"
36 #include "debug.h" 36 #include "debug.h"
37 #include "runtime.h" 37 #include "runtime.h"
38 38
39 #ifdef _MIPS_ARCH_MIPS32R2
40 #define mips32r2 1
41 #else
42 #define mips32r2 0
43 #endif
44
39 namespace v8 { 45 namespace v8 {
40 namespace internal { 46 namespace internal {
41 47
42 MacroAssembler::MacroAssembler(void* buffer, int size) 48 MacroAssembler::MacroAssembler(void* buffer, int size)
43 : Assembler(buffer, size), 49 : Assembler(buffer, size),
44 unresolved_(0),
45 generating_stub_(false), 50 generating_stub_(false),
46 allow_stub_calls_(true), 51 allow_stub_calls_(true),
47 code_object_(Heap::undefined_value()) { 52 code_object_(Heap::undefined_value()) {
48 } 53 }
49 54
50 55
56 // Arguments macros
57 #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
58 #define COND_ARGS cond, r1, r2
51 59
52 void MacroAssembler::Jump(Register target, Condition cond, 60 #define REGISTER_TARGET_BODY(Name) \
53 Register r1, const Operand& r2) { 61 void MacroAssembler::Name(Register target, \
54 Jump(Operand(target), cond, r1, r2); 62 bool ProtectBranchDelaySlot) { \
63 Name(Operand(target), ProtectBranchDelaySlot); \
64 } \
65 void MacroAssembler::Name(Register target, COND_TYPED_ARGS, \
66 bool ProtectBranchDelaySlot) { \
67 Name(Operand(target), COND_ARGS, ProtectBranchDelaySlot); \
55 } 68 }
56 69
57 70
58 void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, 71 #define INT_PTR_TARGET_BODY(Name) \
59 Condition cond, Register r1, const Operand& r2) { 72 void MacroAssembler::Name(intptr_t target, RelocInfo::Mode rmode, \
60 Jump(Operand(target, rmode), cond, r1, r2); 73 bool ProtectBranchDelaySlot) { \
74 Name(Operand(target, rmode), ProtectBranchDelaySlot); \
75 } \
76 void MacroAssembler::Name(intptr_t target, \
77 RelocInfo::Mode rmode, \
78 COND_TYPED_ARGS, \
79 bool ProtectBranchDelaySlot) { \
80 Name(Operand(target, rmode), COND_ARGS, ProtectBranchDelaySlot); \
61 } 81 }
62 82
63 83
64 void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, 84 #define BYTE_PTR_TARGET_BODY(Name) \
65 Condition cond, Register r1, const Operand& r2) { 85 void MacroAssembler::Name(byte* target, RelocInfo::Mode rmode, \
66 ASSERT(!RelocInfo::IsCodeTarget(rmode)); 86 bool ProtectBranchDelaySlot) { \
67 Jump(reinterpret_cast<intptr_t>(target), rmode, cond, r1, r2); 87 Name(reinterpret_cast<intptr_t>(target), rmode, ProtectBranchDelaySlot); \
88 } \
89 void MacroAssembler::Name(byte* target, \
90 RelocInfo::Mode rmode, \
91 COND_TYPED_ARGS, \
92 bool ProtectBranchDelaySlot) { \
93 Name(reinterpret_cast<intptr_t>(target), \
94 rmode, \
95 COND_ARGS, \
96 ProtectBranchDelaySlot); \
68 } 97 }
69 98
70 99
71 void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, 100 #define CODE_TARGET_BODY(Name) \
72 Condition cond, Register r1, const Operand& r2) { 101 void MacroAssembler::Name(Handle<Code> target, RelocInfo::Mode rmode, \
73 ASSERT(RelocInfo::IsCodeTarget(rmode)); 102 bool ProtectBranchDelaySlot) { \
74 Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); 103 Name(reinterpret_cast<intptr_t>(target.location()), \
104 rmode, ProtectBranchDelaySlot); \
105 } \
106 void MacroAssembler::Name(Handle<Code> target, \
107 RelocInfo::Mode rmode, \
108 COND_TYPED_ARGS, \
109 bool ProtectBranchDelaySlot) { \
110 Name(reinterpret_cast<intptr_t>(target.location()), \
111 rmode, \
112 COND_ARGS, \
113 ProtectBranchDelaySlot); \
75 } 114 }
76 115
77 116
78 void MacroAssembler::Call(Register target, 117 REGISTER_TARGET_BODY(Jump)
79 Condition cond, Register r1, const Operand& r2) { 118 REGISTER_TARGET_BODY(Call)
80 Call(Operand(target), cond, r1, r2); 119 INT_PTR_TARGET_BODY(Jump)
120 INT_PTR_TARGET_BODY(Call)
121 BYTE_PTR_TARGET_BODY(Jump)
122 BYTE_PTR_TARGET_BODY(Call)
123 CODE_TARGET_BODY(Jump)
124 CODE_TARGET_BODY(Call)
125
126 #undef COND_TYPED_ARGS
127 #undef COND_ARGS
128 #undef REGISTER_TARGET_BODY
129 #undef BYTE_PTR_TARGET_BODY
130 #undef CODE_TARGET_BODY
131
132
133 void MacroAssembler::Ret(bool ProtectBranchDelaySlot) {
134 Jump(Operand(ra), ProtectBranchDelaySlot);
81 } 135 }
82 136
83 137
84 void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, 138 void MacroAssembler::Ret(Condition cond, Register r1, const Operand& r2,
85 Condition cond, Register r1, const Operand& r2) { 139 bool ProtectBranchDelaySlot) {
86 Call(Operand(target, rmode), cond, r1, r2); 140 Jump(Operand(ra), cond, r1, r2, ProtectBranchDelaySlot);
87 } 141 }
88 142
89 143
90 void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode,
91 Condition cond, Register r1, const Operand& r2) {
92 ASSERT(!RelocInfo::IsCodeTarget(rmode));
93 Call(reinterpret_cast<intptr_t>(target), rmode, cond, r1, r2);
94 }
95
96
97 void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
98 Condition cond, Register r1, const Operand& r2) {
99 ASSERT(RelocInfo::IsCodeTarget(rmode));
100 Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond, r1, r2);
101 }
102
103
104 void MacroAssembler::Ret(Condition cond, Register r1, const Operand& r2) {
105 Jump(Operand(ra), cond, r1, r2);
106 }
107
108
109 void MacroAssembler::LoadRoot(Register destination, 144 void MacroAssembler::LoadRoot(Register destination,
110 Heap::RootListIndex index) { 145 Heap::RootListIndex index) {
111 lw(destination, MemOperand(s6, index << kPointerSizeLog2)); 146 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
112 } 147 }
113 148
149
114 void MacroAssembler::LoadRoot(Register destination, 150 void MacroAssembler::LoadRoot(Register destination,
115 Heap::RootListIndex index, 151 Heap::RootListIndex index,
116 Condition cond, 152 Condition cond,
117 Register src1, const Operand& src2) { 153 Register src1, const Operand& src2) {
118 Branch(NegateCondition(cond), 2, src1, src2); 154 Branch(2, NegateCondition(cond), src1, src2);
119 lw(destination, MemOperand(s6, index << kPointerSizeLog2)); 155 lw(destination, MemOperand(s6, index << kPointerSizeLog2));
120 } 156 }
121 157
122 158
123 void MacroAssembler::RecordWrite(Register object, Register offset, 159 void MacroAssembler::StoreRoot(Register source,
160 Heap::RootListIndex index) {
161 sw(source, MemOperand(s6, index << kPointerSizeLog2));
162 }
163
164
165 void MacroAssembler::StoreRoot(Register source,
166 Heap::RootListIndex index,
167 Condition cond,
168 Register src1, const Operand& src2) {
169 Branch(2, NegateCondition(cond), src1, src2);
170 sw(source, MemOperand(s6, index << kPointerSizeLog2));
171 }
172
173
174 void MacroAssembler::RecordWriteHelper(Register object,
175 Register address,
176 Register scratch) {
177 if (FLAG_debug_code) {
178 // Check that the object is not in new space.
179 Label not_in_new_space;
180 InNewSpace(object, scratch, ne, &not_in_new_space);
181 Abort("new-space object passed to RecordWriteHelper");
182 bind(&not_in_new_space);
183 }
184
185 // Calculate page address: Clear bits from 0 to kPageSizeBits.
186 if (mips32r2) {
187 Ins(object, zero_reg, 0, kPageSizeBits);
188 } else {
189 // The Ins macro is slow on r1, so use shifts instead.
190 srl(object, object, kPageSizeBits);
191 sll(object, object, kPageSizeBits);
192 }
193
194 // Calculate region number.
195 Ext(address, address, Page::kRegionSizeLog2,
196 kPageSizeBits - Page::kRegionSizeLog2);
197
198 // Mark region dirty.
199 lw(scratch, MemOperand(object, Page::kDirtyFlagOffset));
200 li(at, Operand(1));
201 sllv(at, at, address);
202 or_(scratch, scratch, at);
203 sw(scratch, MemOperand(object, Page::kDirtyFlagOffset));
204 }
205
206
207 void MacroAssembler::InNewSpace(Register object,
208 Register scratch,
209 Condition cc,
210 Label* branch) {
211 ASSERT(cc == eq || cc == ne);
212 And(scratch, object, Operand(ExternalReference::new_space_mask()));
213 Branch(branch, cc, scratch, Operand(ExternalReference::new_space_start()));
214 }
215
216
217 // Will clobber 4 registers: object, scratch0, scratch1, at. The
218 // register 'object' contains a heap object pointer. The heap object
219 // tag is shifted away.
220 void MacroAssembler::RecordWrite(Register object,
221 Operand offset,
222 Register scratch0,
223 Register scratch1) {
224 // The compiled code assumes that record write doesn't change the
225 // context register, so we check that none of the clobbered
226 // registers are cp.
227 ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp));
228
229 Label done;
230
231 // First, test that the object is not in the new space. We cannot set
232 // region marks for new space pages.
233 InNewSpace(object, scratch0, eq, &done);
234
235 // Add offset into the object.
236 Addu(scratch0, object, offset);
237
238 // Record the actual write.
239 RecordWriteHelper(object, scratch0, scratch1);
240
241 bind(&done);
242
243 // Clobber all input registers when running with the debug-code flag
244 // turned on to provoke errors.
245 if (FLAG_debug_code) {
246 li(object, Operand(BitCast<int32_t>(kZapValue)));
247 li(scratch0, Operand(BitCast<int32_t>(kZapValue)));
248 li(scratch1, Operand(BitCast<int32_t>(kZapValue)));
249 }
250 }
251
252
253 // Will clobber 4 registers: object, address, scratch, ip. The
254 // register 'object' contains a heap object pointer. The heap object
255 // tag is shifted away.
256 void MacroAssembler::RecordWrite(Register object,
257 Register address,
124 Register scratch) { 258 Register scratch) {
125 UNIMPLEMENTED_MIPS(); 259 // The compiled code assumes that record write doesn't change the
260 // context register, so we check that none of the clobbered
261 // registers are cp.
262 ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp));
263
264 Label done;
265
266 // First, test that the object is not in the new space. We cannot set
267 // region marks for new space pages.
268 InNewSpace(object, scratch, eq, &done);
269
270 // Record the actual write.
271 RecordWriteHelper(object, address, scratch);
272
273 bind(&done);
274
275 // Clobber all input registers when running with the debug-code flag
276 // turned on to provoke errors.
277 if (FLAG_debug_code) {
278 li(object, Operand(BitCast<int32_t>(kZapValue)));
279 li(address, Operand(BitCast<int32_t>(kZapValue)));
280 li(scratch, Operand(BitCast<int32_t>(kZapValue)));
281 }
282 }
283
284
285 // -----------------------------------------------------------------------------
286 // Allocation support
287
288
289 void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
290 Register scratch,
291 Label* miss) {
292 Label same_contexts;
293
294 ASSERT(!holder_reg.is(scratch));
295 ASSERT(!holder_reg.is(at));
296 ASSERT(!scratch.is(at));
297
298 // Load current lexical context from the stack frame.
299 lw(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
300 // In debug mode, make sure the lexical context is set.
301 #ifdef DEBUG
302 Check(ne, "we should not have an empty lexical context",
303 scratch, Operand(zero_reg));
304 #endif
305
306 // Load the global context of the current context.
307 int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
308 lw(scratch, FieldMemOperand(scratch, offset));
309 lw(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset));
310
311 // Check the context is a global context.
312 if (FLAG_debug_code) {
313 // TODO(119): Avoid push(holder_reg)/pop(holder_reg).
314 Push(holder_reg); // Temporarily save holder on the stack.
315 // Read the first word and compare to the global_context_map.
316 lw(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
317 LoadRoot(at, Heap::kGlobalContextMapRootIndex);
318 Check(eq, "JSGlobalObject::global_context should be a global context.",
319 holder_reg, Operand(at));
320 Pop(holder_reg); // Restore holder.
321 }
322
323 // Check if both contexts are the same.
324 lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
325 Branch(&same_contexts, eq, scratch, Operand(at));
326
327 // Check the context is a global context.
328 if (FLAG_debug_code) {
329 // TODO(119): Avoid push(holder_reg)/pop(holder_reg).
330 Push(holder_reg); // Temporarily save holder on the stack.
331 mov(holder_reg, at); // Move at to its holding place.
332 LoadRoot(at, Heap::kNullValueRootIndex);
333 Check(ne, "JSGlobalProxy::context() should not be null.",
334 holder_reg, Operand(at));
335
336 lw(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
337 LoadRoot(at, Heap::kGlobalContextMapRootIndex);
338 Check(eq, "JSGlobalObject::global_context should be a global context.",
339 holder_reg, Operand(at));
340 // Restore at is not needed. at is reloaded below.
341 Pop(holder_reg); // Restore holder.
342 // Restore at to holder's context.
343 lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
344 }
345
346 // Check that the security token in the calling global object is
347 // compatible with the security token in the receiving global
348 // object.
349 int token_offset = Context::kHeaderSize +
350 Context::SECURITY_TOKEN_INDEX * kPointerSize;
351
352 lw(scratch, FieldMemOperand(scratch, token_offset));
353 lw(at, FieldMemOperand(at, token_offset));
354 Branch(miss, ne, scratch, Operand(at));
355
356 bind(&same_contexts);
126 } 357 }
127 358
128 359
129 // --------------------------------------------------------------------------- 360 // ---------------------------------------------------------------------------
130 // Instruction macros 361 // Instruction macros
131 362
132 void MacroAssembler::Add(Register rd, Register rs, const Operand& rt) {
133 if (rt.is_reg()) {
134 add(rd, rs, rt.rm());
135 } else {
136 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) {
137 addi(rd, rs, rt.imm32_);
138 } else {
139 // li handles the relocation.
140 ASSERT(!rs.is(at));
141 li(at, rt);
142 add(rd, rs, at);
143 }
144 }
145 }
146
147
148 void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) { 363 void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) {
149 if (rt.is_reg()) { 364 if (rt.is_reg()) {
150 addu(rd, rs, rt.rm()); 365 addu(rd, rs, rt.rm());
151 } else { 366 } else {
152 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 367 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
153 addiu(rd, rs, rt.imm32_); 368 addiu(rd, rs, rt.imm32_);
154 } else { 369 } else {
155 // li handles the relocation. 370 // li handles the relocation.
156 ASSERT(!rs.is(at)); 371 ASSERT(!rs.is(at));
157 li(at, rt); 372 li(at, rt);
158 addu(rd, rs, at); 373 addu(rd, rs, at);
159 } 374 }
160 } 375 }
161 } 376 }
377
378
379 void MacroAssembler::Subu(Register rd, Register rs, const Operand& rt) {
380 if (rt.is_reg()) {
381 subu(rd, rs, rt.rm());
382 } else {
383 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
384 addiu(rd, rs, -rt.imm32_); // No subiu instr, use addiu(x, y, -imm).
385 } else {
386 // li handles the relocation.
387 ASSERT(!rs.is(at));
388 li(at, rt);
389 subu(rd, rs, at);
390 }
391 }
392 }
162 393
163 394
164 void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) { 395 void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) {
165 if (rt.is_reg()) { 396 if (rt.is_reg()) {
166 mul(rd, rs, rt.rm()); 397 mul(rd, rs, rt.rm());
167 } else { 398 } else {
168 // li handles the relocation. 399 // li handles the relocation.
169 ASSERT(!rs.is(at)); 400 ASSERT(!rs.is(at));
170 li(at, rt); 401 li(at, rt);
171 mul(rd, rs, at); 402 mul(rd, rs, at);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 li(at, rt); 449 li(at, rt);
219 divu(rs, at); 450 divu(rs, at);
220 } 451 }
221 } 452 }
222 453
223 454
224 void MacroAssembler::And(Register rd, Register rs, const Operand& rt) { 455 void MacroAssembler::And(Register rd, Register rs, const Operand& rt) {
225 if (rt.is_reg()) { 456 if (rt.is_reg()) {
226 and_(rd, rs, rt.rm()); 457 and_(rd, rs, rt.rm());
227 } else { 458 } else {
228 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 459 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
229 andi(rd, rs, rt.imm32_); 460 andi(rd, rs, rt.imm32_);
230 } else { 461 } else {
231 // li handles the relocation. 462 // li handles the relocation.
232 ASSERT(!rs.is(at)); 463 ASSERT(!rs.is(at));
233 li(at, rt); 464 li(at, rt);
234 and_(rd, rs, at); 465 and_(rd, rs, at);
235 } 466 }
236 } 467 }
237 } 468 }
238 469
239 470
240 void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) { 471 void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) {
241 if (rt.is_reg()) { 472 if (rt.is_reg()) {
242 or_(rd, rs, rt.rm()); 473 or_(rd, rs, rt.rm());
243 } else { 474 } else {
244 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 475 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
245 ori(rd, rs, rt.imm32_); 476 ori(rd, rs, rt.imm32_);
246 } else { 477 } else {
247 // li handles the relocation. 478 // li handles the relocation.
248 ASSERT(!rs.is(at)); 479 ASSERT(!rs.is(at));
249 li(at, rt); 480 li(at, rt);
250 or_(rd, rs, at); 481 or_(rd, rs, at);
251 } 482 }
252 } 483 }
253 } 484 }
254 485
255 486
256 void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) { 487 void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) {
257 if (rt.is_reg()) { 488 if (rt.is_reg()) {
258 xor_(rd, rs, rt.rm()); 489 xor_(rd, rs, rt.rm());
259 } else { 490 } else {
260 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 491 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
261 xori(rd, rs, rt.imm32_); 492 xori(rd, rs, rt.imm32_);
262 } else { 493 } else {
263 // li handles the relocation. 494 // li handles the relocation.
264 ASSERT(!rs.is(at)); 495 ASSERT(!rs.is(at));
265 li(at, rt); 496 li(at, rt);
266 xor_(rd, rs, at); 497 xor_(rd, rs, at);
267 } 498 }
268 } 499 }
269 } 500 }
270 501
271 502
272 void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) { 503 void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) {
273 if (rt.is_reg()) { 504 if (rt.is_reg()) {
274 nor(rd, rs, rt.rm()); 505 nor(rd, rs, rt.rm());
275 } else { 506 } else {
276 // li handles the relocation. 507 // li handles the relocation.
277 ASSERT(!rs.is(at)); 508 ASSERT(!rs.is(at));
278 li(at, rt); 509 li(at, rt);
279 nor(rd, rs, at); 510 nor(rd, rs, at);
280 } 511 }
281 } 512 }
282 513
283 514
284 void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) { 515 void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) {
285 if (rt.is_reg()) { 516 if (rt.is_reg()) {
286 slt(rd, rs, rt.rm()); 517 slt(rd, rs, rt.rm());
287 } else { 518 } else {
288 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 519 if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
289 slti(rd, rs, rt.imm32_); 520 slti(rd, rs, rt.imm32_);
290 } else { 521 } else {
291 // li handles the relocation. 522 // li handles the relocation.
292 ASSERT(!rs.is(at)); 523 ASSERT(!rs.is(at));
293 li(at, rt); 524 li(at, rt);
294 slt(rd, rs, at); 525 slt(rd, rs, at);
295 } 526 }
296 } 527 }
297 } 528 }
298 529
299 530
300 void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) { 531 void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) {
301 if (rt.is_reg()) { 532 if (rt.is_reg()) {
302 sltu(rd, rs, rt.rm()); 533 sltu(rd, rs, rt.rm());
303 } else { 534 } else {
304 if (is_int16(rt.imm32_) && !MustUseAt(rt.rmode_)) { 535 if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) {
305 sltiu(rd, rs, rt.imm32_); 536 sltiu(rd, rs, rt.imm32_);
306 } else { 537 } else {
307 // li handles the relocation. 538 // li handles the relocation.
308 ASSERT(!rs.is(at)); 539 ASSERT(!rs.is(at));
309 li(at, rt); 540 li(at, rt);
310 sltu(rd, rs, at); 541 sltu(rd, rs, at);
311 } 542 }
312 } 543 }
313 } 544 }
314 545
315 546
547 void MacroAssembler::Ror(Register rd, Register rs, const Operand& rt) {
548 if (mips32r2) {
549 if (rt.is_reg()) {
550 rotrv(rd, rs, rt.rm());
551 } else {
552 rotr(rd, rs, rt.imm32_);
553 }
554 } else {
555 if (rt.is_reg()) {
556 subu(at, zero_reg, rt.rm());
557 sllv(at, rs, at);
558 srlv(rd, rs, rt.rm());
559 or_(rd, rd, at);
560 } else {
561 if (rt.imm32_ == 0) {
562 srl(rd, rs, 0);
563 } else {
564 srl(at, rs, rt.imm32_);
565 sll(rd, rs, (0x20 - rt.imm32_) & 0x1f);
566 or_(rd, rd, at);
567 }
568 }
569 }
570 }
571
572
316 //------------Pseudo-instructions------------- 573 //------------Pseudo-instructions-------------
317 574
318 void MacroAssembler::movn(Register rd, Register rt) {
319 addiu(at, zero_reg, -1); // Fill at with ones.
320 xor_(rd, rt, at);
321 }
322
323
324 void MacroAssembler::li(Register rd, Operand j, bool gen2instr) { 575 void MacroAssembler::li(Register rd, Operand j, bool gen2instr) {
325 ASSERT(!j.is_reg()); 576 ASSERT(!j.is_reg());
326 577 BlockTrampolinePoolScope block_trampoline_pool(this);
327 if (!MustUseAt(j.rmode_) && !gen2instr) { 578 if (!MustUseReg(j.rmode_) && !gen2instr) {
328 // Normal load of an immediate value which does not need Relocation Info. 579 // Normal load of an immediate value which does not need Relocation Info.
329 if (is_int16(j.imm32_)) { 580 if (is_int16(j.imm32_)) {
330 addiu(rd, zero_reg, j.imm32_); 581 addiu(rd, zero_reg, j.imm32_);
331 } else if (!(j.imm32_ & HIMask)) { 582 } else if (!(j.imm32_ & HIMask)) {
332 ori(rd, zero_reg, j.imm32_); 583 ori(rd, zero_reg, j.imm32_);
333 } else if (!(j.imm32_ & LOMask)) { 584 } else if (!(j.imm32_ & LOMask)) {
334 lui(rd, (HIMask & j.imm32_) >> 16); 585 lui(rd, (HIMask & j.imm32_) >> 16);
335 } else { 586 } else {
336 lui(rd, (HIMask & j.imm32_) >> 16); 587 lui(rd, (HIMask & j.imm32_) >> 16);
337 ori(rd, rd, (LOMask & j.imm32_)); 588 ori(rd, rd, (LOMask & j.imm32_));
338 } 589 }
339 } else if (MustUseAt(j.rmode_) || gen2instr) { 590 } else if (MustUseReg(j.rmode_) || gen2instr) {
340 if (MustUseAt(j.rmode_)) { 591 if (MustUseReg(j.rmode_)) {
341 RecordRelocInfo(j.rmode_, j.imm32_); 592 RecordRelocInfo(j.rmode_, j.imm32_);
342 } 593 }
343 // We need always the same number of instructions as we may need to patch 594 // We need always the same number of instructions as we may need to patch
344 // this code to load another value which may need 2 instructions to load. 595 // this code to load another value which may need 2 instructions to load.
345 if (is_int16(j.imm32_)) { 596 if (is_int16(j.imm32_)) {
346 nop(); 597 nop();
347 addiu(rd, zero_reg, j.imm32_); 598 addiu(rd, zero_reg, j.imm32_);
348 } else if (!(j.imm32_ & HIMask)) { 599 } else if (!(j.imm32_ & HIMask)) {
349 nop(); 600 nop();
350 ori(rd, zero_reg, j.imm32_); 601 ori(rd, zero_reg, j.imm32_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 661
411 for (int16_t i = kNumRegisters; i > 0; i--) { 662 for (int16_t i = kNumRegisters; i > 0; i--) {
412 if ((regs & (1 << i)) != 0) { 663 if ((regs & (1 << i)) != 0) {
413 lw(ToRegister(i), MemOperand(sp, 4 * (NumSaved++))); 664 lw(ToRegister(i), MemOperand(sp, 4 * (NumSaved++)));
414 } 665 }
415 } 666 }
416 addiu(sp, sp, 4 * NumSaved); 667 addiu(sp, sp, 4 * NumSaved);
417 } 668 }
418 669
419 670
671 void MacroAssembler::Ext(Register rt,
672 Register rs,
673 uint16_t pos,
674 uint16_t size) {
675 ASSERT(pos < 32);
676 ASSERT(pos + size < 32);
677
678 if (mips32r2) {
679 ext_(rt, rs, pos, size);
680 } else {
681 // Move rs to rt and shift it left then right to get the
682 // desired bitfield on the right side and zeroes on the left.
683 sll(rt, rs, 32 - (pos + size));
684 srl(rt, rt, 32 - size);
685 }
686 }
687
688
689 void MacroAssembler::Ins(Register rt,
690 Register rs,
691 uint16_t pos,
692 uint16_t size) {
693 ASSERT(pos < 32);
694 ASSERT(pos + size < 32);
695
696 if (mips32r2) {
697 ins_(rt, rs, pos, size);
698 } else {
699 ASSERT(!rt.is(t8) && !rs.is(t8));
700
701 srl(t8, rt, pos + size);
702 // The left chunk from rt that needs to
703 // be saved is on the right side of t8.
704 sll(at, t8, pos + size);
705 // The 'at' register now contains the left chunk on
706 // the left (proper position) and zeroes.
707 sll(t8, rt, 32 - pos);
708 // t8 now contains the right chunk on the left and zeroes.
709 srl(t8, t8, 32 - pos);
710 // t8 now contains the right chunk on
711 // the right (proper position) and zeroes.
712 or_(rt, at, t8);
713 // rt now contains the left and right chunks from the original rt
714 // in their proper position and zeroes in the middle.
715 sll(t8, rs, 32 - size);
716 // t8 now contains the chunk from rs on the left and zeroes.
717 srl(t8, t8, 32 - size - pos);
718 // t8 now contains the original chunk from rs in
719 // the middle (proper position).
720 or_(rt, rt, t8);
721 // rt now contains the result of the ins instruction in R2 mode.
722 }
723 }
724
725
726 void MacroAssembler::Cvt_d_uw(FPURegister fd, FPURegister fs) {
727 // Move the data from fs to t4.
728 mfc1(t4, fs);
729 return Cvt_d_uw(fd, t4);
730 }
731
732
733 void MacroAssembler::Cvt_d_uw(FPURegister fd, Register rs) {
734 // Convert rs to a FP value in fd (and fd + 1).
735 // We do this by converting rs minus the MSB to avoid sign conversion,
736 // then adding 2^31-1 and 1 to the result.
737
738 ASSERT(!fd.is(f20));
739 ASSERT(!rs.is(t9));
740 ASSERT(!rs.is(t8));
741
742 // Save rs's MSB to t8
743 And(t8, rs, 0x80000000);
744 // Remove rs's MSB.
745 And(t9, rs, 0x7FFFFFFF);
746 // Move t9 to fd
747 mtc1(t9, fd);
748
749 // Convert fd to a real FP value.
750 cvt_d_w(fd, fd);
751
752 Label conversion_done;
753
754 // If rs's MSB was 0, it's done.
755 // Otherwise we need to add that to the FP register.
756 Branch(&conversion_done, eq, t8, Operand(zero_reg));
757
758 // First load 2^31 - 1 into f20.
759 Or(t9, zero_reg, 0x7FFFFFFF);
760 mtc1(t9, f20);
761
762 // Convert it to FP and add it to fd.
763 cvt_d_w(f20, f20);
764 add_d(fd, fd, f20);
765 // Now add 1.
766 Or(t9, zero_reg, 1);
767 mtc1(t9, f20);
768
769 cvt_d_w(f20, f20);
770 add_d(fd, fd, f20);
771 bind(&conversion_done);
772 }
773
774
775 void MacroAssembler::Trunc_uw_d(FPURegister fd, FPURegister fs) {
776 Trunc_uw_d(fs, t4);
777 mtc1(t4, fd);
778 }
779
780
781 void MacroAssembler::Trunc_uw_d(FPURegister fd, Register rs) {
782 ASSERT(!fd.is(f22));
783 ASSERT(!rs.is(t6));
784
785 // Load 2^31 into f22.
786 Or(t6, zero_reg, 0x80000000);
787 Cvt_d_uw(f22, t6);
788
789 // Test if f22 > fd.
790 c(OLT, D, fd, f22);
791
792 Label simple_convert;
793 // If fd < 2^31 we can convert it normally.
794 bc1t(&simple_convert);
795
796 // First we subtract 2^31 from fd, then trunc it to rs
797 // and add 2^31 to rs.
798
799 sub_d(f22, fd, f22);
800 trunc_w_d(f22, f22);
801 mfc1(rs, f22);
802 or_(rs, rs, t6);
803
804 Label done;
805 Branch(&done);
806 // Simple conversion.
807 bind(&simple_convert);
808 trunc_w_d(f22, fd);
809 mfc1(rs, f22);
810
811 bind(&done);
812 }
813
814
815 // Tries to get a signed int32 out of a double precision floating point heap
816 // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the
817 // 32bits signed integer range.
818 // This method implementation differs from the ARM version for performance
819 // reasons.
820 void MacroAssembler::ConvertToInt32(Register source,
821 Register dest,
822 Register scratch,
823 Register scratch2,
824 FPURegister double_scratch,
825 Label *not_int32) {
826 Label right_exponent, done;
827 // Get exponent word (ENDIAN issues).
828 lw(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset));
829 // Get exponent alone in scratch2.
830 And(scratch2, scratch, Operand(HeapNumber::kExponentMask));
831 // Load dest with zero. We use this either for the final shift or
832 // for the answer.
833 mov(dest, zero_reg);
834 // Check whether the exponent matches a 32 bit signed int that is not a Smi.
835 // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is
836 // the exponent that we are fastest at and also the highest exponent we can
837 // handle here.
838 const uint32_t non_smi_exponent =
839 (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift;
840 // If we have a match of the int32-but-not-Smi exponent then skip some logic.
841 Branch(&right_exponent, eq, scratch2, Operand(non_smi_exponent));
842 // If the exponent is higher than that then go to not_int32 case. This
843 // catches numbers that don't fit in a signed int32, infinities and NaNs.
844 Branch(not_int32, gt, scratch2, Operand(non_smi_exponent));
845
846 // We know the exponent is smaller than 30 (biased). If it is less than
847 // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie
848 // it rounds to zero.
849 const uint32_t zero_exponent =
850 (HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift;
851 Subu(scratch2, scratch2, Operand(zero_exponent));
852 // Dest already has a Smi zero.
853 Branch(&done, lt, scratch2, Operand(zero_reg));
854 if (!CpuFeatures::IsSupported(FPU)) {
855 // We have a shifted exponent between 0 and 30 in scratch2.
856 srl(dest, scratch2, HeapNumber::kExponentShift);
857 // We now have the exponent in dest. Subtract from 30 to get
858 // how much to shift down.
859 li(at, Operand(30));
860 subu(dest, at, dest);
861 }
862 bind(&right_exponent);
863 if (CpuFeatures::IsSupported(FPU)) {
864 CpuFeatures::Scope scope(FPU);
865 // MIPS FPU instructions implementing double precision to integer
866 // conversion using round to zero. Since the FP value was qualified
867 // above, the resulting integer should be a legal int32.
868 // The original 'Exponent' word is still in scratch.
869 lwc1(double_scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset));
870 mtc1(scratch, FPURegister::from_code(double_scratch.code() + 1));
871 trunc_w_d(double_scratch, double_scratch);
872 mfc1(dest, double_scratch);
873 } else {
874 // On entry, dest has final downshift, scratch has original sign/exp/mant.
875 // Save sign bit in top bit of dest.
876 And(scratch2, scratch, Operand(0x80000000));
877 Or(dest, dest, Operand(scratch2));
878 // Put back the implicit 1, just above mantissa field.
879 Or(scratch, scratch, Operand(1 << HeapNumber::kExponentShift));
880
881 // Shift up the mantissa bits to take up the space the exponent used to
882 // take. We just orred in the implicit bit so that took care of one and
883 // we want to leave the sign bit 0 so we subtract 2 bits from the shift
884 // distance. But we want to clear the sign-bit so shift one more bit
885 // left, then shift right one bit.
886 const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2;
887 sll(scratch, scratch, shift_distance + 1);
888 srl(scratch, scratch, 1);
889
890 // Get the second half of the double. For some exponents we don't
891 // actually need this because the bits get shifted out again, but
892 // it's probably slower to test than just to do it.
893 lw(scratch2, FieldMemOperand(source, HeapNumber::kMantissaOffset));
894 // Extract the top 10 bits, and insert those bottom 10 bits of scratch.
895 // The width of the field here is the same as the shift amount above.
896 const int field_width = shift_distance;
897 Ext(scratch2, scratch2, 32-shift_distance, field_width);
898 Ins(scratch, scratch2, 0, field_width);
899 // Move down according to the exponent.
900 srlv(scratch, scratch, dest);
901 // Prepare the negative version of our integer.
902 subu(scratch2, zero_reg, scratch);
903 // Trick to check sign bit (msb) held in dest, count leading zero.
904 // 0 indicates negative, save negative version with conditional move.
905 clz(dest, dest);
906 movz(scratch, scratch2, dest);
907 mov(dest, scratch);
908 }
909 bind(&done);
910 }
911
912
420 // Emulated condtional branches do not emit a nop in the branch delay slot. 913 // Emulated condtional branches do not emit a nop in the branch delay slot.
421 914 //
422 // Trashes the at register if no scratch register is provided. 915 // BRANCH_ARGS_CHECK checks that conditional jump arguments are correct.
423 void MacroAssembler::Branch(Condition cond, int16_t offset, Register rs, 916 #define BRANCH_ARGS_CHECK(cond, rs, rt) ASSERT( \
424 const Operand& rt, Register scratch) { 917 (cond == cc_always && rs.is(zero_reg) && rt.rm().is(zero_reg)) || \
918 (cond != cc_always && (!rs.is(zero_reg) || !rt.rm().is(zero_reg))))
919
920
921 void MacroAssembler::Branch(int16_t offset,
922 bool ProtectBranchDelaySlot) {
923 b(offset);
924
925 // Emit a nop in the branch delay slot if required.
926 if (ProtectBranchDelaySlot)
927 nop();
928 }
929
930
931 void MacroAssembler::Branch(int16_t offset, Condition cond, Register rs,
932 const Operand& rt,
933 bool ProtectBranchDelaySlot) {
934 BRANCH_ARGS_CHECK(cond, rs, rt);
935 ASSERT(!rs.is(zero_reg));
425 Register r2 = no_reg; 936 Register r2 = no_reg;
937 Register scratch = at;
938
426 if (rt.is_reg()) { 939 if (rt.is_reg()) {
427 // We don't want any other register but scratch clobbered. 940 // We don't want any other register but scratch clobbered.
428 ASSERT(!scratch.is(rs) && !scratch.is(rt.rm_)); 941 ASSERT(!scratch.is(rs) && !scratch.is(rt.rm_));
429 r2 = rt.rm_; 942 r2 = rt.rm_;
430 } else if (cond != cc_always) { 943 switch (cond) {
431 // We don't want any other register but scratch clobbered. 944 case cc_always:
432 ASSERT(!scratch.is(rs)); 945 b(offset);
433 r2 = scratch; 946 break;
434 li(r2, rt); 947 case eq:
948 beq(rs, r2, offset);
949 break;
950 case ne:
951 bne(rs, r2, offset);
952 break;
953 // Signed comparison
954 case greater:
955 if (r2.is(zero_reg)) {
956 bgtz(rs, offset);
957 } else {
958 slt(scratch, r2, rs);
959 bne(scratch, zero_reg, offset);
960 }
961 break;
962 case greater_equal:
963 if (r2.is(zero_reg)) {
964 bgez(rs, offset);
965 } else {
966 slt(scratch, rs, r2);
967 beq(scratch, zero_reg, offset);
968 }
969 break;
970 case less:
971 if (r2.is(zero_reg)) {
972 bltz(rs, offset);
973 } else {
974 slt(scratch, rs, r2);
975 bne(scratch, zero_reg, offset);
976 }
977 break;
978 case less_equal:
979 if (r2.is(zero_reg)) {
980 blez(rs, offset);
981 } else {
982 slt(scratch, r2, rs);
983 beq(scratch, zero_reg, offset);
984 }
985 break;
986 // Unsigned comparison.
987 case Ugreater:
988 if (r2.is(zero_reg)) {
989 bgtz(rs, offset);
990 } else {
991 sltu(scratch, r2, rs);
992 bne(scratch, zero_reg, offset);
993 }
994 break;
995 case Ugreater_equal:
996 if (r2.is(zero_reg)) {
997 bgez(rs, offset);
998 } else {
999 sltu(scratch, rs, r2);
1000 beq(scratch, zero_reg, offset);
1001 }
1002 break;
1003 case Uless:
1004 if (r2.is(zero_reg)) {
1005 b(offset);
1006 } else {
1007 sltu(scratch, rs, r2);
1008 bne(scratch, zero_reg, offset);
1009 }
1010 break;
1011 case Uless_equal:
1012 if (r2.is(zero_reg)) {
1013 b(offset);
1014 } else {
1015 sltu(scratch, r2, rs);
1016 beq(scratch, zero_reg, offset);
1017 }
1018 break;
1019 default:
1020 UNREACHABLE();
1021 }
1022 } else {
1023 // Be careful to always use shifted_branch_offset only just before the
1024 // branch instruction, as the location will be remember for patching the
1025 // target.
1026 switch (cond) {
1027 case cc_always:
1028 b(offset);
1029 break;
1030 case eq:
1031 // We don't want any other register but scratch clobbered.
1032 ASSERT(!scratch.is(rs));
1033 r2 = scratch;
1034 li(r2, rt);
1035 beq(rs, r2, offset);
1036 break;
1037 case ne:
1038 // We don't want any other register but scratch clobbered.
1039 ASSERT(!scratch.is(rs));
1040 r2 = scratch;
1041 li(r2, rt);
1042 bne(rs, r2, offset);
1043 break;
1044 // Signed comparison
1045 case greater:
1046 if (rt.imm32_ == 0) {
1047 bgtz(rs, offset);
1048 } else {
1049 r2 = scratch;
1050 li(r2, rt);
1051 slt(scratch, r2, rs);
1052 bne(scratch, zero_reg, offset);
1053 }
1054 break;
1055 case greater_equal:
1056 if (rt.imm32_ == 0) {
1057 bgez(rs, offset);
1058 } else if (is_int16(rt.imm32_)) {
1059 slti(scratch, rs, rt.imm32_);
1060 beq(scratch, zero_reg, offset);
1061 } else {
1062 r2 = scratch;
1063 li(r2, rt);
1064 sltu(scratch, rs, r2);
1065 beq(scratch, zero_reg, offset);
1066 }
1067 break;
1068 case less:
1069 if (rt.imm32_ == 0) {
1070 bltz(rs, offset);
1071 } else if (is_int16(rt.imm32_)) {
1072 slti(scratch, rs, rt.imm32_);
1073 bne(scratch, zero_reg, offset);
1074 } else {
1075 r2 = scratch;
1076 li(r2, rt);
1077 slt(scratch, rs, r2);
1078 bne(scratch, zero_reg, offset);
1079 }
1080 break;
1081 case less_equal:
1082 if (rt.imm32_ == 0) {
1083 blez(rs, offset);
1084 } else {
1085 r2 = scratch;
1086 li(r2, rt);
1087 slt(scratch, r2, rs);
1088 beq(scratch, zero_reg, offset);
1089 }
1090 break;
1091 // Unsigned comparison.
1092 case Ugreater:
1093 if (rt.imm32_ == 0) {
1094 bgtz(rs, offset);
1095 } else {
1096 r2 = scratch;
1097 li(r2, rt);
1098 sltu(scratch, r2, rs);
1099 bne(scratch, zero_reg, offset);
1100 }
1101 break;
1102 case Ugreater_equal:
1103 if (rt.imm32_ == 0) {
1104 bgez(rs, offset);
1105 } else if (is_int16(rt.imm32_)) {
1106 sltiu(scratch, rs, rt.imm32_);
1107 beq(scratch, zero_reg, offset);
1108 } else {
1109 r2 = scratch;
1110 li(r2, rt);
1111 sltu(scratch, rs, r2);
1112 beq(scratch, zero_reg, offset);
1113 }
1114 break;
1115 case Uless:
1116 if (rt.imm32_ == 0) {
1117 b(offset);
1118 } else if (is_int16(rt.imm32_)) {
1119 sltiu(scratch, rs, rt.imm32_);
1120 bne(scratch, zero_reg, offset);
1121 } else {
1122 r2 = scratch;
1123 li(r2, rt);
1124 sltu(scratch, rs, r2);
1125 bne(scratch, zero_reg, offset);
1126 }
1127 break;
1128 case Uless_equal:
1129 if (rt.imm32_ == 0) {
1130 b(offset);
1131 } else {
1132 r2 = scratch;
1133 li(r2, rt);
1134 sltu(scratch, r2, rs);
1135 beq(scratch, zero_reg, offset);
1136 }
1137 break;
1138 default:
1139 UNREACHABLE();
1140 }
435 } 1141 }
436 1142 // Emit a nop in the branch delay slot if required.
437 switch (cond) { 1143 if (ProtectBranchDelaySlot)
438 case cc_always: 1144 nop();
439 b(offset); 1145 }
440 break; 1146
441 case eq: 1147
442 beq(rs, r2, offset); 1148 void MacroAssembler::Branch(Label* L,
443 break; 1149 bool ProtectBranchDelaySlot) {
444 case ne: 1150 // We use branch_offset as an argument for the branch instructions to be sure
445 bne(rs, r2, offset); 1151 // it is called just before generating the branch instruction, as needed.
446 break; 1152
447 1153 b(shifted_branch_offset(L, false));
1154
1155 // Emit a nop in the branch delay slot if required.
1156 if (ProtectBranchDelaySlot)
1157 nop();
1158 }
1159
1160
1161 void MacroAssembler::Branch(Label* L, Condition cond, Register rs,
1162 const Operand& rt,
1163 bool ProtectBranchDelaySlot) {
1164 BRANCH_ARGS_CHECK(cond, rs, rt);
1165
1166 int32_t offset;
1167 Register r2 = no_reg;
1168 Register scratch = at;
1169 if (rt.is_reg()) {
1170 r2 = rt.rm_;
1171 // Be careful to always use shifted_branch_offset only just before the
1172 // branch instruction, as the location will be remember for patching the
1173 // target.
1174 switch (cond) {
1175 case cc_always:
1176 offset = shifted_branch_offset(L, false);
1177 b(offset);
1178 break;
1179 case eq:
1180 offset = shifted_branch_offset(L, false);
1181 beq(rs, r2, offset);
1182 break;
1183 case ne:
1184 offset = shifted_branch_offset(L, false);
1185 bne(rs, r2, offset);
1186 break;
448 // Signed comparison 1187 // Signed comparison
449 case greater: 1188 case greater:
450 slt(scratch, r2, rs); 1189 if (r2.is(zero_reg)) {
451 bne(scratch, zero_reg, offset); 1190 offset = shifted_branch_offset(L, false);
452 break; 1191 bgtz(rs, offset);
453 case greater_equal: 1192 } else {
454 slt(scratch, rs, r2); 1193 slt(scratch, r2, rs);
455 beq(scratch, zero_reg, offset); 1194 offset = shifted_branch_offset(L, false);
456 break; 1195 bne(scratch, zero_reg, offset);
457 case less: 1196 }
458 slt(scratch, rs, r2); 1197 break;
459 bne(scratch, zero_reg, offset); 1198 case greater_equal:
460 break; 1199 if (r2.is(zero_reg)) {
461 case less_equal: 1200 offset = shifted_branch_offset(L, false);
462 slt(scratch, r2, rs); 1201 bgez(rs, offset);
463 beq(scratch, zero_reg, offset); 1202 } else {
464 break; 1203 slt(scratch, rs, r2);
465 1204 offset = shifted_branch_offset(L, false);
1205 beq(scratch, zero_reg, offset);
1206 }
1207 break;
1208 case less:
1209 if (r2.is(zero_reg)) {
1210 offset = shifted_branch_offset(L, false);
1211 bltz(rs, offset);
1212 } else {
1213 slt(scratch, rs, r2);
1214 offset = shifted_branch_offset(L, false);
1215 bne(scratch, zero_reg, offset);
1216 }
1217 break;
1218 case less_equal:
1219 if (r2.is(zero_reg)) {
1220 offset = shifted_branch_offset(L, false);
1221 blez(rs, offset);
1222 } else {
1223 slt(scratch, r2, rs);
1224 offset = shifted_branch_offset(L, false);
1225 beq(scratch, zero_reg, offset);
1226 }
1227 break;
466 // Unsigned comparison. 1228 // Unsigned comparison.
467 case Ugreater: 1229 case Ugreater:
468 sltu(scratch, r2, rs); 1230 if (r2.is(zero_reg)) {
469 bne(scratch, zero_reg, offset); 1231 offset = shifted_branch_offset(L, false);
470 break; 1232 bgtz(rs, offset);
471 case Ugreater_equal: 1233 } else {
472 sltu(scratch, rs, r2); 1234 sltu(scratch, r2, rs);
473 beq(scratch, zero_reg, offset); 1235 offset = shifted_branch_offset(L, false);
474 break; 1236 bne(scratch, zero_reg, offset);
475 case Uless: 1237 }
476 sltu(scratch, rs, r2); 1238 break;
477 bne(scratch, zero_reg, offset); 1239 case Ugreater_equal:
478 break; 1240 if (r2.is(zero_reg)) {
479 case Uless_equal: 1241 offset = shifted_branch_offset(L, false);
480 sltu(scratch, r2, rs); 1242 bgez(rs, offset);
481 beq(scratch, zero_reg, offset); 1243 } else {
482 break; 1244 sltu(scratch, rs, r2);
483 1245 offset = shifted_branch_offset(L, false);
484 default: 1246 beq(scratch, zero_reg, offset);
485 UNREACHABLE(); 1247 }
1248 break;
1249 case Uless:
1250 if (r2.is(zero_reg)) {
1251 offset = shifted_branch_offset(L, false);
1252 b(offset);
1253 } else {
1254 sltu(scratch, rs, r2);
1255 offset = shifted_branch_offset(L, false);
1256 bne(scratch, zero_reg, offset);
1257 }
1258 break;
1259 case Uless_equal:
1260 if (r2.is(zero_reg)) {
1261 offset = shifted_branch_offset(L, false);
1262 b(offset);
1263 } else {
1264 sltu(scratch, r2, rs);
1265 offset = shifted_branch_offset(L, false);
1266 beq(scratch, zero_reg, offset);
1267 }
1268 break;
1269 default:
1270 UNREACHABLE();
1271 }
1272 } else {
1273 // Be careful to always use shifted_branch_offset only just before the
1274 // branch instruction, as the location will be remember for patching the
1275 // target.
1276 switch (cond) {
1277 case cc_always:
1278 offset = shifted_branch_offset(L, false);
1279 b(offset);
1280 break;
1281 case eq:
1282 r2 = scratch;
1283 li(r2, rt);
1284 offset = shifted_branch_offset(L, false);
1285 beq(rs, r2, offset);
1286 break;
1287 case ne:
1288 r2 = scratch;
1289 li(r2, rt);
1290 offset = shifted_branch_offset(L, false);
1291 bne(rs, r2, offset);
1292 break;
1293 // Signed comparison
1294 case greater:
1295 if (rt.imm32_ == 0) {
1296 offset = shifted_branch_offset(L, false);
1297 bgtz(rs, offset);
1298 } else {
1299 r2 = scratch;
1300 li(r2, rt);
1301 slt(scratch, r2, rs);
1302 offset = shifted_branch_offset(L, false);
1303 bne(scratch, zero_reg, offset);
1304 }
1305 break;
1306 case greater_equal:
1307 if (rt.imm32_ == 0) {
1308 offset = shifted_branch_offset(L, false);
1309 bgez(rs, offset);
1310 } else if (is_int16(rt.imm32_)) {
1311 slti(scratch, rs, rt.imm32_);
1312 offset = shifted_branch_offset(L, false);
1313 beq(scratch, zero_reg, offset);
1314 } else {
1315 r2 = scratch;
1316 li(r2, rt);
1317 sltu(scratch, rs, r2);
1318 offset = shifted_branch_offset(L, false);
1319 beq(scratch, zero_reg, offset);
1320 }
1321 break;
1322 case less:
1323 if (rt.imm32_ == 0) {
1324 offset = shifted_branch_offset(L, false);
1325 bltz(rs, offset);
1326 } else if (is_int16(rt.imm32_)) {
1327 slti(scratch, rs, rt.imm32_);
1328 offset = shifted_branch_offset(L, false);
1329 bne(scratch, zero_reg, offset);
1330 } else {
1331 r2 = scratch;
1332 li(r2, rt);
1333 slt(scratch, rs, r2);
1334 offset = shifted_branch_offset(L, false);
1335 bne(scratch, zero_reg, offset);
1336 }
1337 break;
1338 case less_equal:
1339 if (rt.imm32_ == 0) {
1340 offset = shifted_branch_offset(L, false);
1341 blez(rs, offset);
1342 } else {
1343 r2 = scratch;
1344 li(r2, rt);
1345 slt(scratch, r2, rs);
1346 offset = shifted_branch_offset(L, false);
1347 beq(scratch, zero_reg, offset);
1348 }
1349 break;
1350 // Unsigned comparison.
1351 case Ugreater:
1352 if (rt.imm32_ == 0) {
1353 offset = shifted_branch_offset(L, false);
1354 bgtz(rs, offset);
1355 } else {
1356 r2 = scratch;
1357 li(r2, rt);
1358 sltu(scratch, r2, rs);
1359 offset = shifted_branch_offset(L, false);
1360 bne(scratch, zero_reg, offset);
1361 }
1362 break;
1363 case Ugreater_equal:
1364 if (rt.imm32_ == 0) {
1365 offset = shifted_branch_offset(L, false);
1366 bgez(rs, offset);
1367 } else if (is_int16(rt.imm32_)) {
1368 sltiu(scratch, rs, rt.imm32_);
1369 offset = shifted_branch_offset(L, false);
1370 beq(scratch, zero_reg, offset);
1371 } else {
1372 r2 = scratch;
1373 li(r2, rt);
1374 sltu(scratch, rs, r2);
1375 offset = shifted_branch_offset(L, false);
1376 beq(scratch, zero_reg, offset);
1377 }
1378 break;
1379 case Uless:
1380 if (rt.imm32_ == 0) {
1381 offset = shifted_branch_offset(L, false);
1382 b(offset);
1383 } else if (is_int16(rt.imm32_)) {
1384 sltiu(scratch, rs, rt.imm32_);
1385 offset = shifted_branch_offset(L, false);
1386 bne(scratch, zero_reg, offset);
1387 } else {
1388 r2 = scratch;
1389 li(r2, rt);
1390 sltu(scratch, rs, r2);
1391 offset = shifted_branch_offset(L, false);
1392 bne(scratch, zero_reg, offset);
1393 }
1394 break;
1395 case Uless_equal:
1396 if (rt.imm32_ == 0) {
1397 offset = shifted_branch_offset(L, false);
1398 b(offset);
1399 } else {
1400 r2 = scratch;
1401 li(r2, rt);
1402 sltu(scratch, r2, rs);
1403 offset = shifted_branch_offset(L, false);
1404 beq(scratch, zero_reg, offset);
1405 }
1406 break;
1407 default:
1408 UNREACHABLE();
1409 }
486 } 1410 }
487 // Emit a nop in the branch delay slot. 1411 // Check that offset could actually hold on an int16_t.
488 nop(); 1412 ASSERT(is_int16(offset));
489 } 1413 // Emit a nop in the branch delay slot if required.
490 1414 if (ProtectBranchDelaySlot)
491 1415 nop();
492 void MacroAssembler::Branch(Condition cond, Label* L, Register rs, 1416 }
493 const Operand& rt, Register scratch) { 1417
1418
1419 // We need to use a bgezal or bltzal, but they can't be used directly with the
1420 // slt instructions. We could use sub or add instead but we would miss overflow
1421 // cases, so we keep slt and add an intermediate third instruction.
1422 void MacroAssembler::BranchAndLink(int16_t offset,
1423 bool ProtectBranchDelaySlot) {
1424 bal(offset);
1425
1426 // Emit a nop in the branch delay slot if required.
1427 if (ProtectBranchDelaySlot)
1428 nop();
1429 }
1430
1431
1432 void MacroAssembler::BranchAndLink(int16_t offset, Condition cond, Register rs,
1433 const Operand& rt,
1434 bool ProtectBranchDelaySlot) {
1435 BRANCH_ARGS_CHECK(cond, rs, rt);
494 Register r2 = no_reg; 1436 Register r2 = no_reg;
1437 Register scratch = at;
1438
495 if (rt.is_reg()) { 1439 if (rt.is_reg()) {
496 r2 = rt.rm_; 1440 r2 = rt.rm_;
497 } else if (cond != cc_always) { 1441 } else if (cond != cc_always) {
498 r2 = scratch; 1442 r2 = scratch;
499 li(r2, rt); 1443 li(r2, rt);
500 } 1444 }
501 1445
502 // We use branch_offset as an argument for the branch instructions to be sure
503 // it is called just before generating the branch instruction, as needed.
504
505 switch (cond) { 1446 switch (cond) {
506 case cc_always: 1447 case cc_always:
507 b(shifted_branch_offset(L, false)); 1448 bal(offset);
508 break; 1449 break;
509 case eq: 1450 case eq:
510 beq(rs, r2, shifted_branch_offset(L, false)); 1451 bne(rs, r2, 2);
1452 nop();
1453 bal(offset);
511 break; 1454 break;
512 case ne: 1455 case ne:
513 bne(rs, r2, shifted_branch_offset(L, false)); 1456 beq(rs, r2, 2);
1457 nop();
1458 bal(offset);
514 break; 1459 break;
515 1460
516 // Signed comparison 1461 // Signed comparison
517 case greater: 1462 case greater:
518 slt(scratch, r2, rs); 1463 slt(scratch, r2, rs);
519 bne(scratch, zero_reg, shifted_branch_offset(L, false)); 1464 addiu(scratch, scratch, -1);
1465 bgezal(scratch, offset);
520 break; 1466 break;
521 case greater_equal: 1467 case greater_equal:
522 slt(scratch, rs, r2); 1468 slt(scratch, rs, r2);
523 beq(scratch, zero_reg, shifted_branch_offset(L, false)); 1469 addiu(scratch, scratch, -1);
1470 bltzal(scratch, offset);
524 break; 1471 break;
525 case less: 1472 case less:
526 slt(scratch, rs, r2); 1473 slt(scratch, rs, r2);
527 bne(scratch, zero_reg, shifted_branch_offset(L, false)); 1474 addiu(scratch, scratch, -1);
1475 bgezal(scratch, offset);
528 break; 1476 break;
529 case less_equal: 1477 case less_equal:
530 slt(scratch, r2, rs); 1478 slt(scratch, r2, rs);
531 beq(scratch, zero_reg, shifted_branch_offset(L, false)); 1479 addiu(scratch, scratch, -1);
1480 bltzal(scratch, offset);
532 break; 1481 break;
533 1482
534 // Unsigned comparison. 1483 // Unsigned comparison.
535 case Ugreater: 1484 case Ugreater:
536 sltu(scratch, r2, rs); 1485 sltu(scratch, r2, rs);
537 bne(scratch, zero_reg, shifted_branch_offset(L, false)); 1486 addiu(scratch, scratch, -1);
1487 bgezal(scratch, offset);
538 break; 1488 break;
539 case Ugreater_equal: 1489 case Ugreater_equal:
540 sltu(scratch, rs, r2); 1490 sltu(scratch, rs, r2);
541 beq(scratch, zero_reg, shifted_branch_offset(L, false)); 1491 addiu(scratch, scratch, -1);
1492 bltzal(scratch, offset);
542 break; 1493 break;
543 case Uless: 1494 case Uless:
544 sltu(scratch, rs, r2); 1495 sltu(scratch, rs, r2);
545 bne(scratch, zero_reg, shifted_branch_offset(L, false)); 1496 addiu(scratch, scratch, -1);
1497 bgezal(scratch, offset);
546 break; 1498 break;
547 case Uless_equal: 1499 case Uless_equal:
548 sltu(scratch, r2, rs); 1500 sltu(scratch, r2, rs);
549 beq(scratch, zero_reg, shifted_branch_offset(L, false)); 1501 addiu(scratch, scratch, -1);
1502 bltzal(scratch, offset);
550 break; 1503 break;
551 1504
552 default: 1505 default:
553 UNREACHABLE(); 1506 UNREACHABLE();
554 } 1507 }
555 // Emit a nop in the branch delay slot. 1508 // Emit a nop in the branch delay slot if required.
556 nop(); 1509 if (ProtectBranchDelaySlot)
1510 nop();
557 } 1511 }
558 1512
559 1513
560 // Trashes the at register if no scratch register is provided. 1514 void MacroAssembler::BranchAndLink(Label* L,
561 // We need to use a bgezal or bltzal, but they can't be used directly with the 1515 bool ProtectBranchDelaySlot) {
562 // slt instructions. We could use sub or add instead but we would miss overflow 1516 bal(shifted_branch_offset(L, false));
563 // cases, so we keep slt and add an intermediate third instruction. 1517
564 void MacroAssembler::BranchAndLink(Condition cond, int16_t offset, Register rs, 1518 // Emit a nop in the branch delay slot if required.
565 const Operand& rt, Register scratch) { 1519 if (ProtectBranchDelaySlot)
1520 nop();
1521 }
1522
1523
1524 void MacroAssembler::BranchAndLink(Label* L, Condition cond, Register rs,
1525 const Operand& rt,
1526 bool ProtectBranchDelaySlot) {
1527 BRANCH_ARGS_CHECK(cond, rs, rt);
1528
1529 int32_t offset;
566 Register r2 = no_reg; 1530 Register r2 = no_reg;
1531 Register scratch = at;
567 if (rt.is_reg()) { 1532 if (rt.is_reg()) {
568 r2 = rt.rm_; 1533 r2 = rt.rm_;
569 } else if (cond != cc_always) { 1534 } else if (cond != cc_always) {
570 r2 = scratch; 1535 r2 = scratch;
571 li(r2, rt); 1536 li(r2, rt);
572 } 1537 }
573 1538
574 switch (cond) { 1539 switch (cond) {
575 case cc_always: 1540 case cc_always:
1541 offset = shifted_branch_offset(L, false);
576 bal(offset); 1542 bal(offset);
577 break; 1543 break;
578 case eq: 1544 case eq:
579 bne(rs, r2, 2); 1545 bne(rs, r2, 2);
580 nop(); 1546 nop();
1547 offset = shifted_branch_offset(L, false);
581 bal(offset); 1548 bal(offset);
582 break; 1549 break;
583 case ne: 1550 case ne:
584 beq(rs, r2, 2); 1551 beq(rs, r2, 2);
585 nop(); 1552 nop();
1553 offset = shifted_branch_offset(L, false);
586 bal(offset); 1554 bal(offset);
587 break; 1555 break;
588 1556
589 // Signed comparison 1557 // Signed comparison
590 case greater: 1558 case greater:
591 slt(scratch, r2, rs); 1559 slt(scratch, r2, rs);
592 addiu(scratch, scratch, -1); 1560 addiu(scratch, scratch, -1);
1561 offset = shifted_branch_offset(L, false);
593 bgezal(scratch, offset); 1562 bgezal(scratch, offset);
594 break; 1563 break;
595 case greater_equal: 1564 case greater_equal:
596 slt(scratch, rs, r2); 1565 slt(scratch, rs, r2);
597 addiu(scratch, scratch, -1); 1566 addiu(scratch, scratch, -1);
1567 offset = shifted_branch_offset(L, false);
598 bltzal(scratch, offset); 1568 bltzal(scratch, offset);
599 break; 1569 break;
600 case less: 1570 case less:
601 slt(scratch, rs, r2); 1571 slt(scratch, rs, r2);
602 addiu(scratch, scratch, -1); 1572 addiu(scratch, scratch, -1);
1573 offset = shifted_branch_offset(L, false);
603 bgezal(scratch, offset); 1574 bgezal(scratch, offset);
604 break; 1575 break;
605 case less_equal: 1576 case less_equal:
606 slt(scratch, r2, rs); 1577 slt(scratch, r2, rs);
607 addiu(scratch, scratch, -1); 1578 addiu(scratch, scratch, -1);
1579 offset = shifted_branch_offset(L, false);
608 bltzal(scratch, offset); 1580 bltzal(scratch, offset);
609 break; 1581 break;
610 1582
611 // Unsigned comparison. 1583 // Unsigned comparison.
612 case Ugreater: 1584 case Ugreater:
613 sltu(scratch, r2, rs); 1585 sltu(scratch, r2, rs);
614 addiu(scratch, scratch, -1); 1586 addiu(scratch, scratch, -1);
1587 offset = shifted_branch_offset(L, false);
615 bgezal(scratch, offset); 1588 bgezal(scratch, offset);
616 break; 1589 break;
617 case Ugreater_equal: 1590 case Ugreater_equal:
618 sltu(scratch, rs, r2); 1591 sltu(scratch, rs, r2);
619 addiu(scratch, scratch, -1); 1592 addiu(scratch, scratch, -1);
1593 offset = shifted_branch_offset(L, false);
620 bltzal(scratch, offset); 1594 bltzal(scratch, offset);
621 break; 1595 break;
622 case Uless: 1596 case Uless:
623 sltu(scratch, rs, r2); 1597 sltu(scratch, rs, r2);
624 addiu(scratch, scratch, -1); 1598 addiu(scratch, scratch, -1);
1599 offset = shifted_branch_offset(L, false);
625 bgezal(scratch, offset); 1600 bgezal(scratch, offset);
626 break; 1601 break;
627 case Uless_equal: 1602 case Uless_equal:
628 sltu(scratch, r2, rs); 1603 sltu(scratch, r2, rs);
629 addiu(scratch, scratch, -1); 1604 addiu(scratch, scratch, -1);
1605 offset = shifted_branch_offset(L, false);
630 bltzal(scratch, offset); 1606 bltzal(scratch, offset);
631 break; 1607 break;
632 1608
633 default: 1609 default:
634 UNREACHABLE(); 1610 UNREACHABLE();
635 } 1611 }
636 // Emit a nop in the branch delay slot. 1612
637 nop(); 1613 // Check that offset could actually hold on an int16_t.
638 } 1614 ASSERT(is_int16(offset));
639 1615
640 1616 // Emit a nop in the branch delay slot if required.
641 void MacroAssembler::BranchAndLink(Condition cond, Label* L, Register rs, 1617 if (ProtectBranchDelaySlot)
642 const Operand& rt, Register scratch) { 1618 nop();
643 Register r2 = no_reg;
644 if (rt.is_reg()) {
645 r2 = rt.rm_;
646 } else if (cond != cc_always) {
647 r2 = scratch;
648 li(r2, rt);
649 }
650
651 switch (cond) {
652 case cc_always:
653 bal(shifted_branch_offset(L, false));
654 break;
655 case eq:
656 bne(rs, r2, 2);
657 nop();
658 bal(shifted_branch_offset(L, false));
659 break;
660 case ne:
661 beq(rs, r2, 2);
662 nop();
663 bal(shifted_branch_offset(L, false));
664 break;
665
666 // Signed comparison
667 case greater:
668 slt(scratch, r2, rs);
669 addiu(scratch, scratch, -1);
670 bgezal(scratch, shifted_branch_offset(L, false));
671 break;
672 case greater_equal:
673 slt(scratch, rs, r2);
674 addiu(scratch, scratch, -1);
675 bltzal(scratch, shifted_branch_offset(L, false));
676 break;
677 case less:
678 slt(scratch, rs, r2);
679 addiu(scratch, scratch, -1);
680 bgezal(scratch, shifted_branch_offset(L, false));
681 break;
682 case less_equal:
683 slt(scratch, r2, rs);
684 addiu(scratch, scratch, -1);
685 bltzal(scratch, shifted_branch_offset(L, false));
686 break;
687
688 // Unsigned comparison.
689 case Ugreater:
690 sltu(scratch, r2, rs);
691 addiu(scratch, scratch, -1);
692 bgezal(scratch, shifted_branch_offset(L, false));
693 break;
694 case Ugreater_equal:
695 sltu(scratch, rs, r2);
696 addiu(scratch, scratch, -1);
697 bltzal(scratch, shifted_branch_offset(L, false));
698 break;
699 case Uless:
700 sltu(scratch, rs, r2);
701 addiu(scratch, scratch, -1);
702 bgezal(scratch, shifted_branch_offset(L, false));
703 break;
704 case Uless_equal:
705 sltu(scratch, r2, rs);
706 addiu(scratch, scratch, -1);
707 bltzal(scratch, shifted_branch_offset(L, false));
708 break;
709
710 default:
711 UNREACHABLE();
712 }
713 // Emit a nop in the branch delay slot.
714 nop();
715 } 1619 }
716 1620
717 1621
718 void MacroAssembler::Jump(const Operand& target, 1622 void MacroAssembler::Jump(const Operand& target,
719 Condition cond, Register rs, const Operand& rt) { 1623 bool ProtectBranchDelaySlot) {
1624 if (target.is_reg()) {
1625 jr(target.rm());
1626 } else { // !target.is_reg()
1627 if (!MustUseReg(target.rmode_)) {
1628 j(target.imm32_);
1629 } else { // MustUseReg(target)
1630 li(t9, target);
1631 jr(t9);
1632 }
1633 }
1634 // Emit a nop in the branch delay slot if required.
1635 if (ProtectBranchDelaySlot)
1636 nop();
1637 }
1638
1639
1640 void MacroAssembler::Jump(const Operand& target,
1641 Condition cond, Register rs, const Operand& rt,
1642 bool ProtectBranchDelaySlot) {
1643 BRANCH_ARGS_CHECK(cond, rs, rt);
720 if (target.is_reg()) { 1644 if (target.is_reg()) {
721 if (cond == cc_always) { 1645 if (cond == cc_always) {
722 jr(target.rm()); 1646 jr(target.rm());
723 } else { 1647 } else {
724 Branch(NegateCondition(cond), 2, rs, rt); 1648 Branch(2, NegateCondition(cond), rs, rt);
725 jr(target.rm()); 1649 jr(target.rm());
726 } 1650 }
727 } else { // !target.is_reg() 1651 } else { // !target.is_reg()
728 if (!MustUseAt(target.rmode_)) { 1652 if (!MustUseReg(target.rmode_)) {
729 if (cond == cc_always) { 1653 if (cond == cc_always) {
730 j(target.imm32_); 1654 j(target.imm32_);
731 } else { 1655 } else {
732 Branch(NegateCondition(cond), 2, rs, rt); 1656 Branch(2, NegateCondition(cond), rs, rt);
733 j(target.imm32_); // Will generate only one instruction. 1657 j(target.imm32_); // Will generate only one instruction.
734 } 1658 }
735 } else { // MustUseAt(target) 1659 } else { // MustUseReg(target)
736 li(at, target); 1660 li(t9, target);
737 if (cond == cc_always) { 1661 if (cond == cc_always) {
738 jr(at); 1662 jr(t9);
739 } else { 1663 } else {
740 Branch(NegateCondition(cond), 2, rs, rt); 1664 Branch(2, NegateCondition(cond), rs, rt);
741 jr(at); // Will generate only one instruction. 1665 jr(t9); // Will generate only one instruction.
742 } 1666 }
743 } 1667 }
744 } 1668 }
745 // Emit a nop in the branch delay slot. 1669 // Emit a nop in the branch delay slot if required.
746 nop(); 1670 if (ProtectBranchDelaySlot)
747 } 1671 nop();
748 1672 }
749 1673
1674
1675 // Note: To call gcc-compiled C code on mips, you must call thru t9.
750 void MacroAssembler::Call(const Operand& target, 1676 void MacroAssembler::Call(const Operand& target,
751 Condition cond, Register rs, const Operand& rt) { 1677 bool ProtectBranchDelaySlot) {
1678 BlockTrampolinePoolScope block_trampoline_pool(this);
1679 if (target.is_reg()) {
1680 jalr(target.rm());
1681 } else { // !target.is_reg()
1682 if (!MustUseReg(target.rmode_)) {
1683 jal(target.imm32_);
1684 } else { // MustUseReg(target)
1685 li(t9, target);
1686 jalr(t9);
1687 }
1688 }
1689 // Emit a nop in the branch delay slot if required.
1690 if (ProtectBranchDelaySlot)
1691 nop();
1692 }
1693
1694
1695 // Note: To call gcc-compiled C code on mips, you must call thru t9.
1696 void MacroAssembler::Call(const Operand& target,
1697 Condition cond, Register rs, const Operand& rt,
1698 bool ProtectBranchDelaySlot) {
1699 BRANCH_ARGS_CHECK(cond, rs, rt);
1700 BlockTrampolinePoolScope block_trampoline_pool(this);
752 if (target.is_reg()) { 1701 if (target.is_reg()) {
753 if (cond == cc_always) { 1702 if (cond == cc_always) {
754 jalr(target.rm()); 1703 jalr(target.rm());
755 } else { 1704 } else {
756 Branch(NegateCondition(cond), 2, rs, rt); 1705 Branch(2, NegateCondition(cond), rs, rt);
757 jalr(target.rm()); 1706 jalr(target.rm());
758 } 1707 }
759 } else { // !target.is_reg() 1708 } else { // !target.is_reg()
760 if (!MustUseAt(target.rmode_)) { 1709 if (!MustUseReg(target.rmode_)) {
761 if (cond == cc_always) { 1710 if (cond == cc_always) {
762 jal(target.imm32_); 1711 jal(target.imm32_);
763 } else { 1712 } else {
764 Branch(NegateCondition(cond), 2, rs, rt); 1713 Branch(2, NegateCondition(cond), rs, rt);
765 jal(target.imm32_); // Will generate only one instruction. 1714 jal(target.imm32_); // Will generate only one instruction.
766 } 1715 }
767 } else { // MustUseAt(target) 1716 } else { // MustUseReg(target)
768 li(at, target); 1717 li(t9, target);
769 if (cond == cc_always) { 1718 if (cond == cc_always) {
770 jalr(at); 1719 jalr(t9);
771 } else { 1720 } else {
772 Branch(NegateCondition(cond), 2, rs, rt); 1721 Branch(2, NegateCondition(cond), rs, rt);
773 jalr(at); // Will generate only one instruction. 1722 jalr(t9); // Will generate only one instruction.
774 } 1723 }
775 } 1724 }
776 } 1725 }
777 // Emit a nop in the branch delay slot. 1726 // Emit a nop in the branch delay slot if required.
778 nop(); 1727 if (ProtectBranchDelaySlot)
779 } 1728 nop();
780 1729 }
781 void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) { 1730
782 UNIMPLEMENTED_MIPS(); 1731
783 } 1732 void MacroAssembler::Drop(int count,
784 1733 Condition cond,
785 1734 Register reg,
786 void MacroAssembler::Drop(int count, Condition cond) { 1735 const Operand& op) {
787 UNIMPLEMENTED_MIPS(); 1736 if (count <= 0) {
1737 return;
1738 }
1739
1740 Label skip;
1741
1742 if (cond != al) {
1743 Branch(&skip, NegateCondition(cond), reg, op);
1744 }
1745
1746 if (count > 0) {
1747 addiu(sp, sp, count * kPointerSize);
1748 }
1749
1750 if (cond != al) {
1751 bind(&skip);
1752 }
1753 }
1754
1755
1756 void MacroAssembler::DropAndRet(int drop,
1757 Condition cond,
1758 Register r1,
1759 const Operand& r2) {
1760 // This is a workaround to make sure only one branch instruction is
1761 // generated. It relies on Drop and Ret not creating branches if
1762 // cond == cc_always.
1763 Label skip;
1764 if (cond != cc_always) {
1765 Branch(&skip, NegateCondition(cond), r1, r2);
1766 }
1767
1768 Drop(drop);
1769 Ret();
1770
1771 if (cond != cc_always) {
1772 bind(&skip);
1773 }
1774 }
1775
1776
1777 void MacroAssembler::Swap(Register reg1,
1778 Register reg2,
1779 Register scratch) {
1780 if (scratch.is(no_reg)) {
1781 Xor(reg1, reg1, Operand(reg2));
1782 Xor(reg2, reg2, Operand(reg1));
1783 Xor(reg1, reg1, Operand(reg2));
1784 } else {
1785 mov(scratch, reg1);
1786 mov(reg1, reg2);
1787 mov(reg2, scratch);
1788 }
788 } 1789 }
789 1790
790 1791
791 void MacroAssembler::Call(Label* target) { 1792 void MacroAssembler::Call(Label* target) {
792 UNIMPLEMENTED_MIPS(); 1793 BranchAndLink(cc_always, target);
1794 }
1795
1796
1797 void MacroAssembler::Move(Register dst, Register src) {
1798 if (!dst.is(src)) {
1799 mov(dst, src);
1800 }
793 } 1801 }
794 1802
795 1803
796 #ifdef ENABLE_DEBUGGER_SUPPORT 1804 #ifdef ENABLE_DEBUGGER_SUPPORT
797 // --------------------------------------------------------------------------- 1805
798 // Debugger Support 1806 void MacroAssembler::DebugBreak() {
799 1807 ASSERT(allow_stub_calls());
800 void MacroAssembler::DebugBreak() { 1808 mov(a0, zero_reg);
801 UNIMPLEMENTED_MIPS(); 1809 li(a1, Operand(ExternalReference(Runtime::kDebugBreak)));
802 } 1810 CEntryStub ces(1);
803 #endif 1811 Call(ces.GetCode(), RelocInfo::DEBUG_BREAK);
1812 }
1813
1814 #endif // ENABLE_DEBUGGER_SUPPORT
804 1815
805 1816
806 // --------------------------------------------------------------------------- 1817 // ---------------------------------------------------------------------------
807 // Exception handling 1818 // Exception handling
808 1819
809 void MacroAssembler::PushTryHandler(CodeLocation try_location, 1820 void MacroAssembler::PushTryHandler(CodeLocation try_location,
810 HandlerType type) { 1821 HandlerType type) {
811 // Adjust this code if not the case. 1822 // Adjust this code if not the case.
812 ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); 1823 ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize);
813 // The return address is passed in register ra. 1824 // The return address is passed in register ra.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 sw(t0, MemOperand(sp, 4)); 1868 sw(t0, MemOperand(sp, 4));
858 sw(t1, MemOperand(sp, 0)); 1869 sw(t1, MemOperand(sp, 0));
859 1870
860 // Link this handler as the new current one. 1871 // Link this handler as the new current one.
861 sw(sp, MemOperand(t2)); 1872 sw(sp, MemOperand(t2));
862 } 1873 }
863 } 1874 }
864 1875
865 1876
866 void MacroAssembler::PopTryHandler() { 1877 void MacroAssembler::PopTryHandler() {
867 UNIMPLEMENTED_MIPS(); 1878 ASSERT_EQ(0, StackHandlerConstants::kNextOffset);
868 } 1879 pop(a1);
869 1880 Addu(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize));
870 1881 li(at, Operand(ExternalReference(Top::k_handler_address)));
871 1882 sw(a1, MemOperand(at));
872 // ----------------------------------------------------------------------------- 1883 }
873 // Activation frames 1884
874 1885
875 void MacroAssembler::SetupAlignedCall(Register scratch, int arg_count) { 1886 void MacroAssembler::AllocateInNewSpace(int object_size,
876 Label extra_push, end; 1887 Register result,
877 1888 Register scratch1,
878 andi(scratch, sp, 7); 1889 Register scratch2,
879 1890 Label* gc_required,
880 // We check for args and receiver size on the stack, all of them word sized. 1891 AllocationFlags flags) {
881 // We add one for sp, that we also want to store on the stack. 1892 if (!FLAG_inline_new) {
882 if (((arg_count + 1) % kPointerSizeLog2) == 0) { 1893 if (FLAG_debug_code) {
883 Branch(ne, &extra_push, at, Operand(zero_reg)); 1894 // Trash the registers to simulate an allocation failure.
884 } else { // ((arg_count + 1) % 2) == 1 1895 li(result, 0x7091);
885 Branch(eq, &extra_push, at, Operand(zero_reg)); 1896 li(scratch1, 0x7191);
886 } 1897 li(scratch2, 0x7291);
887 1898 }
888 // Save sp on the stack. 1899 jmp(gc_required);
889 mov(scratch, sp); 1900 return;
890 Push(scratch); 1901 }
891 b(&end); 1902
892 1903 ASSERT(!result.is(scratch1));
893 // Align before saving sp on the stack. 1904 ASSERT(!result.is(scratch2));
894 bind(&extra_push); 1905 ASSERT(!scratch1.is(scratch2));
895 mov(scratch, sp); 1906 ASSERT(!scratch1.is(t9));
896 addiu(sp, sp, -8); 1907 ASSERT(!scratch2.is(t9));
897 sw(scratch, MemOperand(sp)); 1908 ASSERT(!result.is(t9));
898 1909
899 // The stack is aligned and sp is stored on the top. 1910 // Make object size into bytes.
900 bind(&end); 1911 if ((flags & SIZE_IN_WORDS) != 0) {
901 } 1912 object_size *= kPointerSize;
902 1913 }
903 1914 ASSERT_EQ(0, object_size & kObjectAlignmentMask);
904 void MacroAssembler::ReturnFromAlignedCall() { 1915
905 lw(sp, MemOperand(sp)); 1916 // Check relative positions of allocation top and limit addresses.
906 } 1917 // ARM adds additional checks to make sure the ldm instruction can be
907 1918 // used. On MIPS we don't have ldm so we don't need additional checks either.
908 1919 ExternalReference new_space_allocation_top =
1920 ExternalReference::new_space_allocation_top_address();
1921 ExternalReference new_space_allocation_limit =
1922 ExternalReference::new_space_allocation_limit_address();
1923 intptr_t top =
1924 reinterpret_cast<intptr_t>(new_space_allocation_top.address());
1925 intptr_t limit =
1926 reinterpret_cast<intptr_t>(new_space_allocation_limit.address());
1927 ASSERT((limit - top) == kPointerSize);
1928
1929 // Set up allocation top address and object size registers.
1930 Register topaddr = scratch1;
1931 Register obj_size_reg = scratch2;
1932 li(topaddr, Operand(new_space_allocation_top));
1933 li(obj_size_reg, Operand(object_size));
1934
1935 // This code stores a temporary value in t9.
1936 if ((flags & RESULT_CONTAINS_TOP) == 0) {
1937 // Load allocation top into result and allocation limit into t9.
1938 lw(result, MemOperand(topaddr));
1939 lw(t9, MemOperand(topaddr, kPointerSize));
1940 } else {
1941 if (FLAG_debug_code) {
1942 // Assert that result actually contains top on entry. t9 is used
1943 // immediately below so this use of t9 does not cause difference with
1944 // respect to register content between debug and release mode.
1945 lw(t9, MemOperand(topaddr));
1946 Check(eq, "Unexpected allocation top", result, Operand(t9));
1947 }
1948 // Load allocation limit into t9. Result already contains allocation top.
1949 lw(t9, MemOperand(topaddr, limit - top));
1950 }
1951
1952 // Calculate new top and bail out if new space is exhausted. Use result
1953 // to calculate the new top.
1954 Addu(scratch2, result, Operand(obj_size_reg));
1955 Branch(gc_required, Ugreater, scratch2, Operand(t9));
1956 sw(scratch2, MemOperand(topaddr));
1957
1958 // Tag object if requested.
1959 if ((flags & TAG_OBJECT) != 0) {
1960 Addu(result, result, Operand(kHeapObjectTag));
1961 }
1962 }
1963
1964
1965 void MacroAssembler::AllocateInNewSpace(Register object_size,
1966 Register result,
1967 Register scratch1,
1968 Register scratch2,
1969 Label* gc_required,
1970 AllocationFlags flags) {
1971 if (!FLAG_inline_new) {
1972 if (FLAG_debug_code) {
1973 // Trash the registers to simulate an allocation failure.
1974 li(result, 0x7091);
1975 li(scratch1, 0x7191);
1976 li(scratch2, 0x7291);
1977 }
1978 jmp(gc_required);
1979 return;
1980 }
1981
1982 ASSERT(!result.is(scratch1));
1983 ASSERT(!result.is(scratch2));
1984 ASSERT(!scratch1.is(scratch2));
1985 ASSERT(!scratch1.is(t9) && !scratch2.is(t9) && !result.is(t9));
1986
1987 // Check relative positions of allocation top and limit addresses.
1988 // ARM adds additional checks to make sure the ldm instruction can be
1989 // used. On MIPS we don't have ldm so we don't need additional checks either.
1990 ExternalReference new_space_allocation_top =
1991 ExternalReference::new_space_allocation_top_address();
1992 ExternalReference new_space_allocation_limit =
1993 ExternalReference::new_space_allocation_limit_address();
1994 intptr_t top =
1995 reinterpret_cast<intptr_t>(new_space_allocation_top.address());
1996 intptr_t limit =
1997 reinterpret_cast<intptr_t>(new_space_allocation_limit.address());
1998 ASSERT((limit - top) == kPointerSize);
1999
2000 // Set up allocation top address and object size registers.
2001 Register topaddr = scratch1;
2002 li(topaddr, Operand(new_space_allocation_top));
2003
2004 // This code stores a temporary value in t9.
2005 if ((flags & RESULT_CONTAINS_TOP) == 0) {
2006 // Load allocation top into result and allocation limit into t9.
2007 lw(result, MemOperand(topaddr));
2008 lw(t9, MemOperand(topaddr, kPointerSize));
2009 } else {
2010 if (FLAG_debug_code) {
2011 // Assert that result actually contains top on entry. t9 is used
2012 // immediately below so this use of t9 does not cause difference with
2013 // respect to register content between debug and release mode.
2014 lw(t9, MemOperand(topaddr));
2015 Check(eq, "Unexpected allocation top", result, Operand(t9));
2016 }
2017 // Load allocation limit into t9. Result already contains allocation top.
2018 lw(t9, MemOperand(topaddr, limit - top));
2019 }
2020
2021 // Calculate new top and bail out if new space is exhausted. Use result
2022 // to calculate the new top. Object size may be in words so a shift is
2023 // required to get the number of bytes.
2024 if ((flags & SIZE_IN_WORDS) != 0) {
2025 sll(scratch2, object_size, kPointerSizeLog2);
2026 Addu(scratch2, result, scratch2);
2027 } else {
2028 Addu(scratch2, result, Operand(object_size));
2029 }
2030 Branch(gc_required, Ugreater, scratch2, Operand(t9));
2031
2032 // Update allocation top. result temporarily holds the new top.
2033 if (FLAG_debug_code) {
2034 And(t9, scratch2, Operand(kObjectAlignmentMask));
2035 Check(eq, "Unaligned allocation in new space", t9, Operand(zero_reg));
2036 }
2037 sw(scratch2, MemOperand(topaddr));
2038
2039 // Tag object if requested.
2040 if ((flags & TAG_OBJECT) != 0) {
2041 Addu(result, result, Operand(kHeapObjectTag));
2042 }
2043 }
2044
2045
2046 void MacroAssembler::UndoAllocationInNewSpace(Register object,
2047 Register scratch) {
2048 ExternalReference new_space_allocation_top =
2049 ExternalReference::new_space_allocation_top_address();
2050
2051 // Make sure the object has no tag before resetting top.
2052 And(object, object, Operand(~kHeapObjectTagMask));
2053 #ifdef DEBUG
2054 // Check that the object un-allocated is below the current top.
2055 li(scratch, Operand(new_space_allocation_top));
2056 lw(scratch, MemOperand(scratch));
2057 Check(less, "Undo allocation of non allocated memory",
2058 object, Operand(scratch));
2059 #endif
2060 // Write the address of the object to un-allocate as the current top.
2061 li(scratch, Operand(new_space_allocation_top));
2062 sw(object, MemOperand(scratch));
2063 }
2064
2065
2066 void MacroAssembler::AllocateTwoByteString(Register result,
2067 Register length,
2068 Register scratch1,
2069 Register scratch2,
2070 Register scratch3,
2071 Label* gc_required) {
2072 // Calculate the number of bytes needed for the characters in the string while
2073 // observing object alignment.
2074 ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0);
2075 sll(scratch1, length, 1); // Length in bytes, not chars.
2076 addiu(scratch1, scratch1,
2077 kObjectAlignmentMask + SeqTwoByteString::kHeaderSize);
2078 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
2079
2080 // Allocate two-byte string in new space.
2081 AllocateInNewSpace(scratch1,
2082 result,
2083 scratch2,
2084 scratch3,
2085 gc_required,
2086 TAG_OBJECT);
2087
2088 // Set the map, length and hash field.
2089 InitializeNewString(result,
2090 length,
2091 Heap::kStringMapRootIndex,
2092 scratch1,
2093 scratch2);
2094 }
2095
2096
2097 void MacroAssembler::AllocateAsciiString(Register result,
2098 Register length,
2099 Register scratch1,
2100 Register scratch2,
2101 Register scratch3,
2102 Label* gc_required) {
2103 // Calculate the number of bytes needed for the characters in the string
2104 // while observing object alignment.
2105 ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0);
2106 ASSERT(kCharSize == 1);
2107 addiu(scratch1, length, kObjectAlignmentMask + SeqAsciiString::kHeaderSize);
2108 And(scratch1, scratch1, Operand(~kObjectAlignmentMask));
2109
2110 // Allocate ASCII string in new space.
2111 AllocateInNewSpace(scratch1,
2112 result,
2113 scratch2,
2114 scratch3,
2115 gc_required,
2116 TAG_OBJECT);
2117
2118 // Set the map, length and hash field.
2119 InitializeNewString(result,
2120 length,
2121 Heap::kAsciiStringMapRootIndex,
2122 scratch1,
2123 scratch2);
2124 }
2125
2126
2127 void MacroAssembler::AllocateTwoByteConsString(Register result,
2128 Register length,
2129 Register scratch1,
2130 Register scratch2,
2131 Label* gc_required) {
2132 AllocateInNewSpace(ConsString::kSize,
2133 result,
2134 scratch1,
2135 scratch2,
2136 gc_required,
2137 TAG_OBJECT);
2138 InitializeNewString(result,
2139 length,
2140 Heap::kConsStringMapRootIndex,
2141 scratch1,
2142 scratch2);
2143 }
2144
2145
2146 void MacroAssembler::AllocateAsciiConsString(Register result,
2147 Register length,
2148 Register scratch1,
2149 Register scratch2,
2150 Label* gc_required) {
2151 AllocateInNewSpace(ConsString::kSize,
2152 result,
2153 scratch1,
2154 scratch2,
2155 gc_required,
2156 TAG_OBJECT);
2157 InitializeNewString(result,
2158 length,
2159 Heap::kConsAsciiStringMapRootIndex,
2160 scratch1,
2161 scratch2);
2162 }
2163
2164
2165 // Allocates a heap number or jumps to the label if the young space is full and
2166 // a scavenge is needed.
2167 void MacroAssembler::AllocateHeapNumber(Register result,
2168 Register scratch1,
2169 Register scratch2,
2170 Register heap_number_map,
2171 Label* need_gc) {
2172 // Allocate an object in the heap for the heap number and tag it as a heap
2173 // object.
2174 // We ask for four more bytes to align it as we need and align the result.
2175 // (HeapNumber::kSize is modified to be 4-byte bigger)
2176 AllocateInNewSpace(HeapNumber::kSize,
2177 result,
2178 scratch1,
2179 scratch2,
2180 need_gc,
2181 TAG_OBJECT);
2182
2183 // Align to 8 bytes. [Commented out pending code review.]
2184 // __ addiu(result, result, 7-1); // -1 because result is tagged.
2185 // __ And(result, result, Operand(~7));
2186 // __ Or(result, result, Operand(1)); // Tag it back.
2187
2188 #ifdef DEBUG
2189 // // TODO(MIPS.6)
2190 // // Check that the result is 8-byte aligned.
2191 // andi(scratch2, result, Operand(7));
2192 // xori(scratch2, scratch2, Operand(1)); // Fail if the tag is missing.
2193 // Check(eq,
2194 // "Error in HeapNumber alloc (not 8-byte aligned or tag missing)",
2195 // scratch2, Operand(zero_reg));
2196 #endif
2197
2198 // Store heap number map in the allocated object.
2199 AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
2200 sw(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset));
2201 }
2202
2203
2204 void MacroAssembler::AllocateHeapNumberWithValue(Register result,
2205 FPURegister value,
2206 Register scratch1,
2207 Register scratch2,
2208 Label* gc_required) {
2209 LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
2210 AllocateHeapNumber(result, scratch1, scratch2, t6, gc_required);
2211 sdc1(value, FieldMemOperand(result, HeapNumber::kValueOffset));
2212 }
2213
2214
2215 // Copies a fixed number of fields of heap objects from src to dst.
2216 void MacroAssembler::CopyFields(Register dst,
2217 Register src,
2218 RegList temps,
2219 int field_count) {
2220 ASSERT((temps & dst.bit()) == 0);
2221 ASSERT((temps & src.bit()) == 0);
2222 // Primitive implementation using only one temporary register.
2223
2224 Register tmp = no_reg;
2225 // Find a temp register in temps list.
2226 for (int i = 0; i < kNumRegisters; i++) {
2227 if ((temps & (1 << i)) != 0) {
2228 tmp.code_ = i;
2229 break;
2230 }
2231 }
2232 ASSERT(!tmp.is(no_reg));
2233
2234 for (int i = 0; i < field_count; i++) {
2235 lw(tmp, FieldMemOperand(src, i * kPointerSize));
2236 sw(tmp, FieldMemOperand(dst, i * kPointerSize));
2237 }
2238 }
2239
2240
2241 void MacroAssembler::CheckMap(Register obj,
2242 Register scratch,
2243 Handle<Map> map,
2244 Label* fail,
2245 bool is_heap_object) {
2246 if (!is_heap_object) {
2247 JumpIfSmi(obj, fail);
2248 }
2249 lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2250 li(at, Operand(map));
2251 Branch(fail, ne, scratch, Operand(at));
2252 }
2253
2254
2255 void MacroAssembler::CheckMap(Register obj,
2256 Register scratch,
2257 Heap::RootListIndex index,
2258 Label* fail,
2259 bool is_heap_object) {
2260 if (!is_heap_object) {
2261 JumpIfSmi(obj, fail);
2262 }
2263 lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset));
2264 LoadRoot(at, index);
2265 Branch(fail, ne, scratch, Operand(at));
2266 }
2267
2268
909 // ----------------------------------------------------------------------------- 2269 // -----------------------------------------------------------------------------
910 // JavaScript invokes 2270 // JavaScript invokes
911 2271
912 void MacroAssembler::InvokePrologue(const ParameterCount& expected, 2272 void MacroAssembler::InvokePrologue(const ParameterCount& expected,
913 const ParameterCount& actual, 2273 const ParameterCount& actual,
914 Handle<Code> code_constant, 2274 Handle<Code> code_constant,
915 Register code_reg, 2275 Register code_reg,
916 Label* done, 2276 Label* done,
917 InvokeFlag flag) { 2277 InvokeFlag flag,
2278 PostCallGenerator* post_call_generator) {
918 bool definitely_matches = false; 2279 bool definitely_matches = false;
919 Label regular_invoke; 2280 Label regular_invoke;
920 2281
921 // Check whether the expected and actual arguments count match. If not, 2282 // Check whether the expected and actual arguments count match. If not,
922 // setup registers according to contract with ArgumentsAdaptorTrampoline: 2283 // setup registers according to contract with ArgumentsAdaptorTrampoline:
923 // a0: actual arguments count 2284 // a0: actual arguments count
924 // a1: function (passed through to callee) 2285 // a1: function (passed through to callee)
925 // a2: expected arguments count 2286 // a2: expected arguments count
926 // a3: callee code entry 2287 // a3: callee code entry
927 2288
(...skipping 15 matching lines...) Expand all
943 // Don't worry about adapting arguments for builtins that 2304 // Don't worry about adapting arguments for builtins that
944 // don't want that done. Skip adaption code by making it look 2305 // don't want that done. Skip adaption code by making it look
945 // like we have a match between expected and actual number of 2306 // like we have a match between expected and actual number of
946 // arguments. 2307 // arguments.
947 definitely_matches = true; 2308 definitely_matches = true;
948 } else { 2309 } else {
949 li(a2, Operand(expected.immediate())); 2310 li(a2, Operand(expected.immediate()));
950 } 2311 }
951 } 2312 }
952 } else if (actual.is_immediate()) { 2313 } else if (actual.is_immediate()) {
953 Branch(eq, &regular_invoke, expected.reg(), Operand(actual.immediate())); 2314 Branch(&regular_invoke, eq, expected.reg(), Operand(actual.immediate()));
954 li(a0, Operand(actual.immediate())); 2315 li(a0, Operand(actual.immediate()));
955 } else { 2316 } else {
956 Branch(eq, &regular_invoke, expected.reg(), Operand(actual.reg())); 2317 Branch(&regular_invoke, eq, expected.reg(), Operand(actual.reg()));
957 } 2318 }
958 2319
959 if (!definitely_matches) { 2320 if (!definitely_matches) {
960 if (!code_constant.is_null()) { 2321 if (!code_constant.is_null()) {
961 li(a3, Operand(code_constant)); 2322 li(a3, Operand(code_constant));
962 addiu(a3, a3, Code::kHeaderSize - kHeapObjectTag); 2323 addiu(a3, a3, Code::kHeaderSize - kHeapObjectTag);
963 } 2324 }
964 2325
965 ExternalReference adaptor(Builtins::ArgumentsAdaptorTrampoline); 2326 ExternalReference adaptor(Builtins::ArgumentsAdaptorTrampoline);
966 if (flag == CALL_FUNCTION) { 2327 if (flag == CALL_FUNCTION) {
967 CallBuiltin(adaptor); 2328 CallBuiltin(adaptor);
968 b(done); 2329 if (post_call_generator != NULL) post_call_generator->Generate();
969 nop(); 2330 jmp(done);
970 } else { 2331 } else {
971 JumpToBuiltin(adaptor); 2332 JumpToBuiltin(adaptor);
2333 // break_(__LINE__);
972 } 2334 }
973 bind(&regular_invoke); 2335 bind(&regular_invoke);
974 } 2336 }
975 } 2337 }
976 2338
2339
977 void MacroAssembler::InvokeCode(Register code, 2340 void MacroAssembler::InvokeCode(Register code,
978 const ParameterCount& expected, 2341 const ParameterCount& expected,
979 const ParameterCount& actual, 2342 const ParameterCount& actual,
980 InvokeFlag flag) { 2343 InvokeFlag flag,
2344 PostCallGenerator* post_call_generator) {
981 Label done; 2345 Label done;
982 2346
983 InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); 2347 InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag,
2348 post_call_generator);
984 if (flag == CALL_FUNCTION) { 2349 if (flag == CALL_FUNCTION) {
985 Call(code); 2350 Call(code);
986 } else { 2351 } else {
987 ASSERT(flag == JUMP_FUNCTION); 2352 ASSERT(flag == JUMP_FUNCTION);
988 Jump(code); 2353 Jump(code);
989 } 2354 }
990 // Continue here if InvokePrologue does handle the invocation due to 2355 // Continue here if InvokePrologue does handle the invocation due to
991 // mismatched parameter counts. 2356 // mismatched parameter counts.
992 bind(&done); 2357 bind(&done);
993 } 2358 }
(...skipping 13 matching lines...) Expand all
1007 Jump(code, rmode); 2372 Jump(code, rmode);
1008 } 2373 }
1009 // Continue here if InvokePrologue does handle the invocation due to 2374 // Continue here if InvokePrologue does handle the invocation due to
1010 // mismatched parameter counts. 2375 // mismatched parameter counts.
1011 bind(&done); 2376 bind(&done);
1012 } 2377 }
1013 2378
1014 2379
1015 void MacroAssembler::InvokeFunction(Register function, 2380 void MacroAssembler::InvokeFunction(Register function,
1016 const ParameterCount& actual, 2381 const ParameterCount& actual,
1017 InvokeFlag flag) { 2382 InvokeFlag flag,
2383 PostCallGenerator* post_call_generator) {
1018 // Contract with called JS functions requires that function is passed in a1. 2384 // Contract with called JS functions requires that function is passed in a1.
1019 ASSERT(function.is(a1)); 2385 ASSERT(function.is(a1));
1020 Register expected_reg = a2; 2386 Register expected_reg = a2;
1021 Register code_reg = a3; 2387 Register code_reg = a3;
1022 2388
1023 lw(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); 2389 lw(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1024 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); 2390 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
1025 lw(expected_reg, 2391 lw(expected_reg,
1026 FieldMemOperand(code_reg, 2392 FieldMemOperand(code_reg,
1027 SharedFunctionInfo::kFormalParameterCountOffset)); 2393 SharedFunctionInfo::kFormalParameterCountOffset));
1028 lw(code_reg, 2394 sra(expected_reg, expected_reg, kSmiTagSize);
1029 MemOperand(code_reg, SharedFunctionInfo::kCodeOffset - kHeapObjectTag)); 2395 lw(code_reg, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
1030 addiu(code_reg, code_reg, Code::kHeaderSize - kHeapObjectTag);
1031 2396
1032 ParameterCount expected(expected_reg); 2397 ParameterCount expected(expected_reg);
1033 InvokeCode(code_reg, expected, actual, flag); 2398 InvokeCode(code_reg, expected, actual, flag, post_call_generator);
2399 }
2400
2401
2402 void MacroAssembler::InvokeFunction(JSFunction* function,
2403 const ParameterCount& actual,
2404 InvokeFlag flag) {
2405 ASSERT(function->is_compiled());
2406
2407 // Get the function and setup the context.
2408 li(a1, Operand(Handle<JSFunction>(function)));
2409 lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2410
2411 // Invoke the cached code.
2412 Handle<Code> code(function->code());
2413 ParameterCount expected(function->shared()->formal_parameter_count());
2414 if (V8::UseCrankshaft()) {
2415 UNIMPLEMENTED_MIPS();
2416 } else {
2417 InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag);
2418 }
2419 }
2420
2421
2422 void MacroAssembler::IsObjectJSObjectType(Register heap_object,
2423 Register map,
2424 Register scratch,
2425 Label* fail) {
2426 lw(map, FieldMemOperand(heap_object, HeapObject::kMapOffset));
2427 IsInstanceJSObjectType(map, scratch, fail);
2428 }
2429
2430
2431 void MacroAssembler::IsInstanceJSObjectType(Register map,
2432 Register scratch,
2433 Label* fail) {
2434 lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset));
2435 Branch(fail, lt, scratch, Operand(FIRST_JS_OBJECT_TYPE));
2436 Branch(fail, gt, scratch, Operand(LAST_JS_OBJECT_TYPE));
2437 }
2438
2439
2440 void MacroAssembler::IsObjectJSStringType(Register object,
2441 Register scratch,
2442 Label* fail) {
2443 ASSERT(kNotStringTag != 0);
2444
2445 lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
2446 lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset));
2447 And(scratch, scratch, Operand(kIsNotStringMask));
2448 Branch(fail, ne, scratch, Operand(zero_reg));
1034 } 2449 }
1035 2450
1036 2451
1037 // --------------------------------------------------------------------------- 2452 // ---------------------------------------------------------------------------
1038 // Support functions. 2453 // Support functions.
1039 2454
1040 void MacroAssembler::GetObjectType(Register function, 2455
1041 Register map, 2456 void MacroAssembler::TryGetFunctionPrototype(Register function,
1042 Register type_reg) { 2457 Register result,
1043 lw(map, FieldMemOperand(function, HeapObject::kMapOffset)); 2458 Register scratch,
1044 lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); 2459 Label* miss) {
1045 } 2460 // Check that the receiver isn't a smi.
2461 JumpIfSmi(function, miss);
2462
2463 // Check that the function really is a function. Load map into result reg.
2464 GetObjectType(function, result, scratch);
2465 Branch(miss, ne, scratch, Operand(JS_FUNCTION_TYPE));
2466
2467 // Make sure that the function has an instance prototype.
2468 Label non_instance;
2469 lbu(scratch, FieldMemOperand(result, Map::kBitFieldOffset));
2470 And(scratch, scratch, Operand(1 << Map::kHasNonInstancePrototype));
2471 Branch(&non_instance, ne, scratch, Operand(zero_reg));
2472
2473 // Get the prototype or initial map from the function.
2474 lw(result,
2475 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2476
2477 // If the prototype or initial map is the hole, don't return it and
2478 // simply miss the cache instead. This will allow us to allocate a
2479 // prototype object on-demand in the runtime system.
2480 LoadRoot(t8, Heap::kTheHoleValueRootIndex);
2481 Branch(miss, eq, result, Operand(t8));
2482
2483 // If the function does not have an initial map, we're done.
2484 Label done;
2485 GetObjectType(result, scratch, scratch);
2486 Branch(&done, ne, scratch, Operand(MAP_TYPE));
2487
2488 // Get the prototype from the initial map.
2489 lw(result, FieldMemOperand(result, Map::kPrototypeOffset));
2490 jmp(&done);
2491
2492 // Non-instance prototype: Fetch prototype from constructor field
2493 // in initial map.
2494 bind(&non_instance);
2495 lw(result, FieldMemOperand(result, Map::kConstructorOffset));
2496
2497 // All done.
2498 bind(&done);
2499 }
1046 2500
1047 2501
1048 void MacroAssembler::CallBuiltin(ExternalReference builtin_entry) { 2502 void MacroAssembler::GetObjectType(Register object,
1049 // Load builtin address. 2503 Register map,
1050 LoadExternalReference(t9, builtin_entry); 2504 Register type_reg) {
1051 lw(t9, MemOperand(t9)); // Deref address. 2505 lw(map, FieldMemOperand(object, HeapObject::kMapOffset));
1052 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); 2506 lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
1053 // Call and allocate arguments slots. 2507 }
1054 jalr(t9);
1055 // Use the branch delay slot to allocated argument slots.
1056 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1057 addiu(sp, sp, StandardFrameConstants::kRArgsSlotsSize);
1058 }
1059 2508
1060 2509
1061 void MacroAssembler::CallBuiltin(Register target) { 2510 void MacroAssembler::CallBuiltin(ExternalReference builtin_entry) {
1062 // Target already holds target address. 2511 // Load builtin address.
1063 // Call and allocate arguments slots. 2512 LoadExternalReference(t9, builtin_entry);
1064 jalr(target); 2513 lw(t9, MemOperand(t9)); // Deref address.
1065 // Use the branch delay slot to allocated argument slots. 2514 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
1066 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize); 2515 // Call and allocate arguments slots.
1067 addiu(sp, sp, StandardFrameConstants::kRArgsSlotsSize); 2516 jalr(t9);
1068 } 2517 // Use the branch delay slot to allocated argument slots.
2518 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
2519 addiu(sp, sp, StandardFrameConstants::kBArgsSlotsSize);
2520 }
1069 2521
1070 2522
1071 void MacroAssembler::JumpToBuiltin(ExternalReference builtin_entry) { 2523 void MacroAssembler::CallBuiltin(Register target) {
1072 // Load builtin address. 2524 // Target already holds target address.
1073 LoadExternalReference(t9, builtin_entry); 2525 // Call and allocate arguments slots.
1074 lw(t9, MemOperand(t9)); // Deref address. 2526 jalr(target);
1075 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag); 2527 // Use the branch delay slot to allocated argument slots.
1076 // Call and allocate arguments slots. 2528 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
1077 jr(t9); 2529 addiu(sp, sp, StandardFrameConstants::kBArgsSlotsSize);
1078 // Use the branch delay slot to allocated argument slots. 2530 }
1079 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize);
1080 }
1081 2531
1082 2532
1083 void MacroAssembler::JumpToBuiltin(Register target) { 2533 void MacroAssembler::CallBuiltin(Handle<Code> code, RelocInfo::Mode rmode) {
1084 // t9 already holds target address. 2534 ASSERT(RelocInfo::IsCodeTarget(rmode));
1085 // Call and allocate arguments slots. 2535 // Jump but do not protect the branch delay slot.
1086 jr(t9); 2536 Call(false, code, rmode);
1087 // Use the branch delay slot to allocated argument slots. 2537 // Use the branch delay slot to allocated argument slots.
1088 addiu(sp, sp, -StandardFrameConstants::kRArgsSlotsSize); 2538 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
1089 } 2539 addiu(sp, sp, StandardFrameConstants::kBArgsSlotsSize);
2540 }
2541
2542
2543 void MacroAssembler::JumpToBuiltin(ExternalReference builtin_entry) {
2544 // Load builtin address.
2545 LoadExternalReference(t9, builtin_entry);
2546 lw(t9, MemOperand(t9)); // Deref address.
2547 addiu(t9, t9, Code::kHeaderSize - kHeapObjectTag);
2548 // Call and allocate arguments slots.
2549 jr(t9);
2550 // Use the branch delay slot to allocated argument slots.
2551 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
2552 }
2553
2554
2555 void MacroAssembler::JumpToBuiltin(Register target) {
2556 // t9 already holds target address.
2557 // Call and allocate arguments slots.
2558 jr(t9);
2559 // Use the branch delay slot to allocated argument slots.
2560 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
2561 }
2562
2563
2564 void MacroAssembler::JumpToBuiltin(Handle<Code> code, RelocInfo::Mode rmode) {
2565 ASSERT(RelocInfo::IsCodeTarget(rmode));
2566 // Jump but do not protect the branch delay slot.
2567 Jump(false, code, rmode);
2568 // Use the branch delay slot to allocated argument slots.
2569 addiu(sp, sp, -StandardFrameConstants::kBArgsSlotsSize);
2570 }
1090 2571
1091 2572
1092 // ----------------------------------------------------------------------------- 2573 // -----------------------------------------------------------------------------
1093 // Runtime calls 2574 // Runtime calls
1094 2575
1095 void MacroAssembler::CallStub(CodeStub* stub, Condition cond, 2576 void MacroAssembler::CallStub(CodeStub* stub, Condition cond,
1096 Register r1, const Operand& r2) { 2577 Register r1, const Operand& r2) {
1097 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. 2578 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs.
1098 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond, r1, r2); 2579 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond, r1, r2);
1099 } 2580 }
1100 2581
1101 2582
1102 void MacroAssembler::StubReturn(int argc) { 2583 void MacroAssembler::TailCallStub(CodeStub* stub) {
1103 UNIMPLEMENTED_MIPS(); 2584 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs
2585 Jump(stub->GetCode(), RelocInfo::CODE_TARGET);
1104 } 2586 }
1105 2587
1106 2588
1107 void MacroAssembler::IllegalOperation(int num_arguments) { 2589 void MacroAssembler::IllegalOperation(int num_arguments) {
1108 if (num_arguments > 0) { 2590 if (num_arguments > 0) {
1109 addiu(sp, sp, num_arguments * kPointerSize); 2591 addiu(sp, sp, num_arguments * kPointerSize);
1110 } 2592 }
1111 LoadRoot(v0, Heap::kUndefinedValueRootIndex); 2593 LoadRoot(v0, Heap::kUndefinedValueRootIndex);
1112 } 2594 }
1113 2595
1114 2596
2597 void MacroAssembler::IndexFromHash(Register hash,
2598 Register index) {
2599 // If the hash field contains an array index pick it out. The assert checks
2600 // that the constants for the maximum number of digits for an array index
2601 // cached in the hash field and the number of bits reserved for it does not
2602 // conflict.
2603 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
2604 (1 << String::kArrayIndexValueBits));
2605 // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in
2606 // the low kHashShift bits.
2607 STATIC_ASSERT(kSmiTag == 0);
2608 Ext(hash, hash, String::kHashShift, String::kArrayIndexValueBits);
2609 sll(index, hash, kSmiTagSize);
2610 }
2611
2612
2613 void MacroAssembler::ObjectToDoubleFPURegister(Register object,
2614 FPURegister result,
2615 Register scratch1,
2616 Register scratch2,
2617 Register heap_number_map,
2618 Label* not_number,
2619 ObjectToDoubleFlags flags) {
2620 Label done;
2621 if ((flags & OBJECT_NOT_SMI) == 0) {
2622 Label not_smi;
2623 JumpIfNotSmi(object, &not_smi);
2624 // Remove smi tag and convert to double.
2625 sra(scratch1, object, kSmiTagSize);
2626 mtc1(scratch1, result);
2627 cvt_d_w(result, result);
2628 Branch(&done);
2629 bind(&not_smi);
2630 }
2631 // Check for heap number and load double value from it.
2632 lw(scratch1, FieldMemOperand(object, HeapObject::kMapOffset));
2633 Subu(scratch2, object, Operand(kHeapObjectTag));
2634 Branch(not_number, ne, scratch1, Operand(heap_number_map));
2635
2636 if ((flags & AVOID_NANS_AND_INFINITIES) != 0) {
2637 // If exponent is all ones the number is either a NaN or +/-Infinity.
2638 lw(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset));
2639 {
2640 // Signed bitfield extraction, based on ARM's Sbfx macro.
2641 // We cannot use the ext instruction, because it doesn't sign-extend.
2642 int lsb = HeapNumber::kExponentShift;
2643 int width = HeapNumber::kExponentBits;
2644 Register dst = scratch1;
2645 Register src = scratch1;
2646
2647 int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1);
2648 And(dst, src, mask);
2649 int shift_up = 32 - lsb - width;
2650 int shift_down = lsb + shift_up;
2651 if (shift_up != 0) {
2652 sll(dst, dst, shift_up);
2653 }
2654 if (shift_down != 0) {
2655 sra(dst, dst, shift_down);
2656 }
2657 }
2658 // All-one value sign extend to -1.
2659 Branch(not_number, eq, scratch1, Operand(-1));
2660 }
2661 ldc1(result, MemOperand(scratch2, HeapNumber::kValueOffset));
2662 bind(&done);
2663 }
2664
2665
2666 void MacroAssembler::SmiToDoubleFPURegister(Register smi,
2667 FPURegister value,
2668 Register scratch1) {
2669 sra(scratch1, smi, kSmiTagSize);
2670 mtc1(scratch1, value);
2671 cvt_d_w(value, value);
2672 }
2673
2674
1115 void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { 2675 void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) {
1116 // All parameters are on the stack. v0 has the return value after call. 2676 // All parameters are on the stack. v0 has the return value after call.
1117 2677
1118 // If the expected number of arguments of the runtime function is 2678 // If the expected number of arguments of the runtime function is
1119 // constant, we check that the actual number of arguments match the 2679 // constant, we check that the actual number of arguments match the
1120 // expectation. 2680 // expectation.
1121 if (f->nargs >= 0 && f->nargs != num_arguments) { 2681 if (f->nargs >= 0 && f->nargs != num_arguments) {
1122 IllegalOperation(num_arguments); 2682 IllegalOperation(num_arguments);
1123 return; 2683 return;
1124 } 2684 }
1125 2685
1126 // TODO(1236192): Most runtime routines don't need the number of 2686 // TODO(1236192): Most runtime routines don't need the number of
1127 // arguments passed in because it is constant. At some point we 2687 // arguments passed in because it is constant. At some point we
1128 // should remove this need and make the runtime routine entry code 2688 // should remove this need and make the runtime routine entry code
1129 // smarter. 2689 // smarter.
1130 li(a0, num_arguments); 2690 li(a0, num_arguments);
1131 LoadExternalReference(a1, ExternalReference(f)); 2691 LoadExternalReference(a1, ExternalReference(f));
1132 CEntryStub stub(1); 2692 CEntryStub stub(1);
1133 CallStub(&stub); 2693 CallStub(&stub);
1134 } 2694 }
1135 2695
1136 2696
2697 void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) {
2698 Runtime::Function* function = Runtime::FunctionForId(id);
2699 li(a0, Operand(function->nargs));
2700 li(a1, Operand(ExternalReference(function)));
2701 CEntryStub stub(1);
2702 stub.SaveDoubles();
2703 CallStub(&stub);
2704 }
2705
2706
1137 void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { 2707 void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) {
1138 CallRuntime(Runtime::FunctionForId(fid), num_arguments); 2708 CallRuntime(Runtime::FunctionForId(fid), num_arguments);
1139 } 2709 }
1140 2710
1141 2711
2712 void MacroAssembler::CallExternalReference(const ExternalReference& ext,
2713 int num_arguments) {
2714 li(a0, Operand(num_arguments));
2715 li(a1, Operand(ext));
2716
2717 CEntryStub stub(1);
2718 CallStub(&stub);
2719 }
2720
2721
1142 void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, 2722 void MacroAssembler::TailCallExternalReference(const ExternalReference& ext,
1143 int num_arguments, 2723 int num_arguments,
1144 int result_size) { 2724 int result_size) {
1145 UNIMPLEMENTED_MIPS(); 2725 // TODO(1236192): Most runtime routines don't need the number of
2726 // arguments passed in because it is constant. At some point we
2727 // should remove this need and make the runtime routine entry code
2728 // smarter.
2729 li(a0, Operand(num_arguments));
2730 JumpToExternalReference(ext);
1146 } 2731 }
1147 2732
1148 2733
1149 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, 2734 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
1150 int num_arguments, 2735 int num_arguments,
1151 int result_size) { 2736 int result_size) {
1152 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); 2737 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size);
1153 } 2738 }
1154 2739
1155 2740
1156 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { 2741 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) {
1157 UNIMPLEMENTED_MIPS(); 2742 li(a1, Operand(builtin));
1158 } 2743 CEntryStub stub(1);
1159 2744 Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
1160
1161 Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id,
1162 bool* resolved) {
1163 UNIMPLEMENTED_MIPS();
1164 return Handle<Code>(reinterpret_cast<Code*>(NULL)); // UNIMPLEMENTED RETURN
1165 } 2745 }
1166 2746
1167 2747
1168 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, 2748 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
1169 InvokeJSFlags flags) { 2749 InvokeJSFlags flags,
1170 UNIMPLEMENTED_MIPS(); 2750 PostCallGenerator* post_call_generator) {
2751 GetBuiltinEntry(t9, id);
2752 if (flags == CALL_JS) {
2753 Call(t9);
2754 if (post_call_generator != NULL) post_call_generator->Generate();
2755 } else {
2756 ASSERT(flags == JUMP_JS);
2757 Jump(t9);
2758 }
2759 }
2760
2761
2762 void MacroAssembler::GetBuiltinFunction(Register target,
2763 Builtins::JavaScript id) {
2764 // Load the builtins object into target register.
2765 lw(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
2766 lw(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset));
2767 // Load the JavaScript builtin function from the builtins object.
2768 lw(target, FieldMemOperand(target,
2769 JSBuiltinsObject::OffsetOfFunctionWithId(id)));
1171 } 2770 }
1172 2771
1173 2772
1174 void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { 2773 void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
1175 UNIMPLEMENTED_MIPS(); 2774 ASSERT(!target.is(a1));
2775 GetBuiltinFunction(a1, id);
2776 // Load the code entry point from the builtins object.
2777 lw(target, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
1176 } 2778 }
1177 2779
1178 2780
1179 void MacroAssembler::SetCounter(StatsCounter* counter, int value, 2781 void MacroAssembler::SetCounter(StatsCounter* counter, int value,
1180 Register scratch1, Register scratch2) { 2782 Register scratch1, Register scratch2) {
1181 UNIMPLEMENTED_MIPS(); 2783 if (FLAG_native_code_counters && counter->Enabled()) {
2784 li(scratch1, Operand(value));
2785 li(scratch2, Operand(ExternalReference(counter)));
2786 sw(scratch1, MemOperand(scratch2));
2787 }
1182 } 2788 }
1183 2789
1184 2790
1185 void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, 2791 void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
1186 Register scratch1, Register scratch2) { 2792 Register scratch1, Register scratch2) {
1187 UNIMPLEMENTED_MIPS(); 2793 ASSERT(value > 0);
2794 if (FLAG_native_code_counters && counter->Enabled()) {
2795 li(scratch2, Operand(ExternalReference(counter)));
2796 lw(scratch1, MemOperand(scratch2));
2797 Addu(scratch1, scratch1, Operand(value));
2798 sw(scratch1, MemOperand(scratch2));
2799 }
1188 } 2800 }
1189 2801
1190 2802
1191 void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, 2803 void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
1192 Register scratch1, Register scratch2) { 2804 Register scratch1, Register scratch2) {
1193 UNIMPLEMENTED_MIPS(); 2805 ASSERT(value > 0);
2806 if (FLAG_native_code_counters && counter->Enabled()) {
2807 li(scratch2, Operand(ExternalReference(counter)));
2808 lw(scratch1, MemOperand(scratch2));
2809 Subu(scratch1, scratch1, Operand(value));
2810 sw(scratch1, MemOperand(scratch2));
2811 }
1194 } 2812 }
1195 2813
1196 2814
1197 // ----------------------------------------------------------------------------- 2815 // -----------------------------------------------------------------------------
1198 // Debugging 2816 // Debugging
1199 2817
1200 void MacroAssembler::Assert(Condition cc, const char* msg, 2818 void MacroAssembler::Assert(Condition cc, const char* msg,
1201 Register rs, Operand rt) { 2819 Register rs, Operand rt) {
1202 UNIMPLEMENTED_MIPS(); 2820 if (FLAG_debug_code)
2821 Check(cc, msg, rs, rt);
2822 }
2823
2824
2825 void MacroAssembler::AssertRegisterIsRoot(Register reg,
2826 Heap::RootListIndex index) {
2827 if (FLAG_debug_code) {
2828 LoadRoot(at, index);
2829 Check(eq, "Register did not match expected root", reg, Operand(at));
2830 }
2831 }
2832
2833
2834 void MacroAssembler::AssertFastElements(Register elements) {
2835 if (FLAG_debug_code) {
2836 ASSERT(!elements.is(at));
2837 Label ok;
2838 Push(elements);
2839 lw(elements, FieldMemOperand(elements, HeapObject::kMapOffset));
2840 LoadRoot(at, Heap::kFixedArrayMapRootIndex);
2841 Branch(&ok, eq, elements, Operand(at));
2842 LoadRoot(at, Heap::kFixedCOWArrayMapRootIndex);
2843 Branch(&ok, eq, elements, Operand(at));
2844 Abort("JSObject with fast elements map has slow elements");
2845 bind(&ok);
2846 Pop(elements);
2847 }
1203 } 2848 }
1204 2849
1205 2850
1206 void MacroAssembler::Check(Condition cc, const char* msg, 2851 void MacroAssembler::Check(Condition cc, const char* msg,
1207 Register rs, Operand rt) { 2852 Register rs, Operand rt) {
1208 UNIMPLEMENTED_MIPS(); 2853 Label L;
2854 Branch(&L, cc, rs, rt);
2855 Abort(msg);
2856 // will not return here
2857 bind(&L);
1209 } 2858 }
1210 2859
1211 2860
1212 void MacroAssembler::Abort(const char* msg) { 2861 void MacroAssembler::Abort(const char* msg) {
1213 UNIMPLEMENTED_MIPS(); 2862 Label abort_start;
2863 bind(&abort_start);
2864 // We want to pass the msg string like a smi to avoid GC
2865 // problems, however msg is not guaranteed to be aligned
2866 // properly. Instead, we pass an aligned pointer that is
2867 // a proper v8 smi, but also pass the alignment difference
2868 // from the real pointer as a smi.
2869 intptr_t p1 = reinterpret_cast<intptr_t>(msg);
2870 intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag;
2871 ASSERT(reinterpret_cast<Object*>(p0)->IsSmi());
2872 #ifdef DEBUG
2873 if (msg != NULL) {
2874 RecordComment("Abort message: ");
2875 RecordComment(msg);
2876 }
2877 #endif
2878 // Disable stub call restrictions to always allow calls to abort.
2879 AllowStubCallsScope allow_scope(this, true);
2880
2881 li(a0, Operand(p0));
2882 Push(a0);
2883 li(a0, Operand(Smi::FromInt(p1 - p0)));
2884 Push(a0);
2885 CallRuntime(Runtime::kAbort, 2);
2886 // will not return here
2887 if (is_trampoline_pool_blocked()) {
2888 // If the calling code cares about the exact number of
2889 // instructions generated, we insert padding here to keep the size
2890 // of the Abort macro constant.
2891 // Currently in debug mode with debug_code enabled the number of
2892 // generated instructions is 14, so we use this as a maximum value.
2893 static const int kExpectedAbortInstructions = 14;
2894 int abort_instructions = InstructionsGeneratedSince(&abort_start);
2895 ASSERT(abort_instructions <= kExpectedAbortInstructions);
2896 while (abort_instructions++ < kExpectedAbortInstructions) {
2897 nop();
2898 }
2899 }
2900 }
2901
2902
2903 void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
2904 if (context_chain_length > 0) {
2905 // Move up the chain of contexts to the context containing the slot.
2906 lw(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX)));
2907 // Load the function context (which is the incoming, outer context).
2908 lw(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
2909 for (int i = 1; i < context_chain_length; i++) {
2910 lw(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX)));
2911 lw(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
2912 }
2913 // The context may be an intermediate context, not a function context.
2914 lw(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX)));
2915 } else { // Slot is in the current function context.
2916 // The context may be an intermediate context, not a function context.
2917 lw(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX)));
2918 }
2919 }
2920
2921
2922 void MacroAssembler::LoadGlobalFunction(int index, Register function) {
2923 // Load the global or builtins object from the current context.
2924 lw(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
2925 // Load the global context from the global or builtins object.
2926 lw(function, FieldMemOperand(function,
2927 GlobalObject::kGlobalContextOffset));
2928 // Load the function from the global context.
2929 lw(function, MemOperand(function, Context::SlotOffset(index)));
2930 }
2931
2932
2933 void MacroAssembler::LoadGlobalFunctionInitialMap(Register function,
2934 Register map,
2935 Register scratch) {
2936 // Load the initial map. The global functions all have initial maps.
2937 lw(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
2938 if (FLAG_debug_code) {
2939 Label ok, fail;
2940 CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, false);
2941 Branch(&ok);
2942 bind(&fail);
2943 Abort("Global functions must have initial map");
2944 bind(&ok);
2945 }
1214 } 2946 }
1215 2947
1216 2948
1217 void MacroAssembler::EnterFrame(StackFrame::Type type) { 2949 void MacroAssembler::EnterFrame(StackFrame::Type type) {
1218 addiu(sp, sp, -5 * kPointerSize); 2950 addiu(sp, sp, -5 * kPointerSize);
1219 li(t0, Operand(Smi::FromInt(type))); 2951 li(t8, Operand(Smi::FromInt(type)));
1220 li(t1, Operand(CodeObject())); 2952 li(t9, Operand(CodeObject()));
1221 sw(ra, MemOperand(sp, 4 * kPointerSize)); 2953 sw(ra, MemOperand(sp, 4 * kPointerSize));
1222 sw(fp, MemOperand(sp, 3 * kPointerSize)); 2954 sw(fp, MemOperand(sp, 3 * kPointerSize));
1223 sw(cp, MemOperand(sp, 2 * kPointerSize)); 2955 sw(cp, MemOperand(sp, 2 * kPointerSize));
1224 sw(t0, MemOperand(sp, 1 * kPointerSize)); 2956 sw(t8, MemOperand(sp, 1 * kPointerSize));
1225 sw(t1, MemOperand(sp, 0 * kPointerSize)); 2957 sw(t9, MemOperand(sp, 0 * kPointerSize));
1226 addiu(fp, sp, 3 * kPointerSize); 2958 addiu(fp, sp, 3 * kPointerSize);
1227 } 2959 }
1228 2960
1229 2961
1230 void MacroAssembler::LeaveFrame(StackFrame::Type type) { 2962 void MacroAssembler::LeaveFrame(StackFrame::Type type) {
1231 mov(sp, fp); 2963 mov(sp, fp);
1232 lw(fp, MemOperand(sp, 0 * kPointerSize)); 2964 lw(fp, MemOperand(sp, 0 * kPointerSize));
1233 lw(ra, MemOperand(sp, 1 * kPointerSize)); 2965 lw(ra, MemOperand(sp, 1 * kPointerSize));
1234 addiu(sp, sp, 2 * kPointerSize); 2966 addiu(sp, sp, 2 * kPointerSize);
1235 } 2967 }
1236 2968
1237 2969
1238 void MacroAssembler::EnterExitFrame(ExitFrame::Mode mode, 2970 void MacroAssembler::EnterExitFrame(Register hold_argc,
1239 Register hold_argc,
1240 Register hold_argv, 2971 Register hold_argv,
1241 Register hold_function) { 2972 Register hold_function,
1242 // Compute the argv pointer and keep it in a callee-saved register. 2973 bool save_doubles) {
1243 // a0 is argc. 2974 // a0 is argc.
1244 sll(t0, a0, kPointerSizeLog2); 2975 sll(t8, a0, kPointerSizeLog2);
1245 add(hold_argv, sp, t0); 2976 addu(hold_argv, sp, t8);
1246 addi(hold_argv, hold_argv, -kPointerSize); 2977 addiu(hold_argv, hold_argv, -kPointerSize);
1247 2978
1248 // Compute callee's stack pointer before making changes and save it as 2979 // Compute callee's stack pointer before making changes and save it as
1249 // t1 register so that it is restored as sp register on exit, thereby 2980 // t9 register so that it is restored as sp register on exit, thereby
1250 // popping the args. 2981 // popping the args.
1251 // t1 = sp + kPointerSize * #args 2982 // t9 = sp + kPointerSize * #args
1252 add(t1, sp, t0); 2983 addu(t9, sp, t8);
2984
2985 // Compute the argv pointer and keep it in a callee-saved register.
2986 // This only seems to be needed for crankshaft and may cause problems
2987 // so it's disabled for now.
2988 // Subu(s6, t9, Operand(kPointerSize));
1253 2989
1254 // Align the stack at this point. 2990 // Align the stack at this point.
1255 AlignStack(0); 2991 AlignStack(0);
1256 2992
1257 // Save registers. 2993 // Save registers.
1258 addiu(sp, sp, -12); 2994 addiu(sp, sp, -12);
1259 sw(t1, MemOperand(sp, 8)); 2995 sw(t9, MemOperand(sp, 8));
1260 sw(ra, MemOperand(sp, 4)); 2996 sw(ra, MemOperand(sp, 4));
1261 sw(fp, MemOperand(sp, 0)); 2997 sw(fp, MemOperand(sp, 0));
1262 mov(fp, sp); // Setup new frame pointer. 2998 mov(fp, sp); // Setup new frame pointer.
1263 2999
1264 // Push debug marker. 3000 li(t8, Operand(CodeObject()));
1265 if (mode == ExitFrame::MODE_DEBUG) { 3001 Push(t8); // Accessed from ExitFrame::code_slot.
1266 Push(zero_reg);
1267 } else {
1268 li(t0, Operand(CodeObject()));
1269 Push(t0);
1270 }
1271 3002
1272 // Save the frame pointer and the context in top. 3003 // Save the frame pointer and the context in top.
1273 LoadExternalReference(t0, ExternalReference(Top::k_c_entry_fp_address)); 3004 LoadExternalReference(t8, ExternalReference(Top::k_c_entry_fp_address));
1274 sw(fp, MemOperand(t0)); 3005 sw(fp, MemOperand(t8));
1275 LoadExternalReference(t0, ExternalReference(Top::k_context_address)); 3006 LoadExternalReference(t8, ExternalReference(Top::k_context_address));
1276 sw(cp, MemOperand(t0)); 3007 sw(cp, MemOperand(t8));
1277 3008
1278 // Setup argc and the builtin function in callee-saved registers. 3009 // Setup argc and the builtin function in callee-saved registers.
1279 mov(hold_argc, a0); 3010 mov(hold_argc, a0);
1280 mov(hold_function, a1); 3011 mov(hold_function, a1);
3012
3013 // Optionally save all double registers.
3014 if (save_doubles) {
3015 #ifdef DEBUG
3016 int frame_alignment = ActivationFrameAlignment();
3017 #endif
3018 // TODO(regis): Use vstrm instruction.
3019 // The stack alignment code above made sp unaligned, so add space for one
3020 // more double register and use aligned addresses.
3021 ASSERT(kDoubleSize == frame_alignment);
3022 // Mark the frame as containing doubles by pushing a non-valid return
3023 // address, i.e. 0.
3024 ASSERT(ExitFrameConstants::kMarkerOffset == -2 * kPointerSize);
3025 push(zero_reg); // Marker and alignment word.
3026 int space = FPURegister::kNumRegisters * kDoubleSize + kPointerSize;
3027 Subu(sp, sp, Operand(space));
3028 // Remember: we only need to save every 2nd double FPU value.
3029 for (int i = 0; i < FPURegister::kNumRegisters; i+=2) {
3030 FPURegister reg = FPURegister::from_code(i);
3031 sdc1(reg, MemOperand(sp, i * kDoubleSize + kPointerSize));
3032 }
3033 // Note that f0 will be accessible at fp - 2*kPointerSize -
3034 // FPURegister::kNumRegisters * kDoubleSize, since the code slot and the
3035 // alignment word were pushed after the fp.
3036 }
1281 } 3037 }
1282 3038
1283 3039
1284 void MacroAssembler::LeaveExitFrame(ExitFrame::Mode mode) { 3040 void MacroAssembler::LeaveExitFrame(bool save_doubles) {
3041 // Optionally restore all double registers.
3042 if (save_doubles) {
3043 // TODO(regis): Use vldrm instruction.
3044 // Remember: we only need to restore every 2nd double FPU value.
3045 for (int i = 0; i < FPURegister::kNumRegisters; i+=2) {
3046 FPURegister reg = FPURegister::from_code(i);
3047 // Register f30-f31 is just below the marker.
3048 const int offset = ExitFrameConstants::kMarkerOffset;
3049 ldc1(reg, MemOperand(fp,
3050 (i - FPURegister::kNumRegisters) * kDoubleSize + offset));
3051 }
3052 }
3053
1285 // Clear top frame. 3054 // Clear top frame.
1286 LoadExternalReference(t0, ExternalReference(Top::k_c_entry_fp_address)); 3055 LoadExternalReference(t8, ExternalReference(Top::k_c_entry_fp_address));
1287 sw(zero_reg, MemOperand(t0)); 3056 sw(zero_reg, MemOperand(t8));
1288 3057
1289 // Restore current context from top and clear it in debug mode. 3058 // Restore current context from top and clear it in debug mode.
1290 LoadExternalReference(t0, ExternalReference(Top::k_context_address)); 3059 LoadExternalReference(t8, ExternalReference(Top::k_context_address));
1291 lw(cp, MemOperand(t0)); 3060 lw(cp, MemOperand(t8));
1292 #ifdef DEBUG 3061 #ifdef DEBUG
1293 sw(a3, MemOperand(t0)); 3062 sw(a3, MemOperand(t8));
1294 #endif 3063 #endif
1295 3064
1296 // Pop the arguments, restore registers, and return. 3065 // Pop the arguments, restore registers, and return.
1297 mov(sp, fp); // Respect ABI stack constraint. 3066 mov(sp, fp); // Respect ABI stack constraint.
1298 lw(fp, MemOperand(sp, 0)); 3067 lw(fp, MemOperand(sp, 0));
1299 lw(ra, MemOperand(sp, 4)); 3068 lw(ra, MemOperand(sp, 4));
1300 lw(sp, MemOperand(sp, 8)); 3069 lw(sp, MemOperand(sp, 8));
1301 jr(ra); 3070 jr(ra);
1302 nop(); // Branch delay slot nop. 3071 nop(); // Branch delay slot nop.
1303 } 3072 }
1304 3073
1305 3074
3075 void MacroAssembler::InitializeNewString(Register string,
3076 Register length,
3077 Heap::RootListIndex map_index,
3078 Register scratch1,
3079 Register scratch2) {
3080 sll(scratch1, length, kSmiTagSize);
3081 LoadRoot(scratch2, map_index);
3082 sw(scratch1, FieldMemOperand(string, String::kLengthOffset));
3083 li(scratch1, Operand(String::kEmptyHashField));
3084 sw(scratch2, FieldMemOperand(string, HeapObject::kMapOffset));
3085 sw(scratch1, FieldMemOperand(string, String::kHashFieldOffset));
3086 }
3087
3088
3089 int MacroAssembler::ActivationFrameAlignment() {
3090 #if defined(V8_HOST_ARCH_MIPS)
3091 // Running on the real platform. Use the alignment as mandated by the local
3092 // environment.
3093 // Note: This will break if we ever start generating snapshots on one ARM
3094 // platform for another ARM platform with a different alignment.
3095 return OS::ActivationFrameAlignment();
3096 #else // defined(V8_HOST_ARCH_MIPS)
3097 // If we are using the simulator then we should always align to the expected
3098 // alignment. As the simulator is used to generate snapshots we do not know
3099 // if the target platform will need alignment, so this is controlled from a
3100 // flag.
3101 // return FLAG_sim_stack_alignment; // TODO(REBASE): uncomment
3102 return 2 * kPointerSize; // TODO(REBASE): use above flog & remove this line.
3103 #endif // defined(V8_HOST_ARCH_MIPS)
3104 }
3105
3106
1306 void MacroAssembler::AlignStack(int offset) { 3107 void MacroAssembler::AlignStack(int offset) {
1307 // On MIPS an offset of 0 aligns to 0 modulo 8 bytes, 3108 // On MIPS an offset of 0 aligns to 0 modulo 8 bytes,
1308 // and an offset of 1 aligns to 4 modulo 8 bytes. 3109 // and an offset of 1 aligns to 4 modulo 8 bytes.
3110 #if defined(V8_HOST_ARCH_MIPS)
3111 // Running on the real platform. Use the alignment as mandated by the local
3112 // environment.
3113 // Note: This will break if we ever start generating snapshots on one MIPS
3114 // platform for another MIPS platform with a different alignment.
1309 int activation_frame_alignment = OS::ActivationFrameAlignment(); 3115 int activation_frame_alignment = OS::ActivationFrameAlignment();
3116 #else // defined(V8_HOST_ARCH_MIPS)
3117 // If we are using the simulator then we should always align to the expected
3118 // alignment. As the simulator is used to generate snapshots we do not know
3119 // if the target platform will need alignment, so we will always align at
3120 // this point here.
3121 int activation_frame_alignment = 2 * kPointerSize;
3122 #endif // defined(V8_HOST_ARCH_MIPS)
1310 if (activation_frame_alignment != kPointerSize) { 3123 if (activation_frame_alignment != kPointerSize) {
1311 // This code needs to be made more general if this assert doesn't hold. 3124 // This code needs to be made more general if this assert doesn't hold.
1312 ASSERT(activation_frame_alignment == 2 * kPointerSize); 3125 ASSERT(activation_frame_alignment == 2 * kPointerSize);
1313 if (offset == 0) { 3126 if (offset == 0) {
1314 andi(t0, sp, activation_frame_alignment - 1); 3127 andi(t8, sp, activation_frame_alignment - 1);
1315 Push(zero_reg, eq, t0, zero_reg); 3128 Push(zero_reg, eq, t8, zero_reg);
1316 } else { 3129 } else {
1317 andi(t0, sp, activation_frame_alignment - 1); 3130 andi(t8, sp, activation_frame_alignment - 1);
1318 addiu(t0, t0, -4); 3131 addiu(t8, t8, -4);
1319 Push(zero_reg, eq, t0, zero_reg); 3132 Push(zero_reg, eq, t8, zero_reg);
1320 } 3133 }
1321 } 3134 }
1322 } 3135 }
1323 3136
3137
3138
3139 void MacroAssembler::JumpIfNotPowerOfTwoOrZero(
3140 Register reg,
3141 Register scratch,
3142 Label* not_power_of_two_or_zero) {
3143 Subu(scratch, reg, Operand(1));
3144 Branch(not_power_of_two_or_zero, lt, scratch, Operand(zero_reg), false);
3145 and_(at, scratch, reg); // In the delay slot.
3146 Branch(not_power_of_two_or_zero, ne, at, Operand(zero_reg));
3147 }
3148
3149
3150 void MacroAssembler::JumpIfNotBothSmi(Register reg1,
3151 Register reg2,
3152 Label* on_not_both_smi) {
3153 STATIC_ASSERT(kSmiTag == 0);
3154 ASSERT_EQ(1, kSmiTagMask);
3155 or_(at, reg1, reg2);
3156 andi(at, at, kSmiTagMask);
3157 Branch(on_not_both_smi, ne, at, Operand(zero_reg));
3158 }
3159
3160
3161 void MacroAssembler::JumpIfEitherSmi(Register reg1,
3162 Register reg2,
3163 Label* on_either_smi) {
3164 STATIC_ASSERT(kSmiTag == 0);
3165 ASSERT_EQ(1, kSmiTagMask);
3166 // Both Smi tags must be 1 (not Smi).
3167 and_(at, reg1, reg2);
3168 andi(at, at, kSmiTagMask);
3169 Branch(on_either_smi, eq, at, Operand(zero_reg));
3170 }
3171
3172
3173 void MacroAssembler::AbortIfSmi(Register object) {
3174 STATIC_ASSERT(kSmiTag == 0);
3175 andi(at, object, kSmiTagMask);
3176 Assert(ne, "Operand is a smi", at, Operand(zero_reg));
3177 }
3178
3179
3180 void MacroAssembler::AbortIfNotSmi(Register object) {
3181 STATIC_ASSERT(kSmiTag == 0);
3182 andi(at, object, kSmiTagMask);
3183 Assert(eq, "Operand is a smi", at, Operand(zero_reg));
3184 }
3185
3186
3187 void MacroAssembler::AbortIfNotRootValue(Register src,
3188 Heap::RootListIndex root_value_index,
3189 const char* message) {
3190 ASSERT(!src.is(at));
3191 LoadRoot(at, root_value_index);
3192 Assert(eq, message, src, Operand(at));
3193 }
3194
3195
3196 void MacroAssembler::JumpIfNotHeapNumber(Register object,
3197 Register heap_number_map,
3198 Register scratch,
3199 Label* on_not_heap_number) {
3200 lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset));
3201 AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
3202 Branch(on_not_heap_number, ne, scratch, Operand(heap_number_map));
3203 }
3204
3205
3206 void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings(
3207 Register first,
3208 Register second,
3209 Register scratch1,
3210 Register scratch2,
3211 Label* failure) {
3212 // Test that both first and second are sequential ASCII strings.
3213 // Assume that they are non-smis.
3214 lw(scratch1, FieldMemOperand(first, HeapObject::kMapOffset));
3215 lw(scratch2, FieldMemOperand(second, HeapObject::kMapOffset));
3216 lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3217 lbu(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset));
3218
3219 JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1,
3220 scratch2,
3221 scratch1,
3222 scratch2,
3223 failure);
3224 }
3225
3226
3227 void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first,
3228 Register second,
3229 Register scratch1,
3230 Register scratch2,
3231 Label* failure) {
3232 // Check that neither is a smi.
3233 STATIC_ASSERT(kSmiTag == 0);
3234 And(scratch1, first, Operand(second));
3235 And(scratch1, scratch1, Operand(kSmiTagMask));
3236 Branch(failure, eq, scratch1, Operand(zero_reg));
3237 JumpIfNonSmisNotBothSequentialAsciiStrings(first,
3238 second,
3239 scratch1,
3240 scratch2,
3241 failure);
3242 }
3243
3244
3245 void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii(
3246 Register first,
3247 Register second,
3248 Register scratch1,
3249 Register scratch2,
3250 Label* failure) {
3251 int kFlatAsciiStringMask =
3252 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
3253 int kFlatAsciiStringTag = ASCII_STRING_TYPE;
3254 ASSERT(kFlatAsciiStringTag <= 0xffff); // Ensure this fits 16-bit immed.
3255 andi(scratch1, first, kFlatAsciiStringMask);
3256 Branch(failure, ne, scratch1, Operand(kFlatAsciiStringTag));
3257 andi(scratch2, second, kFlatAsciiStringMask);
3258 Branch(failure, ne, scratch2, Operand(kFlatAsciiStringTag));
3259 }
3260
3261
3262 void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type,
3263 Register scratch,
3264 Label* failure) {
3265 int kFlatAsciiStringMask =
3266 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask;
3267 int kFlatAsciiStringTag = ASCII_STRING_TYPE;
3268 And(scratch, type, Operand(kFlatAsciiStringMask));
3269 Branch(failure, ne, scratch, Operand(kFlatAsciiStringTag));
3270 }
3271
3272
3273 void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
3274 int frame_alignment = ActivationFrameAlignment();
3275 // Up to four simple arguments are passed in registers a0..a3.
3276 // Those four arguments must have reserved argument slots on the stack for
3277 // mips, even though those argument slots are not normally used.
3278 // Remaining arguments are pushed on the stack, above (higher address than)
3279 // the argument slots.
3280 ASSERT(StandardFrameConstants::kCArgsSlotsSize % kPointerSize == 0);
3281 int stack_passed_arguments = ((num_arguments <= 4) ? 0 : num_arguments - 4) +
3282 StandardFrameConstants::kCArgsSlotsSize /
3283 kPointerSize;
3284 if (frame_alignment > kPointerSize) {
3285 // Make stack end at alignment and make room for num_arguments - 4 words
3286 // and the original value of sp.
3287 mov(scratch, sp);
3288 Subu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
3289 ASSERT(IsPowerOf2(frame_alignment));
3290 And(sp, sp, Operand(-frame_alignment));
3291 sw(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
3292 } else {
3293 Subu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
3294 }
3295 }
3296
3297
3298 void MacroAssembler::CallCFunction(ExternalReference function,
3299 int num_arguments) {
3300 li(t9, Operand(function));
3301 CallCFunction(t9, num_arguments);
3302 }
3303
3304
3305 void MacroAssembler::CallCFunction(Register function, int num_arguments) {
3306 // Make sure that the stack is aligned before calling a C function unless
3307 // running in the simulator. The simulator has its own alignment check which
3308 // provides more information.
3309 // The argument stots are presumed to have been set up by
3310 // PrepareCallCFunction. The C function must be called via t9, for mips ABI.
3311 #if defined(V8_HOST_ARCH_MIPS)
3312 if (FLAG_debug_code) {
3313 int frame_alignment = OS::ActivationFrameAlignment();
3314 int frame_alignment_mask = frame_alignment - 1;
3315 if (frame_alignment > kPointerSize) {
3316 ASSERT(IsPowerOf2(frame_alignment));
3317 Label alignment_as_expected;
3318 And(at, sp, Operand(frame_alignment_mask));
3319 Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
3320 // Don't use Check here, as it will call Runtime_Abort possibly
3321 // re-entering here.
3322 stop("Unexpected alignment in CallCFunction");
3323 bind(&alignment_as_expected);
3324 }
3325 }
3326 #endif // V8_HOST_ARCH_MIPS
3327
3328 // Just call directly. The function called cannot cause a GC, or
3329 // allow preemption, so the return address in the link register
3330 // stays correct.
3331 if (!function.is(t9)) {
3332 mov(t9, function);
3333 }
3334 Call(t9);
3335
3336 ASSERT(StandardFrameConstants::kCArgsSlotsSize % kPointerSize == 0);
3337 int stack_passed_arguments = ((num_arguments <= 4) ? 0 : num_arguments - 4) +
3338 StandardFrameConstants::kCArgsSlotsSize /
3339 kPointerSize;
3340
3341 if (OS::ActivationFrameAlignment() > kPointerSize) {
3342 lw(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
3343 } else {
3344 Addu(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize)));
3345 }
3346 }
3347
3348
3349 #undef BRANCH_ARGS_CHECK
3350
3351
3352 #ifdef ENABLE_DEBUGGER_SUPPORT
3353 CodePatcher::CodePatcher(byte* address, int instructions)
3354 : address_(address),
3355 instructions_(instructions),
3356 size_(instructions * Assembler::kInstrSize),
3357 masm_(address, size_ + Assembler::kGap) {
3358 // Create a new macro assembler pointing to the address of the code to patch.
3359 // The size is adjusted with kGap on order for the assembler to generate size
3360 // bytes of instructions without failing with buffer size constraints.
3361 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
3362 }
3363
3364
3365 CodePatcher::~CodePatcher() {
3366 // Indicate that code has changed.
3367 CPU::FlushICache(address_, size_);
3368
3369 // Check that the code was patched as expected.
3370 ASSERT(masm_.pc_ == address_ + size_);
3371 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
3372 }
3373
3374
3375 void CodePatcher::Emit(Instr x) {
3376 masm()->emit(x);
3377 }
3378
3379
3380 void CodePatcher::Emit(Address addr) {
3381 masm()->emit(reinterpret_cast<Instr>(addr));
3382 }
3383
3384
3385 #endif // ENABLE_DEBUGGER_SUPPORT
3386
3387
1324 } } // namespace v8::internal 3388 } } // namespace v8::internal
1325 3389
1326 #endif // V8_TARGET_ARCH_MIPS 3390 #endif // V8_TARGET_ARCH_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698