jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 28 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 29 | |
| 30 | #include "v8.h" |
| 31 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 32 | #if defined(V8_TARGET_ARCH_MIPS) |
| 33 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 34 | #include "bootstrapper.h" |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 35 | #include "codegen.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 36 | #include "debug.h" |
| 37 | #include "runtime.h" |
| 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 42 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 43 | : Assembler(arg_isolate, buffer, size), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 45 | allow_stub_calls_(true), |
| 46 | has_frame_(false) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 47 | if (isolate() != NULL) { |
| 48 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 49 | isolate()); |
| 50 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 54 | void MacroAssembler::LoadRoot(Register destination, |
| 55 | Heap::RootListIndex index) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 56 | lw(destination, MemOperand(s6, index << kPointerSizeLog2)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 57 | } |
| 58 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 59 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 60 | void MacroAssembler::LoadRoot(Register destination, |
| 61 | Heap::RootListIndex index, |
| 62 | Condition cond, |
| 63 | Register src1, const Operand& src2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 64 | Branch(2, NegateCondition(cond), src1, src2); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 65 | lw(destination, MemOperand(s6, index << kPointerSizeLog2)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 69 | void MacroAssembler::StoreRoot(Register source, |
| 70 | Heap::RootListIndex index) { |
| 71 | sw(source, MemOperand(s6, index << kPointerSizeLog2)); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void MacroAssembler::StoreRoot(Register source, |
| 76 | Heap::RootListIndex index, |
| 77 | Condition cond, |
| 78 | Register src1, const Operand& src2) { |
| 79 | Branch(2, NegateCondition(cond), src1, src2); |
| 80 | sw(source, MemOperand(s6, index << kPointerSizeLog2)); |
| 81 | } |
| 82 | |
| 83 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 84 | void MacroAssembler::LoadHeapObject(Register result, |
| 85 | Handle<HeapObject> object) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 86 | ALLOW_HANDLE_DEREF(isolate(), "using raw address"); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 87 | if (isolate()->heap()->InNewSpace(*object)) { |
| 88 | Handle<JSGlobalPropertyCell> cell = |
| 89 | isolate()->factory()->NewJSGlobalPropertyCell(object); |
| 90 | li(result, Operand(cell)); |
| 91 | lw(result, FieldMemOperand(result, JSGlobalPropertyCell::kValueOffset)); |
| 92 | } else { |
| 93 | li(result, Operand(object)); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 98 | // Push and pop all registers that can hold pointers. |
| 99 | void MacroAssembler::PushSafepointRegisters() { |
| 100 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 101 | // stack, so adjust the stack for unsaved registers. |
| 102 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 103 | ASSERT(num_unsaved >= 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 104 | if (num_unsaved > 0) { |
| 105 | Subu(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 106 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 107 | MultiPush(kSafepointSavedRegisters); |
| 108 | } |
| 109 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 110 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 111 | void MacroAssembler::PopSafepointRegisters() { |
| 112 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 113 | MultiPop(kSafepointSavedRegisters); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 114 | if (num_unsaved > 0) { |
| 115 | Addu(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 116 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 117 | } |
| 118 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 119 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 120 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
| 121 | PushSafepointRegisters(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 122 | Subu(sp, sp, Operand(FPURegister::NumAllocatableRegisters() * kDoubleSize)); |
| 123 | for (int i = 0; i < FPURegister::NumAllocatableRegisters(); i+=2) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 124 | FPURegister reg = FPURegister::FromAllocationIndex(i); |
| 125 | sdc1(reg, MemOperand(sp, i * kDoubleSize)); |
| 126 | } |
| 127 | } |
| 128 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 129 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 130 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 131 | for (int i = 0; i < FPURegister::NumAllocatableRegisters(); i+=2) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 132 | FPURegister reg = FPURegister::FromAllocationIndex(i); |
| 133 | ldc1(reg, MemOperand(sp, i * kDoubleSize)); |
| 134 | } |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 135 | Addu(sp, sp, Operand(FPURegister::NumAllocatableRegisters() * kDoubleSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 136 | PopSafepointRegisters(); |
| 137 | } |
| 138 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 139 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 140 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register src, |
| 141 | Register dst) { |
| 142 | sw(src, SafepointRegistersAndDoublesSlot(dst)); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | void MacroAssembler::StoreToSafepointRegisterSlot(Register src, Register dst) { |
| 147 | sw(src, SafepointRegisterSlot(dst)); |
| 148 | } |
| 149 | |
| 150 | |
| 151 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 152 | lw(dst, SafepointRegisterSlot(src)); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 157 | // The registers are pushed starting with the highest encoding, |
| 158 | // which means that lowest encodings are closest to the stack pointer. |
| 159 | return kSafepointRegisterStackIndexMap[reg_code]; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 164 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 169 | UNIMPLEMENTED_MIPS(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 170 | // General purpose registers are pushed last on the stack. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 171 | int doubles_size = FPURegister::NumAllocatableRegisters() * kDoubleSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 172 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 173 | return MemOperand(sp, doubles_size + register_offset); |
| 174 | } |
| 175 | |
| 176 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 177 | void MacroAssembler::InNewSpace(Register object, |
| 178 | Register scratch, |
| 179 | Condition cc, |
| 180 | Label* branch) { |
| 181 | ASSERT(cc == eq || cc == ne); |
| 182 | And(scratch, object, Operand(ExternalReference::new_space_mask(isolate()))); |
| 183 | Branch(branch, cc, scratch, |
| 184 | Operand(ExternalReference::new_space_start(isolate()))); |
| 185 | } |
| 186 | |
| 187 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 188 | void MacroAssembler::RecordWriteField( |
| 189 | Register object, |
| 190 | int offset, |
| 191 | Register value, |
| 192 | Register dst, |
| 193 | RAStatus ra_status, |
| 194 | SaveFPRegsMode save_fp, |
| 195 | RememberedSetAction remembered_set_action, |
| 196 | SmiCheck smi_check) { |
| 197 | ASSERT(!AreAliased(value, dst, t8, object)); |
| 198 | // First, check if a write barrier is even needed. The tests below |
| 199 | // catch stores of Smis. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 200 | Label done; |
| 201 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 202 | // Skip barrier if writing a smi. |
| 203 | if (smi_check == INLINE_SMI_CHECK) { |
| 204 | JumpIfSmi(value, &done); |
| 205 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 206 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 207 | // Although the object register is tagged, the offset is relative to the start |
| 208 | // of the object, so so offset must be a multiple of kPointerSize. |
| 209 | ASSERT(IsAligned(offset, kPointerSize)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 210 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 211 | Addu(dst, object, Operand(offset - kHeapObjectTag)); |
| 212 | if (emit_debug_code()) { |
| 213 | Label ok; |
| 214 | And(t8, dst, Operand((1 << kPointerSizeLog2) - 1)); |
| 215 | Branch(&ok, eq, t8, Operand(zero_reg)); |
| 216 | stop("Unaligned cell in write barrier"); |
| 217 | bind(&ok); |
| 218 | } |
| 219 | |
| 220 | RecordWrite(object, |
| 221 | dst, |
| 222 | value, |
| 223 | ra_status, |
| 224 | save_fp, |
| 225 | remembered_set_action, |
| 226 | OMIT_SMI_CHECK); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 227 | |
| 228 | bind(&done); |
| 229 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 230 | // Clobber clobbered input registers when running with the debug-code flag |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 231 | // turned on to provoke errors. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 232 | if (emit_debug_code()) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 233 | li(value, Operand(BitCast<int32_t>(kZapValue + 4))); |
| 234 | li(dst, Operand(BitCast<int32_t>(kZapValue + 8))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
| 238 | |
| 239 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 240 | // register 'object' contains a heap object pointer. The heap object |
| 241 | // tag is shifted away. |
| 242 | void MacroAssembler::RecordWrite(Register object, |
| 243 | Register address, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 244 | Register value, |
| 245 | RAStatus ra_status, |
| 246 | SaveFPRegsMode fp_mode, |
| 247 | RememberedSetAction remembered_set_action, |
| 248 | SmiCheck smi_check) { |
| 249 | ASSERT(!AreAliased(object, address, value, t8)); |
| 250 | ASSERT(!AreAliased(object, address, value, t9)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 251 | // The compiled code assumes that record write doesn't change the |
| 252 | // context register, so we check that none of the clobbered |
| 253 | // registers are cp. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 254 | ASSERT(!address.is(cp) && !value.is(cp)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 255 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 256 | if (emit_debug_code()) { |
| 257 | lw(at, MemOperand(address)); |
| 258 | Assert( |
| 259 | eq, "Wrong address or value passed to RecordWrite", at, Operand(value)); |
| 260 | } |
| 261 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 262 | Label done; |
| 263 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 264 | if (smi_check == INLINE_SMI_CHECK) { |
| 265 | ASSERT_EQ(0, kSmiTag); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 266 | JumpIfSmi(value, &done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | CheckPageFlag(value, |
| 270 | value, // Used as scratch. |
| 271 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 272 | eq, |
| 273 | &done); |
| 274 | CheckPageFlag(object, |
| 275 | value, // Used as scratch. |
| 276 | MemoryChunk::kPointersFromHereAreInterestingMask, |
| 277 | eq, |
| 278 | &done); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 279 | |
| 280 | // Record the actual write. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 281 | if (ra_status == kRAHasNotBeenSaved) { |
| 282 | push(ra); |
| 283 | } |
| 284 | RecordWriteStub stub(object, value, address, remembered_set_action, fp_mode); |
| 285 | CallStub(&stub); |
| 286 | if (ra_status == kRAHasNotBeenSaved) { |
| 287 | pop(ra); |
| 288 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 289 | |
| 290 | bind(&done); |
| 291 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 292 | // Clobber clobbered registers when running with the debug-code flag |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 293 | // turned on to provoke errors. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 294 | if (emit_debug_code()) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 295 | li(address, Operand(BitCast<int32_t>(kZapValue + 12))); |
| 296 | li(value, Operand(BitCast<int32_t>(kZapValue + 16))); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. |
| 302 | Register address, |
| 303 | Register scratch, |
| 304 | SaveFPRegsMode fp_mode, |
| 305 | RememberedSetFinalAction and_then) { |
| 306 | Label done; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 307 | if (emit_debug_code()) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 308 | Label ok; |
| 309 | JumpIfNotInNewSpace(object, scratch, &ok); |
| 310 | stop("Remembered set pointer is in new space"); |
| 311 | bind(&ok); |
| 312 | } |
| 313 | // Load store buffer top. |
| 314 | ExternalReference store_buffer = |
| 315 | ExternalReference::store_buffer_top(isolate()); |
| 316 | li(t8, Operand(store_buffer)); |
| 317 | lw(scratch, MemOperand(t8)); |
| 318 | // Store pointer to buffer and increment buffer top. |
| 319 | sw(address, MemOperand(scratch)); |
| 320 | Addu(scratch, scratch, kPointerSize); |
| 321 | // Write back new top of buffer. |
| 322 | sw(scratch, MemOperand(t8)); |
| 323 | // Call stub on end of buffer. |
| 324 | // Check for end of buffer. |
| 325 | And(t8, scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); |
| 326 | if (and_then == kFallThroughAtEnd) { |
| 327 | Branch(&done, eq, t8, Operand(zero_reg)); |
| 328 | } else { |
| 329 | ASSERT(and_then == kReturnAtEnd); |
| 330 | Ret(eq, t8, Operand(zero_reg)); |
| 331 | } |
| 332 | push(ra); |
| 333 | StoreBufferOverflowStub store_buffer_overflow = |
| 334 | StoreBufferOverflowStub(fp_mode); |
| 335 | CallStub(&store_buffer_overflow); |
| 336 | pop(ra); |
| 337 | bind(&done); |
| 338 | if (and_then == kReturnAtEnd) { |
| 339 | Ret(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
| 343 | |
| 344 | // ----------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 345 | // Allocation support. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 346 | |
| 347 | |
| 348 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 349 | Register scratch, |
| 350 | Label* miss) { |
| 351 | Label same_contexts; |
| 352 | |
| 353 | ASSERT(!holder_reg.is(scratch)); |
| 354 | ASSERT(!holder_reg.is(at)); |
| 355 | ASSERT(!scratch.is(at)); |
| 356 | |
| 357 | // Load current lexical context from the stack frame. |
| 358 | lw(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 359 | // In debug mode, make sure the lexical context is set. |
| 360 | #ifdef DEBUG |
| 361 | Check(ne, "we should not have an empty lexical context", |
| 362 | scratch, Operand(zero_reg)); |
| 363 | #endif |
| 364 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 365 | // Load the native context of the current context. |
| 366 | int offset = |
| 367 | Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 368 | lw(scratch, FieldMemOperand(scratch, offset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 369 | lw(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 370 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 371 | // Check the context is a native context. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 372 | if (emit_debug_code()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 373 | push(holder_reg); // Temporarily save holder on the stack. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 374 | // Read the first word and compare to the native_context_map. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 375 | lw(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 376 | LoadRoot(at, Heap::kNativeContextMapRootIndex); |
| 377 | Check(eq, "JSGlobalObject::native_context should be a native context.", |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 378 | holder_reg, Operand(at)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 379 | pop(holder_reg); // Restore holder. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Check if both contexts are the same. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 383 | lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 384 | Branch(&same_contexts, eq, scratch, Operand(at)); |
| 385 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 386 | // Check the context is a native context. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 387 | if (emit_debug_code()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 388 | push(holder_reg); // Temporarily save holder on the stack. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 389 | mov(holder_reg, at); // Move at to its holding place. |
| 390 | LoadRoot(at, Heap::kNullValueRootIndex); |
| 391 | Check(ne, "JSGlobalProxy::context() should not be null.", |
| 392 | holder_reg, Operand(at)); |
| 393 | |
| 394 | lw(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 395 | LoadRoot(at, Heap::kNativeContextMapRootIndex); |
| 396 | Check(eq, "JSGlobalObject::native_context should be a native context.", |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 397 | holder_reg, Operand(at)); |
| 398 | // Restore at is not needed. at is reloaded below. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 399 | pop(holder_reg); // Restore holder. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 400 | // Restore at to holder's context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 401 | lw(at, FieldMemOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // Check that the security token in the calling global object is |
| 405 | // compatible with the security token in the receiving global |
| 406 | // object. |
| 407 | int token_offset = Context::kHeaderSize + |
| 408 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 409 | |
| 410 | lw(scratch, FieldMemOperand(scratch, token_offset)); |
| 411 | lw(at, FieldMemOperand(at, token_offset)); |
| 412 | Branch(miss, ne, scratch, Operand(at)); |
| 413 | |
| 414 | bind(&same_contexts); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 418 | void MacroAssembler::GetNumberHash(Register reg0, Register scratch) { |
| 419 | // First of all we assign the hash seed to scratch. |
| 420 | LoadRoot(scratch, Heap::kHashSeedRootIndex); |
| 421 | SmiUntag(scratch); |
| 422 | |
| 423 | // Xor original key with a seed. |
| 424 | xor_(reg0, reg0, scratch); |
| 425 | |
| 426 | // Compute the hash code from the untagged key. This must be kept in sync |
| 427 | // with ComputeIntegerHash in utils.h. |
| 428 | // |
| 429 | // hash = ~hash + (hash << 15); |
| 430 | nor(scratch, reg0, zero_reg); |
| 431 | sll(at, reg0, 15); |
| 432 | addu(reg0, scratch, at); |
| 433 | |
| 434 | // hash = hash ^ (hash >> 12); |
| 435 | srl(at, reg0, 12); |
| 436 | xor_(reg0, reg0, at); |
| 437 | |
| 438 | // hash = hash + (hash << 2); |
| 439 | sll(at, reg0, 2); |
| 440 | addu(reg0, reg0, at); |
| 441 | |
| 442 | // hash = hash ^ (hash >> 4); |
| 443 | srl(at, reg0, 4); |
| 444 | xor_(reg0, reg0, at); |
| 445 | |
| 446 | // hash = hash * 2057; |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 447 | sll(scratch, reg0, 11); |
| 448 | sll(at, reg0, 3); |
| 449 | addu(reg0, reg0, at); |
| 450 | addu(reg0, reg0, scratch); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 451 | |
| 452 | // hash = hash ^ (hash >> 16); |
| 453 | srl(at, reg0, 16); |
| 454 | xor_(reg0, reg0, at); |
| 455 | } |
| 456 | |
| 457 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 458 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 459 | Register elements, |
| 460 | Register key, |
| 461 | Register result, |
| 462 | Register reg0, |
| 463 | Register reg1, |
| 464 | Register reg2) { |
| 465 | // Register use: |
| 466 | // |
| 467 | // elements - holds the slow-case elements of the receiver on entry. |
| 468 | // Unchanged unless 'result' is the same register. |
| 469 | // |
| 470 | // key - holds the smi key on entry. |
| 471 | // Unchanged unless 'result' is the same register. |
| 472 | // |
| 473 | // |
| 474 | // result - holds the result on exit if the load succeeded. |
| 475 | // Allowed to be the same as 'key' or 'result'. |
| 476 | // Unchanged on bailout so 'key' or 'result' can be used |
| 477 | // in further computation. |
| 478 | // |
| 479 | // Scratch registers: |
| 480 | // |
| 481 | // reg0 - holds the untagged key on entry and holds the hash once computed. |
| 482 | // |
| 483 | // reg1 - Used to hold the capacity mask of the dictionary. |
| 484 | // |
| 485 | // reg2 - Used for the index into the dictionary. |
| 486 | // at - Temporary (avoid MacroAssembler instructions also using 'at'). |
| 487 | Label done; |
| 488 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 489 | GetNumberHash(reg0, reg1); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 490 | |
| 491 | // Compute the capacity mask. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 492 | lw(reg1, FieldMemOperand(elements, SeededNumberDictionary::kCapacityOffset)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 493 | sra(reg1, reg1, kSmiTagSize); |
| 494 | Subu(reg1, reg1, Operand(1)); |
| 495 | |
| 496 | // Generate an unrolled loop that performs a few probes before giving up. |
| 497 | static const int kProbes = 4; |
| 498 | for (int i = 0; i < kProbes; i++) { |
| 499 | // Use reg2 for index calculations and keep the hash intact in reg0. |
| 500 | mov(reg2, reg0); |
| 501 | // Compute the masked index: (hash + i + i * i) & mask. |
| 502 | if (i > 0) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 503 | Addu(reg2, reg2, Operand(SeededNumberDictionary::GetProbeOffset(i))); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 504 | } |
| 505 | and_(reg2, reg2, reg1); |
| 506 | |
| 507 | // Scale the index by multiplying by the element size. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 508 | ASSERT(SeededNumberDictionary::kEntrySize == 3); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 509 | sll(at, reg2, 1); // 2x. |
| 510 | addu(reg2, reg2, at); // reg2 = reg2 * 3. |
| 511 | |
| 512 | // Check if the key is identical to the name. |
| 513 | sll(at, reg2, kPointerSizeLog2); |
| 514 | addu(reg2, elements, at); |
| 515 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 516 | lw(at, FieldMemOperand(reg2, SeededNumberDictionary::kElementsStartOffset)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 517 | if (i != kProbes - 1) { |
| 518 | Branch(&done, eq, key, Operand(at)); |
| 519 | } else { |
| 520 | Branch(miss, ne, key, Operand(at)); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | bind(&done); |
| 525 | // Check that the value is a normal property. |
| 526 | // reg2: elements + (index * kPointerSize). |
| 527 | const int kDetailsOffset = |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 528 | SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 529 | lw(reg1, FieldMemOperand(reg2, kDetailsOffset)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 530 | And(at, reg1, Operand(Smi::FromInt(PropertyDetails::TypeField::kMask))); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 531 | Branch(miss, ne, at, Operand(zero_reg)); |
| 532 | |
| 533 | // Get the value at the masked, scaled index and return. |
| 534 | const int kValueOffset = |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 535 | SeededNumberDictionary::kElementsStartOffset + kPointerSize; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 536 | lw(result, FieldMemOperand(reg2, kValueOffset)); |
| 537 | } |
| 538 | |
| 539 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 540 | // --------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 541 | // Instruction macros. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 542 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 543 | void MacroAssembler::Addu(Register rd, Register rs, const Operand& rt) { |
| 544 | if (rt.is_reg()) { |
| 545 | addu(rd, rs, rt.rm()); |
| 546 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 547 | if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 548 | addiu(rd, rs, rt.imm32_); |
| 549 | } else { |
| 550 | // li handles the relocation. |
| 551 | ASSERT(!rs.is(at)); |
| 552 | li(at, rt); |
| 553 | addu(rd, rs, at); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 559 | void MacroAssembler::Subu(Register rd, Register rs, const Operand& rt) { |
| 560 | if (rt.is_reg()) { |
| 561 | subu(rd, rs, rt.rm()); |
| 562 | } else { |
| 563 | if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
| 564 | addiu(rd, rs, -rt.imm32_); // No subiu instr, use addiu(x, y, -imm). |
| 565 | } else { |
| 566 | // li handles the relocation. |
| 567 | ASSERT(!rs.is(at)); |
| 568 | li(at, rt); |
| 569 | subu(rd, rs, at); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 575 | void MacroAssembler::Mul(Register rd, Register rs, const Operand& rt) { |
| 576 | if (rt.is_reg()) { |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 577 | if (kArchVariant == kLoongson) { |
| 578 | mult(rs, rt.rm()); |
| 579 | mflo(rd); |
| 580 | } else { |
| 581 | mul(rd, rs, rt.rm()); |
| 582 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 583 | } else { |
| 584 | // li handles the relocation. |
| 585 | ASSERT(!rs.is(at)); |
| 586 | li(at, rt); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 587 | if (kArchVariant == kLoongson) { |
| 588 | mult(rs, at); |
| 589 | mflo(rd); |
| 590 | } else { |
| 591 | mul(rd, rs, at); |
| 592 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
| 596 | |
| 597 | void MacroAssembler::Mult(Register rs, const Operand& rt) { |
| 598 | if (rt.is_reg()) { |
| 599 | mult(rs, rt.rm()); |
| 600 | } else { |
| 601 | // li handles the relocation. |
| 602 | ASSERT(!rs.is(at)); |
| 603 | li(at, rt); |
| 604 | mult(rs, at); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | |
| 609 | void MacroAssembler::Multu(Register rs, const Operand& rt) { |
| 610 | if (rt.is_reg()) { |
| 611 | multu(rs, rt.rm()); |
| 612 | } else { |
| 613 | // li handles the relocation. |
| 614 | ASSERT(!rs.is(at)); |
| 615 | li(at, rt); |
| 616 | multu(rs, at); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | |
| 621 | void MacroAssembler::Div(Register rs, const Operand& rt) { |
| 622 | if (rt.is_reg()) { |
| 623 | div(rs, rt.rm()); |
| 624 | } else { |
| 625 | // li handles the relocation. |
| 626 | ASSERT(!rs.is(at)); |
| 627 | li(at, rt); |
| 628 | div(rs, at); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | |
| 633 | void MacroAssembler::Divu(Register rs, const Operand& rt) { |
| 634 | if (rt.is_reg()) { |
| 635 | divu(rs, rt.rm()); |
| 636 | } else { |
| 637 | // li handles the relocation. |
| 638 | ASSERT(!rs.is(at)); |
| 639 | li(at, rt); |
| 640 | divu(rs, at); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | |
| 645 | void MacroAssembler::And(Register rd, Register rs, const Operand& rt) { |
| 646 | if (rt.is_reg()) { |
| 647 | and_(rd, rs, rt.rm()); |
| 648 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 649 | if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 650 | andi(rd, rs, rt.imm32_); |
| 651 | } else { |
| 652 | // li handles the relocation. |
| 653 | ASSERT(!rs.is(at)); |
| 654 | li(at, rt); |
| 655 | and_(rd, rs, at); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | |
| 661 | void MacroAssembler::Or(Register rd, Register rs, const Operand& rt) { |
| 662 | if (rt.is_reg()) { |
| 663 | or_(rd, rs, rt.rm()); |
| 664 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 665 | if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 666 | ori(rd, rs, rt.imm32_); |
| 667 | } else { |
| 668 | // li handles the relocation. |
| 669 | ASSERT(!rs.is(at)); |
| 670 | li(at, rt); |
| 671 | or_(rd, rs, at); |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | |
| 677 | void MacroAssembler::Xor(Register rd, Register rs, const Operand& rt) { |
| 678 | if (rt.is_reg()) { |
| 679 | xor_(rd, rs, rt.rm()); |
| 680 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 681 | if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 682 | xori(rd, rs, rt.imm32_); |
| 683 | } else { |
| 684 | // li handles the relocation. |
| 685 | ASSERT(!rs.is(at)); |
| 686 | li(at, rt); |
| 687 | xor_(rd, rs, at); |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | |
| 693 | void MacroAssembler::Nor(Register rd, Register rs, const Operand& rt) { |
| 694 | if (rt.is_reg()) { |
| 695 | nor(rd, rs, rt.rm()); |
| 696 | } else { |
| 697 | // li handles the relocation. |
| 698 | ASSERT(!rs.is(at)); |
| 699 | li(at, rt); |
| 700 | nor(rd, rs, at); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 705 | void MacroAssembler::Neg(Register rs, const Operand& rt) { |
| 706 | ASSERT(rt.is_reg()); |
| 707 | ASSERT(!at.is(rs)); |
| 708 | ASSERT(!at.is(rt.rm())); |
| 709 | li(at, -1); |
| 710 | xor_(rs, rt.rm(), at); |
| 711 | } |
| 712 | |
| 713 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 714 | void MacroAssembler::Slt(Register rd, Register rs, const Operand& rt) { |
| 715 | if (rt.is_reg()) { |
| 716 | slt(rd, rs, rt.rm()); |
| 717 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 718 | if (is_int16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 719 | slti(rd, rs, rt.imm32_); |
| 720 | } else { |
| 721 | // li handles the relocation. |
| 722 | ASSERT(!rs.is(at)); |
| 723 | li(at, rt); |
| 724 | slt(rd, rs, at); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | |
| 730 | void MacroAssembler::Sltu(Register rd, Register rs, const Operand& rt) { |
| 731 | if (rt.is_reg()) { |
| 732 | sltu(rd, rs, rt.rm()); |
| 733 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 734 | if (is_uint16(rt.imm32_) && !MustUseReg(rt.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 735 | sltiu(rd, rs, rt.imm32_); |
| 736 | } else { |
| 737 | // li handles the relocation. |
| 738 | ASSERT(!rs.is(at)); |
| 739 | li(at, rt); |
| 740 | sltu(rd, rs, at); |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 746 | void MacroAssembler::Ror(Register rd, Register rs, const Operand& rt) { |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 747 | if (kArchVariant == kMips32r2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 748 | if (rt.is_reg()) { |
| 749 | rotrv(rd, rs, rt.rm()); |
| 750 | } else { |
| 751 | rotr(rd, rs, rt.imm32_); |
| 752 | } |
| 753 | } else { |
| 754 | if (rt.is_reg()) { |
| 755 | subu(at, zero_reg, rt.rm()); |
| 756 | sllv(at, rs, at); |
| 757 | srlv(rd, rs, rt.rm()); |
| 758 | or_(rd, rd, at); |
| 759 | } else { |
| 760 | if (rt.imm32_ == 0) { |
| 761 | srl(rd, rs, 0); |
| 762 | } else { |
| 763 | srl(at, rs, rt.imm32_); |
| 764 | sll(rd, rs, (0x20 - rt.imm32_) & 0x1f); |
| 765 | or_(rd, rd, at); |
| 766 | } |
| 767 | } |
| 768 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 769 | } |
| 770 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 771 | //------------Pseudo-instructions------------- |
| 772 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 773 | void MacroAssembler::li(Register rd, Operand j, LiFlags mode) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 774 | ASSERT(!j.is_reg()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 775 | BlockTrampolinePoolScope block_trampoline_pool(this); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 776 | if (!MustUseReg(j.rmode_) && mode == OPTIMIZE_SIZE) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 777 | // Normal load of an immediate value which does not need Relocation Info. |
| 778 | if (is_int16(j.imm32_)) { |
| 779 | addiu(rd, zero_reg, j.imm32_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 780 | } else if (!(j.imm32_ & kHiMask)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 781 | ori(rd, zero_reg, j.imm32_); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 782 | } else if (!(j.imm32_ & kImm16Mask)) { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 783 | lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 784 | } else { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 785 | lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 786 | ori(rd, rd, (j.imm32_ & kImm16Mask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 787 | } |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 788 | } else { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 789 | if (MustUseReg(j.rmode_)) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 790 | RecordRelocInfo(j.rmode_, j.imm32_); |
| 791 | } |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 792 | // We always need the same number of instructions as we may need to patch |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 793 | // this code to load another value which may need 2 instructions to load. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 794 | lui(rd, (j.imm32_ >> kLuiShift) & kImm16Mask); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 795 | ori(rd, rd, (j.imm32_ & kImm16Mask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 800 | void MacroAssembler::MultiPush(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 801 | int16_t num_to_push = NumberOfBitsSet(regs); |
| 802 | int16_t stack_offset = num_to_push * kPointerSize; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 803 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 804 | Subu(sp, sp, Operand(stack_offset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 805 | for (int16_t i = kNumRegisters - 1; i >= 0; i--) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 806 | if ((regs & (1 << i)) != 0) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 807 | stack_offset -= kPointerSize; |
| 808 | sw(ToRegister(i), MemOperand(sp, stack_offset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | |
| 814 | void MacroAssembler::MultiPushReversed(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 815 | int16_t num_to_push = NumberOfBitsSet(regs); |
| 816 | int16_t stack_offset = num_to_push * kPointerSize; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 817 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 818 | Subu(sp, sp, Operand(stack_offset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 819 | for (int16_t i = 0; i < kNumRegisters; i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 820 | if ((regs & (1 << i)) != 0) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 821 | stack_offset -= kPointerSize; |
| 822 | sw(ToRegister(i), MemOperand(sp, stack_offset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | |
| 828 | void MacroAssembler::MultiPop(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 829 | int16_t stack_offset = 0; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 830 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 831 | for (int16_t i = 0; i < kNumRegisters; i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 832 | if ((regs & (1 << i)) != 0) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 833 | lw(ToRegister(i), MemOperand(sp, stack_offset)); |
| 834 | stack_offset += kPointerSize; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 837 | addiu(sp, sp, stack_offset); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | |
| 841 | void MacroAssembler::MultiPopReversed(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 842 | int16_t stack_offset = 0; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 843 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 844 | for (int16_t i = kNumRegisters - 1; i >= 0; i--) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 845 | if ((regs & (1 << i)) != 0) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 846 | lw(ToRegister(i), MemOperand(sp, stack_offset)); |
| 847 | stack_offset += kPointerSize; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 848 | } |
| 849 | } |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 850 | addiu(sp, sp, stack_offset); |
| 851 | } |
| 852 | |
| 853 | |
| 854 | void MacroAssembler::MultiPushFPU(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 855 | int16_t num_to_push = NumberOfBitsSet(regs); |
| 856 | int16_t stack_offset = num_to_push * kDoubleSize; |
| 857 | |
| 858 | Subu(sp, sp, Operand(stack_offset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 859 | for (int16_t i = kNumRegisters - 1; i >= 0; i--) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 860 | if ((regs & (1 << i)) != 0) { |
| 861 | stack_offset -= kDoubleSize; |
| 862 | sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset)); |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | |
| 868 | void MacroAssembler::MultiPushReversedFPU(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 869 | int16_t num_to_push = NumberOfBitsSet(regs); |
| 870 | int16_t stack_offset = num_to_push * kDoubleSize; |
| 871 | |
| 872 | Subu(sp, sp, Operand(stack_offset)); |
| 873 | for (int16_t i = 0; i < kNumRegisters; i++) { |
| 874 | if ((regs & (1 << i)) != 0) { |
| 875 | stack_offset -= kDoubleSize; |
| 876 | sdc1(FPURegister::from_code(i), MemOperand(sp, stack_offset)); |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | |
| 882 | void MacroAssembler::MultiPopFPU(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 883 | int16_t stack_offset = 0; |
| 884 | |
| 885 | for (int16_t i = 0; i < kNumRegisters; i++) { |
| 886 | if ((regs & (1 << i)) != 0) { |
| 887 | ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset)); |
| 888 | stack_offset += kDoubleSize; |
| 889 | } |
| 890 | } |
| 891 | addiu(sp, sp, stack_offset); |
| 892 | } |
| 893 | |
| 894 | |
| 895 | void MacroAssembler::MultiPopReversedFPU(RegList regs) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 896 | int16_t stack_offset = 0; |
| 897 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 898 | for (int16_t i = kNumRegisters - 1; i >= 0; i--) { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 899 | if ((regs & (1 << i)) != 0) { |
| 900 | ldc1(FPURegister::from_code(i), MemOperand(sp, stack_offset)); |
| 901 | stack_offset += kDoubleSize; |
| 902 | } |
| 903 | } |
| 904 | addiu(sp, sp, stack_offset); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 908 | void MacroAssembler::FlushICache(Register address, unsigned instructions) { |
| 909 | RegList saved_regs = kJSCallerSaved | ra.bit(); |
| 910 | MultiPush(saved_regs); |
| 911 | AllowExternalCallThatCantCauseGC scope(this); |
| 912 | |
| 913 | // Save to a0 in case address == t0. |
| 914 | Move(a0, address); |
| 915 | PrepareCallCFunction(2, t0); |
| 916 | |
| 917 | li(a1, instructions * kInstrSize); |
| 918 | CallCFunction(ExternalReference::flush_icache_function(isolate()), 2); |
| 919 | MultiPop(saved_regs); |
| 920 | } |
| 921 | |
| 922 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 923 | void MacroAssembler::Ext(Register rt, |
| 924 | Register rs, |
| 925 | uint16_t pos, |
| 926 | uint16_t size) { |
| 927 | ASSERT(pos < 32); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 928 | ASSERT(pos + size < 33); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 929 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 930 | if (kArchVariant == kMips32r2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 931 | ext_(rt, rs, pos, size); |
| 932 | } else { |
| 933 | // Move rs to rt and shift it left then right to get the |
| 934 | // desired bitfield on the right side and zeroes on the left. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 935 | int shift_left = 32 - (pos + size); |
| 936 | sll(rt, rs, shift_left); // Acts as a move if shift_left == 0. |
| 937 | |
| 938 | int shift_right = 32 - size; |
| 939 | if (shift_right > 0) { |
| 940 | srl(rt, rt, shift_right); |
| 941 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
| 945 | |
| 946 | void MacroAssembler::Ins(Register rt, |
| 947 | Register rs, |
| 948 | uint16_t pos, |
| 949 | uint16_t size) { |
| 950 | ASSERT(pos < 32); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 951 | ASSERT(pos + size <= 32); |
| 952 | ASSERT(size != 0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 953 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 954 | if (kArchVariant == kMips32r2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 955 | ins_(rt, rs, pos, size); |
| 956 | } else { |
| 957 | ASSERT(!rt.is(t8) && !rs.is(t8)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 958 | Subu(at, zero_reg, Operand(1)); |
| 959 | srl(at, at, 32 - size); |
| 960 | and_(t8, rs, at); |
| 961 | sll(t8, t8, pos); |
| 962 | sll(at, at, pos); |
| 963 | nor(at, at, zero_reg); |
| 964 | and_(at, rt, at); |
| 965 | or_(rt, t8, at); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 970 | void MacroAssembler::Cvt_d_uw(FPURegister fd, |
| 971 | FPURegister fs, |
| 972 | FPURegister scratch) { |
| 973 | // Move the data from fs to t8. |
| 974 | mfc1(t8, fs); |
| 975 | Cvt_d_uw(fd, t8, scratch); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 979 | void MacroAssembler::Cvt_d_uw(FPURegister fd, |
| 980 | Register rs, |
| 981 | FPURegister scratch) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 982 | // Convert rs to a FP value in fd (and fd + 1). |
| 983 | // We do this by converting rs minus the MSB to avoid sign conversion, |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 984 | // then adding 2^31 to the result (if needed). |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 985 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 986 | ASSERT(!fd.is(scratch)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 987 | ASSERT(!rs.is(t9)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 988 | ASSERT(!rs.is(at)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 989 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 990 | // Save rs's MSB to t9. |
| 991 | Ext(t9, rs, 31, 1); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 992 | // Remove rs's MSB. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 993 | Ext(at, rs, 0, 31); |
| 994 | // Move the result to fd. |
| 995 | mtc1(at, fd); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 996 | |
| 997 | // Convert fd to a real FP value. |
| 998 | cvt_d_w(fd, fd); |
| 999 | |
| 1000 | Label conversion_done; |
| 1001 | |
| 1002 | // If rs's MSB was 0, it's done. |
| 1003 | // Otherwise we need to add that to the FP register. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1004 | Branch(&conversion_done, eq, t9, Operand(zero_reg)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1005 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1006 | // Load 2^31 into f20 as its float representation. |
| 1007 | li(at, 0x41E00000); |
| 1008 | mtc1(at, FPURegister::from_code(scratch.code() + 1)); |
| 1009 | mtc1(zero_reg, scratch); |
| 1010 | // Add it to fd. |
| 1011 | add_d(fd, fd, scratch); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1012 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1013 | bind(&conversion_done); |
| 1014 | } |
| 1015 | |
| 1016 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1017 | void MacroAssembler::Trunc_uw_d(FPURegister fd, |
| 1018 | FPURegister fs, |
| 1019 | FPURegister scratch) { |
| 1020 | Trunc_uw_d(fs, t8, scratch); |
| 1021 | mtc1(t8, fd); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1024 | void MacroAssembler::Trunc_w_d(FPURegister fd, FPURegister fs) { |
| 1025 | if (kArchVariant == kLoongson && fd.is(fs)) { |
| 1026 | mfc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1027 | trunc_w_d(fd, fs); |
| 1028 | mtc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1029 | } else { |
| 1030 | trunc_w_d(fd, fs); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | void MacroAssembler::Round_w_d(FPURegister fd, FPURegister fs) { |
| 1035 | if (kArchVariant == kLoongson && fd.is(fs)) { |
| 1036 | mfc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1037 | round_w_d(fd, fs); |
| 1038 | mtc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1039 | } else { |
| 1040 | round_w_d(fd, fs); |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void MacroAssembler::Floor_w_d(FPURegister fd, FPURegister fs) { |
| 1046 | if (kArchVariant == kLoongson && fd.is(fs)) { |
| 1047 | mfc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1048 | floor_w_d(fd, fs); |
| 1049 | mtc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1050 | } else { |
| 1051 | floor_w_d(fd, fs); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | void MacroAssembler::Ceil_w_d(FPURegister fd, FPURegister fs) { |
| 1057 | if (kArchVariant == kLoongson && fd.is(fs)) { |
| 1058 | mfc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1059 | ceil_w_d(fd, fs); |
| 1060 | mtc1(t8, FPURegister::from_code(fs.code() + 1)); |
| 1061 | } else { |
| 1062 | ceil_w_d(fd, fs); |
| 1063 | } |
| 1064 | } |
| 1065 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1066 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1067 | void MacroAssembler::Trunc_uw_d(FPURegister fd, |
| 1068 | Register rs, |
| 1069 | FPURegister scratch) { |
| 1070 | ASSERT(!fd.is(scratch)); |
| 1071 | ASSERT(!rs.is(at)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1072 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1073 | // Load 2^31 into scratch as its float representation. |
| 1074 | li(at, 0x41E00000); |
| 1075 | mtc1(at, FPURegister::from_code(scratch.code() + 1)); |
| 1076 | mtc1(zero_reg, scratch); |
| 1077 | // Test if scratch > fd. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1078 | // If fd < 2^31 we can convert it normally. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1079 | Label simple_convert; |
| 1080 | BranchF(&simple_convert, NULL, lt, fd, scratch); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1081 | |
| 1082 | // First we subtract 2^31 from fd, then trunc it to rs |
| 1083 | // and add 2^31 to rs. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1084 | sub_d(scratch, fd, scratch); |
| 1085 | trunc_w_d(scratch, scratch); |
| 1086 | mfc1(rs, scratch); |
| 1087 | Or(rs, rs, 1 << 31); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1088 | |
| 1089 | Label done; |
| 1090 | Branch(&done); |
| 1091 | // Simple conversion. |
| 1092 | bind(&simple_convert); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1093 | trunc_w_d(scratch, fd); |
| 1094 | mfc1(rs, scratch); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1095 | |
| 1096 | bind(&done); |
| 1097 | } |
| 1098 | |
| 1099 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1100 | void MacroAssembler::BranchF(Label* target, |
| 1101 | Label* nan, |
| 1102 | Condition cc, |
| 1103 | FPURegister cmp1, |
| 1104 | FPURegister cmp2, |
| 1105 | BranchDelaySlot bd) { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1106 | BlockTrampolinePoolScope block_trampoline_pool(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1107 | if (cc == al) { |
| 1108 | Branch(bd, target); |
| 1109 | return; |
| 1110 | } |
| 1111 | |
| 1112 | ASSERT(nan || target); |
| 1113 | // Check for unordered (NaN) cases. |
| 1114 | if (nan) { |
| 1115 | c(UN, D, cmp1, cmp2); |
| 1116 | bc1t(nan); |
| 1117 | } |
| 1118 | |
| 1119 | if (target) { |
| 1120 | // Here NaN cases were either handled by this function or are assumed to |
| 1121 | // have been handled by the caller. |
| 1122 | // Unsigned conditions are treated as their signed counterpart. |
| 1123 | switch (cc) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1124 | case lt: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1125 | c(OLT, D, cmp1, cmp2); |
| 1126 | bc1t(target); |
| 1127 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1128 | case gt: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1129 | c(ULE, D, cmp1, cmp2); |
| 1130 | bc1f(target); |
| 1131 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1132 | case ge: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1133 | c(ULT, D, cmp1, cmp2); |
| 1134 | bc1f(target); |
| 1135 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1136 | case le: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1137 | c(OLE, D, cmp1, cmp2); |
| 1138 | bc1t(target); |
| 1139 | break; |
| 1140 | case eq: |
| 1141 | c(EQ, D, cmp1, cmp2); |
| 1142 | bc1t(target); |
| 1143 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1144 | case ueq: |
| 1145 | c(UEQ, D, cmp1, cmp2); |
| 1146 | bc1t(target); |
| 1147 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1148 | case ne: |
| 1149 | c(EQ, D, cmp1, cmp2); |
| 1150 | bc1f(target); |
| 1151 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1152 | case nue: |
| 1153 | c(UEQ, D, cmp1, cmp2); |
| 1154 | bc1f(target); |
| 1155 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1156 | default: |
| 1157 | CHECK(0); |
| 1158 | }; |
| 1159 | } |
| 1160 | |
| 1161 | if (bd == PROTECT) { |
| 1162 | nop(); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void MacroAssembler::Move(FPURegister dst, double imm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1168 | static const DoubleRepresentation minus_zero(-0.0); |
| 1169 | static const DoubleRepresentation zero(0.0); |
| 1170 | DoubleRepresentation value(imm); |
| 1171 | // Handle special values first. |
| 1172 | bool force_load = dst.is(kDoubleRegZero); |
| 1173 | if (value.bits == zero.bits && !force_load) { |
| 1174 | mov_d(dst, kDoubleRegZero); |
| 1175 | } else if (value.bits == minus_zero.bits && !force_load) { |
| 1176 | neg_d(dst, kDoubleRegZero); |
| 1177 | } else { |
| 1178 | uint32_t lo, hi; |
| 1179 | DoubleAsTwoUInt32(imm, &lo, &hi); |
| 1180 | // Move the low part of the double into the lower of the corresponding FPU |
| 1181 | // register of FPU register pair. |
| 1182 | if (lo != 0) { |
| 1183 | li(at, Operand(lo)); |
| 1184 | mtc1(at, dst); |
| 1185 | } else { |
| 1186 | mtc1(zero_reg, dst); |
| 1187 | } |
| 1188 | // Move the high part of the double into the higher of the corresponding FPU |
| 1189 | // register of FPU register pair. |
| 1190 | if (hi != 0) { |
| 1191 | li(at, Operand(hi)); |
| 1192 | mtc1(at, dst.high()); |
| 1193 | } else { |
| 1194 | mtc1(zero_reg, dst.high()); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1200 | void MacroAssembler::Movz(Register rd, Register rs, Register rt) { |
| 1201 | if (kArchVariant == kLoongson) { |
| 1202 | Label done; |
| 1203 | Branch(&done, ne, rt, Operand(zero_reg)); |
| 1204 | mov(rd, rs); |
| 1205 | bind(&done); |
| 1206 | } else { |
| 1207 | movz(rd, rs, rt); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | void MacroAssembler::Movn(Register rd, Register rs, Register rt) { |
| 1213 | if (kArchVariant == kLoongson) { |
| 1214 | Label done; |
| 1215 | Branch(&done, eq, rt, Operand(zero_reg)); |
| 1216 | mov(rd, rs); |
| 1217 | bind(&done); |
| 1218 | } else { |
| 1219 | movn(rd, rs, rt); |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | void MacroAssembler::Movt(Register rd, Register rs, uint16_t cc) { |
| 1225 | if (kArchVariant == kLoongson) { |
| 1226 | // Tests an FP condition code and then conditionally move rs to rd. |
| 1227 | // We do not currently use any FPU cc bit other than bit 0. |
| 1228 | ASSERT(cc == 0); |
| 1229 | ASSERT(!(rs.is(t8) || rd.is(t8))); |
| 1230 | Label done; |
| 1231 | Register scratch = t8; |
| 1232 | // For testing purposes we need to fetch content of the FCSR register and |
| 1233 | // than test its cc (floating point condition code) bit (for cc = 0, it is |
| 1234 | // 24. bit of the FCSR). |
| 1235 | cfc1(scratch, FCSR); |
| 1236 | // For the MIPS I, II and III architectures, the contents of scratch is |
| 1237 | // UNPREDICTABLE for the instruction immediately following CFC1. |
| 1238 | nop(); |
| 1239 | srl(scratch, scratch, 16); |
| 1240 | andi(scratch, scratch, 0x0080); |
| 1241 | Branch(&done, eq, scratch, Operand(zero_reg)); |
| 1242 | mov(rd, rs); |
| 1243 | bind(&done); |
| 1244 | } else { |
| 1245 | movt(rd, rs, cc); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | void MacroAssembler::Movf(Register rd, Register rs, uint16_t cc) { |
| 1251 | if (kArchVariant == kLoongson) { |
| 1252 | // Tests an FP condition code and then conditionally move rs to rd. |
| 1253 | // We do not currently use any FPU cc bit other than bit 0. |
| 1254 | ASSERT(cc == 0); |
| 1255 | ASSERT(!(rs.is(t8) || rd.is(t8))); |
| 1256 | Label done; |
| 1257 | Register scratch = t8; |
| 1258 | // For testing purposes we need to fetch content of the FCSR register and |
| 1259 | // than test its cc (floating point condition code) bit (for cc = 0, it is |
| 1260 | // 24. bit of the FCSR). |
| 1261 | cfc1(scratch, FCSR); |
| 1262 | // For the MIPS I, II and III architectures, the contents of scratch is |
| 1263 | // UNPREDICTABLE for the instruction immediately following CFC1. |
| 1264 | nop(); |
| 1265 | srl(scratch, scratch, 16); |
| 1266 | andi(scratch, scratch, 0x0080); |
| 1267 | Branch(&done, ne, scratch, Operand(zero_reg)); |
| 1268 | mov(rd, rs); |
| 1269 | bind(&done); |
| 1270 | } else { |
| 1271 | movf(rd, rs, cc); |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | void MacroAssembler::Clz(Register rd, Register rs) { |
| 1277 | if (kArchVariant == kLoongson) { |
| 1278 | ASSERT(!(rd.is(t8) || rd.is(t9)) && !(rs.is(t8) || rs.is(t9))); |
| 1279 | Register mask = t8; |
| 1280 | Register scratch = t9; |
| 1281 | Label loop, end; |
| 1282 | mov(at, rs); |
| 1283 | mov(rd, zero_reg); |
| 1284 | lui(mask, 0x8000); |
| 1285 | bind(&loop); |
| 1286 | and_(scratch, at, mask); |
| 1287 | Branch(&end, ne, scratch, Operand(zero_reg)); |
| 1288 | addiu(rd, rd, 1); |
| 1289 | Branch(&loop, ne, mask, Operand(zero_reg), USE_DELAY_SLOT); |
| 1290 | srl(mask, mask, 1); |
| 1291 | bind(&end); |
| 1292 | } else { |
| 1293 | clz(rd, rs); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1298 | // Tries to get a signed int32 out of a double precision floating point heap |
| 1299 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 1300 | // 32bits signed integer range. |
| 1301 | // This method implementation differs from the ARM version for performance |
| 1302 | // reasons. |
| 1303 | void MacroAssembler::ConvertToInt32(Register source, |
| 1304 | Register dest, |
| 1305 | Register scratch, |
| 1306 | Register scratch2, |
| 1307 | FPURegister double_scratch, |
| 1308 | Label *not_int32) { |
| 1309 | Label right_exponent, done; |
| 1310 | // Get exponent word (ENDIAN issues). |
| 1311 | lw(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 1312 | // Get exponent alone in scratch2. |
| 1313 | And(scratch2, scratch, Operand(HeapNumber::kExponentMask)); |
| 1314 | // Load dest with zero. We use this either for the final shift or |
| 1315 | // for the answer. |
| 1316 | mov(dest, zero_reg); |
| 1317 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 1318 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 1319 | // the exponent that we are fastest at and also the highest exponent we can |
| 1320 | // handle here. |
| 1321 | const uint32_t non_smi_exponent = |
| 1322 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 1323 | // If we have a match of the int32-but-not-Smi exponent then skip some logic. |
| 1324 | Branch(&right_exponent, eq, scratch2, Operand(non_smi_exponent)); |
| 1325 | // If the exponent is higher than that then go to not_int32 case. This |
| 1326 | // catches numbers that don't fit in a signed int32, infinities and NaNs. |
| 1327 | Branch(not_int32, gt, scratch2, Operand(non_smi_exponent)); |
| 1328 | |
| 1329 | // We know the exponent is smaller than 30 (biased). If it is less than |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1330 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, i.e. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1331 | // it rounds to zero. |
| 1332 | const uint32_t zero_exponent = |
| 1333 | (HeapNumber::kExponentBias + 0) << HeapNumber::kExponentShift; |
| 1334 | Subu(scratch2, scratch2, Operand(zero_exponent)); |
| 1335 | // Dest already has a Smi zero. |
| 1336 | Branch(&done, lt, scratch2, Operand(zero_reg)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1337 | bind(&right_exponent); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1338 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1339 | // MIPS FPU instructions implementing double precision to integer |
| 1340 | // conversion using round to zero. Since the FP value was qualified |
| 1341 | // above, the resulting integer should be a legal int32. |
| 1342 | // The original 'Exponent' word is still in scratch. |
| 1343 | lwc1(double_scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 1344 | mtc1(scratch, FPURegister::from_code(double_scratch.code() + 1)); |
| 1345 | trunc_w_d(double_scratch, double_scratch); |
| 1346 | mfc1(dest, double_scratch); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1347 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1348 | bind(&done); |
| 1349 | } |
| 1350 | |
| 1351 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1352 | void MacroAssembler::EmitFPUTruncate(FPURoundingMode rounding_mode, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1353 | Register result, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1354 | DoubleRegister double_input, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1355 | Register scratch, |
| 1356 | DoubleRegister double_scratch, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1357 | Register except_flag, |
| 1358 | CheckForInexactConversion check_inexact) { |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1359 | ASSERT(!result.is(scratch)); |
| 1360 | ASSERT(!double_input.is(double_scratch)); |
| 1361 | ASSERT(!except_flag.is(scratch)); |
| 1362 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1363 | Label done; |
| 1364 | |
| 1365 | // Clear the except flag (0 = no exception) |
| 1366 | mov(except_flag, zero_reg); |
| 1367 | |
| 1368 | // Test for values that can be exactly represented as a signed 32-bit integer. |
| 1369 | cvt_w_d(double_scratch, double_input); |
| 1370 | mfc1(result, double_scratch); |
| 1371 | cvt_d_w(double_scratch, double_scratch); |
| 1372 | BranchF(&done, NULL, eq, double_input, double_scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1373 | |
| 1374 | int32_t except_mask = kFCSRFlagMask; // Assume interested in all exceptions. |
| 1375 | |
| 1376 | if (check_inexact == kDontCheckForInexactConversion) { |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1377 | // Ignore inexact exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1378 | except_mask &= ~kFCSRInexactFlagMask; |
| 1379 | } |
| 1380 | |
| 1381 | // Save FCSR. |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1382 | cfc1(scratch, FCSR); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1383 | // Disable FPU exceptions. |
| 1384 | ctc1(zero_reg, FCSR); |
| 1385 | |
| 1386 | // Do operation based on rounding mode. |
| 1387 | switch (rounding_mode) { |
| 1388 | case kRoundToNearest: |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1389 | Round_w_d(double_scratch, double_input); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1390 | break; |
| 1391 | case kRoundToZero: |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1392 | Trunc_w_d(double_scratch, double_input); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1393 | break; |
| 1394 | case kRoundToPlusInf: |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1395 | Ceil_w_d(double_scratch, double_input); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1396 | break; |
| 1397 | case kRoundToMinusInf: |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1398 | Floor_w_d(double_scratch, double_input); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1399 | break; |
| 1400 | } // End of switch-statement. |
| 1401 | |
| 1402 | // Retrieve FCSR. |
| 1403 | cfc1(except_flag, FCSR); |
| 1404 | // Restore FCSR. |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1405 | ctc1(scratch, FCSR); |
| 1406 | // Move the converted value into the result register. |
| 1407 | mfc1(result, double_scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1408 | |
| 1409 | // Check for fpu exceptions. |
| 1410 | And(except_flag, except_flag, Operand(except_mask)); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1411 | |
| 1412 | bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1416 | void MacroAssembler::EmitOutOfInt32RangeTruncate(Register result, |
| 1417 | Register input_high, |
| 1418 | Register input_low, |
| 1419 | Register scratch) { |
| 1420 | Label done, normal_exponent, restore_sign; |
| 1421 | // Extract the biased exponent in result. |
| 1422 | Ext(result, |
| 1423 | input_high, |
| 1424 | HeapNumber::kExponentShift, |
| 1425 | HeapNumber::kExponentBits); |
| 1426 | |
| 1427 | // Check for Infinity and NaNs, which should return 0. |
| 1428 | Subu(scratch, result, HeapNumber::kExponentMask); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1429 | Movz(result, zero_reg, scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1430 | Branch(&done, eq, scratch, Operand(zero_reg)); |
| 1431 | |
| 1432 | // Express exponent as delta to (number of mantissa bits + 31). |
| 1433 | Subu(result, |
| 1434 | result, |
| 1435 | Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits + 31)); |
| 1436 | |
| 1437 | // If the delta is strictly positive, all bits would be shifted away, |
| 1438 | // which means that we can return 0. |
| 1439 | Branch(&normal_exponent, le, result, Operand(zero_reg)); |
| 1440 | mov(result, zero_reg); |
| 1441 | Branch(&done); |
| 1442 | |
| 1443 | bind(&normal_exponent); |
| 1444 | const int kShiftBase = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 1445 | // Calculate shift. |
| 1446 | Addu(scratch, result, Operand(kShiftBase + HeapNumber::kMantissaBits)); |
| 1447 | |
| 1448 | // Save the sign. |
| 1449 | Register sign = result; |
| 1450 | result = no_reg; |
| 1451 | And(sign, input_high, Operand(HeapNumber::kSignMask)); |
| 1452 | |
| 1453 | // On ARM shifts > 31 bits are valid and will result in zero. On MIPS we need |
| 1454 | // to check for this specific case. |
| 1455 | Label high_shift_needed, high_shift_done; |
| 1456 | Branch(&high_shift_needed, lt, scratch, Operand(32)); |
| 1457 | mov(input_high, zero_reg); |
| 1458 | Branch(&high_shift_done); |
| 1459 | bind(&high_shift_needed); |
| 1460 | |
| 1461 | // Set the implicit 1 before the mantissa part in input_high. |
| 1462 | Or(input_high, |
| 1463 | input_high, |
| 1464 | Operand(1 << HeapNumber::kMantissaBitsInTopWord)); |
| 1465 | // Shift the mantissa bits to the correct position. |
| 1466 | // We don't need to clear non-mantissa bits as they will be shifted away. |
| 1467 | // If they weren't, it would mean that the answer is in the 32bit range. |
| 1468 | sllv(input_high, input_high, scratch); |
| 1469 | |
| 1470 | bind(&high_shift_done); |
| 1471 | |
| 1472 | // Replace the shifted bits with bits from the lower mantissa word. |
| 1473 | Label pos_shift, shift_done; |
| 1474 | li(at, 32); |
| 1475 | subu(scratch, at, scratch); |
| 1476 | Branch(&pos_shift, ge, scratch, Operand(zero_reg)); |
| 1477 | |
| 1478 | // Negate scratch. |
| 1479 | Subu(scratch, zero_reg, scratch); |
| 1480 | sllv(input_low, input_low, scratch); |
| 1481 | Branch(&shift_done); |
| 1482 | |
| 1483 | bind(&pos_shift); |
| 1484 | srlv(input_low, input_low, scratch); |
| 1485 | |
| 1486 | bind(&shift_done); |
| 1487 | Or(input_high, input_high, Operand(input_low)); |
| 1488 | // Restore sign if necessary. |
| 1489 | mov(scratch, sign); |
| 1490 | result = sign; |
| 1491 | sign = no_reg; |
| 1492 | Subu(result, zero_reg, input_high); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 1493 | Movz(result, input_high, scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1494 | bind(&done); |
| 1495 | } |
| 1496 | |
| 1497 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1498 | void MacroAssembler::EmitECMATruncate(Register result, |
| 1499 | FPURegister double_input, |
| 1500 | FPURegister single_scratch, |
| 1501 | Register scratch, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1502 | Register scratch2, |
| 1503 | Register scratch3) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1504 | ASSERT(!scratch2.is(result)); |
| 1505 | ASSERT(!scratch3.is(result)); |
| 1506 | ASSERT(!scratch3.is(scratch2)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1507 | ASSERT(!scratch.is(result) && |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1508 | !scratch.is(scratch2) && |
| 1509 | !scratch.is(scratch3)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1510 | ASSERT(!single_scratch.is(double_input)); |
| 1511 | |
| 1512 | Label done; |
| 1513 | Label manual; |
| 1514 | |
| 1515 | // Clear cumulative exception flags and save the FCSR. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1516 | cfc1(scratch2, FCSR); |
| 1517 | ctc1(zero_reg, FCSR); |
| 1518 | // Try a conversion to a signed integer. |
| 1519 | trunc_w_d(single_scratch, double_input); |
| 1520 | mfc1(result, single_scratch); |
| 1521 | // Retrieve and restore the FCSR. |
| 1522 | cfc1(scratch, FCSR); |
| 1523 | ctc1(scratch2, FCSR); |
| 1524 | // Check for overflow and NaNs. |
| 1525 | And(scratch, |
| 1526 | scratch, |
| 1527 | kFCSROverflowFlagMask | kFCSRUnderflowFlagMask | kFCSRInvalidOpFlagMask); |
| 1528 | // If we had no exceptions we are done. |
| 1529 | Branch(&done, eq, scratch, Operand(zero_reg)); |
| 1530 | |
| 1531 | // Load the double value and perform a manual truncation. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1532 | Register input_high = scratch2; |
| 1533 | Register input_low = scratch3; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1534 | Move(input_low, input_high, double_input); |
| 1535 | EmitOutOfInt32RangeTruncate(result, |
| 1536 | input_high, |
| 1537 | input_low, |
| 1538 | scratch); |
| 1539 | bind(&done); |
| 1540 | } |
| 1541 | |
| 1542 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1543 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 1544 | Register src, |
| 1545 | int num_least_bits) { |
| 1546 | Ext(dst, src, kSmiTagSize, num_least_bits); |
| 1547 | } |
| 1548 | |
| 1549 | |
| 1550 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 1551 | Register src, |
| 1552 | int num_least_bits) { |
| 1553 | And(dst, src, Operand((1 << num_least_bits) - 1)); |
| 1554 | } |
| 1555 | |
| 1556 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1557 | // Emulated condtional branches do not emit a nop in the branch delay slot. |
| 1558 | // |
| 1559 | // BRANCH_ARGS_CHECK checks that conditional jump arguments are correct. |
| 1560 | #define BRANCH_ARGS_CHECK(cond, rs, rt) ASSERT( \ |
| 1561 | (cond == cc_always && rs.is(zero_reg) && rt.rm().is(zero_reg)) || \ |
| 1562 | (cond != cc_always && (!rs.is(zero_reg) || !rt.rm().is(zero_reg)))) |
| 1563 | |
| 1564 | |
| 1565 | void MacroAssembler::Branch(int16_t offset, BranchDelaySlot bdslot) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1566 | BranchShort(offset, bdslot); |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | void MacroAssembler::Branch(int16_t offset, Condition cond, Register rs, |
| 1571 | const Operand& rt, |
| 1572 | BranchDelaySlot bdslot) { |
| 1573 | BranchShort(offset, cond, rs, rt, bdslot); |
| 1574 | } |
| 1575 | |
| 1576 | |
| 1577 | void MacroAssembler::Branch(Label* L, BranchDelaySlot bdslot) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1578 | if (L->is_bound()) { |
| 1579 | if (is_near(L)) { |
| 1580 | BranchShort(L, bdslot); |
| 1581 | } else { |
| 1582 | Jr(L, bdslot); |
| 1583 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1584 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1585 | if (is_trampoline_emitted()) { |
| 1586 | Jr(L, bdslot); |
| 1587 | } else { |
| 1588 | BranchShort(L, bdslot); |
| 1589 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | void MacroAssembler::Branch(Label* L, Condition cond, Register rs, |
| 1595 | const Operand& rt, |
| 1596 | BranchDelaySlot bdslot) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1597 | if (L->is_bound()) { |
| 1598 | if (is_near(L)) { |
| 1599 | BranchShort(L, cond, rs, rt, bdslot); |
| 1600 | } else { |
| 1601 | Label skip; |
| 1602 | Condition neg_cond = NegateCondition(cond); |
| 1603 | BranchShort(&skip, neg_cond, rs, rt); |
| 1604 | Jr(L, bdslot); |
| 1605 | bind(&skip); |
| 1606 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1607 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1608 | if (is_trampoline_emitted()) { |
| 1609 | Label skip; |
| 1610 | Condition neg_cond = NegateCondition(cond); |
| 1611 | BranchShort(&skip, neg_cond, rs, rt); |
| 1612 | Jr(L, bdslot); |
| 1613 | bind(&skip); |
| 1614 | } else { |
| 1615 | BranchShort(L, cond, rs, rt, bdslot); |
| 1616 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1621 | void MacroAssembler::Branch(Label* L, |
| 1622 | Condition cond, |
| 1623 | Register rs, |
| 1624 | Heap::RootListIndex index, |
| 1625 | BranchDelaySlot bdslot) { |
| 1626 | LoadRoot(at, index); |
| 1627 | Branch(L, cond, rs, Operand(at), bdslot); |
| 1628 | } |
| 1629 | |
| 1630 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1631 | void MacroAssembler::BranchShort(int16_t offset, BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1632 | b(offset); |
| 1633 | |
| 1634 | // Emit a nop in the branch delay slot if required. |
| 1635 | if (bdslot == PROTECT) |
| 1636 | nop(); |
| 1637 | } |
| 1638 | |
| 1639 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1640 | void MacroAssembler::BranchShort(int16_t offset, Condition cond, Register rs, |
| 1641 | const Operand& rt, |
| 1642 | BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1643 | BRANCH_ARGS_CHECK(cond, rs, rt); |
| 1644 | ASSERT(!rs.is(zero_reg)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1645 | Register r2 = no_reg; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1646 | Register scratch = at; |
| 1647 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1648 | if (rt.is_reg()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1649 | // NOTE: 'at' can be clobbered by Branch but it is legal to use it as rs or |
| 1650 | // rt. |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1651 | BlockTrampolinePoolScope block_trampoline_pool(this); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1652 | r2 = rt.rm_; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1653 | switch (cond) { |
| 1654 | case cc_always: |
| 1655 | b(offset); |
| 1656 | break; |
| 1657 | case eq: |
| 1658 | beq(rs, r2, offset); |
| 1659 | break; |
| 1660 | case ne: |
| 1661 | bne(rs, r2, offset); |
| 1662 | break; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1663 | // Signed comparison. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1664 | case greater: |
| 1665 | if (r2.is(zero_reg)) { |
| 1666 | bgtz(rs, offset); |
| 1667 | } else { |
| 1668 | slt(scratch, r2, rs); |
| 1669 | bne(scratch, zero_reg, offset); |
| 1670 | } |
| 1671 | break; |
| 1672 | case greater_equal: |
| 1673 | if (r2.is(zero_reg)) { |
| 1674 | bgez(rs, offset); |
| 1675 | } else { |
| 1676 | slt(scratch, rs, r2); |
| 1677 | beq(scratch, zero_reg, offset); |
| 1678 | } |
| 1679 | break; |
| 1680 | case less: |
| 1681 | if (r2.is(zero_reg)) { |
| 1682 | bltz(rs, offset); |
| 1683 | } else { |
| 1684 | slt(scratch, rs, r2); |
| 1685 | bne(scratch, zero_reg, offset); |
| 1686 | } |
| 1687 | break; |
| 1688 | case less_equal: |
| 1689 | if (r2.is(zero_reg)) { |
| 1690 | blez(rs, offset); |
| 1691 | } else { |
| 1692 | slt(scratch, r2, rs); |
| 1693 | beq(scratch, zero_reg, offset); |
| 1694 | } |
| 1695 | break; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1696 | // Unsigned comparison. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1697 | case Ugreater: |
| 1698 | if (r2.is(zero_reg)) { |
| 1699 | bgtz(rs, offset); |
| 1700 | } else { |
| 1701 | sltu(scratch, r2, rs); |
| 1702 | bne(scratch, zero_reg, offset); |
| 1703 | } |
| 1704 | break; |
| 1705 | case Ugreater_equal: |
| 1706 | if (r2.is(zero_reg)) { |
| 1707 | bgez(rs, offset); |
| 1708 | } else { |
| 1709 | sltu(scratch, rs, r2); |
| 1710 | beq(scratch, zero_reg, offset); |
| 1711 | } |
| 1712 | break; |
| 1713 | case Uless: |
| 1714 | if (r2.is(zero_reg)) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1715 | // No code needs to be emitted. |
| 1716 | return; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1717 | } else { |
| 1718 | sltu(scratch, rs, r2); |
| 1719 | bne(scratch, zero_reg, offset); |
| 1720 | } |
| 1721 | break; |
| 1722 | case Uless_equal: |
| 1723 | if (r2.is(zero_reg)) { |
| 1724 | b(offset); |
| 1725 | } else { |
| 1726 | sltu(scratch, r2, rs); |
| 1727 | beq(scratch, zero_reg, offset); |
| 1728 | } |
| 1729 | break; |
| 1730 | default: |
| 1731 | UNREACHABLE(); |
| 1732 | } |
| 1733 | } else { |
| 1734 | // Be careful to always use shifted_branch_offset only just before the |
| 1735 | // branch instruction, as the location will be remember for patching the |
| 1736 | // target. |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1737 | BlockTrampolinePoolScope block_trampoline_pool(this); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1738 | switch (cond) { |
| 1739 | case cc_always: |
| 1740 | b(offset); |
| 1741 | break; |
| 1742 | case eq: |
| 1743 | // We don't want any other register but scratch clobbered. |
| 1744 | ASSERT(!scratch.is(rs)); |
| 1745 | r2 = scratch; |
| 1746 | li(r2, rt); |
| 1747 | beq(rs, r2, offset); |
| 1748 | break; |
| 1749 | case ne: |
| 1750 | // We don't want any other register but scratch clobbered. |
| 1751 | ASSERT(!scratch.is(rs)); |
| 1752 | r2 = scratch; |
| 1753 | li(r2, rt); |
| 1754 | bne(rs, r2, offset); |
| 1755 | break; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1756 | // Signed comparison. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1757 | case greater: |
| 1758 | if (rt.imm32_ == 0) { |
| 1759 | bgtz(rs, offset); |
| 1760 | } else { |
| 1761 | r2 = scratch; |
| 1762 | li(r2, rt); |
| 1763 | slt(scratch, r2, rs); |
| 1764 | bne(scratch, zero_reg, offset); |
| 1765 | } |
| 1766 | break; |
| 1767 | case greater_equal: |
| 1768 | if (rt.imm32_ == 0) { |
| 1769 | bgez(rs, offset); |
| 1770 | } else if (is_int16(rt.imm32_)) { |
| 1771 | slti(scratch, rs, rt.imm32_); |
| 1772 | beq(scratch, zero_reg, offset); |
| 1773 | } else { |
| 1774 | r2 = scratch; |
| 1775 | li(r2, rt); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1776 | slt(scratch, rs, r2); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1777 | beq(scratch, zero_reg, offset); |
| 1778 | } |
| 1779 | break; |
| 1780 | case less: |
| 1781 | if (rt.imm32_ == 0) { |
| 1782 | bltz(rs, offset); |
| 1783 | } else if (is_int16(rt.imm32_)) { |
| 1784 | slti(scratch, rs, rt.imm32_); |
| 1785 | bne(scratch, zero_reg, offset); |
| 1786 | } else { |
| 1787 | r2 = scratch; |
| 1788 | li(r2, rt); |
| 1789 | slt(scratch, rs, r2); |
| 1790 | bne(scratch, zero_reg, offset); |
| 1791 | } |
| 1792 | break; |
| 1793 | case less_equal: |
| 1794 | if (rt.imm32_ == 0) { |
| 1795 | blez(rs, offset); |
| 1796 | } else { |
| 1797 | r2 = scratch; |
| 1798 | li(r2, rt); |
| 1799 | slt(scratch, r2, rs); |
| 1800 | beq(scratch, zero_reg, offset); |
| 1801 | } |
| 1802 | break; |
| 1803 | // Unsigned comparison. |
| 1804 | case Ugreater: |
| 1805 | if (rt.imm32_ == 0) { |
| 1806 | bgtz(rs, offset); |
| 1807 | } else { |
| 1808 | r2 = scratch; |
| 1809 | li(r2, rt); |
| 1810 | sltu(scratch, r2, rs); |
| 1811 | bne(scratch, zero_reg, offset); |
| 1812 | } |
| 1813 | break; |
| 1814 | case Ugreater_equal: |
| 1815 | if (rt.imm32_ == 0) { |
| 1816 | bgez(rs, offset); |
| 1817 | } else if (is_int16(rt.imm32_)) { |
| 1818 | sltiu(scratch, rs, rt.imm32_); |
| 1819 | beq(scratch, zero_reg, offset); |
| 1820 | } else { |
| 1821 | r2 = scratch; |
| 1822 | li(r2, rt); |
| 1823 | sltu(scratch, rs, r2); |
| 1824 | beq(scratch, zero_reg, offset); |
| 1825 | } |
| 1826 | break; |
| 1827 | case Uless: |
| 1828 | if (rt.imm32_ == 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1829 | // No code needs to be emitted. |
| 1830 | return; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1831 | } else if (is_int16(rt.imm32_)) { |
| 1832 | sltiu(scratch, rs, rt.imm32_); |
| 1833 | bne(scratch, zero_reg, offset); |
| 1834 | } else { |
| 1835 | r2 = scratch; |
| 1836 | li(r2, rt); |
| 1837 | sltu(scratch, rs, r2); |
| 1838 | bne(scratch, zero_reg, offset); |
| 1839 | } |
| 1840 | break; |
| 1841 | case Uless_equal: |
| 1842 | if (rt.imm32_ == 0) { |
| 1843 | b(offset); |
| 1844 | } else { |
| 1845 | r2 = scratch; |
| 1846 | li(r2, rt); |
| 1847 | sltu(scratch, r2, rs); |
| 1848 | beq(scratch, zero_reg, offset); |
| 1849 | } |
| 1850 | break; |
| 1851 | default: |
| 1852 | UNREACHABLE(); |
| 1853 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1854 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1855 | // Emit a nop in the branch delay slot if required. |
| 1856 | if (bdslot == PROTECT) |
| 1857 | nop(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1861 | void MacroAssembler::BranchShort(Label* L, BranchDelaySlot bdslot) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1862 | // We use branch_offset as an argument for the branch instructions to be sure |
| 1863 | // it is called just before generating the branch instruction, as needed. |
| 1864 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1865 | b(shifted_branch_offset(L, false)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1866 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1867 | // Emit a nop in the branch delay slot if required. |
| 1868 | if (bdslot == PROTECT) |
| 1869 | nop(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1873 | void MacroAssembler::BranchShort(Label* L, Condition cond, Register rs, |
| 1874 | const Operand& rt, |
| 1875 | BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1876 | BRANCH_ARGS_CHECK(cond, rs, rt); |
| 1877 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1878 | int32_t offset = 0; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1879 | Register r2 = no_reg; |
| 1880 | Register scratch = at; |
| 1881 | if (rt.is_reg()) { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1882 | BlockTrampolinePoolScope block_trampoline_pool(this); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1883 | r2 = rt.rm_; |
| 1884 | // Be careful to always use shifted_branch_offset only just before the |
| 1885 | // branch instruction, as the location will be remember for patching the |
| 1886 | // target. |
| 1887 | switch (cond) { |
| 1888 | case cc_always: |
| 1889 | offset = shifted_branch_offset(L, false); |
| 1890 | b(offset); |
| 1891 | break; |
| 1892 | case eq: |
| 1893 | offset = shifted_branch_offset(L, false); |
| 1894 | beq(rs, r2, offset); |
| 1895 | break; |
| 1896 | case ne: |
| 1897 | offset = shifted_branch_offset(L, false); |
| 1898 | bne(rs, r2, offset); |
| 1899 | break; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1900 | // Signed comparison. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1901 | case greater: |
| 1902 | if (r2.is(zero_reg)) { |
| 1903 | offset = shifted_branch_offset(L, false); |
| 1904 | bgtz(rs, offset); |
| 1905 | } else { |
| 1906 | slt(scratch, r2, rs); |
| 1907 | offset = shifted_branch_offset(L, false); |
| 1908 | bne(scratch, zero_reg, offset); |
| 1909 | } |
| 1910 | break; |
| 1911 | case greater_equal: |
| 1912 | if (r2.is(zero_reg)) { |
| 1913 | offset = shifted_branch_offset(L, false); |
| 1914 | bgez(rs, offset); |
| 1915 | } else { |
| 1916 | slt(scratch, rs, r2); |
| 1917 | offset = shifted_branch_offset(L, false); |
| 1918 | beq(scratch, zero_reg, offset); |
| 1919 | } |
| 1920 | break; |
| 1921 | case less: |
| 1922 | if (r2.is(zero_reg)) { |
| 1923 | offset = shifted_branch_offset(L, false); |
| 1924 | bltz(rs, offset); |
| 1925 | } else { |
| 1926 | slt(scratch, rs, r2); |
| 1927 | offset = shifted_branch_offset(L, false); |
| 1928 | bne(scratch, zero_reg, offset); |
| 1929 | } |
| 1930 | break; |
| 1931 | case less_equal: |
| 1932 | if (r2.is(zero_reg)) { |
| 1933 | offset = shifted_branch_offset(L, false); |
| 1934 | blez(rs, offset); |
| 1935 | } else { |
| 1936 | slt(scratch, r2, rs); |
| 1937 | offset = shifted_branch_offset(L, false); |
| 1938 | beq(scratch, zero_reg, offset); |
| 1939 | } |
| 1940 | break; |
| 1941 | // Unsigned comparison. |
| 1942 | case Ugreater: |
| 1943 | if (r2.is(zero_reg)) { |
| 1944 | offset = shifted_branch_offset(L, false); |
| 1945 | bgtz(rs, offset); |
| 1946 | } else { |
| 1947 | sltu(scratch, r2, rs); |
| 1948 | offset = shifted_branch_offset(L, false); |
| 1949 | bne(scratch, zero_reg, offset); |
| 1950 | } |
| 1951 | break; |
| 1952 | case Ugreater_equal: |
| 1953 | if (r2.is(zero_reg)) { |
| 1954 | offset = shifted_branch_offset(L, false); |
| 1955 | bgez(rs, offset); |
| 1956 | } else { |
| 1957 | sltu(scratch, rs, r2); |
| 1958 | offset = shifted_branch_offset(L, false); |
| 1959 | beq(scratch, zero_reg, offset); |
| 1960 | } |
| 1961 | break; |
| 1962 | case Uless: |
| 1963 | if (r2.is(zero_reg)) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1964 | // No code needs to be emitted. |
| 1965 | return; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1966 | } else { |
| 1967 | sltu(scratch, rs, r2); |
| 1968 | offset = shifted_branch_offset(L, false); |
| 1969 | bne(scratch, zero_reg, offset); |
| 1970 | } |
| 1971 | break; |
| 1972 | case Uless_equal: |
| 1973 | if (r2.is(zero_reg)) { |
| 1974 | offset = shifted_branch_offset(L, false); |
| 1975 | b(offset); |
| 1976 | } else { |
| 1977 | sltu(scratch, r2, rs); |
| 1978 | offset = shifted_branch_offset(L, false); |
| 1979 | beq(scratch, zero_reg, offset); |
| 1980 | } |
| 1981 | break; |
| 1982 | default: |
| 1983 | UNREACHABLE(); |
| 1984 | } |
| 1985 | } else { |
| 1986 | // Be careful to always use shifted_branch_offset only just before the |
| 1987 | // branch instruction, as the location will be remember for patching the |
| 1988 | // target. |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 1989 | BlockTrampolinePoolScope block_trampoline_pool(this); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1990 | switch (cond) { |
| 1991 | case cc_always: |
| 1992 | offset = shifted_branch_offset(L, false); |
| 1993 | b(offset); |
| 1994 | break; |
| 1995 | case eq: |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1996 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1997 | r2 = scratch; |
| 1998 | li(r2, rt); |
| 1999 | offset = shifted_branch_offset(L, false); |
| 2000 | beq(rs, r2, offset); |
| 2001 | break; |
| 2002 | case ne: |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2003 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2004 | r2 = scratch; |
| 2005 | li(r2, rt); |
| 2006 | offset = shifted_branch_offset(L, false); |
| 2007 | bne(rs, r2, offset); |
| 2008 | break; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2009 | // Signed comparison. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2010 | case greater: |
| 2011 | if (rt.imm32_ == 0) { |
| 2012 | offset = shifted_branch_offset(L, false); |
| 2013 | bgtz(rs, offset); |
| 2014 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2015 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2016 | r2 = scratch; |
| 2017 | li(r2, rt); |
| 2018 | slt(scratch, r2, rs); |
| 2019 | offset = shifted_branch_offset(L, false); |
| 2020 | bne(scratch, zero_reg, offset); |
| 2021 | } |
| 2022 | break; |
| 2023 | case greater_equal: |
| 2024 | if (rt.imm32_ == 0) { |
| 2025 | offset = shifted_branch_offset(L, false); |
| 2026 | bgez(rs, offset); |
| 2027 | } else if (is_int16(rt.imm32_)) { |
| 2028 | slti(scratch, rs, rt.imm32_); |
| 2029 | offset = shifted_branch_offset(L, false); |
| 2030 | beq(scratch, zero_reg, offset); |
| 2031 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2032 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2033 | r2 = scratch; |
| 2034 | li(r2, rt); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2035 | slt(scratch, rs, r2); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2036 | offset = shifted_branch_offset(L, false); |
| 2037 | beq(scratch, zero_reg, offset); |
| 2038 | } |
| 2039 | break; |
| 2040 | case less: |
| 2041 | if (rt.imm32_ == 0) { |
| 2042 | offset = shifted_branch_offset(L, false); |
| 2043 | bltz(rs, offset); |
| 2044 | } else if (is_int16(rt.imm32_)) { |
| 2045 | slti(scratch, rs, rt.imm32_); |
| 2046 | offset = shifted_branch_offset(L, false); |
| 2047 | bne(scratch, zero_reg, offset); |
| 2048 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2049 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2050 | r2 = scratch; |
| 2051 | li(r2, rt); |
| 2052 | slt(scratch, rs, r2); |
| 2053 | offset = shifted_branch_offset(L, false); |
| 2054 | bne(scratch, zero_reg, offset); |
| 2055 | } |
| 2056 | break; |
| 2057 | case less_equal: |
| 2058 | if (rt.imm32_ == 0) { |
| 2059 | offset = shifted_branch_offset(L, false); |
| 2060 | blez(rs, offset); |
| 2061 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2062 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2063 | r2 = scratch; |
| 2064 | li(r2, rt); |
| 2065 | slt(scratch, r2, rs); |
| 2066 | offset = shifted_branch_offset(L, false); |
| 2067 | beq(scratch, zero_reg, offset); |
| 2068 | } |
| 2069 | break; |
| 2070 | // Unsigned comparison. |
| 2071 | case Ugreater: |
| 2072 | if (rt.imm32_ == 0) { |
| 2073 | offset = shifted_branch_offset(L, false); |
| 2074 | bgtz(rs, offset); |
| 2075 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2076 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2077 | r2 = scratch; |
| 2078 | li(r2, rt); |
| 2079 | sltu(scratch, r2, rs); |
| 2080 | offset = shifted_branch_offset(L, false); |
| 2081 | bne(scratch, zero_reg, offset); |
| 2082 | } |
| 2083 | break; |
| 2084 | case Ugreater_equal: |
| 2085 | if (rt.imm32_ == 0) { |
| 2086 | offset = shifted_branch_offset(L, false); |
| 2087 | bgez(rs, offset); |
| 2088 | } else if (is_int16(rt.imm32_)) { |
| 2089 | sltiu(scratch, rs, rt.imm32_); |
| 2090 | offset = shifted_branch_offset(L, false); |
| 2091 | beq(scratch, zero_reg, offset); |
| 2092 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2093 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2094 | r2 = scratch; |
| 2095 | li(r2, rt); |
| 2096 | sltu(scratch, rs, r2); |
| 2097 | offset = shifted_branch_offset(L, false); |
| 2098 | beq(scratch, zero_reg, offset); |
| 2099 | } |
| 2100 | break; |
| 2101 | case Uless: |
| 2102 | if (rt.imm32_ == 0) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2103 | // No code needs to be emitted. |
| 2104 | return; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2105 | } else if (is_int16(rt.imm32_)) { |
| 2106 | sltiu(scratch, rs, rt.imm32_); |
| 2107 | offset = shifted_branch_offset(L, false); |
| 2108 | bne(scratch, zero_reg, offset); |
| 2109 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2110 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2111 | r2 = scratch; |
| 2112 | li(r2, rt); |
| 2113 | sltu(scratch, rs, r2); |
| 2114 | offset = shifted_branch_offset(L, false); |
| 2115 | bne(scratch, zero_reg, offset); |
| 2116 | } |
| 2117 | break; |
| 2118 | case Uless_equal: |
| 2119 | if (rt.imm32_ == 0) { |
| 2120 | offset = shifted_branch_offset(L, false); |
| 2121 | b(offset); |
| 2122 | } else { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2123 | ASSERT(!scratch.is(rs)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2124 | r2 = scratch; |
| 2125 | li(r2, rt); |
| 2126 | sltu(scratch, r2, rs); |
| 2127 | offset = shifted_branch_offset(L, false); |
| 2128 | beq(scratch, zero_reg, offset); |
| 2129 | } |
| 2130 | break; |
| 2131 | default: |
| 2132 | UNREACHABLE(); |
| 2133 | } |
| 2134 | } |
| 2135 | // Check that offset could actually hold on an int16_t. |
| 2136 | ASSERT(is_int16(offset)); |
| 2137 | // Emit a nop in the branch delay slot if required. |
| 2138 | if (bdslot == PROTECT) |
| 2139 | nop(); |
| 2140 | } |
| 2141 | |
| 2142 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2143 | void MacroAssembler::BranchAndLink(int16_t offset, BranchDelaySlot bdslot) { |
| 2144 | BranchAndLinkShort(offset, bdslot); |
| 2145 | } |
| 2146 | |
| 2147 | |
| 2148 | void MacroAssembler::BranchAndLink(int16_t offset, Condition cond, Register rs, |
| 2149 | const Operand& rt, |
| 2150 | BranchDelaySlot bdslot) { |
| 2151 | BranchAndLinkShort(offset, cond, rs, rt, bdslot); |
| 2152 | } |
| 2153 | |
| 2154 | |
| 2155 | void MacroAssembler::BranchAndLink(Label* L, BranchDelaySlot bdslot) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2156 | if (L->is_bound()) { |
| 2157 | if (is_near(L)) { |
| 2158 | BranchAndLinkShort(L, bdslot); |
| 2159 | } else { |
| 2160 | Jalr(L, bdslot); |
| 2161 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2162 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2163 | if (is_trampoline_emitted()) { |
| 2164 | Jalr(L, bdslot); |
| 2165 | } else { |
| 2166 | BranchAndLinkShort(L, bdslot); |
| 2167 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | |
| 2172 | void MacroAssembler::BranchAndLink(Label* L, Condition cond, Register rs, |
| 2173 | const Operand& rt, |
| 2174 | BranchDelaySlot bdslot) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2175 | if (L->is_bound()) { |
| 2176 | if (is_near(L)) { |
| 2177 | BranchAndLinkShort(L, cond, rs, rt, bdslot); |
| 2178 | } else { |
| 2179 | Label skip; |
| 2180 | Condition neg_cond = NegateCondition(cond); |
| 2181 | BranchShort(&skip, neg_cond, rs, rt); |
| 2182 | Jalr(L, bdslot); |
| 2183 | bind(&skip); |
| 2184 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2185 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2186 | if (is_trampoline_emitted()) { |
| 2187 | Label skip; |
| 2188 | Condition neg_cond = NegateCondition(cond); |
| 2189 | BranchShort(&skip, neg_cond, rs, rt); |
| 2190 | Jalr(L, bdslot); |
| 2191 | bind(&skip); |
| 2192 | } else { |
| 2193 | BranchAndLinkShort(L, cond, rs, rt, bdslot); |
| 2194 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2199 | // We need to use a bgezal or bltzal, but they can't be used directly with the |
| 2200 | // slt instructions. We could use sub or add instead but we would miss overflow |
| 2201 | // cases, so we keep slt and add an intermediate third instruction. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2202 | void MacroAssembler::BranchAndLinkShort(int16_t offset, |
| 2203 | BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2204 | bal(offset); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2205 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2206 | // Emit a nop in the branch delay slot if required. |
| 2207 | if (bdslot == PROTECT) |
| 2208 | nop(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2212 | void MacroAssembler::BranchAndLinkShort(int16_t offset, Condition cond, |
| 2213 | Register rs, const Operand& rt, |
| 2214 | BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2215 | BRANCH_ARGS_CHECK(cond, rs, rt); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2216 | Register r2 = no_reg; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2217 | Register scratch = at; |
| 2218 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2219 | if (rt.is_reg()) { |
| 2220 | r2 = rt.rm_; |
| 2221 | } else if (cond != cc_always) { |
| 2222 | r2 = scratch; |
| 2223 | li(r2, rt); |
| 2224 | } |
| 2225 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2226 | { |
| 2227 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2228 | switch (cond) { |
| 2229 | case cc_always: |
| 2230 | bal(offset); |
| 2231 | break; |
| 2232 | case eq: |
| 2233 | bne(rs, r2, 2); |
| 2234 | nop(); |
| 2235 | bal(offset); |
| 2236 | break; |
| 2237 | case ne: |
| 2238 | beq(rs, r2, 2); |
| 2239 | nop(); |
| 2240 | bal(offset); |
| 2241 | break; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2242 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2243 | // Signed comparison. |
| 2244 | case greater: |
| 2245 | slt(scratch, r2, rs); |
| 2246 | addiu(scratch, scratch, -1); |
| 2247 | bgezal(scratch, offset); |
| 2248 | break; |
| 2249 | case greater_equal: |
| 2250 | slt(scratch, rs, r2); |
| 2251 | addiu(scratch, scratch, -1); |
| 2252 | bltzal(scratch, offset); |
| 2253 | break; |
| 2254 | case less: |
| 2255 | slt(scratch, rs, r2); |
| 2256 | addiu(scratch, scratch, -1); |
| 2257 | bgezal(scratch, offset); |
| 2258 | break; |
| 2259 | case less_equal: |
| 2260 | slt(scratch, r2, rs); |
| 2261 | addiu(scratch, scratch, -1); |
| 2262 | bltzal(scratch, offset); |
| 2263 | break; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2264 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2265 | // Unsigned comparison. |
| 2266 | case Ugreater: |
| 2267 | sltu(scratch, r2, rs); |
| 2268 | addiu(scratch, scratch, -1); |
| 2269 | bgezal(scratch, offset); |
| 2270 | break; |
| 2271 | case Ugreater_equal: |
| 2272 | sltu(scratch, rs, r2); |
| 2273 | addiu(scratch, scratch, -1); |
| 2274 | bltzal(scratch, offset); |
| 2275 | break; |
| 2276 | case Uless: |
| 2277 | sltu(scratch, rs, r2); |
| 2278 | addiu(scratch, scratch, -1); |
| 2279 | bgezal(scratch, offset); |
| 2280 | break; |
| 2281 | case Uless_equal: |
| 2282 | sltu(scratch, r2, rs); |
| 2283 | addiu(scratch, scratch, -1); |
| 2284 | bltzal(scratch, offset); |
| 2285 | break; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2286 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2287 | default: |
| 2288 | UNREACHABLE(); |
| 2289 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2290 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2291 | // Emit a nop in the branch delay slot if required. |
| 2292 | if (bdslot == PROTECT) |
| 2293 | nop(); |
| 2294 | } |
| 2295 | |
| 2296 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2297 | void MacroAssembler::BranchAndLinkShort(Label* L, BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2298 | bal(shifted_branch_offset(L, false)); |
| 2299 | |
| 2300 | // Emit a nop in the branch delay slot if required. |
| 2301 | if (bdslot == PROTECT) |
| 2302 | nop(); |
| 2303 | } |
| 2304 | |
| 2305 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2306 | void MacroAssembler::BranchAndLinkShort(Label* L, Condition cond, Register rs, |
| 2307 | const Operand& rt, |
| 2308 | BranchDelaySlot bdslot) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2309 | BRANCH_ARGS_CHECK(cond, rs, rt); |
| 2310 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2311 | int32_t offset = 0; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2312 | Register r2 = no_reg; |
| 2313 | Register scratch = at; |
| 2314 | if (rt.is_reg()) { |
| 2315 | r2 = rt.rm_; |
| 2316 | } else if (cond != cc_always) { |
| 2317 | r2 = scratch; |
| 2318 | li(r2, rt); |
| 2319 | } |
| 2320 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2321 | { |
| 2322 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2323 | switch (cond) { |
| 2324 | case cc_always: |
| 2325 | offset = shifted_branch_offset(L, false); |
| 2326 | bal(offset); |
| 2327 | break; |
| 2328 | case eq: |
| 2329 | bne(rs, r2, 2); |
| 2330 | nop(); |
| 2331 | offset = shifted_branch_offset(L, false); |
| 2332 | bal(offset); |
| 2333 | break; |
| 2334 | case ne: |
| 2335 | beq(rs, r2, 2); |
| 2336 | nop(); |
| 2337 | offset = shifted_branch_offset(L, false); |
| 2338 | bal(offset); |
| 2339 | break; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2340 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2341 | // Signed comparison. |
| 2342 | case greater: |
| 2343 | slt(scratch, r2, rs); |
| 2344 | addiu(scratch, scratch, -1); |
| 2345 | offset = shifted_branch_offset(L, false); |
| 2346 | bgezal(scratch, offset); |
| 2347 | break; |
| 2348 | case greater_equal: |
| 2349 | slt(scratch, rs, r2); |
| 2350 | addiu(scratch, scratch, -1); |
| 2351 | offset = shifted_branch_offset(L, false); |
| 2352 | bltzal(scratch, offset); |
| 2353 | break; |
| 2354 | case less: |
| 2355 | slt(scratch, rs, r2); |
| 2356 | addiu(scratch, scratch, -1); |
| 2357 | offset = shifted_branch_offset(L, false); |
| 2358 | bgezal(scratch, offset); |
| 2359 | break; |
| 2360 | case less_equal: |
| 2361 | slt(scratch, r2, rs); |
| 2362 | addiu(scratch, scratch, -1); |
| 2363 | offset = shifted_branch_offset(L, false); |
| 2364 | bltzal(scratch, offset); |
| 2365 | break; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2366 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2367 | // Unsigned comparison. |
| 2368 | case Ugreater: |
| 2369 | sltu(scratch, r2, rs); |
| 2370 | addiu(scratch, scratch, -1); |
| 2371 | offset = shifted_branch_offset(L, false); |
| 2372 | bgezal(scratch, offset); |
| 2373 | break; |
| 2374 | case Ugreater_equal: |
| 2375 | sltu(scratch, rs, r2); |
| 2376 | addiu(scratch, scratch, -1); |
| 2377 | offset = shifted_branch_offset(L, false); |
| 2378 | bltzal(scratch, offset); |
| 2379 | break; |
| 2380 | case Uless: |
| 2381 | sltu(scratch, rs, r2); |
| 2382 | addiu(scratch, scratch, -1); |
| 2383 | offset = shifted_branch_offset(L, false); |
| 2384 | bgezal(scratch, offset); |
| 2385 | break; |
| 2386 | case Uless_equal: |
| 2387 | sltu(scratch, r2, rs); |
| 2388 | addiu(scratch, scratch, -1); |
| 2389 | offset = shifted_branch_offset(L, false); |
| 2390 | bltzal(scratch, offset); |
| 2391 | break; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2392 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 2393 | default: |
| 2394 | UNREACHABLE(); |
| 2395 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2396 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2397 | // Check that offset could actually hold on an int16_t. |
| 2398 | ASSERT(is_int16(offset)); |
| 2399 | |
| 2400 | // Emit a nop in the branch delay slot if required. |
| 2401 | if (bdslot == PROTECT) |
| 2402 | nop(); |
| 2403 | } |
| 2404 | |
| 2405 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2406 | void MacroAssembler::Jump(Register target, |
| 2407 | Condition cond, |
| 2408 | Register rs, |
| 2409 | const Operand& rt, |
| 2410 | BranchDelaySlot bd) { |
| 2411 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2412 | if (cond == cc_always) { |
| 2413 | jr(target); |
| 2414 | } else { |
| 2415 | BRANCH_ARGS_CHECK(cond, rs, rt); |
| 2416 | Branch(2, NegateCondition(cond), rs, rt); |
| 2417 | jr(target); |
| 2418 | } |
| 2419 | // Emit a nop in the branch delay slot if required. |
| 2420 | if (bd == PROTECT) |
| 2421 | nop(); |
| 2422 | } |
| 2423 | |
| 2424 | |
| 2425 | void MacroAssembler::Jump(intptr_t target, |
| 2426 | RelocInfo::Mode rmode, |
| 2427 | Condition cond, |
| 2428 | Register rs, |
| 2429 | const Operand& rt, |
| 2430 | BranchDelaySlot bd) { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2431 | Label skip; |
| 2432 | if (cond != cc_always) { |
| 2433 | Branch(USE_DELAY_SLOT, &skip, NegateCondition(cond), rs, rt); |
| 2434 | } |
| 2435 | // The first instruction of 'li' may be placed in the delay slot. |
| 2436 | // This is not an issue, t9 is expected to be clobbered anyway. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2437 | li(t9, Operand(target, rmode)); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2438 | Jump(t9, al, zero_reg, Operand(zero_reg), bd); |
| 2439 | bind(&skip); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | void MacroAssembler::Jump(Address target, |
| 2444 | RelocInfo::Mode rmode, |
| 2445 | Condition cond, |
| 2446 | Register rs, |
| 2447 | const Operand& rt, |
| 2448 | BranchDelaySlot bd) { |
| 2449 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 2450 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond, rs, rt, bd); |
| 2451 | } |
| 2452 | |
| 2453 | |
| 2454 | void MacroAssembler::Jump(Handle<Code> code, |
| 2455 | RelocInfo::Mode rmode, |
| 2456 | Condition cond, |
| 2457 | Register rs, |
| 2458 | const Operand& rt, |
| 2459 | BranchDelaySlot bd) { |
| 2460 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2461 | ALLOW_HANDLE_DEREF(isolate(), "embedding raw address"); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2462 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond, rs, rt, bd); |
| 2463 | } |
| 2464 | |
| 2465 | |
| 2466 | int MacroAssembler::CallSize(Register target, |
| 2467 | Condition cond, |
| 2468 | Register rs, |
| 2469 | const Operand& rt, |
| 2470 | BranchDelaySlot bd) { |
| 2471 | int size = 0; |
| 2472 | |
| 2473 | if (cond == cc_always) { |
| 2474 | size += 1; |
| 2475 | } else { |
| 2476 | size += 3; |
| 2477 | } |
| 2478 | |
| 2479 | if (bd == PROTECT) |
| 2480 | size += 1; |
| 2481 | |
| 2482 | return size * kInstrSize; |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | // Note: To call gcc-compiled C code on mips, you must call thru t9. |
| 2487 | void MacroAssembler::Call(Register target, |
| 2488 | Condition cond, |
| 2489 | Register rs, |
| 2490 | const Operand& rt, |
| 2491 | BranchDelaySlot bd) { |
| 2492 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2493 | Label start; |
| 2494 | bind(&start); |
| 2495 | if (cond == cc_always) { |
| 2496 | jalr(target); |
| 2497 | } else { |
| 2498 | BRANCH_ARGS_CHECK(cond, rs, rt); |
| 2499 | Branch(2, NegateCondition(cond), rs, rt); |
| 2500 | jalr(target); |
| 2501 | } |
| 2502 | // Emit a nop in the branch delay slot if required. |
| 2503 | if (bd == PROTECT) |
| 2504 | nop(); |
| 2505 | |
| 2506 | ASSERT_EQ(CallSize(target, cond, rs, rt, bd), |
| 2507 | SizeOfCodeGeneratedSince(&start)); |
| 2508 | } |
| 2509 | |
| 2510 | |
| 2511 | int MacroAssembler::CallSize(Address target, |
| 2512 | RelocInfo::Mode rmode, |
| 2513 | Condition cond, |
| 2514 | Register rs, |
| 2515 | const Operand& rt, |
| 2516 | BranchDelaySlot bd) { |
| 2517 | int size = CallSize(t9, cond, rs, rt, bd); |
| 2518 | return size + 2 * kInstrSize; |
| 2519 | } |
| 2520 | |
| 2521 | |
| 2522 | void MacroAssembler::Call(Address target, |
| 2523 | RelocInfo::Mode rmode, |
| 2524 | Condition cond, |
| 2525 | Register rs, |
| 2526 | const Operand& rt, |
| 2527 | BranchDelaySlot bd) { |
| 2528 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2529 | Label start; |
| 2530 | bind(&start); |
| 2531 | int32_t target_int = reinterpret_cast<int32_t>(target); |
| 2532 | // Must record previous source positions before the |
| 2533 | // li() generates a new code target. |
| 2534 | positions_recorder()->WriteRecordedPositions(); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2535 | li(t9, Operand(target_int, rmode), CONSTANT_SIZE); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2536 | Call(t9, cond, rs, rt, bd); |
| 2537 | ASSERT_EQ(CallSize(target, rmode, cond, rs, rt, bd), |
| 2538 | SizeOfCodeGeneratedSince(&start)); |
| 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | int MacroAssembler::CallSize(Handle<Code> code, |
| 2543 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2544 | TypeFeedbackId ast_id, |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2545 | Condition cond, |
| 2546 | Register rs, |
| 2547 | const Operand& rt, |
| 2548 | BranchDelaySlot bd) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2549 | ALLOW_HANDLE_DEREF(isolate(), "using raw address"); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2550 | return CallSize(reinterpret_cast<Address>(code.location()), |
| 2551 | rmode, cond, rs, rt, bd); |
| 2552 | } |
| 2553 | |
| 2554 | |
| 2555 | void MacroAssembler::Call(Handle<Code> code, |
| 2556 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2557 | TypeFeedbackId ast_id, |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2558 | Condition cond, |
| 2559 | Register rs, |
| 2560 | const Operand& rt, |
| 2561 | BranchDelaySlot bd) { |
| 2562 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2563 | Label start; |
| 2564 | bind(&start); |
| 2565 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2566 | if (rmode == RelocInfo::CODE_TARGET && !ast_id.IsNone()) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2567 | SetRecordedAstId(ast_id); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2568 | rmode = RelocInfo::CODE_TARGET_WITH_ID; |
| 2569 | } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2570 | ALLOW_HANDLE_DEREF(isolate(), "embedding raw address"); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2571 | Call(reinterpret_cast<Address>(code.location()), rmode, cond, rs, rt, bd); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2572 | ASSERT_EQ(CallSize(code, rmode, ast_id, cond, rs, rt, bd), |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2573 | SizeOfCodeGeneratedSince(&start)); |
| 2574 | } |
| 2575 | |
| 2576 | |
| 2577 | void MacroAssembler::Ret(Condition cond, |
| 2578 | Register rs, |
| 2579 | const Operand& rt, |
| 2580 | BranchDelaySlot bd) { |
| 2581 | Jump(ra, cond, rs, rt, bd); |
| 2582 | } |
| 2583 | |
| 2584 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2585 | void MacroAssembler::J(Label* L, BranchDelaySlot bdslot) { |
| 2586 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2587 | |
| 2588 | uint32_t imm28; |
| 2589 | imm28 = jump_address(L); |
| 2590 | imm28 &= kImm28Mask; |
| 2591 | { BlockGrowBufferScope block_buf_growth(this); |
| 2592 | // Buffer growth (and relocation) must be blocked for internal references |
| 2593 | // until associated instructions are emitted and available to be patched. |
| 2594 | RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE); |
| 2595 | j(imm28); |
| 2596 | } |
| 2597 | // Emit a nop in the branch delay slot if required. |
| 2598 | if (bdslot == PROTECT) |
| 2599 | nop(); |
| 2600 | } |
| 2601 | |
| 2602 | |
| 2603 | void MacroAssembler::Jr(Label* L, BranchDelaySlot bdslot) { |
| 2604 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2605 | |
| 2606 | uint32_t imm32; |
| 2607 | imm32 = jump_address(L); |
| 2608 | { BlockGrowBufferScope block_buf_growth(this); |
| 2609 | // Buffer growth (and relocation) must be blocked for internal references |
| 2610 | // until associated instructions are emitted and available to be patched. |
| 2611 | RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE); |
| 2612 | lui(at, (imm32 & kHiMask) >> kLuiShift); |
| 2613 | ori(at, at, (imm32 & kImm16Mask)); |
| 2614 | } |
| 2615 | jr(at); |
| 2616 | |
| 2617 | // Emit a nop in the branch delay slot if required. |
| 2618 | if (bdslot == PROTECT) |
| 2619 | nop(); |
| 2620 | } |
| 2621 | |
| 2622 | |
| 2623 | void MacroAssembler::Jalr(Label* L, BranchDelaySlot bdslot) { |
| 2624 | BlockTrampolinePoolScope block_trampoline_pool(this); |
| 2625 | |
| 2626 | uint32_t imm32; |
| 2627 | imm32 = jump_address(L); |
| 2628 | { BlockGrowBufferScope block_buf_growth(this); |
| 2629 | // Buffer growth (and relocation) must be blocked for internal references |
| 2630 | // until associated instructions are emitted and available to be patched. |
| 2631 | RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE); |
| 2632 | lui(at, (imm32 & kHiMask) >> kLuiShift); |
| 2633 | ori(at, at, (imm32 & kImm16Mask)); |
| 2634 | } |
| 2635 | jalr(at); |
| 2636 | |
| 2637 | // Emit a nop in the branch delay slot if required. |
| 2638 | if (bdslot == PROTECT) |
| 2639 | nop(); |
| 2640 | } |
| 2641 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2642 | void MacroAssembler::DropAndRet(int drop) { |
| 2643 | Ret(USE_DELAY_SLOT); |
| 2644 | addiu(sp, sp, drop * kPointerSize); |
| 2645 | } |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 2646 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2647 | void MacroAssembler::DropAndRet(int drop, |
| 2648 | Condition cond, |
| 2649 | Register r1, |
| 2650 | const Operand& r2) { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2651 | // Both Drop and Ret need to be conditional. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2652 | Label skip; |
| 2653 | if (cond != cc_always) { |
| 2654 | Branch(&skip, NegateCondition(cond), r1, r2); |
| 2655 | } |
| 2656 | |
| 2657 | Drop(drop); |
| 2658 | Ret(); |
| 2659 | |
| 2660 | if (cond != cc_always) { |
| 2661 | bind(&skip); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2666 | void MacroAssembler::Drop(int count, |
| 2667 | Condition cond, |
| 2668 | Register reg, |
| 2669 | const Operand& op) { |
| 2670 | if (count <= 0) { |
| 2671 | return; |
| 2672 | } |
| 2673 | |
| 2674 | Label skip; |
| 2675 | |
| 2676 | if (cond != al) { |
| 2677 | Branch(&skip, NegateCondition(cond), reg, op); |
| 2678 | } |
| 2679 | |
| 2680 | addiu(sp, sp, count * kPointerSize); |
| 2681 | |
| 2682 | if (cond != al) { |
| 2683 | bind(&skip); |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2689 | void MacroAssembler::Swap(Register reg1, |
| 2690 | Register reg2, |
| 2691 | Register scratch) { |
| 2692 | if (scratch.is(no_reg)) { |
| 2693 | Xor(reg1, reg1, Operand(reg2)); |
| 2694 | Xor(reg2, reg2, Operand(reg1)); |
| 2695 | Xor(reg1, reg1, Operand(reg2)); |
| 2696 | } else { |
| 2697 | mov(scratch, reg1); |
| 2698 | mov(reg1, reg2); |
| 2699 | mov(reg2, scratch); |
| 2700 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | |
| 2704 | void MacroAssembler::Call(Label* target) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2705 | BranchAndLink(target); |
| 2706 | } |
| 2707 | |
| 2708 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2709 | void MacroAssembler::Push(Handle<Object> handle) { |
| 2710 | li(at, Operand(handle)); |
| 2711 | push(at); |
| 2712 | } |
| 2713 | |
| 2714 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2715 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2716 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2717 | void MacroAssembler::DebugBreak() { |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 2718 | PrepareCEntryArgs(0); |
| 2719 | PrepareCEntryFunction(ExternalReference(Runtime::kDebugBreak, isolate())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2720 | CEntryStub ces(1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2721 | ASSERT(AllowThisStubCall(&ces)); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2722 | Call(ces.GetCode(isolate()), RelocInfo::DEBUG_BREAK); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2726 | |
| 2727 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2728 | // --------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2729 | // Exception handling. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2730 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2731 | void MacroAssembler::PushTryHandler(StackHandler::Kind kind, |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2732 | int handler_index) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2733 | // Adjust this code if not the case. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2734 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 2735 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2736 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 2737 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 2738 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 2739 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2740 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2741 | // For the JSEntry handler, we must preserve a0-a3 and s0. |
| 2742 | // t1-t3 are available. We will build up the handler from the bottom by |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2743 | // pushing on the stack. |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2744 | // Set up the code object (t1) and the state (t2) for pushing. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2745 | unsigned state = |
| 2746 | StackHandler::IndexField::encode(handler_index) | |
| 2747 | StackHandler::KindField::encode(kind); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2748 | li(t1, Operand(CodeObject()), CONSTANT_SIZE); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2749 | li(t2, Operand(state)); |
| 2750 | |
| 2751 | // Push the frame pointer, context, state, and code object. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2752 | if (kind == StackHandler::JS_ENTRY) { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2753 | ASSERT_EQ(Smi::FromInt(0), 0); |
| 2754 | // The second zero_reg indicates no context. |
| 2755 | // The first zero_reg is the NULL frame pointer. |
| 2756 | // The operands are reversed to match the order of MultiPush/Pop. |
| 2757 | Push(zero_reg, zero_reg, t2, t1); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2758 | } else { |
| 2759 | MultiPush(t1.bit() | t2.bit() | cp.bit() | fp.bit()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | // Link the current handler as the next handler. |
| 2763 | li(t2, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 2764 | lw(t1, MemOperand(t2)); |
| 2765 | push(t1); |
| 2766 | // Set this new handler as the current one. |
| 2767 | sw(sp, MemOperand(t2)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | |
| 2771 | void MacroAssembler::PopTryHandler() { |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2772 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2773 | pop(a1); |
| 2774 | Addu(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2775 | li(at, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2776 | sw(a1, MemOperand(at)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2780 | void MacroAssembler::JumpToHandlerEntry() { |
| 2781 | // Compute the handler entry address and jump to it. The handler table is |
| 2782 | // a fixed array of (smi-tagged) code offsets. |
| 2783 | // v0 = exception, a1 = code object, a2 = state. |
| 2784 | lw(a3, FieldMemOperand(a1, Code::kHandlerTableOffset)); // Handler table. |
| 2785 | Addu(a3, a3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2786 | srl(a2, a2, StackHandler::kKindWidth); // Handler index. |
| 2787 | sll(a2, a2, kPointerSizeLog2); |
| 2788 | Addu(a2, a3, a2); |
| 2789 | lw(a2, MemOperand(a2)); // Smi-tagged offset. |
| 2790 | Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start. |
| 2791 | sra(t9, a2, kSmiTagSize); |
| 2792 | Addu(t9, t9, a1); |
| 2793 | Jump(t9); // Jump. |
| 2794 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2795 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2796 | |
| 2797 | void MacroAssembler::Throw(Register value) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2798 | // Adjust this code if not the case. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2799 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2800 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 2801 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 2802 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 2803 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 2804 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2805 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2806 | // The exception is expected in v0. |
| 2807 | Move(v0, value); |
| 2808 | |
| 2809 | // Drop the stack pointer to the top of the top handler. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2810 | li(a3, Operand(ExternalReference(Isolate::kHandlerAddress, |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2811 | isolate()))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2812 | lw(sp, MemOperand(a3)); |
| 2813 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2814 | // Restore the next handler. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2815 | pop(a2); |
| 2816 | sw(a2, MemOperand(a3)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2817 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2818 | // Get the code object (a1) and state (a2). Restore the context and frame |
| 2819 | // pointer. |
| 2820 | MultiPop(a1.bit() | a2.bit() | cp.bit() | fp.bit()); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2821 | |
| 2822 | // If the handler is a JS frame, restore the context to the frame. |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2823 | // (kind == ENTRY) == (fp == 0) == (cp == 0), so we could test either fp |
| 2824 | // or cp. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2825 | Label done; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2826 | Branch(&done, eq, cp, Operand(zero_reg)); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2827 | sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2828 | bind(&done); |
| 2829 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2830 | JumpToHandlerEntry(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2834 | void MacroAssembler::ThrowUncatchable(Register value) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2835 | // Adjust this code if not the case. |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 2836 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 2837 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2838 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 2839 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 2840 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 2841 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2842 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2843 | // The exception is expected in v0. |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2844 | if (!value.is(v0)) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2845 | mov(v0, value); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2846 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2847 | // Drop the stack pointer to the top of the top stack handler. |
| 2848 | li(a3, Operand(ExternalReference(Isolate::kHandlerAddress, isolate()))); |
| 2849 | lw(sp, MemOperand(a3)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2850 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2851 | // Unwind the handlers until the ENTRY handler is found. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2852 | Label fetch_next, check_kind; |
| 2853 | jmp(&check_kind); |
| 2854 | bind(&fetch_next); |
| 2855 | lw(sp, MemOperand(sp, StackHandlerConstants::kNextOffset)); |
| 2856 | |
| 2857 | bind(&check_kind); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2858 | STATIC_ASSERT(StackHandler::JS_ENTRY == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2859 | lw(a2, MemOperand(sp, StackHandlerConstants::kStateOffset)); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2860 | And(a2, a2, Operand(StackHandler::KindField::kMask)); |
| 2861 | Branch(&fetch_next, ne, a2, Operand(zero_reg)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2862 | |
| 2863 | // Set the top handler address to next handler past the top ENTRY handler. |
| 2864 | pop(a2); |
| 2865 | sw(a2, MemOperand(a3)); |
| 2866 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2867 | // Get the code object (a1) and state (a2). Clear the context and frame |
| 2868 | // pointer (0 was saved in the handler). |
| 2869 | MultiPop(a1.bit() | a2.bit() | cp.bit() | fp.bit()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2870 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2871 | JumpToHandlerEntry(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 2875 | void MacroAssembler::Allocate(int object_size, |
| 2876 | Register result, |
| 2877 | Register scratch1, |
| 2878 | Register scratch2, |
| 2879 | Label* gc_required, |
| 2880 | AllocationFlags flags) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2881 | if (!FLAG_inline_new) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2882 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2883 | // Trash the registers to simulate an allocation failure. |
| 2884 | li(result, 0x7091); |
| 2885 | li(scratch1, 0x7191); |
| 2886 | li(scratch2, 0x7291); |
| 2887 | } |
| 2888 | jmp(gc_required); |
| 2889 | return; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2892 | ASSERT(!result.is(scratch1)); |
| 2893 | ASSERT(!result.is(scratch2)); |
| 2894 | ASSERT(!scratch1.is(scratch2)); |
| 2895 | ASSERT(!scratch1.is(t9)); |
| 2896 | ASSERT(!scratch2.is(t9)); |
| 2897 | ASSERT(!result.is(t9)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2898 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2899 | // Make object size into bytes. |
| 2900 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 2901 | object_size *= kPointerSize; |
| 2902 | } |
| 2903 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2904 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2905 | // Check relative positions of allocation top and limit addresses. |
| 2906 | // ARM adds additional checks to make sure the ldm instruction can be |
| 2907 | // used. On MIPS we don't have ldm so we don't need additional checks either. |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 2908 | ExternalReference allocation_top = |
| 2909 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 2910 | ExternalReference allocation_limit = |
| 2911 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 2912 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2913 | intptr_t top = |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 2914 | reinterpret_cast<intptr_t>(allocation_top.address()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2915 | intptr_t limit = |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 2916 | reinterpret_cast<intptr_t>(allocation_limit.address()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2917 | ASSERT((limit - top) == kPointerSize); |
| 2918 | |
| 2919 | // Set up allocation top address and object size registers. |
| 2920 | Register topaddr = scratch1; |
| 2921 | Register obj_size_reg = scratch2; |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 2922 | li(topaddr, Operand(allocation_top)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2923 | li(obj_size_reg, Operand(object_size)); |
| 2924 | |
| 2925 | // This code stores a temporary value in t9. |
| 2926 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 2927 | // Load allocation top into result and allocation limit into t9. |
| 2928 | lw(result, MemOperand(topaddr)); |
| 2929 | lw(t9, MemOperand(topaddr, kPointerSize)); |
| 2930 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2931 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2932 | // Assert that result actually contains top on entry. t9 is used |
| 2933 | // immediately below so this use of t9 does not cause difference with |
| 2934 | // respect to register content between debug and release mode. |
| 2935 | lw(t9, MemOperand(topaddr)); |
| 2936 | Check(eq, "Unexpected allocation top", result, Operand(t9)); |
| 2937 | } |
| 2938 | // Load allocation limit into t9. Result already contains allocation top. |
| 2939 | lw(t9, MemOperand(topaddr, limit - top)); |
| 2940 | } |
| 2941 | |
| 2942 | // Calculate new top and bail out if new space is exhausted. Use result |
| 2943 | // to calculate the new top. |
| 2944 | Addu(scratch2, result, Operand(obj_size_reg)); |
| 2945 | Branch(gc_required, Ugreater, scratch2, Operand(t9)); |
| 2946 | sw(scratch2, MemOperand(topaddr)); |
| 2947 | |
| 2948 | // Tag object if requested. |
| 2949 | if ((flags & TAG_OBJECT) != 0) { |
| 2950 | Addu(result, result, Operand(kHeapObjectTag)); |
| 2951 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2955 | void MacroAssembler::Allocate(Register object_size, |
| 2956 | Register result, |
| 2957 | Register scratch1, |
| 2958 | Register scratch2, |
| 2959 | Label* gc_required, |
| 2960 | AllocationFlags flags) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2961 | if (!FLAG_inline_new) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2962 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2963 | // Trash the registers to simulate an allocation failure. |
| 2964 | li(result, 0x7091); |
| 2965 | li(scratch1, 0x7191); |
| 2966 | li(scratch2, 0x7291); |
| 2967 | } |
| 2968 | jmp(gc_required); |
| 2969 | return; |
| 2970 | } |
| 2971 | |
| 2972 | ASSERT(!result.is(scratch1)); |
| 2973 | ASSERT(!result.is(scratch2)); |
| 2974 | ASSERT(!scratch1.is(scratch2)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2975 | ASSERT(!object_size.is(t9)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2976 | ASSERT(!scratch1.is(t9) && !scratch2.is(t9) && !result.is(t9)); |
| 2977 | |
| 2978 | // Check relative positions of allocation top and limit addresses. |
| 2979 | // ARM adds additional checks to make sure the ldm instruction can be |
| 2980 | // used. On MIPS we don't have ldm so we don't need additional checks either. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2981 | ExternalReference allocation_top = |
| 2982 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
| 2983 | ExternalReference allocation_limit = |
| 2984 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2985 | intptr_t top = |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2986 | reinterpret_cast<intptr_t>(allocation_top.address()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2987 | intptr_t limit = |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2988 | reinterpret_cast<intptr_t>(allocation_limit.address()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2989 | ASSERT((limit - top) == kPointerSize); |
| 2990 | |
| 2991 | // Set up allocation top address and object size registers. |
| 2992 | Register topaddr = scratch1; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2993 | li(topaddr, Operand(allocation_top)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2994 | |
| 2995 | // This code stores a temporary value in t9. |
| 2996 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 2997 | // Load allocation top into result and allocation limit into t9. |
| 2998 | lw(result, MemOperand(topaddr)); |
| 2999 | lw(t9, MemOperand(topaddr, kPointerSize)); |
| 3000 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3001 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3002 | // Assert that result actually contains top on entry. t9 is used |
| 3003 | // immediately below so this use of t9 does not cause difference with |
| 3004 | // respect to register content between debug and release mode. |
| 3005 | lw(t9, MemOperand(topaddr)); |
| 3006 | Check(eq, "Unexpected allocation top", result, Operand(t9)); |
| 3007 | } |
| 3008 | // Load allocation limit into t9. Result already contains allocation top. |
| 3009 | lw(t9, MemOperand(topaddr, limit - top)); |
| 3010 | } |
| 3011 | |
| 3012 | // Calculate new top and bail out if new space is exhausted. Use result |
| 3013 | // to calculate the new top. Object size may be in words so a shift is |
| 3014 | // required to get the number of bytes. |
| 3015 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 3016 | sll(scratch2, object_size, kPointerSizeLog2); |
| 3017 | Addu(scratch2, result, scratch2); |
| 3018 | } else { |
| 3019 | Addu(scratch2, result, Operand(object_size)); |
| 3020 | } |
| 3021 | Branch(gc_required, Ugreater, scratch2, Operand(t9)); |
| 3022 | |
| 3023 | // Update allocation top. result temporarily holds the new top. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3024 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3025 | And(t9, scratch2, Operand(kObjectAlignmentMask)); |
| 3026 | Check(eq, "Unaligned allocation in new space", t9, Operand(zero_reg)); |
| 3027 | } |
| 3028 | sw(scratch2, MemOperand(topaddr)); |
| 3029 | |
| 3030 | // Tag object if requested. |
| 3031 | if ((flags & TAG_OBJECT) != 0) { |
| 3032 | Addu(result, result, Operand(kHeapObjectTag)); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | |
| 3037 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 3038 | Register scratch) { |
| 3039 | ExternalReference new_space_allocation_top = |
| 3040 | ExternalReference::new_space_allocation_top_address(isolate()); |
| 3041 | |
| 3042 | // Make sure the object has no tag before resetting top. |
| 3043 | And(object, object, Operand(~kHeapObjectTagMask)); |
| 3044 | #ifdef DEBUG |
| 3045 | // Check that the object un-allocated is below the current top. |
| 3046 | li(scratch, Operand(new_space_allocation_top)); |
| 3047 | lw(scratch, MemOperand(scratch)); |
| 3048 | Check(less, "Undo allocation of non allocated memory", |
| 3049 | object, Operand(scratch)); |
| 3050 | #endif |
| 3051 | // Write the address of the object to un-allocate as the current top. |
| 3052 | li(scratch, Operand(new_space_allocation_top)); |
| 3053 | sw(object, MemOperand(scratch)); |
| 3054 | } |
| 3055 | |
| 3056 | |
| 3057 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 3058 | Register length, |
| 3059 | Register scratch1, |
| 3060 | Register scratch2, |
| 3061 | Register scratch3, |
| 3062 | Label* gc_required) { |
| 3063 | // Calculate the number of bytes needed for the characters in the string while |
| 3064 | // observing object alignment. |
| 3065 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 3066 | sll(scratch1, length, 1); // Length in bytes, not chars. |
| 3067 | addiu(scratch1, scratch1, |
| 3068 | kObjectAlignmentMask + SeqTwoByteString::kHeaderSize); |
| 3069 | And(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
| 3070 | |
| 3071 | // Allocate two-byte string in new space. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3072 | Allocate(scratch1, |
| 3073 | result, |
| 3074 | scratch2, |
| 3075 | scratch3, |
| 3076 | gc_required, |
| 3077 | TAG_OBJECT); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3078 | |
| 3079 | // Set the map, length and hash field. |
| 3080 | InitializeNewString(result, |
| 3081 | length, |
| 3082 | Heap::kStringMapRootIndex, |
| 3083 | scratch1, |
| 3084 | scratch2); |
| 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | void MacroAssembler::AllocateAsciiString(Register result, |
| 3089 | Register length, |
| 3090 | Register scratch1, |
| 3091 | Register scratch2, |
| 3092 | Register scratch3, |
| 3093 | Label* gc_required) { |
| 3094 | // Calculate the number of bytes needed for the characters in the string |
| 3095 | // while observing object alignment. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3096 | ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3097 | ASSERT(kCharSize == 1); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3098 | addiu(scratch1, length, kObjectAlignmentMask + SeqOneByteString::kHeaderSize); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3099 | And(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
| 3100 | |
| 3101 | // Allocate ASCII string in new space. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3102 | Allocate(scratch1, |
| 3103 | result, |
| 3104 | scratch2, |
| 3105 | scratch3, |
| 3106 | gc_required, |
| 3107 | TAG_OBJECT); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3108 | |
| 3109 | // Set the map, length and hash field. |
| 3110 | InitializeNewString(result, |
| 3111 | length, |
| 3112 | Heap::kAsciiStringMapRootIndex, |
| 3113 | scratch1, |
| 3114 | scratch2); |
| 3115 | } |
| 3116 | |
| 3117 | |
| 3118 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 3119 | Register length, |
| 3120 | Register scratch1, |
| 3121 | Register scratch2, |
| 3122 | Label* gc_required) { |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 3123 | Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| 3124 | TAG_OBJECT); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3125 | InitializeNewString(result, |
| 3126 | length, |
| 3127 | Heap::kConsStringMapRootIndex, |
| 3128 | scratch1, |
| 3129 | scratch2); |
| 3130 | } |
| 3131 | |
| 3132 | |
| 3133 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 3134 | Register length, |
| 3135 | Register scratch1, |
| 3136 | Register scratch2, |
| 3137 | Label* gc_required) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 3138 | Label allocate_new_space, install_map; |
| 3139 | AllocationFlags flags = TAG_OBJECT; |
| 3140 | |
| 3141 | ExternalReference high_promotion_mode = ExternalReference:: |
| 3142 | new_space_high_promotion_mode_active_address(isolate()); |
| 3143 | li(scratch1, Operand(high_promotion_mode)); |
| 3144 | lw(scratch1, MemOperand(scratch1, 0)); |
| 3145 | Branch(&allocate_new_space, eq, scratch1, Operand(zero_reg)); |
| 3146 | |
| 3147 | Allocate(ConsString::kSize, |
| 3148 | result, |
| 3149 | scratch1, |
| 3150 | scratch2, |
| 3151 | gc_required, |
| 3152 | static_cast<AllocationFlags>(flags | PRETENURE_OLD_POINTER_SPACE)); |
| 3153 | |
| 3154 | jmp(&install_map); |
| 3155 | |
| 3156 | bind(&allocate_new_space); |
| 3157 | Allocate(ConsString::kSize, |
| 3158 | result, |
| 3159 | scratch1, |
| 3160 | scratch2, |
| 3161 | gc_required, |
| 3162 | flags); |
| 3163 | |
| 3164 | bind(&install_map); |
| 3165 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3166 | InitializeNewString(result, |
| 3167 | length, |
| 3168 | Heap::kConsAsciiStringMapRootIndex, |
| 3169 | scratch1, |
| 3170 | scratch2); |
| 3171 | } |
| 3172 | |
| 3173 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3174 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
| 3175 | Register length, |
| 3176 | Register scratch1, |
| 3177 | Register scratch2, |
| 3178 | Label* gc_required) { |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 3179 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 3180 | TAG_OBJECT); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3181 | |
| 3182 | InitializeNewString(result, |
| 3183 | length, |
| 3184 | Heap::kSlicedStringMapRootIndex, |
| 3185 | scratch1, |
| 3186 | scratch2); |
| 3187 | } |
| 3188 | |
| 3189 | |
| 3190 | void MacroAssembler::AllocateAsciiSlicedString(Register result, |
| 3191 | Register length, |
| 3192 | Register scratch1, |
| 3193 | Register scratch2, |
| 3194 | Label* gc_required) { |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 3195 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 3196 | TAG_OBJECT); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3197 | |
| 3198 | InitializeNewString(result, |
| 3199 | length, |
| 3200 | Heap::kSlicedAsciiStringMapRootIndex, |
| 3201 | scratch1, |
| 3202 | scratch2); |
| 3203 | } |
| 3204 | |
| 3205 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3206 | // Allocates a heap number or jumps to the label if the young space is full and |
| 3207 | // a scavenge is needed. |
| 3208 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 3209 | Register scratch1, |
| 3210 | Register scratch2, |
| 3211 | Register heap_number_map, |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3212 | Label* need_gc, |
| 3213 | TaggingMode tagging_mode) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3214 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 3215 | // object. |
jkummerow@chromium.org | 4c54a2a | 2013-03-19 17:51:30 +0000 | [diff] [blame] | 3216 | Allocate(HeapNumber::kSize, result, scratch1, scratch2, need_gc, |
| 3217 | tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3218 | |
| 3219 | // Store heap number map in the allocated object. |
| 3220 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3221 | if (tagging_mode == TAG_RESULT) { |
| 3222 | sw(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
| 3223 | } else { |
| 3224 | sw(heap_number_map, MemOperand(result, HeapObject::kMapOffset)); |
| 3225 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | |
| 3229 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 3230 | FPURegister value, |
| 3231 | Register scratch1, |
| 3232 | Register scratch2, |
| 3233 | Label* gc_required) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3234 | LoadRoot(t8, Heap::kHeapNumberMapRootIndex); |
| 3235 | AllocateHeapNumber(result, scratch1, scratch2, t8, gc_required); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3236 | sdc1(value, FieldMemOperand(result, HeapNumber::kValueOffset)); |
| 3237 | } |
| 3238 | |
| 3239 | |
| 3240 | // Copies a fixed number of fields of heap objects from src to dst. |
| 3241 | void MacroAssembler::CopyFields(Register dst, |
| 3242 | Register src, |
| 3243 | RegList temps, |
| 3244 | int field_count) { |
| 3245 | ASSERT((temps & dst.bit()) == 0); |
| 3246 | ASSERT((temps & src.bit()) == 0); |
| 3247 | // Primitive implementation using only one temporary register. |
| 3248 | |
| 3249 | Register tmp = no_reg; |
| 3250 | // Find a temp register in temps list. |
| 3251 | for (int i = 0; i < kNumRegisters; i++) { |
| 3252 | if ((temps & (1 << i)) != 0) { |
| 3253 | tmp.code_ = i; |
| 3254 | break; |
| 3255 | } |
| 3256 | } |
| 3257 | ASSERT(!tmp.is(no_reg)); |
| 3258 | |
| 3259 | for (int i = 0; i < field_count; i++) { |
| 3260 | lw(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 3261 | sw(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3266 | void MacroAssembler::CopyBytes(Register src, |
| 3267 | Register dst, |
| 3268 | Register length, |
| 3269 | Register scratch) { |
| 3270 | Label align_loop, align_loop_1, word_loop, byte_loop, byte_loop_1, done; |
| 3271 | |
| 3272 | // Align src before copying in word size chunks. |
| 3273 | bind(&align_loop); |
| 3274 | Branch(&done, eq, length, Operand(zero_reg)); |
| 3275 | bind(&align_loop_1); |
| 3276 | And(scratch, src, kPointerSize - 1); |
| 3277 | Branch(&word_loop, eq, scratch, Operand(zero_reg)); |
| 3278 | lbu(scratch, MemOperand(src)); |
| 3279 | Addu(src, src, 1); |
| 3280 | sb(scratch, MemOperand(dst)); |
| 3281 | Addu(dst, dst, 1); |
| 3282 | Subu(length, length, Operand(1)); |
| 3283 | Branch(&byte_loop_1, ne, length, Operand(zero_reg)); |
| 3284 | |
| 3285 | // Copy bytes in word size chunks. |
| 3286 | bind(&word_loop); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3287 | if (emit_debug_code()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3288 | And(scratch, src, kPointerSize - 1); |
| 3289 | Assert(eq, "Expecting alignment for CopyBytes", |
| 3290 | scratch, Operand(zero_reg)); |
| 3291 | } |
| 3292 | Branch(&byte_loop, lt, length, Operand(kPointerSize)); |
| 3293 | lw(scratch, MemOperand(src)); |
| 3294 | Addu(src, src, kPointerSize); |
| 3295 | |
| 3296 | // TODO(kalmard) check if this can be optimized to use sw in most cases. |
| 3297 | // Can't use unaligned access - copy byte by byte. |
| 3298 | sb(scratch, MemOperand(dst, 0)); |
| 3299 | srl(scratch, scratch, 8); |
| 3300 | sb(scratch, MemOperand(dst, 1)); |
| 3301 | srl(scratch, scratch, 8); |
| 3302 | sb(scratch, MemOperand(dst, 2)); |
| 3303 | srl(scratch, scratch, 8); |
| 3304 | sb(scratch, MemOperand(dst, 3)); |
| 3305 | Addu(dst, dst, 4); |
| 3306 | |
| 3307 | Subu(length, length, Operand(kPointerSize)); |
| 3308 | Branch(&word_loop); |
| 3309 | |
| 3310 | // Copy the last bytes if any left. |
| 3311 | bind(&byte_loop); |
| 3312 | Branch(&done, eq, length, Operand(zero_reg)); |
| 3313 | bind(&byte_loop_1); |
| 3314 | lbu(scratch, MemOperand(src)); |
| 3315 | Addu(src, src, 1); |
| 3316 | sb(scratch, MemOperand(dst)); |
| 3317 | Addu(dst, dst, 1); |
| 3318 | Subu(length, length, Operand(1)); |
| 3319 | Branch(&byte_loop_1, ne, length, Operand(zero_reg)); |
| 3320 | bind(&done); |
| 3321 | } |
| 3322 | |
| 3323 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3324 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 3325 | Register end_offset, |
| 3326 | Register filler) { |
| 3327 | Label loop, entry; |
| 3328 | Branch(&entry); |
| 3329 | bind(&loop); |
| 3330 | sw(filler, MemOperand(start_offset)); |
| 3331 | Addu(start_offset, start_offset, kPointerSize); |
| 3332 | bind(&entry); |
| 3333 | Branch(&loop, lt, start_offset, Operand(end_offset)); |
| 3334 | } |
| 3335 | |
| 3336 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3337 | void MacroAssembler::CheckFastElements(Register map, |
| 3338 | Register scratch, |
| 3339 | Label* fail) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3340 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 3341 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 3342 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 3343 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3344 | lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3345 | Branch(fail, hi, scratch, |
| 3346 | Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3350 | void MacroAssembler::CheckFastObjectElements(Register map, |
| 3351 | Register scratch, |
| 3352 | Label* fail) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3353 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 3354 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 3355 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 3356 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3357 | lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 3358 | Branch(fail, ls, scratch, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3359 | Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3360 | Branch(fail, hi, scratch, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3361 | Operand(Map::kMaximumBitField2FastHoleyElementValue)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3365 | void MacroAssembler::CheckFastSmiElements(Register map, |
| 3366 | Register scratch, |
| 3367 | Label* fail) { |
| 3368 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 3369 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3370 | lbu(scratch, FieldMemOperand(map, Map::kBitField2Offset)); |
| 3371 | Branch(fail, hi, scratch, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3372 | Operand(Map::kMaximumBitField2FastHoleySmiElementValue)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | |
| 3376 | void MacroAssembler::StoreNumberToDoubleElements(Register value_reg, |
| 3377 | Register key_reg, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3378 | Register elements_reg, |
| 3379 | Register scratch1, |
| 3380 | Register scratch2, |
| 3381 | Register scratch3, |
| 3382 | Register scratch4, |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3383 | Label* fail, |
| 3384 | int elements_offset) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3385 | Label smi_value, maybe_nan, have_double_value, is_nan, done; |
| 3386 | Register mantissa_reg = scratch2; |
| 3387 | Register exponent_reg = scratch3; |
| 3388 | |
| 3389 | // Handle smi values specially. |
| 3390 | JumpIfSmi(value_reg, &smi_value); |
| 3391 | |
| 3392 | // Ensure that the object is a heap number |
| 3393 | CheckMap(value_reg, |
| 3394 | scratch1, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 3395 | Heap::kHeapNumberMapRootIndex, |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3396 | fail, |
| 3397 | DONT_DO_SMI_CHECK); |
| 3398 | |
| 3399 | // Check for nan: all NaN values have a value greater (signed) than 0x7ff00000 |
| 3400 | // in the exponent. |
| 3401 | li(scratch1, Operand(kNaNOrInfinityLowerBoundUpper32)); |
| 3402 | lw(exponent_reg, FieldMemOperand(value_reg, HeapNumber::kExponentOffset)); |
| 3403 | Branch(&maybe_nan, ge, exponent_reg, Operand(scratch1)); |
| 3404 | |
| 3405 | lw(mantissa_reg, FieldMemOperand(value_reg, HeapNumber::kMantissaOffset)); |
| 3406 | |
| 3407 | bind(&have_double_value); |
| 3408 | sll(scratch1, key_reg, kDoubleSizeLog2 - kSmiTagSize); |
| 3409 | Addu(scratch1, scratch1, elements_reg); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3410 | sw(mantissa_reg, FieldMemOperand( |
| 3411 | scratch1, FixedDoubleArray::kHeaderSize - elements_offset)); |
| 3412 | uint32_t offset = FixedDoubleArray::kHeaderSize - elements_offset + |
| 3413 | sizeof(kHoleNanLower32); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3414 | sw(exponent_reg, FieldMemOperand(scratch1, offset)); |
| 3415 | jmp(&done); |
| 3416 | |
| 3417 | bind(&maybe_nan); |
| 3418 | // Could be NaN or Infinity. If fraction is not zero, it's NaN, otherwise |
| 3419 | // it's an Infinity, and the non-NaN code path applies. |
| 3420 | Branch(&is_nan, gt, exponent_reg, Operand(scratch1)); |
| 3421 | lw(mantissa_reg, FieldMemOperand(value_reg, HeapNumber::kMantissaOffset)); |
| 3422 | Branch(&have_double_value, eq, mantissa_reg, Operand(zero_reg)); |
| 3423 | bind(&is_nan); |
| 3424 | // Load canonical NaN for storing into the double array. |
| 3425 | uint64_t nan_int64 = BitCast<uint64_t>( |
| 3426 | FixedDoubleArray::canonical_not_the_hole_nan_as_double()); |
| 3427 | li(mantissa_reg, Operand(static_cast<uint32_t>(nan_int64))); |
| 3428 | li(exponent_reg, Operand(static_cast<uint32_t>(nan_int64 >> 32))); |
| 3429 | jmp(&have_double_value); |
| 3430 | |
| 3431 | bind(&smi_value); |
| 3432 | Addu(scratch1, elements_reg, |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3433 | Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag - |
| 3434 | elements_offset)); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3435 | sll(scratch2, key_reg, kDoubleSizeLog2 - kSmiTagSize); |
| 3436 | Addu(scratch1, scratch1, scratch2); |
| 3437 | // scratch1 is now effective address of the double element |
| 3438 | |
| 3439 | FloatingPointHelper::Destination destination; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3440 | destination = FloatingPointHelper::kFPURegisters; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3441 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 3442 | Register untagged_value = elements_reg; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3443 | SmiUntag(untagged_value, value_reg); |
| 3444 | FloatingPointHelper::ConvertIntToDouble(this, |
| 3445 | untagged_value, |
| 3446 | destination, |
| 3447 | f0, |
| 3448 | mantissa_reg, |
| 3449 | exponent_reg, |
| 3450 | scratch4, |
| 3451 | f2); |
| 3452 | if (destination == FloatingPointHelper::kFPURegisters) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3453 | sdc1(f0, MemOperand(scratch1, 0)); |
| 3454 | } else { |
| 3455 | sw(mantissa_reg, MemOperand(scratch1, 0)); |
| 3456 | sw(exponent_reg, MemOperand(scratch1, Register::kSizeInBytes)); |
| 3457 | } |
| 3458 | bind(&done); |
| 3459 | } |
| 3460 | |
| 3461 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3462 | void MacroAssembler::CompareMapAndBranch(Register obj, |
| 3463 | Register scratch, |
| 3464 | Handle<Map> map, |
| 3465 | Label* early_success, |
| 3466 | Condition cond, |
| 3467 | Label* branch_to, |
| 3468 | CompareMapMode mode) { |
| 3469 | lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3470 | CompareMapAndBranch(scratch, map, early_success, cond, branch_to, mode); |
| 3471 | } |
| 3472 | |
| 3473 | |
| 3474 | void MacroAssembler::CompareMapAndBranch(Register obj_map, |
| 3475 | Handle<Map> map, |
| 3476 | Label* early_success, |
| 3477 | Condition cond, |
| 3478 | Label* branch_to, |
| 3479 | CompareMapMode mode) { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3480 | Operand right = Operand(map); |
| 3481 | if (mode == ALLOW_ELEMENT_TRANSITION_MAPS) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3482 | ElementsKind kind = map->elements_kind(); |
| 3483 | if (IsFastElementsKind(kind)) { |
| 3484 | bool packed = IsFastPackedElementsKind(kind); |
| 3485 | Map* current_map = *map; |
| 3486 | while (CanTransitionToMoreGeneralFastElementsKind(kind, packed)) { |
| 3487 | kind = GetNextMoreGeneralFastElementsKind(kind, packed); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3488 | current_map = current_map->LookupElementsTransitionMap(kind); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3489 | if (!current_map) break; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3490 | Branch(early_success, eq, obj_map, right); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 3491 | right = Operand(Handle<Map>(current_map)); |
| 3492 | } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3493 | } |
| 3494 | } |
| 3495 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3496 | Branch(branch_to, cond, obj_map, right); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3500 | void MacroAssembler::CheckMap(Register obj, |
| 3501 | Register scratch, |
| 3502 | Handle<Map> map, |
| 3503 | Label* fail, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3504 | SmiCheckType smi_check_type, |
| 3505 | CompareMapMode mode) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3506 | if (smi_check_type == DO_SMI_CHECK) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3507 | JumpIfSmi(obj, fail); |
| 3508 | } |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3509 | Label success; |
| 3510 | CompareMapAndBranch(obj, scratch, map, &success, ne, fail, mode); |
| 3511 | bind(&success); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3515 | void MacroAssembler::DispatchMap(Register obj, |
| 3516 | Register scratch, |
| 3517 | Handle<Map> map, |
| 3518 | Handle<Code> success, |
| 3519 | SmiCheckType smi_check_type) { |
| 3520 | Label fail; |
| 3521 | if (smi_check_type == DO_SMI_CHECK) { |
| 3522 | JumpIfSmi(obj, &fail); |
| 3523 | } |
| 3524 | lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 3525 | Jump(success, RelocInfo::CODE_TARGET, eq, scratch, Operand(map)); |
| 3526 | bind(&fail); |
| 3527 | } |
| 3528 | |
| 3529 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3530 | void MacroAssembler::CheckMap(Register obj, |
| 3531 | Register scratch, |
| 3532 | Heap::RootListIndex index, |
| 3533 | Label* fail, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3534 | SmiCheckType smi_check_type) { |
| 3535 | if (smi_check_type == DO_SMI_CHECK) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3536 | JumpIfSmi(obj, fail); |
| 3537 | } |
| 3538 | lw(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 3539 | LoadRoot(at, index); |
| 3540 | Branch(fail, ne, scratch, Operand(at)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3544 | void MacroAssembler::GetCFunctionDoubleResult(const DoubleRegister dst) { |
| 3545 | if (IsMipsSoftFloatABI) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3546 | Move(dst, v0, v1); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3547 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3548 | Move(dst, f0); // Reg f0 is o32 ABI FP return value. |
| 3549 | } |
| 3550 | } |
| 3551 | |
| 3552 | |
| 3553 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3554 | if (!IsMipsSoftFloatABI) { |
| 3555 | Move(f12, dreg); |
| 3556 | } else { |
| 3557 | Move(a0, a1, dreg); |
| 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg1, |
| 3563 | DoubleRegister dreg2) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3564 | if (!IsMipsSoftFloatABI) { |
| 3565 | if (dreg2.is(f12)) { |
| 3566 | ASSERT(!dreg1.is(f14)); |
| 3567 | Move(f14, dreg2); |
| 3568 | Move(f12, dreg1); |
| 3569 | } else { |
| 3570 | Move(f12, dreg1); |
| 3571 | Move(f14, dreg2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3572 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3573 | } else { |
| 3574 | Move(a0, a1, dreg1); |
| 3575 | Move(a2, a3, dreg2); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | |
| 3580 | void MacroAssembler::SetCallCDoubleArguments(DoubleRegister dreg, |
| 3581 | Register reg) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3582 | if (!IsMipsSoftFloatABI) { |
| 3583 | Move(f12, dreg); |
| 3584 | Move(a2, reg); |
| 3585 | } else { |
| 3586 | Move(a2, reg); |
| 3587 | Move(a0, a1, dreg); |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | |
| 3592 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 3593 | // This macro takes the dst register to make the code more readable |
| 3594 | // at the call sites. However, the dst register has to be t1 to |
| 3595 | // follow the calling convention which requires the call type to be |
| 3596 | // in t1. |
| 3597 | ASSERT(dst.is(t1)); |
| 3598 | if (call_kind == CALL_AS_FUNCTION) { |
| 3599 | li(dst, Operand(Smi::FromInt(1))); |
| 3600 | } else { |
| 3601 | li(dst, Operand(Smi::FromInt(0))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3606 | // ----------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3607 | // JavaScript invokes. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3608 | |
| 3609 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 3610 | const ParameterCount& actual, |
| 3611 | Handle<Code> code_constant, |
| 3612 | Register code_reg, |
| 3613 | Label* done, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3614 | bool* definitely_mismatches, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3615 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3616 | const CallWrapper& call_wrapper, |
| 3617 | CallKind call_kind) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3618 | bool definitely_matches = false; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3619 | *definitely_mismatches = false; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3620 | Label regular_invoke; |
| 3621 | |
| 3622 | // Check whether the expected and actual arguments count match. If not, |
| 3623 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 3624 | // a0: actual arguments count |
| 3625 | // a1: function (passed through to callee) |
| 3626 | // a2: expected arguments count |
| 3627 | // a3: callee code entry |
| 3628 | |
| 3629 | // The code below is made a lot easier because the calling code already sets |
| 3630 | // up actual and expected registers according to the contract if values are |
| 3631 | // passed in registers. |
| 3632 | ASSERT(actual.is_immediate() || actual.reg().is(a0)); |
| 3633 | ASSERT(expected.is_immediate() || expected.reg().is(a2)); |
| 3634 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(a3)); |
| 3635 | |
| 3636 | if (expected.is_immediate()) { |
| 3637 | ASSERT(actual.is_immediate()); |
| 3638 | if (expected.immediate() == actual.immediate()) { |
| 3639 | definitely_matches = true; |
| 3640 | } else { |
| 3641 | li(a0, Operand(actual.immediate())); |
| 3642 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3643 | if (expected.immediate() == sentinel) { |
| 3644 | // Don't worry about adapting arguments for builtins that |
| 3645 | // don't want that done. Skip adaption code by making it look |
| 3646 | // like we have a match between expected and actual number of |
| 3647 | // arguments. |
| 3648 | definitely_matches = true; |
| 3649 | } else { |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3650 | *definitely_mismatches = true; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3651 | li(a2, Operand(expected.immediate())); |
| 3652 | } |
| 3653 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3654 | } else if (actual.is_immediate()) { |
| 3655 | Branch(®ular_invoke, eq, expected.reg(), Operand(actual.immediate())); |
| 3656 | li(a0, Operand(actual.immediate())); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3657 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3658 | Branch(®ular_invoke, eq, expected.reg(), Operand(actual.reg())); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | if (!definitely_matches) { |
| 3662 | if (!code_constant.is_null()) { |
| 3663 | li(a3, Operand(code_constant)); |
| 3664 | addiu(a3, a3, Code::kHeaderSize - kHeapObjectTag); |
| 3665 | } |
| 3666 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3667 | Handle<Code> adaptor = |
| 3668 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3669 | if (flag == CALL_FUNCTION) { |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3670 | call_wrapper.BeforeCall(CallSize(adaptor)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3671 | SetCallKind(t1, call_kind); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3672 | Call(adaptor); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3673 | call_wrapper.AfterCall(); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3674 | if (!*definitely_mismatches) { |
| 3675 | Branch(done); |
| 3676 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3677 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3678 | SetCallKind(t1, call_kind); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3679 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3680 | } |
| 3681 | bind(®ular_invoke); |
| 3682 | } |
| 3683 | } |
| 3684 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3685 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3686 | void MacroAssembler::InvokeCode(Register code, |
| 3687 | const ParameterCount& expected, |
| 3688 | const ParameterCount& actual, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3689 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3690 | const CallWrapper& call_wrapper, |
| 3691 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3692 | // You can't call a function without a valid frame. |
| 3693 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3694 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3695 | Label done; |
| 3696 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3697 | bool definitely_mismatches = false; |
| 3698 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
| 3699 | &done, &definitely_mismatches, flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3700 | call_wrapper, call_kind); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3701 | if (!definitely_mismatches) { |
| 3702 | if (flag == CALL_FUNCTION) { |
| 3703 | call_wrapper.BeforeCall(CallSize(code)); |
| 3704 | SetCallKind(t1, call_kind); |
| 3705 | Call(code); |
| 3706 | call_wrapper.AfterCall(); |
| 3707 | } else { |
| 3708 | ASSERT(flag == JUMP_FUNCTION); |
| 3709 | SetCallKind(t1, call_kind); |
| 3710 | Jump(code); |
| 3711 | } |
| 3712 | // Continue here if InvokePrologue does handle the invocation due to |
| 3713 | // mismatched parameter counts. |
| 3714 | bind(&done); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3715 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | |
| 3719 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 3720 | const ParameterCount& expected, |
| 3721 | const ParameterCount& actual, |
| 3722 | RelocInfo::Mode rmode, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3723 | InvokeFlag flag, |
| 3724 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3725 | // You can't call a function without a valid frame. |
| 3726 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3727 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3728 | Label done; |
| 3729 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3730 | bool definitely_mismatches = false; |
| 3731 | InvokePrologue(expected, actual, code, no_reg, |
| 3732 | &done, &definitely_mismatches, flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3733 | NullCallWrapper(), call_kind); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3734 | if (!definitely_mismatches) { |
| 3735 | if (flag == CALL_FUNCTION) { |
| 3736 | SetCallKind(t1, call_kind); |
| 3737 | Call(code, rmode); |
| 3738 | } else { |
| 3739 | SetCallKind(t1, call_kind); |
| 3740 | Jump(code, rmode); |
| 3741 | } |
| 3742 | // Continue here if InvokePrologue does handle the invocation due to |
| 3743 | // mismatched parameter counts. |
| 3744 | bind(&done); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3745 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | |
| 3749 | void MacroAssembler::InvokeFunction(Register function, |
| 3750 | const ParameterCount& actual, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3751 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3752 | const CallWrapper& call_wrapper, |
| 3753 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3754 | // You can't call a function without a valid frame. |
| 3755 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3756 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3757 | // Contract with called JS functions requires that function is passed in a1. |
| 3758 | ASSERT(function.is(a1)); |
| 3759 | Register expected_reg = a2; |
| 3760 | Register code_reg = a3; |
| 3761 | |
| 3762 | lw(code_reg, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 3763 | lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 3764 | lw(expected_reg, |
| 3765 | FieldMemOperand(code_reg, |
| 3766 | SharedFunctionInfo::kFormalParameterCountOffset)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3767 | sra(expected_reg, expected_reg, kSmiTagSize); |
| 3768 | lw(code_reg, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3769 | |
| 3770 | ParameterCount expected(expected_reg); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3771 | InvokeCode(code_reg, expected, actual, flag, call_wrapper, call_kind); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3775 | void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3776 | const ParameterCount& expected, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3777 | const ParameterCount& actual, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3778 | InvokeFlag flag, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3779 | const CallWrapper& call_wrapper, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3780 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3781 | // You can't call a function without a valid frame. |
| 3782 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3783 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3784 | // Get the function and setup the context. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3785 | LoadHeapObject(a1, function); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3786 | lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 3787 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3788 | // We call indirectly through the code field in the function to |
| 3789 | // allow recompilation to take effect without changing any of the |
| 3790 | // call sites. |
| 3791 | lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 3792 | InvokeCode(a3, expected, actual, flag, call_wrapper, call_kind); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | |
| 3796 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 3797 | Register map, |
| 3798 | Register scratch, |
| 3799 | Label* fail) { |
| 3800 | lw(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 3801 | IsInstanceJSObjectType(map, scratch, fail); |
| 3802 | } |
| 3803 | |
| 3804 | |
| 3805 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 3806 | Register scratch, |
| 3807 | Label* fail) { |
| 3808 | lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3809 | Branch(fail, lt, scratch, Operand(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 3810 | Branch(fail, gt, scratch, Operand(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | |
| 3814 | void MacroAssembler::IsObjectJSStringType(Register object, |
| 3815 | Register scratch, |
| 3816 | Label* fail) { |
| 3817 | ASSERT(kNotStringTag != 0); |
| 3818 | |
| 3819 | lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3820 | lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 3821 | And(scratch, scratch, Operand(kIsNotStringMask)); |
| 3822 | Branch(fail, ne, scratch, Operand(zero_reg)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 3826 | void MacroAssembler::IsObjectNameType(Register object, |
| 3827 | Register scratch, |
| 3828 | Label* fail) { |
| 3829 | lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3830 | lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 3831 | Branch(fail, hi, scratch, Operand(LAST_NAME_TYPE)); |
| 3832 | } |
| 3833 | |
| 3834 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3835 | // --------------------------------------------------------------------------- |
| 3836 | // Support functions. |
| 3837 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3838 | |
| 3839 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 3840 | Register result, |
| 3841 | Register scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3842 | Label* miss, |
| 3843 | bool miss_on_bound_function) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3844 | // Check that the receiver isn't a smi. |
| 3845 | JumpIfSmi(function, miss); |
| 3846 | |
| 3847 | // Check that the function really is a function. Load map into result reg. |
| 3848 | GetObjectType(function, result, scratch); |
| 3849 | Branch(miss, ne, scratch, Operand(JS_FUNCTION_TYPE)); |
| 3850 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3851 | if (miss_on_bound_function) { |
| 3852 | lw(scratch, |
| 3853 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3854 | lw(scratch, |
| 3855 | FieldMemOperand(scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3856 | And(scratch, scratch, |
| 3857 | Operand(Smi::FromInt(1 << SharedFunctionInfo::kBoundFunction))); |
| 3858 | Branch(miss, ne, scratch, Operand(zero_reg)); |
| 3859 | } |
| 3860 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3861 | // Make sure that the function has an instance prototype. |
| 3862 | Label non_instance; |
| 3863 | lbu(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 3864 | And(scratch, scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 3865 | Branch(&non_instance, ne, scratch, Operand(zero_reg)); |
| 3866 | |
| 3867 | // Get the prototype or initial map from the function. |
| 3868 | lw(result, |
| 3869 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 3870 | |
| 3871 | // If the prototype or initial map is the hole, don't return it and |
| 3872 | // simply miss the cache instead. This will allow us to allocate a |
| 3873 | // prototype object on-demand in the runtime system. |
| 3874 | LoadRoot(t8, Heap::kTheHoleValueRootIndex); |
| 3875 | Branch(miss, eq, result, Operand(t8)); |
| 3876 | |
| 3877 | // If the function does not have an initial map, we're done. |
| 3878 | Label done; |
| 3879 | GetObjectType(result, scratch, scratch); |
| 3880 | Branch(&done, ne, scratch, Operand(MAP_TYPE)); |
| 3881 | |
| 3882 | // Get the prototype from the initial map. |
| 3883 | lw(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 3884 | jmp(&done); |
| 3885 | |
| 3886 | // Non-instance prototype: Fetch prototype from constructor field |
| 3887 | // in initial map. |
| 3888 | bind(&non_instance); |
| 3889 | lw(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 3890 | |
| 3891 | // All done. |
| 3892 | bind(&done); |
| 3893 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3894 | |
| 3895 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3896 | void MacroAssembler::GetObjectType(Register object, |
| 3897 | Register map, |
| 3898 | Register type_reg) { |
| 3899 | lw(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 3900 | lbu(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 3901 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3902 | |
| 3903 | |
| 3904 | // ----------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3905 | // Runtime calls. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3906 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 3907 | void MacroAssembler::CallStub(CodeStub* stub, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3908 | TypeFeedbackId ast_id, |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 3909 | Condition cond, |
| 3910 | Register r1, |
| 3911 | const Operand& r2, |
| 3912 | BranchDelaySlot bd) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3913 | ASSERT(AllowThisStubCall(stub)); // Stub calls are not allowed in some stubs. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3914 | Call(stub->GetCode(isolate()), RelocInfo::CODE_TARGET, ast_id, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3915 | cond, r1, r2, bd); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 3919 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3920 | ASSERT(allow_stub_calls_ || |
| 3921 | stub->CompilingCallsToThisStubIsGCSafe(isolate())); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3922 | Jump(stub->GetCode(isolate()), RelocInfo::CODE_TARGET); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3925 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3926 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 3927 | return ref0.address() - ref1.address(); |
| 3928 | } |
| 3929 | |
| 3930 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3931 | void MacroAssembler::CallApiFunctionAndReturn(ExternalReference function, |
| 3932 | int stack_space) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3933 | ExternalReference next_address = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3934 | ExternalReference::handle_scope_next_address(isolate()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3935 | const int kNextOffset = 0; |
| 3936 | const int kLimitOffset = AddressOffset( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3937 | ExternalReference::handle_scope_limit_address(isolate()), |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3938 | next_address); |
| 3939 | const int kLevelOffset = AddressOffset( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3940 | ExternalReference::handle_scope_level_address(isolate()), |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3941 | next_address); |
| 3942 | |
| 3943 | // Allocate HandleScope in callee-save registers. |
| 3944 | li(s3, Operand(next_address)); |
| 3945 | lw(s0, MemOperand(s3, kNextOffset)); |
| 3946 | lw(s1, MemOperand(s3, kLimitOffset)); |
| 3947 | lw(s2, MemOperand(s3, kLevelOffset)); |
| 3948 | Addu(s2, s2, Operand(1)); |
| 3949 | sw(s2, MemOperand(s3, kLevelOffset)); |
| 3950 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3951 | if (FLAG_log_timer_events) { |
| 3952 | FrameScope frame(this, StackFrame::MANUAL); |
| 3953 | PushSafepointRegisters(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3954 | PrepareCallCFunction(1, a0); |
| 3955 | li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 3956 | CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3957 | PopSafepointRegisters(); |
| 3958 | } |
| 3959 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3960 | // The O32 ABI requires us to pass a pointer in a0 where the returned struct |
| 3961 | // (4 bytes) will be placed. This is also built into the Simulator. |
| 3962 | // Set up the pointer to the returned value (a0). It was allocated in |
| 3963 | // EnterExitFrame. |
| 3964 | addiu(a0, fp, ExitFrameConstants::kStackSpaceOffset); |
| 3965 | |
| 3966 | // Native call returns to the DirectCEntry stub which redirects to the |
| 3967 | // return address pushed on stack (could have moved after GC). |
| 3968 | // DirectCEntry stub itself is generated early and never moves. |
| 3969 | DirectCEntryStub stub; |
| 3970 | stub.GenerateCall(this, function); |
| 3971 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3972 | if (FLAG_log_timer_events) { |
| 3973 | FrameScope frame(this, StackFrame::MANUAL); |
| 3974 | PushSafepointRegisters(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3975 | PrepareCallCFunction(1, a0); |
| 3976 | li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
| 3977 | CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 3978 | PopSafepointRegisters(); |
| 3979 | } |
| 3980 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3981 | // As mentioned above, on MIPS a pointer is returned - we need to dereference |
| 3982 | // it to get the actual return value (which is also a pointer). |
| 3983 | lw(v0, MemOperand(v0)); |
| 3984 | |
| 3985 | Label promote_scheduled_exception; |
| 3986 | Label delete_allocated_handles; |
| 3987 | Label leave_exit_frame; |
| 3988 | |
| 3989 | // If result is non-zero, dereference to get the result value |
| 3990 | // otherwise set it to undefined. |
| 3991 | Label skip; |
| 3992 | LoadRoot(a0, Heap::kUndefinedValueRootIndex); |
| 3993 | Branch(&skip, eq, v0, Operand(zero_reg)); |
| 3994 | lw(a0, MemOperand(v0)); |
| 3995 | bind(&skip); |
| 3996 | mov(v0, a0); |
| 3997 | |
| 3998 | // No more valid handles (the result handle was the last one). Restore |
| 3999 | // previous handle scope. |
| 4000 | sw(s0, MemOperand(s3, kNextOffset)); |
| 4001 | if (emit_debug_code()) { |
| 4002 | lw(a1, MemOperand(s3, kLevelOffset)); |
| 4003 | Check(eq, "Unexpected level after return from api call", a1, Operand(s2)); |
| 4004 | } |
| 4005 | Subu(s2, s2, Operand(1)); |
| 4006 | sw(s2, MemOperand(s3, kLevelOffset)); |
| 4007 | lw(at, MemOperand(s3, kLimitOffset)); |
| 4008 | Branch(&delete_allocated_handles, ne, s1, Operand(at)); |
| 4009 | |
| 4010 | // Check if the function scheduled an exception. |
| 4011 | bind(&leave_exit_frame); |
| 4012 | LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 4013 | li(at, Operand(ExternalReference::scheduled_exception_address(isolate()))); |
| 4014 | lw(t1, MemOperand(at)); |
| 4015 | Branch(&promote_scheduled_exception, ne, t0, Operand(t1)); |
| 4016 | li(s0, Operand(stack_space)); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4017 | LeaveExitFrame(false, s0, true); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4018 | |
| 4019 | bind(&promote_scheduled_exception); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4020 | TailCallExternalReference( |
| 4021 | ExternalReference(Runtime::kPromoteScheduledException, isolate()), |
| 4022 | 0, |
| 4023 | 1); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4024 | |
| 4025 | // HandleScope limit has changed. Delete allocated extensions. |
| 4026 | bind(&delete_allocated_handles); |
| 4027 | sw(s1, MemOperand(s3, kLimitOffset)); |
| 4028 | mov(s0, v0); |
| 4029 | mov(a0, v0); |
| 4030 | PrepareCallCFunction(1, s1); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4031 | li(a0, Operand(ExternalReference::isolate_address(isolate()))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4032 | CallCFunction(ExternalReference::delete_handle_scope_extensions(isolate()), |
| 4033 | 1); |
| 4034 | mov(v0, s0); |
| 4035 | jmp(&leave_exit_frame); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4038 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4039 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
| 4040 | if (!has_frame_ && stub->SometimesSetsUpAFrame()) return false; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4041 | return allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe(isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4045 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 4046 | if (num_arguments > 0) { |
| 4047 | addiu(sp, sp, num_arguments * kPointerSize); |
| 4048 | } |
| 4049 | LoadRoot(v0, Heap::kUndefinedValueRootIndex); |
| 4050 | } |
| 4051 | |
| 4052 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4053 | void MacroAssembler::IndexFromHash(Register hash, |
| 4054 | Register index) { |
| 4055 | // If the hash field contains an array index pick it out. The assert checks |
| 4056 | // that the constants for the maximum number of digits for an array index |
| 4057 | // cached in the hash field and the number of bits reserved for it does not |
| 4058 | // conflict. |
| 4059 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 4060 | (1 << String::kArrayIndexValueBits)); |
| 4061 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 4062 | // the low kHashShift bits. |
| 4063 | STATIC_ASSERT(kSmiTag == 0); |
| 4064 | Ext(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 4065 | sll(index, hash, kSmiTagSize); |
| 4066 | } |
| 4067 | |
| 4068 | |
| 4069 | void MacroAssembler::ObjectToDoubleFPURegister(Register object, |
| 4070 | FPURegister result, |
| 4071 | Register scratch1, |
| 4072 | Register scratch2, |
| 4073 | Register heap_number_map, |
| 4074 | Label* not_number, |
| 4075 | ObjectToDoubleFlags flags) { |
| 4076 | Label done; |
| 4077 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 4078 | Label not_smi; |
| 4079 | JumpIfNotSmi(object, ¬_smi); |
| 4080 | // Remove smi tag and convert to double. |
| 4081 | sra(scratch1, object, kSmiTagSize); |
| 4082 | mtc1(scratch1, result); |
| 4083 | cvt_d_w(result, result); |
| 4084 | Branch(&done); |
| 4085 | bind(¬_smi); |
| 4086 | } |
| 4087 | // Check for heap number and load double value from it. |
| 4088 | lw(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 4089 | Branch(not_number, ne, scratch1, Operand(heap_number_map)); |
| 4090 | |
| 4091 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 4092 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 4093 | Register exponent = scratch1; |
| 4094 | Register mask_reg = scratch2; |
| 4095 | lw(exponent, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 4096 | li(mask_reg, HeapNumber::kExponentMask); |
| 4097 | |
| 4098 | And(exponent, exponent, mask_reg); |
| 4099 | Branch(not_number, eq, exponent, Operand(mask_reg)); |
| 4100 | } |
| 4101 | ldc1(result, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 4102 | bind(&done); |
| 4103 | } |
| 4104 | |
| 4105 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4106 | void MacroAssembler::SmiToDoubleFPURegister(Register smi, |
| 4107 | FPURegister value, |
| 4108 | Register scratch1) { |
| 4109 | sra(scratch1, smi, kSmiTagSize); |
| 4110 | mtc1(scratch1, value); |
| 4111 | cvt_d_w(value, value); |
| 4112 | } |
| 4113 | |
| 4114 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4115 | void MacroAssembler::AdduAndCheckForOverflow(Register dst, |
| 4116 | Register left, |
| 4117 | Register right, |
| 4118 | Register overflow_dst, |
| 4119 | Register scratch) { |
| 4120 | ASSERT(!dst.is(overflow_dst)); |
| 4121 | ASSERT(!dst.is(scratch)); |
| 4122 | ASSERT(!overflow_dst.is(scratch)); |
| 4123 | ASSERT(!overflow_dst.is(left)); |
| 4124 | ASSERT(!overflow_dst.is(right)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4125 | |
| 4126 | if (left.is(right) && dst.is(left)) { |
| 4127 | ASSERT(!dst.is(t9)); |
| 4128 | ASSERT(!scratch.is(t9)); |
| 4129 | ASSERT(!left.is(t9)); |
| 4130 | ASSERT(!right.is(t9)); |
| 4131 | ASSERT(!overflow_dst.is(t9)); |
| 4132 | mov(t9, right); |
| 4133 | right = t9; |
| 4134 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4135 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4136 | if (dst.is(left)) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4137 | mov(scratch, left); // Preserve left. |
| 4138 | addu(dst, left, right); // Left is overwritten. |
| 4139 | xor_(scratch, dst, scratch); // Original left. |
| 4140 | xor_(overflow_dst, dst, right); |
| 4141 | and_(overflow_dst, overflow_dst, scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4142 | } else if (dst.is(right)) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4143 | mov(scratch, right); // Preserve right. |
| 4144 | addu(dst, left, right); // Right is overwritten. |
| 4145 | xor_(scratch, dst, scratch); // Original right. |
| 4146 | xor_(overflow_dst, dst, left); |
| 4147 | and_(overflow_dst, overflow_dst, scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4148 | } else { |
| 4149 | addu(dst, left, right); |
| 4150 | xor_(overflow_dst, dst, left); |
| 4151 | xor_(scratch, dst, right); |
| 4152 | and_(overflow_dst, scratch, overflow_dst); |
| 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | |
| 4157 | void MacroAssembler::SubuAndCheckForOverflow(Register dst, |
| 4158 | Register left, |
| 4159 | Register right, |
| 4160 | Register overflow_dst, |
| 4161 | Register scratch) { |
| 4162 | ASSERT(!dst.is(overflow_dst)); |
| 4163 | ASSERT(!dst.is(scratch)); |
| 4164 | ASSERT(!overflow_dst.is(scratch)); |
| 4165 | ASSERT(!overflow_dst.is(left)); |
| 4166 | ASSERT(!overflow_dst.is(right)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4167 | ASSERT(!scratch.is(left)); |
| 4168 | ASSERT(!scratch.is(right)); |
| 4169 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4170 | // This happens with some crankshaft code. Since Subu works fine if |
| 4171 | // left == right, let's not make that restriction here. |
| 4172 | if (left.is(right)) { |
| 4173 | mov(dst, zero_reg); |
| 4174 | mov(overflow_dst, zero_reg); |
| 4175 | return; |
| 4176 | } |
| 4177 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4178 | if (dst.is(left)) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4179 | mov(scratch, left); // Preserve left. |
| 4180 | subu(dst, left, right); // Left is overwritten. |
| 4181 | xor_(overflow_dst, dst, scratch); // scratch is original left. |
| 4182 | xor_(scratch, scratch, right); // scratch is original left. |
| 4183 | and_(overflow_dst, scratch, overflow_dst); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4184 | } else if (dst.is(right)) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4185 | mov(scratch, right); // Preserve right. |
| 4186 | subu(dst, left, right); // Right is overwritten. |
| 4187 | xor_(overflow_dst, dst, left); |
| 4188 | xor_(scratch, left, scratch); // Original right. |
| 4189 | and_(overflow_dst, scratch, overflow_dst); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4190 | } else { |
| 4191 | subu(dst, left, right); |
| 4192 | xor_(overflow_dst, dst, left); |
| 4193 | xor_(scratch, left, right); |
| 4194 | and_(overflow_dst, scratch, overflow_dst); |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4199 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 4200 | int num_arguments) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4201 | // All parameters are on the stack. v0 has the return value after call. |
| 4202 | |
| 4203 | // If the expected number of arguments of the runtime function is |
| 4204 | // constant, we check that the actual number of arguments match the |
| 4205 | // expectation. |
| 4206 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 4207 | IllegalOperation(num_arguments); |
| 4208 | return; |
| 4209 | } |
| 4210 | |
| 4211 | // TODO(1236192): Most runtime routines don't need the number of |
| 4212 | // arguments passed in because it is constant. At some point we |
| 4213 | // should remove this need and make the runtime routine entry code |
| 4214 | // smarter. |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4215 | PrepareCEntryArgs(num_arguments); |
| 4216 | PrepareCEntryFunction(ExternalReference(f, isolate())); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4217 | CEntryStub stub(1); |
| 4218 | CallStub(&stub); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4222 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
| 4223 | const Runtime::Function* function = Runtime::FunctionForId(id); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4224 | PrepareCEntryArgs(function->nargs); |
| 4225 | PrepareCEntryFunction(ExternalReference(function, isolate())); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4226 | CEntryStub stub(1, kSaveFPRegs); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4227 | CallStub(&stub); |
| 4228 | } |
| 4229 | |
| 4230 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4231 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4232 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4236 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4237 | int num_arguments, |
| 4238 | BranchDelaySlot bd) { |
| 4239 | PrepareCEntryArgs(num_arguments); |
| 4240 | PrepareCEntryFunction(ext); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4241 | |
| 4242 | CEntryStub stub(1); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4243 | CallStub(&stub, TypeFeedbackId::None(), al, zero_reg, Operand(zero_reg), bd); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4247 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 4248 | int num_arguments, |
| 4249 | int result_size) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4250 | // TODO(1236192): Most runtime routines don't need the number of |
| 4251 | // arguments passed in because it is constant. At some point we |
| 4252 | // should remove this need and make the runtime routine entry code |
| 4253 | // smarter. |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4254 | PrepareCEntryArgs(num_arguments); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4255 | JumpToExternalReference(ext); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4258 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4259 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 4260 | int num_arguments, |
| 4261 | int result_size) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4262 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 4263 | num_arguments, |
| 4264 | result_size); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4268 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin, |
| 4269 | BranchDelaySlot bd) { |
| 4270 | PrepareCEntryFunction(builtin); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4271 | CEntryStub stub(1); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4272 | Jump(stub.GetCode(isolate()), |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4273 | RelocInfo::CODE_TARGET, |
| 4274 | al, |
| 4275 | zero_reg, |
| 4276 | Operand(zero_reg), |
| 4277 | bd); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | |
| 4281 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4282 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4283 | const CallWrapper& call_wrapper) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4284 | // You can't call a builtin without a valid frame. |
| 4285 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 4286 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4287 | GetBuiltinEntry(t9, id); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4288 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4289 | call_wrapper.BeforeCall(CallSize(t9)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4290 | SetCallKind(t1, CALL_AS_METHOD); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4291 | Call(t9); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4292 | call_wrapper.AfterCall(); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4293 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4294 | ASSERT(flag == JUMP_FUNCTION); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4295 | SetCallKind(t1, CALL_AS_METHOD); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4296 | Jump(t9); |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | |
| 4301 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 4302 | Builtins::JavaScript id) { |
| 4303 | // Load the builtins object into target register. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4304 | lw(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4305 | lw(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
| 4306 | // Load the JavaScript builtin function from the builtins object. |
| 4307 | lw(target, FieldMemOperand(target, |
| 4308 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4313 | ASSERT(!target.is(a1)); |
| 4314 | GetBuiltinFunction(a1, id); |
| 4315 | // Load the code entry point from the builtins object. |
| 4316 | lw(target, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | |
| 4320 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 4321 | Register scratch1, Register scratch2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4322 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 4323 | li(scratch1, Operand(value)); |
| 4324 | li(scratch2, Operand(ExternalReference(counter))); |
| 4325 | sw(scratch1, MemOperand(scratch2)); |
| 4326 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | |
| 4330 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 4331 | Register scratch1, Register scratch2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4332 | ASSERT(value > 0); |
| 4333 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 4334 | li(scratch2, Operand(ExternalReference(counter))); |
| 4335 | lw(scratch1, MemOperand(scratch2)); |
| 4336 | Addu(scratch1, scratch1, Operand(value)); |
| 4337 | sw(scratch1, MemOperand(scratch2)); |
| 4338 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | |
| 4342 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 4343 | Register scratch1, Register scratch2) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4344 | ASSERT(value > 0); |
| 4345 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 4346 | li(scratch2, Operand(ExternalReference(counter))); |
| 4347 | lw(scratch1, MemOperand(scratch2)); |
| 4348 | Subu(scratch1, scratch1, Operand(value)); |
| 4349 | sw(scratch1, MemOperand(scratch2)); |
| 4350 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4354 | // ----------------------------------------------------------------------------- |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4355 | // Debugging. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4356 | |
| 4357 | void MacroAssembler::Assert(Condition cc, const char* msg, |
| 4358 | Register rs, Operand rt) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4359 | if (emit_debug_code()) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4360 | Check(cc, msg, rs, rt); |
| 4361 | } |
| 4362 | |
| 4363 | |
| 4364 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 4365 | Heap::RootListIndex index) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4366 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4367 | LoadRoot(at, index); |
| 4368 | Check(eq, "Register did not match expected root", reg, Operand(at)); |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | |
| 4373 | void MacroAssembler::AssertFastElements(Register elements) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4374 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4375 | ASSERT(!elements.is(at)); |
| 4376 | Label ok; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4377 | push(elements); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4378 | lw(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 4379 | LoadRoot(at, Heap::kFixedArrayMapRootIndex); |
| 4380 | Branch(&ok, eq, elements, Operand(at)); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4381 | LoadRoot(at, Heap::kFixedDoubleArrayMapRootIndex); |
| 4382 | Branch(&ok, eq, elements, Operand(at)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4383 | LoadRoot(at, Heap::kFixedCOWArrayMapRootIndex); |
| 4384 | Branch(&ok, eq, elements, Operand(at)); |
| 4385 | Abort("JSObject with fast elements map has slow elements"); |
| 4386 | bind(&ok); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4387 | pop(elements); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4388 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | |
| 4392 | void MacroAssembler::Check(Condition cc, const char* msg, |
| 4393 | Register rs, Operand rt) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4394 | Label L; |
| 4395 | Branch(&L, cc, rs, rt); |
| 4396 | Abort(msg); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4397 | // Will not return here. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4398 | bind(&L); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | |
| 4402 | void MacroAssembler::Abort(const char* msg) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4403 | Label abort_start; |
| 4404 | bind(&abort_start); |
| 4405 | // We want to pass the msg string like a smi to avoid GC |
| 4406 | // problems, however msg is not guaranteed to be aligned |
| 4407 | // properly. Instead, we pass an aligned pointer that is |
| 4408 | // a proper v8 smi, but also pass the alignment difference |
| 4409 | // from the real pointer as a smi. |
| 4410 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 4411 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 4412 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 4413 | #ifdef DEBUG |
| 4414 | if (msg != NULL) { |
| 4415 | RecordComment("Abort message: "); |
| 4416 | RecordComment(msg); |
| 4417 | } |
| 4418 | #endif |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4419 | |
| 4420 | li(a0, Operand(p0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4421 | push(a0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4422 | li(a0, Operand(Smi::FromInt(p1 - p0))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4423 | push(a0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4424 | // Disable stub call restrictions to always allow calls to abort. |
| 4425 | if (!has_frame_) { |
| 4426 | // We don't actually want to generate a pile of code for this, so just |
| 4427 | // claim there is a stack frame, without generating one. |
| 4428 | FrameScope scope(this, StackFrame::NONE); |
| 4429 | CallRuntime(Runtime::kAbort, 2); |
| 4430 | } else { |
| 4431 | CallRuntime(Runtime::kAbort, 2); |
| 4432 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4433 | // Will not return here. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4434 | if (is_trampoline_pool_blocked()) { |
| 4435 | // If the calling code cares about the exact number of |
| 4436 | // instructions generated, we insert padding here to keep the size |
| 4437 | // of the Abort macro constant. |
| 4438 | // Currently in debug mode with debug_code enabled the number of |
| 4439 | // generated instructions is 14, so we use this as a maximum value. |
| 4440 | static const int kExpectedAbortInstructions = 14; |
| 4441 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 4442 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 4443 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 4444 | nop(); |
| 4445 | } |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | |
| 4450 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 4451 | if (context_chain_length > 0) { |
| 4452 | // Move up the chain of contexts to the context containing the slot. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4453 | lw(dst, MemOperand(cp, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4454 | for (int i = 1; i < context_chain_length; i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4455 | lw(dst, MemOperand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4456 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4457 | } else { |
| 4458 | // Slot is in the current function context. Move it into the |
| 4459 | // destination register in case we store into it (the write barrier |
| 4460 | // cannot be allowed to destroy the context in esi). |
| 4461 | Move(dst, cp); |
| 4462 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4466 | void MacroAssembler::LoadTransitionedArrayMapConditional( |
| 4467 | ElementsKind expected_kind, |
| 4468 | ElementsKind transitioned_kind, |
| 4469 | Register map_in_out, |
| 4470 | Register scratch, |
| 4471 | Label* no_map_match) { |
| 4472 | // Load the global or builtins object from the current context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4473 | lw(scratch, |
| 4474 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 4475 | lw(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4476 | |
| 4477 | // Check that the function's map is the same as the expected cached map. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4478 | lw(scratch, |
| 4479 | MemOperand(scratch, |
| 4480 | Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX))); |
| 4481 | size_t offset = expected_kind * kPointerSize + |
| 4482 | FixedArrayBase::kHeaderSize; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 4483 | lw(at, FieldMemOperand(scratch, offset)); |
| 4484 | Branch(no_map_match, ne, map_in_out, Operand(at)); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4485 | |
| 4486 | // Use the transitioned cached map. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4487 | offset = transitioned_kind * kPointerSize + |
| 4488 | FixedArrayBase::kHeaderSize; |
| 4489 | lw(map_in_out, FieldMemOperand(scratch, offset)); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | |
| 4493 | void MacroAssembler::LoadInitialArrayMap( |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4494 | Register function_in, Register scratch, |
| 4495 | Register map_out, bool can_have_holes) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4496 | ASSERT(!function_in.is(map_out)); |
| 4497 | Label done; |
| 4498 | lw(map_out, FieldMemOperand(function_in, |
| 4499 | JSFunction::kPrototypeOrInitialMapOffset)); |
| 4500 | if (!FLAG_smi_only_arrays) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4501 | ElementsKind kind = can_have_holes ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS; |
| 4502 | LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
| 4503 | kind, |
| 4504 | map_out, |
| 4505 | scratch, |
| 4506 | &done); |
| 4507 | } else if (can_have_holes) { |
| 4508 | LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, |
| 4509 | FAST_HOLEY_SMI_ELEMENTS, |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4510 | map_out, |
| 4511 | scratch, |
| 4512 | &done); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4513 | } |
| 4514 | bind(&done); |
| 4515 | } |
| 4516 | |
| 4517 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4518 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 4519 | // Load the global or builtins object from the current context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4520 | lw(function, |
| 4521 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 4522 | // Load the native context from the global or builtins object. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4523 | lw(function, FieldMemOperand(function, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4524 | GlobalObject::kNativeContextOffset)); |
| 4525 | // Load the function from the native context. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4526 | lw(function, MemOperand(function, Context::SlotOffset(index))); |
| 4527 | } |
| 4528 | |
| 4529 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4530 | void MacroAssembler::LoadArrayFunction(Register function) { |
| 4531 | // Load the global or builtins object from the current context. |
| 4532 | lw(function, |
| 4533 | MemOperand(cp, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 4534 | // Load the global context from the global or builtins object. |
| 4535 | lw(function, |
| 4536 | FieldMemOperand(function, GlobalObject::kGlobalContextOffset)); |
| 4537 | // Load the array function from the native context. |
| 4538 | lw(function, |
| 4539 | MemOperand(function, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4540 | } |
| 4541 | |
| 4542 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4543 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 4544 | Register map, |
| 4545 | Register scratch) { |
| 4546 | // Load the initial map. The global functions all have initial maps. |
| 4547 | lw(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4548 | if (emit_debug_code()) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4549 | Label ok, fail; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4550 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, DO_SMI_CHECK); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4551 | Branch(&ok); |
| 4552 | bind(&fail); |
| 4553 | Abort("Global functions must have initial map"); |
| 4554 | bind(&ok); |
| 4555 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4558 | |
| 4559 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 4560 | addiu(sp, sp, -5 * kPointerSize); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4561 | li(t8, Operand(Smi::FromInt(type))); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4562 | li(t9, Operand(CodeObject()), CONSTANT_SIZE); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4563 | sw(ra, MemOperand(sp, 4 * kPointerSize)); |
| 4564 | sw(fp, MemOperand(sp, 3 * kPointerSize)); |
| 4565 | sw(cp, MemOperand(sp, 2 * kPointerSize)); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4566 | sw(t8, MemOperand(sp, 1 * kPointerSize)); |
| 4567 | sw(t9, MemOperand(sp, 0 * kPointerSize)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4568 | addiu(fp, sp, 3 * kPointerSize); |
| 4569 | } |
| 4570 | |
| 4571 | |
| 4572 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
| 4573 | mov(sp, fp); |
| 4574 | lw(fp, MemOperand(sp, 0 * kPointerSize)); |
| 4575 | lw(ra, MemOperand(sp, 1 * kPointerSize)); |
| 4576 | addiu(sp, sp, 2 * kPointerSize); |
| 4577 | } |
| 4578 | |
| 4579 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4580 | void MacroAssembler::EnterExitFrame(bool save_doubles, |
| 4581 | int stack_space) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4582 | // Set up the frame structure on the stack. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4583 | STATIC_ASSERT(2 * kPointerSize == ExitFrameConstants::kCallerSPDisplacement); |
| 4584 | STATIC_ASSERT(1 * kPointerSize == ExitFrameConstants::kCallerPCOffset); |
| 4585 | STATIC_ASSERT(0 * kPointerSize == ExitFrameConstants::kCallerFPOffset); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4586 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4587 | // This is how the stack will look: |
| 4588 | // fp + 2 (==kCallerSPDisplacement) - old stack's end |
| 4589 | // [fp + 1 (==kCallerPCOffset)] - saved old ra |
| 4590 | // [fp + 0 (==kCallerFPOffset)] - saved old fp |
| 4591 | // [fp - 1 (==kSPOffset)] - sp of the called function |
| 4592 | // [fp - 2 (==kCodeOffset)] - CodeObject |
| 4593 | // fp - (2 + stack_space + alignment) == sp == [fp - kSPOffset] - top of the |
| 4594 | // new stack (will contain saved ra) |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4595 | |
| 4596 | // Save registers. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4597 | addiu(sp, sp, -4 * kPointerSize); |
| 4598 | sw(ra, MemOperand(sp, 3 * kPointerSize)); |
| 4599 | sw(fp, MemOperand(sp, 2 * kPointerSize)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4600 | addiu(fp, sp, 2 * kPointerSize); // Set up new frame pointer. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4601 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4602 | if (emit_debug_code()) { |
| 4603 | sw(zero_reg, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 4604 | } |
| 4605 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4606 | // Accessed from ExitFrame::code_slot. |
| 4607 | li(t8, Operand(CodeObject()), CONSTANT_SIZE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4608 | sw(t8, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4609 | |
| 4610 | // Save the frame pointer and the context in top. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4611 | li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4612 | sw(fp, MemOperand(t8)); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4613 | li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4614 | sw(cp, MemOperand(t8)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4615 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4616 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 4617 | if (save_doubles) { |
| 4618 | // The stack must be allign to 0 modulo 8 for stores with sdc1. |
| 4619 | ASSERT(kDoubleSize == frame_alignment); |
| 4620 | if (frame_alignment > 0) { |
| 4621 | ASSERT(IsPowerOf2(frame_alignment)); |
| 4622 | And(sp, sp, Operand(-frame_alignment)); // Align stack. |
| 4623 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4624 | int space = FPURegister::kMaxNumRegisters * kDoubleSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4625 | Subu(sp, sp, Operand(space)); |
| 4626 | // Remember: we only need to save every 2nd double FPU value. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4627 | for (int i = 0; i < FPURegister::kMaxNumRegisters; i+=2) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4628 | FPURegister reg = FPURegister::from_code(i); |
| 4629 | sdc1(reg, MemOperand(sp, i * kDoubleSize)); |
| 4630 | } |
| 4631 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4632 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4633 | // Reserve place for the return address, stack space and an optional slot |
| 4634 | // (used by the DirectCEntryStub to hold the return value if a struct is |
| 4635 | // returned) and align the frame preparing for calling the runtime function. |
| 4636 | ASSERT(stack_space >= 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4637 | Subu(sp, sp, Operand((stack_space + 2) * kPointerSize)); |
| 4638 | if (frame_alignment > 0) { |
| 4639 | ASSERT(IsPowerOf2(frame_alignment)); |
| 4640 | And(sp, sp, Operand(-frame_alignment)); // Align stack. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4641 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4642 | |
| 4643 | // Set the exit frame sp value to point just before the return address |
| 4644 | // location. |
| 4645 | addiu(at, sp, kPointerSize); |
| 4646 | sw(at, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4650 | void MacroAssembler::LeaveExitFrame(bool save_doubles, |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4651 | Register argument_count, |
| 4652 | bool do_return) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4653 | // Optionally restore all double registers. |
| 4654 | if (save_doubles) { |
| 4655 | // Remember: we only need to restore every 2nd double FPU value. |
| 4656 | lw(t8, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4657 | for (int i = 0; i < FPURegister::kMaxNumRegisters; i+=2) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4658 | FPURegister reg = FPURegister::from_code(i); |
| 4659 | ldc1(reg, MemOperand(t8, i * kDoubleSize + kPointerSize)); |
| 4660 | } |
| 4661 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4662 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4663 | // Clear top frame. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4664 | li(t8, Operand(ExternalReference(Isolate::kCEntryFPAddress, isolate()))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4665 | sw(zero_reg, MemOperand(t8)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4666 | |
| 4667 | // Restore current context from top and clear it in debug mode. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4668 | li(t8, Operand(ExternalReference(Isolate::kContextAddress, isolate()))); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4669 | lw(cp, MemOperand(t8)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4670 | #ifdef DEBUG |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4671 | sw(a3, MemOperand(t8)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4672 | #endif |
| 4673 | |
| 4674 | // Pop the arguments, restore registers, and return. |
| 4675 | mov(sp, fp); // Respect ABI stack constraint. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4676 | lw(fp, MemOperand(sp, ExitFrameConstants::kCallerFPOffset)); |
| 4677 | lw(ra, MemOperand(sp, ExitFrameConstants::kCallerPCOffset)); |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4678 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4679 | if (argument_count.is_valid()) { |
| 4680 | sll(t8, argument_count, kPointerSizeLog2); |
| 4681 | addu(sp, sp, t8); |
| 4682 | } |
ulan@chromium.org | 6ff6514 | 2012-03-21 09:52:17 +0000 | [diff] [blame] | 4683 | |
| 4684 | if (do_return) { |
| 4685 | Ret(USE_DELAY_SLOT); |
| 4686 | // If returning, the instruction in the delay slot will be the addiu below. |
| 4687 | } |
| 4688 | addiu(sp, sp, 8); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4692 | void MacroAssembler::InitializeNewString(Register string, |
| 4693 | Register length, |
| 4694 | Heap::RootListIndex map_index, |
| 4695 | Register scratch1, |
| 4696 | Register scratch2) { |
| 4697 | sll(scratch1, length, kSmiTagSize); |
| 4698 | LoadRoot(scratch2, map_index); |
| 4699 | sw(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 4700 | li(scratch1, Operand(String::kEmptyHashField)); |
| 4701 | sw(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 4702 | sw(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 4703 | } |
| 4704 | |
| 4705 | |
| 4706 | int MacroAssembler::ActivationFrameAlignment() { |
| 4707 | #if defined(V8_HOST_ARCH_MIPS) |
| 4708 | // Running on the real platform. Use the alignment as mandated by the local |
| 4709 | // environment. |
| 4710 | // Note: This will break if we ever start generating snapshots on one Mips |
| 4711 | // platform for another Mips platform with a different alignment. |
| 4712 | return OS::ActivationFrameAlignment(); |
| 4713 | #else // defined(V8_HOST_ARCH_MIPS) |
| 4714 | // If we are using the simulator then we should always align to the expected |
| 4715 | // alignment. As the simulator is used to generate snapshots we do not know |
| 4716 | // if the target platform will need alignment, so this is controlled from a |
| 4717 | // flag. |
| 4718 | return FLAG_sim_stack_alignment; |
| 4719 | #endif // defined(V8_HOST_ARCH_MIPS) |
| 4720 | } |
| 4721 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4722 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4723 | void MacroAssembler::AssertStackIsAligned() { |
| 4724 | if (emit_debug_code()) { |
| 4725 | const int frame_alignment = ActivationFrameAlignment(); |
| 4726 | const int frame_alignment_mask = frame_alignment - 1; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4727 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4728 | if (frame_alignment > kPointerSize) { |
| 4729 | Label alignment_as_expected; |
| 4730 | ASSERT(IsPowerOf2(frame_alignment)); |
| 4731 | andi(at, sp, frame_alignment_mask); |
| 4732 | Branch(&alignment_as_expected, eq, at, Operand(zero_reg)); |
| 4733 | // Don't use Check here, as it will call Runtime_Abort re-entering here. |
| 4734 | stop("Unexpected stack alignment"); |
| 4735 | bind(&alignment_as_expected); |
| 4736 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4737 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4740 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4741 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 4742 | Register reg, |
| 4743 | Register scratch, |
| 4744 | Label* not_power_of_two_or_zero) { |
| 4745 | Subu(scratch, reg, Operand(1)); |
| 4746 | Branch(USE_DELAY_SLOT, not_power_of_two_or_zero, lt, |
| 4747 | scratch, Operand(zero_reg)); |
| 4748 | and_(at, scratch, reg); // In the delay slot. |
| 4749 | Branch(not_power_of_two_or_zero, ne, at, Operand(zero_reg)); |
| 4750 | } |
| 4751 | |
| 4752 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4753 | void MacroAssembler::SmiTagCheckOverflow(Register reg, Register overflow) { |
| 4754 | ASSERT(!reg.is(overflow)); |
| 4755 | mov(overflow, reg); // Save original value. |
| 4756 | SmiTag(reg); |
| 4757 | xor_(overflow, overflow, reg); // Overflow if (value ^ 2 * value) < 0. |
| 4758 | } |
| 4759 | |
| 4760 | |
| 4761 | void MacroAssembler::SmiTagCheckOverflow(Register dst, |
| 4762 | Register src, |
| 4763 | Register overflow) { |
| 4764 | if (dst.is(src)) { |
| 4765 | // Fall back to slower case. |
| 4766 | SmiTagCheckOverflow(dst, overflow); |
| 4767 | } else { |
| 4768 | ASSERT(!dst.is(src)); |
| 4769 | ASSERT(!dst.is(overflow)); |
| 4770 | ASSERT(!src.is(overflow)); |
| 4771 | SmiTag(dst, src); |
| 4772 | xor_(overflow, dst, src); // Overflow if (value ^ 2 * value) < 0. |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | |
| 4777 | void MacroAssembler::UntagAndJumpIfSmi(Register dst, |
| 4778 | Register src, |
| 4779 | Label* smi_case) { |
| 4780 | JumpIfSmi(src, smi_case, at, USE_DELAY_SLOT); |
| 4781 | SmiUntag(dst, src); |
| 4782 | } |
| 4783 | |
| 4784 | |
| 4785 | void MacroAssembler::UntagAndJumpIfNotSmi(Register dst, |
| 4786 | Register src, |
| 4787 | Label* non_smi_case) { |
| 4788 | JumpIfNotSmi(src, non_smi_case, at, USE_DELAY_SLOT); |
| 4789 | SmiUntag(dst, src); |
| 4790 | } |
| 4791 | |
| 4792 | void MacroAssembler::JumpIfSmi(Register value, |
| 4793 | Label* smi_label, |
| 4794 | Register scratch, |
| 4795 | BranchDelaySlot bd) { |
| 4796 | ASSERT_EQ(0, kSmiTag); |
| 4797 | andi(scratch, value, kSmiTagMask); |
| 4798 | Branch(bd, smi_label, eq, scratch, Operand(zero_reg)); |
| 4799 | } |
| 4800 | |
| 4801 | void MacroAssembler::JumpIfNotSmi(Register value, |
| 4802 | Label* not_smi_label, |
| 4803 | Register scratch, |
| 4804 | BranchDelaySlot bd) { |
| 4805 | ASSERT_EQ(0, kSmiTag); |
| 4806 | andi(scratch, value, kSmiTagMask); |
| 4807 | Branch(bd, not_smi_label, ne, scratch, Operand(zero_reg)); |
| 4808 | } |
| 4809 | |
| 4810 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4811 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 4812 | Register reg2, |
| 4813 | Label* on_not_both_smi) { |
| 4814 | STATIC_ASSERT(kSmiTag == 0); |
| 4815 | ASSERT_EQ(1, kSmiTagMask); |
| 4816 | or_(at, reg1, reg2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4817 | JumpIfNotSmi(at, on_not_both_smi); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | |
| 4821 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 4822 | Register reg2, |
| 4823 | Label* on_either_smi) { |
| 4824 | STATIC_ASSERT(kSmiTag == 0); |
| 4825 | ASSERT_EQ(1, kSmiTagMask); |
| 4826 | // Both Smi tags must be 1 (not Smi). |
| 4827 | and_(at, reg1, reg2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4828 | JumpIfSmi(at, on_either_smi); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
| 4831 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4832 | void MacroAssembler::AssertNotSmi(Register object) { |
| 4833 | if (emit_debug_code()) { |
| 4834 | STATIC_ASSERT(kSmiTag == 0); |
| 4835 | andi(at, object, kSmiTagMask); |
| 4836 | Check(ne, "Operand is a smi", at, Operand(zero_reg)); |
| 4837 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4841 | void MacroAssembler::AssertSmi(Register object) { |
| 4842 | if (emit_debug_code()) { |
| 4843 | STATIC_ASSERT(kSmiTag == 0); |
| 4844 | andi(at, object, kSmiTagMask); |
| 4845 | Check(eq, "Operand is a smi", at, Operand(zero_reg)); |
| 4846 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4850 | void MacroAssembler::AssertString(Register object) { |
| 4851 | if (emit_debug_code()) { |
| 4852 | STATIC_ASSERT(kSmiTag == 0); |
| 4853 | And(t0, object, Operand(kSmiTagMask)); |
| 4854 | Check(ne, "Operand is a smi and not a string", t0, Operand(zero_reg)); |
| 4855 | push(object); |
| 4856 | lw(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 4857 | lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset)); |
| 4858 | Check(lo, "Operand is not a string", object, Operand(FIRST_NONSTRING_TYPE)); |
| 4859 | pop(object); |
| 4860 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 4864 | void MacroAssembler::AssertName(Register object) { |
| 4865 | if (emit_debug_code()) { |
| 4866 | STATIC_ASSERT(kSmiTag == 0); |
| 4867 | And(t0, object, Operand(kSmiTagMask)); |
| 4868 | Check(ne, "Operand is a smi and not a name", t0, Operand(zero_reg)); |
| 4869 | push(object); |
| 4870 | lw(object, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 4871 | lbu(object, FieldMemOperand(object, Map::kInstanceTypeOffset)); |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 4872 | Check(le, "Operand is not a name", object, Operand(LAST_NAME_TYPE)); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4873 | pop(object); |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 4878 | void MacroAssembler::AssertRootValue(Register src, |
| 4879 | Heap::RootListIndex root_value_index, |
| 4880 | const char* message) { |
| 4881 | if (emit_debug_code()) { |
| 4882 | ASSERT(!src.is(at)); |
| 4883 | LoadRoot(at, root_value_index); |
| 4884 | Check(eq, message, src, Operand(at)); |
| 4885 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | |
| 4889 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 4890 | Register heap_number_map, |
| 4891 | Register scratch, |
| 4892 | Label* on_not_heap_number) { |
| 4893 | lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 4894 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4895 | Branch(on_not_heap_number, ne, scratch, Operand(heap_number_map)); |
| 4896 | } |
| 4897 | |
| 4898 | |
| 4899 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 4900 | Register first, |
| 4901 | Register second, |
| 4902 | Register scratch1, |
| 4903 | Register scratch2, |
| 4904 | Label* failure) { |
| 4905 | // Test that both first and second are sequential ASCII strings. |
| 4906 | // Assume that they are non-smis. |
| 4907 | lw(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 4908 | lw(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 4909 | lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 4910 | lbu(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
| 4911 | |
| 4912 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 4913 | scratch2, |
| 4914 | scratch1, |
| 4915 | scratch2, |
| 4916 | failure); |
| 4917 | } |
| 4918 | |
| 4919 | |
| 4920 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 4921 | Register second, |
| 4922 | Register scratch1, |
| 4923 | Register scratch2, |
| 4924 | Label* failure) { |
| 4925 | // Check that neither is a smi. |
| 4926 | STATIC_ASSERT(kSmiTag == 0); |
| 4927 | And(scratch1, first, Operand(second)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4928 | JumpIfSmi(scratch1, failure); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4929 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 4930 | second, |
| 4931 | scratch1, |
| 4932 | scratch2, |
| 4933 | failure); |
| 4934 | } |
| 4935 | |
| 4936 | |
| 4937 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 4938 | Register first, |
| 4939 | Register second, |
| 4940 | Register scratch1, |
| 4941 | Register scratch2, |
| 4942 | Label* failure) { |
| 4943 | int kFlatAsciiStringMask = |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4944 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4945 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 4946 | ASSERT(kFlatAsciiStringTag <= 0xffff); // Ensure this fits 16-bit immed. |
| 4947 | andi(scratch1, first, kFlatAsciiStringMask); |
| 4948 | Branch(failure, ne, scratch1, Operand(kFlatAsciiStringTag)); |
| 4949 | andi(scratch2, second, kFlatAsciiStringMask); |
| 4950 | Branch(failure, ne, scratch2, Operand(kFlatAsciiStringTag)); |
| 4951 | } |
| 4952 | |
| 4953 | |
| 4954 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 4955 | Register scratch, |
| 4956 | Label* failure) { |
| 4957 | int kFlatAsciiStringMask = |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4958 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4959 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 4960 | And(scratch, type, Operand(kFlatAsciiStringMask)); |
| 4961 | Branch(failure, ne, scratch, Operand(kFlatAsciiStringTag)); |
| 4962 | } |
| 4963 | |
| 4964 | |
| 4965 | static const int kRegisterPassedArguments = 4; |
| 4966 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4967 | int MacroAssembler::CalculateStackPassedWords(int num_reg_arguments, |
| 4968 | int num_double_arguments) { |
| 4969 | int stack_passed_words = 0; |
| 4970 | num_reg_arguments += 2 * num_double_arguments; |
| 4971 | |
| 4972 | // Up to four simple arguments are passed in registers a0..a3. |
| 4973 | if (num_reg_arguments > kRegisterPassedArguments) { |
| 4974 | stack_passed_words += num_reg_arguments - kRegisterPassedArguments; |
| 4975 | } |
| 4976 | stack_passed_words += kCArgSlotCount; |
| 4977 | return stack_passed_words; |
| 4978 | } |
| 4979 | |
| 4980 | |
| 4981 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 4982 | int num_double_arguments, |
| 4983 | Register scratch) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4984 | int frame_alignment = ActivationFrameAlignment(); |
| 4985 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4986 | // Up to four simple arguments are passed in registers a0..a3. |
| 4987 | // Those four arguments must have reserved argument slots on the stack for |
| 4988 | // mips, even though those argument slots are not normally used. |
| 4989 | // Remaining arguments are pushed on the stack, above (higher address than) |
| 4990 | // the argument slots. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4991 | int stack_passed_arguments = CalculateStackPassedWords( |
| 4992 | num_reg_arguments, num_double_arguments); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 4993 | if (frame_alignment > kPointerSize) { |
| 4994 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 4995 | // and the original value of sp. |
| 4996 | mov(scratch, sp); |
| 4997 | Subu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
| 4998 | ASSERT(IsPowerOf2(frame_alignment)); |
| 4999 | And(sp, sp, Operand(-frame_alignment)); |
| 5000 | sw(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 5001 | } else { |
| 5002 | Subu(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 5003 | } |
| 5004 | } |
| 5005 | |
| 5006 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5007 | void MacroAssembler::PrepareCallCFunction(int num_reg_arguments, |
| 5008 | Register scratch) { |
| 5009 | PrepareCallCFunction(num_reg_arguments, 0, scratch); |
| 5010 | } |
| 5011 | |
| 5012 | |
| 5013 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 5014 | int num_reg_arguments, |
| 5015 | int num_double_arguments) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5016 | li(t8, Operand(function)); |
| 5017 | CallCFunctionHelper(t8, num_reg_arguments, num_double_arguments); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | |
| 5021 | void MacroAssembler::CallCFunction(Register function, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5022 | int num_reg_arguments, |
| 5023 | int num_double_arguments) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5024 | CallCFunctionHelper(function, num_reg_arguments, num_double_arguments); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5028 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 5029 | int num_arguments) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5030 | CallCFunction(function, num_arguments, 0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | |
| 5034 | void MacroAssembler::CallCFunction(Register function, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5035 | int num_arguments) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5036 | CallCFunction(function, num_arguments, 0); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | |
| 5040 | void MacroAssembler::CallCFunctionHelper(Register function, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5041 | int num_reg_arguments, |
| 5042 | int num_double_arguments) { |
| 5043 | ASSERT(has_frame()); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5044 | // Make sure that the stack is aligned before calling a C function unless |
| 5045 | // running in the simulator. The simulator has its own alignment check which |
| 5046 | // provides more information. |
| 5047 | // The argument stots are presumed to have been set up by |
| 5048 | // PrepareCallCFunction. The C function must be called via t9, for mips ABI. |
| 5049 | |
| 5050 | #if defined(V8_HOST_ARCH_MIPS) |
| 5051 | if (emit_debug_code()) { |
| 5052 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 5053 | int frame_alignment_mask = frame_alignment - 1; |
| 5054 | if (frame_alignment > kPointerSize) { |
| 5055 | ASSERT(IsPowerOf2(frame_alignment)); |
| 5056 | Label alignment_as_expected; |
| 5057 | And(at, sp, Operand(frame_alignment_mask)); |
| 5058 | Branch(&alignment_as_expected, eq, at, Operand(zero_reg)); |
| 5059 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 5060 | // re-entering here. |
| 5061 | stop("Unexpected alignment in CallCFunction"); |
| 5062 | bind(&alignment_as_expected); |
| 5063 | } |
| 5064 | } |
| 5065 | #endif // V8_HOST_ARCH_MIPS |
| 5066 | |
| 5067 | // Just call directly. The function called cannot cause a GC, or |
| 5068 | // allow preemption, so the return address in the link register |
| 5069 | // stays correct. |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5070 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5071 | if (!function.is(t9)) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5072 | mov(t9, function); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5073 | function = t9; |
| 5074 | } |
| 5075 | |
| 5076 | Call(function); |
| 5077 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5078 | int stack_passed_arguments = CalculateStackPassedWords( |
| 5079 | num_reg_arguments, num_double_arguments); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5080 | |
| 5081 | if (OS::ActivationFrameAlignment() > kPointerSize) { |
| 5082 | lw(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 5083 | } else { |
| 5084 | Addu(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | |
| 5089 | #undef BRANCH_ARGS_CHECK |
| 5090 | |
| 5091 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5092 | void MacroAssembler::PatchRelocatedValue(Register li_location, |
| 5093 | Register scratch, |
| 5094 | Register new_value) { |
| 5095 | lw(scratch, MemOperand(li_location)); |
| 5096 | // At this point scratch is a lui(at, ...) instruction. |
| 5097 | if (emit_debug_code()) { |
| 5098 | And(scratch, scratch, kOpcodeMask); |
| 5099 | Check(eq, "The instruction to patch should be a lui.", |
| 5100 | scratch, Operand(LUI)); |
| 5101 | lw(scratch, MemOperand(li_location)); |
| 5102 | } |
| 5103 | srl(t9, new_value, kImm16Bits); |
| 5104 | Ins(scratch, t9, 0, kImm16Bits); |
| 5105 | sw(scratch, MemOperand(li_location)); |
| 5106 | |
| 5107 | lw(scratch, MemOperand(li_location, kInstrSize)); |
| 5108 | // scratch is now ori(at, ...). |
| 5109 | if (emit_debug_code()) { |
| 5110 | And(scratch, scratch, kOpcodeMask); |
| 5111 | Check(eq, "The instruction to patch should be an ori.", |
| 5112 | scratch, Operand(ORI)); |
| 5113 | lw(scratch, MemOperand(li_location, kInstrSize)); |
| 5114 | } |
| 5115 | Ins(scratch, new_value, 0, kImm16Bits); |
| 5116 | sw(scratch, MemOperand(li_location, kInstrSize)); |
| 5117 | |
| 5118 | // Update the I-cache so the new lui and ori can be executed. |
| 5119 | FlushICache(li_location, 2); |
| 5120 | } |
| 5121 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 5122 | void MacroAssembler::GetRelocatedValue(Register li_location, |
| 5123 | Register value, |
| 5124 | Register scratch) { |
| 5125 | lw(value, MemOperand(li_location)); |
| 5126 | if (emit_debug_code()) { |
| 5127 | And(value, value, kOpcodeMask); |
| 5128 | Check(eq, "The instruction should be a lui.", |
| 5129 | value, Operand(LUI)); |
| 5130 | lw(value, MemOperand(li_location)); |
| 5131 | } |
| 5132 | |
| 5133 | // value now holds a lui instruction. Extract the immediate. |
| 5134 | sll(value, value, kImm16Bits); |
| 5135 | |
| 5136 | lw(scratch, MemOperand(li_location, kInstrSize)); |
| 5137 | if (emit_debug_code()) { |
| 5138 | And(scratch, scratch, kOpcodeMask); |
| 5139 | Check(eq, "The instruction should be an ori.", |
| 5140 | scratch, Operand(ORI)); |
| 5141 | lw(scratch, MemOperand(li_location, kInstrSize)); |
| 5142 | } |
| 5143 | // "scratch" now holds an ori instruction. Extract the immediate. |
| 5144 | andi(scratch, scratch, kImm16Mask); |
| 5145 | |
| 5146 | // Merge the results. |
| 5147 | or_(value, value, scratch); |
| 5148 | } |
| 5149 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5150 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5151 | void MacroAssembler::CheckPageFlag( |
| 5152 | Register object, |
| 5153 | Register scratch, |
| 5154 | int mask, |
| 5155 | Condition cc, |
| 5156 | Label* condition_met) { |
| 5157 | And(scratch, object, Operand(~Page::kPageAlignmentMask)); |
| 5158 | lw(scratch, MemOperand(scratch, MemoryChunk::kFlagsOffset)); |
| 5159 | And(scratch, scratch, Operand(mask)); |
| 5160 | Branch(condition_met, cc, scratch, Operand(zero_reg)); |
| 5161 | } |
| 5162 | |
| 5163 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5164 | void MacroAssembler::CheckMapDeprecated(Handle<Map> map, |
| 5165 | Register scratch, |
| 5166 | Label* if_deprecated) { |
| 5167 | if (map->CanBeDeprecated()) { |
| 5168 | li(scratch, Operand(map)); |
| 5169 | lw(scratch, FieldMemOperand(scratch, Map::kBitField3Offset)); |
| 5170 | And(scratch, scratch, Operand(Smi::FromInt(Map::Deprecated::kMask))); |
| 5171 | Branch(if_deprecated, ne, scratch, Operand(zero_reg)); |
| 5172 | } |
| 5173 | } |
| 5174 | |
| 5175 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5176 | void MacroAssembler::JumpIfBlack(Register object, |
| 5177 | Register scratch0, |
| 5178 | Register scratch1, |
| 5179 | Label* on_black) { |
| 5180 | HasColor(object, scratch0, scratch1, on_black, 1, 0); // kBlackBitPattern. |
| 5181 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 5182 | } |
| 5183 | |
| 5184 | |
| 5185 | void MacroAssembler::HasColor(Register object, |
| 5186 | Register bitmap_scratch, |
| 5187 | Register mask_scratch, |
| 5188 | Label* has_color, |
| 5189 | int first_bit, |
| 5190 | int second_bit) { |
| 5191 | ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, t8)); |
| 5192 | ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, t9)); |
| 5193 | |
| 5194 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 5195 | |
| 5196 | Label other_color, word_boundary; |
| 5197 | lw(t9, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 5198 | And(t8, t9, Operand(mask_scratch)); |
| 5199 | Branch(&other_color, first_bit == 1 ? eq : ne, t8, Operand(zero_reg)); |
| 5200 | // Shift left 1 by adding. |
| 5201 | Addu(mask_scratch, mask_scratch, Operand(mask_scratch)); |
| 5202 | Branch(&word_boundary, eq, mask_scratch, Operand(zero_reg)); |
| 5203 | And(t8, t9, Operand(mask_scratch)); |
| 5204 | Branch(has_color, second_bit == 1 ? ne : eq, t8, Operand(zero_reg)); |
| 5205 | jmp(&other_color); |
| 5206 | |
| 5207 | bind(&word_boundary); |
| 5208 | lw(t9, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize)); |
| 5209 | And(t9, t9, Operand(1)); |
| 5210 | Branch(has_color, second_bit == 1 ? ne : eq, t9, Operand(zero_reg)); |
| 5211 | bind(&other_color); |
| 5212 | } |
| 5213 | |
| 5214 | |
| 5215 | // Detect some, but not all, common pointer-free objects. This is used by the |
| 5216 | // incremental write barrier which doesn't care about oddballs (they are always |
| 5217 | // marked black immediately so this code is not hit). |
| 5218 | void MacroAssembler::JumpIfDataObject(Register value, |
| 5219 | Register scratch, |
| 5220 | Label* not_data_object) { |
| 5221 | ASSERT(!AreAliased(value, scratch, t8, no_reg)); |
| 5222 | Label is_data_object; |
| 5223 | lw(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 5224 | LoadRoot(t8, Heap::kHeapNumberMapRootIndex); |
| 5225 | Branch(&is_data_object, eq, t8, Operand(scratch)); |
| 5226 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 5227 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 5228 | // If it's a string and it's not a cons string then it's an object containing |
| 5229 | // no GC pointers. |
| 5230 | lbu(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 5231 | And(t8, scratch, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 5232 | Branch(not_data_object, ne, t8, Operand(zero_reg)); |
| 5233 | bind(&is_data_object); |
| 5234 | } |
| 5235 | |
| 5236 | |
| 5237 | void MacroAssembler::GetMarkBits(Register addr_reg, |
| 5238 | Register bitmap_reg, |
| 5239 | Register mask_reg) { |
| 5240 | ASSERT(!AreAliased(addr_reg, bitmap_reg, mask_reg, no_reg)); |
| 5241 | And(bitmap_reg, addr_reg, Operand(~Page::kPageAlignmentMask)); |
| 5242 | Ext(mask_reg, addr_reg, kPointerSizeLog2, Bitmap::kBitsPerCellLog2); |
| 5243 | const int kLowBits = kPointerSizeLog2 + Bitmap::kBitsPerCellLog2; |
| 5244 | Ext(t8, addr_reg, kLowBits, kPageSizeBits - kLowBits); |
| 5245 | sll(t8, t8, kPointerSizeLog2); |
| 5246 | Addu(bitmap_reg, bitmap_reg, t8); |
| 5247 | li(t8, Operand(1)); |
| 5248 | sllv(mask_reg, t8, mask_reg); |
| 5249 | } |
| 5250 | |
| 5251 | |
| 5252 | void MacroAssembler::EnsureNotWhite( |
| 5253 | Register value, |
| 5254 | Register bitmap_scratch, |
| 5255 | Register mask_scratch, |
| 5256 | Register load_scratch, |
| 5257 | Label* value_is_white_and_not_data) { |
| 5258 | ASSERT(!AreAliased(value, bitmap_scratch, mask_scratch, t8)); |
| 5259 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 5260 | |
| 5261 | // If the value is black or grey we don't need to do anything. |
| 5262 | ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 5263 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 5264 | ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 5265 | ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 5266 | |
| 5267 | Label done; |
| 5268 | |
| 5269 | // Since both black and grey have a 1 in the first position and white does |
| 5270 | // not have a 1 there we only need to check one bit. |
| 5271 | lw(load_scratch, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 5272 | And(t8, mask_scratch, load_scratch); |
| 5273 | Branch(&done, ne, t8, Operand(zero_reg)); |
| 5274 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5275 | if (emit_debug_code()) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5276 | // Check for impossible bit pattern. |
| 5277 | Label ok; |
| 5278 | // sll may overflow, making the check conservative. |
| 5279 | sll(t8, mask_scratch, 1); |
| 5280 | And(t8, load_scratch, t8); |
| 5281 | Branch(&ok, eq, t8, Operand(zero_reg)); |
| 5282 | stop("Impossible marking bit pattern"); |
| 5283 | bind(&ok); |
| 5284 | } |
| 5285 | |
| 5286 | // Value is white. We check whether it is data that doesn't need scanning. |
| 5287 | // Currently only checks for HeapNumber and non-cons strings. |
| 5288 | Register map = load_scratch; // Holds map while checking type. |
| 5289 | Register length = load_scratch; // Holds length of object after testing type. |
| 5290 | Label is_data_object; |
| 5291 | |
| 5292 | // Check for heap-number |
| 5293 | lw(map, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 5294 | LoadRoot(t8, Heap::kHeapNumberMapRootIndex); |
| 5295 | { |
| 5296 | Label skip; |
| 5297 | Branch(&skip, ne, t8, Operand(map)); |
| 5298 | li(length, HeapNumber::kSize); |
| 5299 | Branch(&is_data_object); |
| 5300 | bind(&skip); |
| 5301 | } |
| 5302 | |
| 5303 | // Check for strings. |
| 5304 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 5305 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 5306 | // If it's a string and it's not a cons string then it's an object containing |
| 5307 | // no GC pointers. |
| 5308 | Register instance_type = load_scratch; |
| 5309 | lbu(instance_type, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 5310 | And(t8, instance_type, Operand(kIsIndirectStringMask | kIsNotStringMask)); |
| 5311 | Branch(value_is_white_and_not_data, ne, t8, Operand(zero_reg)); |
| 5312 | // It's a non-indirect (non-cons and non-slice) string. |
| 5313 | // If it's external, the length is just ExternalString::kSize. |
| 5314 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 5315 | // External strings are the only ones with the kExternalStringTag bit |
| 5316 | // set. |
| 5317 | ASSERT_EQ(0, kSeqStringTag & kExternalStringTag); |
| 5318 | ASSERT_EQ(0, kConsStringTag & kExternalStringTag); |
| 5319 | And(t8, instance_type, Operand(kExternalStringTag)); |
| 5320 | { |
| 5321 | Label skip; |
| 5322 | Branch(&skip, eq, t8, Operand(zero_reg)); |
| 5323 | li(length, ExternalString::kSize); |
| 5324 | Branch(&is_data_object); |
| 5325 | bind(&skip); |
| 5326 | } |
| 5327 | |
| 5328 | // Sequential string, either ASCII or UC16. |
| 5329 | // For ASCII (char-size of 1) we shift the smi tag away to get the length. |
| 5330 | // For UC16 (char-size of 2) we just leave the smi tag in place, thereby |
| 5331 | // getting the length multiplied by 2. |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5332 | ASSERT(kOneByteStringTag == 4 && kStringEncodingMask == 4); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5333 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 5334 | lw(t9, FieldMemOperand(value, String::kLengthOffset)); |
| 5335 | And(t8, instance_type, Operand(kStringEncodingMask)); |
| 5336 | { |
| 5337 | Label skip; |
| 5338 | Branch(&skip, eq, t8, Operand(zero_reg)); |
| 5339 | srl(t9, t9, 1); |
| 5340 | bind(&skip); |
| 5341 | } |
| 5342 | Addu(length, t9, Operand(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 5343 | And(length, length, Operand(~kObjectAlignmentMask)); |
| 5344 | |
| 5345 | bind(&is_data_object); |
| 5346 | // Value is a data object, and it is white. Mark it black. Since we know |
| 5347 | // that the object is white we can make it black by flipping one bit. |
| 5348 | lw(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 5349 | Or(t8, t8, Operand(mask_scratch)); |
| 5350 | sw(t8, MemOperand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 5351 | |
| 5352 | And(bitmap_scratch, bitmap_scratch, Operand(~Page::kPageAlignmentMask)); |
| 5353 | lw(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 5354 | Addu(t8, t8, Operand(length)); |
| 5355 | sw(t8, MemOperand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 5356 | |
| 5357 | bind(&done); |
| 5358 | } |
| 5359 | |
| 5360 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5361 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5362 | Register descriptors) { |
| 5363 | lw(descriptors, FieldMemOperand(map, Map::kDescriptorsOffset)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5367 | void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) { |
| 5368 | lw(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
| 5369 | DecodeField<Map::NumberOfOwnDescriptorsBits>(dst); |
| 5370 | } |
| 5371 | |
| 5372 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5373 | void MacroAssembler::EnumLength(Register dst, Register map) { |
| 5374 | STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); |
| 5375 | lw(dst, FieldMemOperand(map, Map::kBitField3Offset)); |
| 5376 | And(dst, dst, Operand(Smi::FromInt(Map::EnumLengthBits::kMask))); |
| 5377 | } |
| 5378 | |
| 5379 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5380 | void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5381 | Register empty_fixed_array_value = t2; |
| 5382 | LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5383 | Label next, start; |
| 5384 | mov(a2, a0); |
| 5385 | |
| 5386 | // Check if the enum length field is properly initialized, indicating that |
| 5387 | // there is an enum cache. |
| 5388 | lw(a1, FieldMemOperand(a2, HeapObject::kMapOffset)); |
| 5389 | |
| 5390 | EnumLength(a3, a1); |
| 5391 | Branch(call_runtime, eq, a3, Operand(Smi::FromInt(Map::kInvalidEnumCache))); |
| 5392 | |
| 5393 | jmp(&start); |
| 5394 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5395 | bind(&next); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5396 | lw(a1, FieldMemOperand(a2, HeapObject::kMapOffset)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5397 | |
| 5398 | // For all objects but the receiver, check that the cache is empty. |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5399 | EnumLength(a3, a1); |
| 5400 | Branch(call_runtime, ne, a3, Operand(Smi::FromInt(0))); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5401 | |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 5402 | bind(&start); |
| 5403 | |
| 5404 | // Check that there are no elements. Register r2 contains the current JS |
| 5405 | // object we've reached through the prototype chain. |
| 5406 | lw(a2, FieldMemOperand(a2, JSObject::kElementsOffset)); |
| 5407 | Branch(call_runtime, ne, a2, Operand(empty_fixed_array_value)); |
| 5408 | |
| 5409 | lw(a2, FieldMemOperand(a1, Map::kPrototypeOffset)); |
| 5410 | Branch(&next, ne, a2, Operand(null_value)); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5414 | void MacroAssembler::ClampUint8(Register output_reg, Register input_reg) { |
| 5415 | ASSERT(!output_reg.is(input_reg)); |
| 5416 | Label done; |
| 5417 | li(output_reg, Operand(255)); |
| 5418 | // Normal branch: nop in delay slot. |
| 5419 | Branch(&done, gt, input_reg, Operand(output_reg)); |
| 5420 | // Use delay slot in this branch. |
| 5421 | Branch(USE_DELAY_SLOT, &done, lt, input_reg, Operand(zero_reg)); |
| 5422 | mov(output_reg, zero_reg); // In delay slot. |
| 5423 | mov(output_reg, input_reg); // Value is in range 0..255. |
| 5424 | bind(&done); |
| 5425 | } |
| 5426 | |
| 5427 | |
| 5428 | void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
| 5429 | DoubleRegister input_reg, |
| 5430 | DoubleRegister temp_double_reg) { |
| 5431 | Label above_zero; |
| 5432 | Label done; |
| 5433 | Label in_bounds; |
| 5434 | |
| 5435 | Move(temp_double_reg, 0.0); |
| 5436 | BranchF(&above_zero, NULL, gt, input_reg, temp_double_reg); |
| 5437 | |
| 5438 | // Double value is less than zero, NaN or Inf, return 0. |
| 5439 | mov(result_reg, zero_reg); |
| 5440 | Branch(&done); |
| 5441 | |
| 5442 | // Double value is >= 255, return 255. |
| 5443 | bind(&above_zero); |
| 5444 | Move(temp_double_reg, 255.0); |
| 5445 | BranchF(&in_bounds, NULL, le, input_reg, temp_double_reg); |
| 5446 | li(result_reg, Operand(255)); |
| 5447 | Branch(&done); |
| 5448 | |
| 5449 | // In 0-255 range, round and truncate. |
| 5450 | bind(&in_bounds); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5451 | cvt_w_d(temp_double_reg, input_reg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5452 | mfc1(result_reg, temp_double_reg); |
| 5453 | bind(&done); |
| 5454 | } |
| 5455 | |
| 5456 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5457 | void MacroAssembler::TestJSArrayForAllocationSiteInfo( |
| 5458 | Register receiver_reg, |
| 5459 | Register scratch_reg, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5460 | Condition cond, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5461 | Label* allocation_info_present) { |
| 5462 | Label no_info_available; |
| 5463 | ExternalReference new_space_start = |
| 5464 | ExternalReference::new_space_start(isolate()); |
| 5465 | ExternalReference new_space_allocation_top = |
| 5466 | ExternalReference::new_space_allocation_top_address(isolate()); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 5467 | Addu(scratch_reg, receiver_reg, |
| 5468 | Operand(JSArray::kSize + AllocationSiteInfo::kSize - kHeapObjectTag)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5469 | Branch(&no_info_available, lt, scratch_reg, Operand(new_space_start)); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 5470 | li(at, Operand(new_space_allocation_top)); |
| 5471 | lw(at, MemOperand(at)); |
| 5472 | Branch(&no_info_available, gt, scratch_reg, Operand(at)); |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 5473 | lw(scratch_reg, MemOperand(scratch_reg, -AllocationSiteInfo::kSize)); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5474 | Branch(allocation_info_present, cond, scratch_reg, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5475 | Operand(Handle<Map>(isolate()->heap()->allocation_site_info_map()))); |
| 5476 | bind(&no_info_available); |
| 5477 | } |
| 5478 | |
| 5479 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5480 | bool AreAliased(Register r1, Register r2, Register r3, Register r4) { |
| 5481 | if (r1.is(r2)) return true; |
| 5482 | if (r1.is(r3)) return true; |
| 5483 | if (r1.is(r4)) return true; |
| 5484 | if (r2.is(r3)) return true; |
| 5485 | if (r2.is(r4)) return true; |
| 5486 | if (r3.is(r4)) return true; |
| 5487 | return false; |
| 5488 | } |
| 5489 | |
| 5490 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5491 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 5492 | : address_(address), |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5493 | size_(instructions * Assembler::kInstrSize), |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 5494 | masm_(NULL, address, size_ + Assembler::kGap) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5495 | // Create a new macro assembler pointing to the address of the code to patch. |
| 5496 | // The size is adjusted with kGap on order for the assembler to generate size |
| 5497 | // bytes of instructions without failing with buffer size constraints. |
| 5498 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 5499 | } |
| 5500 | |
| 5501 | |
| 5502 | CodePatcher::~CodePatcher() { |
| 5503 | // Indicate that code has changed. |
| 5504 | CPU::FlushICache(address_, size_); |
| 5505 | |
| 5506 | // Check that the code was patched as expected. |
| 5507 | ASSERT(masm_.pc_ == address_ + size_); |
| 5508 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 5509 | } |
| 5510 | |
| 5511 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5512 | void CodePatcher::Emit(Instr instr) { |
| 5513 | masm()->emit(instr); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | |
| 5517 | void CodePatcher::Emit(Address addr) { |
| 5518 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 5519 | } |
| 5520 | |
| 5521 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5522 | void CodePatcher::ChangeBranchCondition(Condition cond) { |
| 5523 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 5524 | ASSERT(Assembler::IsBranch(instr)); |
| 5525 | uint32_t opcode = Assembler::GetOpcodeField(instr); |
| 5526 | // Currently only the 'eq' and 'ne' cond values are supported and the simple |
| 5527 | // branch instructions (with opcode being the branch type). |
| 5528 | // There are some special cases (see Assembler::IsBranch()) so extending this |
| 5529 | // would be tricky. |
| 5530 | ASSERT(opcode == BEQ || |
| 5531 | opcode == BNE || |
| 5532 | opcode == BLEZ || |
| 5533 | opcode == BGTZ || |
| 5534 | opcode == BEQL || |
| 5535 | opcode == BNEL || |
| 5536 | opcode == BLEZL || |
| 5537 | opcode == BGTZL); |
| 5538 | opcode = (cond == eq) ? BEQ : BNE; |
| 5539 | instr = (instr & ~kOpcodeMask) | opcode; |
| 5540 | masm_.emit(instr); |
| 5541 | } |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 5542 | |
| 5543 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5544 | } } // namespace v8::internal |
| 5545 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5546 | #endif // V8_TARGET_ARCH_MIPS |