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

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

Powered by Google App Engine
This is Rietveld 408576698